diff --git a/src/libstore/db.cc b/src/libstore/db.cc index 9324a36ae..f935f0846 100644 --- a/src/libstore/db.cc +++ b/src/libstore/db.cc @@ -466,7 +466,7 @@ void Database::splitStatePathRevision(const Path & revisionedStatePath, Path & s int Database::getNewRevisionNumber(const Transaction & txn, TableId table, - const Path & statePath, bool update) + const Path & statePath) { //query string data; @@ -482,10 +482,8 @@ int Database::getNewRevisionNumber(const Transaction & txn, TableId table, if(!succeed) throw Error(format("Malformed revision counter value of path '%1%'") % statePath); - if(update){ - revision++; - setString(txn, table, statePath, int2String(revision)); - } + revision++; + setString(txn, table, statePath, int2String(revision)); return revision; } @@ -591,10 +589,10 @@ bool Database::queryStateReferrers(const Transaction & txn, TableId table, void Database::setStateRevisions(const Transaction & txn, TableId table, - const Path & statePath, const RevisionNumbersSet & revisions, int root_revision) + const Path & statePath, const RevisionNumbersSet & revisions) { - if(root_revision == -1) - root_revision = getNewRevisionNumber(txn, table, statePath); + //get a new revision number + int root_revision = getNewRevisionNumber(txn, table, statePath); //Sort based on statePath to RevisionNumbersClosure RevisionNumbers sorted_revisions; @@ -624,38 +622,46 @@ void Database::setStateRevisions(const Transaction & txn, TableId table, setStrings(txn, table, key, data); } -bool Database::queryStateRevisions(const Transaction & txn, TableId table, - const Path & statePath, RevisionNumbers & revisions, int revision) +bool Database::queryStateRevisions(const Transaction & txn, TableId table, const PathSet statePath_deps, + const Path & statePath, RevisionNumbersSet & revisions, int root_revision) { Strings keys; enumTable(txn, table, keys); //get all revisions string key; - if(revision == -1){ + if(root_revision == -1){ bool foundsomething = lookupHighestRevivison(keys, statePath, key); if(!foundsomething) return false; } else - key = makeStatePathRevision(statePath, revision); + key = makeStatePathRevision(statePath, root_revision); Strings data; - bool succeed = queryStrings(txn, table, key, data); //now that we have the key, we can query the references + bool notempty = queryStrings(txn, table, key, data); //now that we have the key, we can query the revisions - //Convert the Strings into int's - for (Strings::iterator i = data.begin(); i != data.end(); ++i){ - string getRevisionS = *i; + //sort all state references recursively + vector sortedStatePaths; + for (PathSet::iterator i = statePath_deps.begin(); i != statePath_deps.end(); ++i) + sortedStatePaths.push_back(*i); + sort(sortedStatePaths.begin(), sortedStatePaths.end()); + + //Convert the Strings into int's and match them to the sorted statePaths + for (vector::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i){ + string getRevisionS = data.front(); + data.pop_front(); + int getRevision; bool succeed = string2Int(getRevisionS, getRevision); if(!succeed) throw Error(format("Cannot read revision number from db of path '%1%'") % statePath); - revisions.push_back(getRevision); + revisions[*i] = getRevision; } - if(!succeed) - throw Error(format("Revision '%1%' not found of statePath '%2%'") % int2String(revision) % statePath); + if(!notempty) + throw Error(format("Root revision '%1%' not found of statePath '%2%'") % int2String(root_revision) % statePath); - return succeed; + return notempty; } //TODO include comments into revisions? diff --git a/src/libstore/db.hh b/src/libstore/db.hh index c267e3018..6f9f08b5e 100644 --- a/src/libstore/db.hh +++ b/src/libstore/db.hh @@ -63,6 +63,9 @@ private: /* TODO */ bool lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, int lowerthan = -1); + /* TODO */ + int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath); + public: Database(); ~Database(); @@ -113,18 +116,17 @@ public: /* Set the revision number of the statePath and the revision numbers of all state paths in the references closure */ void setStateRevisions(const Transaction & txn, TableId table, - const Path & statePath, const RevisionNumbersSet & revisions, int revision = -1); + const Path & statePath, const RevisionNumbersSet & revisions); /* Returns all the revision numbers of the state references closure of the given state path */ - bool queryStateRevisions(const Transaction & txn, TableId table, - const Path & statePath, RevisionNumbers & revisions, int revision = -1); + bool queryStateRevisions(const Transaction & txn, TableId table, const PathSet statePath_deps, + const Path & statePath, RevisionNumbersSet & revisions, int root_revision = -1); /* Returns all available revision numbers of the given state path */ bool queryAvailableStateRevisions(const Transaction & txn, TableId table, const Path & statePath, RevisionNumbers & revisions); - /* TODO */ - int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath, bool update = true); + }; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index b82043426..048761851 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1694,12 +1694,6 @@ void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath) */ -//TODO REMOVE -void LocalStore::scanAndUpdateAllReferences(const Path & storeOrStatePath, const int revision, bool recursive) -{ - //nix::scanAndUpdateAllReferencesTxn(noTxn, storeOrStatePath, revision, recursive); -} - void queryAllValidPaths(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths) { Paths allComponentPaths2; @@ -1717,22 +1711,24 @@ void queryAllValidPaths(const Transaction & txn, PathSet & allComponentPaths, Pa } -void setStateRevisionsTxn(const Transaction & txn, const Path & statePath, const RevisionNumbersSet & revisions, const int revision) +void setStateRevisionsTxn(const Transaction & txn, const Path & statePath, const RevisionNumbersSet & revisions) { - nixDB.setStateRevisions(txn, dbStateRevisions, statePath, revisions, revision); + nixDB.setStateRevisions(txn, dbStateRevisions, statePath, revisions); } -void LocalStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) +void LocalStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions) { - nix::setStateRevisionsTxn(noTxn, statePath, revisions, revision); + nix::setStateRevisionsTxn(noTxn, statePath, revisions); } -bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionNumbers & revisions, const int revision) +bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionNumbersSet & revisions, const int revision) { - return nixDB.queryStateRevisions(txn, dbStateRevisions, statePath, revisions, revision); + PathSet statePaths; + storePathRequisites(statePath, false, statePaths, false, true, revision); //Get all current state dependencies + return nixDB.queryStateRevisions(txn, dbStateRevisions, statePaths, statePath, revisions, revision); } -bool LocalStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision) +bool LocalStore::queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision) { return nix::queryStateRevisionsTxn(noTxn, statePath, revisions, revision); } @@ -1747,15 +1743,6 @@ bool LocalStore::queryAvailableStateRevisions(const Path & statePath, RevisionNu return nix::queryAvailableStateRevisionsTxn(noTxn, statePath, revisions); } -int getNewRevisionNumberTxn(const Transaction & txn, const Path & statePath, const bool update) -{ - return nixDB.getNewRevisionNumber(txn, dbStateRevisions, statePath, update); -} - -int LocalStore::getNewRevisionNumber(const Path & statePath, bool update) -{ - return nix::getNewRevisionNumberTxn(noTxn, statePath, update); -} diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index e28457d87..09af5c70e 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -100,16 +100,12 @@ public: void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); - void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive); + void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions); - void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision); - - bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision); + bool queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision); bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions); - int getNewRevisionNumber(const Path & statePath, bool update = true); - }; @@ -223,7 +219,7 @@ bool isStateDrvPathTxn(const Transaction & txn, const Path & drvPath); bool isStateDrvTxn(const Transaction & txn, const Derivation & drv); -//TODO +//TODO can this ????? void queryAllValidPaths(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths); bool isValidStatePathTxn(const Transaction & txn, const Path & path); void queryReferencesTxn(const Transaction & txn, const Path & path, PathSet & references, const int revision); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 5d310ac0f..88fbfbbeb 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -469,19 +469,13 @@ void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool } //TODO -void RemoteStore::scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive) +void RemoteStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions) { } //TODO -void RemoteStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) -{ - -} - -//TODO -bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision) +bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision) { return false; } @@ -492,10 +486,5 @@ bool RemoteStore::queryAvailableStateRevisions(const Path & statePath, RevisionN return false; } -//TODO -int RemoteStore::getNewRevisionNumber(const Path & statePath, bool update) -{ - return 0; -} } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index e49903ec6..beea481b1 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -88,15 +88,11 @@ public: void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); - void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive); + void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions); - void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision); - - bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision); + bool queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision); bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions); - - int getNewRevisionNumber(const Path & statePath, bool update = true); private: AutoCloseFD fdSocket; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index b09e6b905..0c9dbe50d 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -220,19 +220,13 @@ public: virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) = 0; /* TODO */ - virtual void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive) = 0; + virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions) = 0; /* TODO */ - virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) = 0; - - /* TODO */ - virtual bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision) = 0; + virtual bool queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision) = 0; /* TODO */ virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0; - - /* TODO */ - virtual int getNewRevisionNumber(const Path & statePath, bool update = true) = 0; }; diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index 7630f9395..e2bd68b03 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -271,25 +271,26 @@ static void revertToRevision(Strings opFlags, Strings opArgs) statePaths.insert(derivationPath); //Insert direct state path //Get the revisions recursively to also roll them back - RevisionNumbers getRivisions; + RevisionNumbersSet getRivisions; bool b = store->queryStateRevisions(statePath, getRivisions, revision_arg); //Sort the statePaths from all drvs - map state_repos; - vector sorted_paths; - for (PathSet::iterator d = statePaths.begin(); d != statePaths.end(); ++d){ - string repos = getStateReposPath("stateOutput:staterepospath", *d); //this is a copy from store-state.cc - state_repos[statePath] = repos; - sorted_paths.push_back(statePath); - } - sort(sorted_paths.begin(), sorted_paths.end()); + //map state_repos; + //vector sorted_paths; + //for (PathSet::iterator d = statePaths.begin(); d != statePaths.end(); ++d){ + + //state_repos[statePath] = repos; +// sorted_paths.push_back(statePath); + //} + //sort(sorted_paths.begin(), sorted_paths.end()); + + //string repos = //Revert each statePath in the list - for (vector::iterator i = sorted_paths.begin(); i != sorted_paths.end(); ++i){ - Path statePath = *i; - string repos = state_repos[statePath]; - int revision = getRivisions.front(); - getRivisions.pop_front(); + for (RevisionNumbersSet::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){ + Path statePath = (*i).first; + int revision = (*i).second; + string repos = getStateReposPath("stateOutput:staterepospath", statePath); //this is a copy from store-state.cc printMsg(lvlError, format("Reverting statePath '%1%' to revision: %2%") % statePath % int2String(revision)); Strings p_args; @@ -399,7 +400,7 @@ void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path //We dont need to sort since the db does that //call scanForAllReferences again on all statePaths - for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i){ + for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i){ int revision = readRevisionNumber(*i); //Scan, update, call recursively @@ -416,9 +417,6 @@ void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path void updateRevisionsRecursively(Path statePath) { - // - int newRevisionNumber = store->getNewRevisionNumber(statePath); - //Save all revisions for the call to RevisionNumbersSet rivisionMapping; @@ -439,7 +437,7 @@ void updateRevisionsRecursively(Path statePath) rivisionMapping[*i] = readRevisionNumber(*i); //Store the revision numbers in the database for this statePath with revision number - store->setStateRevisions(statePath, rivisionMapping, newRevisionNumber); //TODO !!!!!!!!!!!!!!!!!! merge getNewRevisionNumber back into Database::setStateRevisions + store->setStateRevisions(statePath, rivisionMapping); } @@ -597,10 +595,10 @@ static void opRunComponent(Strings opFlags, Strings opArgs) //Commit transaction TODO //Debugging - RevisionNumbers getRivisions; + RevisionNumbersSet getRivisions; bool b = store->queryStateRevisions(root_statePath, getRivisions, -1); - for (RevisionNumbers::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){ - printMsg(lvlError, format("REV %1%") % int2String(*i)); + for (RevisionNumbersSet::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){ + printMsg(lvlError, format("State %1% has revision %2%") % (*i).first % int2String((*i).second)); }