From 2e7539bd273b3fcc9fd8a4a38ea28308db5d939c Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Mon, 27 Aug 2007 18:54:05 +0000 Subject: [PATCH] Added state marshall functions in RemoteStore.cc (still unfinished in Nix-worker.cc) --- src/libstore/build.cc | 6 +- src/libstore/local-store.cc | 57 ++------ src/libstore/local-store.hh | 24 ++-- src/libstore/remote-store.cc | 245 ++++++++++++++++++-------------- src/libstore/remote-store.hh | 14 +- src/libstore/store-api.hh | 24 ++-- src/libstore/store-state.cc | 6 +- src/libstore/store-state.hh | 2 +- src/libstore/worker-protocol.hh | 12 ++ src/libutil/serialise.cc | 125 ++++++++++++++++ src/libutil/serialise.hh | 11 ++ src/libutil/types.hh | 2 +- src/libutil/util.cc | 8 +- src/nix-env/nix-env.cc | 2 +- src/nix-state/nix-state.cc | 4 +- src/nix-store/dotgraph.cc | 8 +- src/nix-store/nix-store.cc | 8 +- src/nix-worker/nix-worker.cc | 89 +++++++++--- 18 files changed, 423 insertions(+), 224 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 2b01ea129..ff1281630 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1308,7 +1308,7 @@ bool DerivationGoal::prepareBuild() } /* The state output is a referenceable path */ - if(store->isStateDrv(drv)) + if(isStateDrv(drv)) allStatePaths.insert(drv.stateOutputs.find("state")->second.statepath); /* Determine the full set of input paths. */ @@ -1754,7 +1754,7 @@ void DerivationGoal::computeClosure() * If state is enabled for the path we: * [scan for and state references and component references in the state path] //3,4 */ - if(isStateDrvTxn(noTxn, drv)){ //TODO + if(isStateDrv(drv)){ //TODO Path sharedState = drv.stateOutputs.find("state")->second.sharedState; if(sharedState != ""){ @@ -1799,7 +1799,7 @@ void DerivationGoal::computeClosure() } //Register the state path valid - if(isStateDrvTxn(txn, drv)) + if(isStateDrv(drv)) { Path statePath = drv.stateOutputs.find("state")->second.statepath; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index e0532ce2f..ae6727f24 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -140,7 +140,7 @@ static TableId dbStateRevisions = 0; */ static TableId dbStateRevisionsComments = 0; -/* dbStateSnapshots :: StatePath -> RevisionNumbers +/* dbStateSnapshots :: StatePath -> IntVector * * This table stores the snapshot numbers the sub state files/folders * at a certain timestamp. These snapshot numbers are just timestamps @@ -541,20 +541,6 @@ void LocalStore::queryStateReferences(const Path & componentOrstatePath, PathSet nix::queryXReferencesTxn(noTxn, componentOrstatePath, stateReferences, revision, false); } -void queryAllReferencesTxn(const Transaction & txn, const Path & path, PathSet & allReferences, const int revision) -{ - PathSet references; - PathSet stateReferences; - queryXReferencesTxn(txn, path, references, true, revision); - queryXReferencesTxn(txn, path, stateReferences, false, revision); - allReferences = pathSets_union(references, stateReferences); -} - -void LocalStore::queryAllReferences(const Path & path, PathSet & allReferences, const int revision) -{ - queryAllReferencesTxn(noTxn, path, allReferences, revision); -} - static PathSet getXReferrers(const Transaction & txn, const Path & store_or_statePath, const bool component_or_state, const int revision) { TableId table = 0; @@ -788,25 +774,12 @@ bool LocalStore::isStateComponent(const Path & storePath) bool isStateDrvPathTxn(const Transaction & txn, const Path & drvPath) { Derivation drv = derivationFromPathTxn(txn, drvPath); - return isStateDrvTxn(txn, drv); + return isStateDrv(drv); } -bool LocalStore::isStateDrvPath(const Path & isStateDrv) +bool isStateDrv(const Derivation & drv) { - return nix::isStateDrvPathTxn(noTxn, isStateDrv); -} - -bool isStateDrvTxn(const Transaction & txn, const Derivation & drv) -{ - if (drv.stateOutputs.size() != 0) - return true; - else - return false; -} - -bool LocalStore::isStateDrv(const Derivation & drv) -{ - return nix::isStateDrvTxn(noTxn, drv); + return (drv.stateOutputs.size() != 0); } static Path queryDeriver(const Transaction & txn, const Path & storePath) @@ -818,7 +791,7 @@ static Path queryDeriver(const Transaction & txn, const Path & storePath) bool b = nixDB.queryString(txn, dbDerivers, storePath, deriver); Derivation drv = derivationFromPathTxn(txn, deriver); - if (isStateDrvTxn(txn, drv)) + if (isStateDrv(drv)) throw Error(format("This deriver `%1%' is a state deriver, u should use queryDerivers instead of queryDeriver") % deriver); if (b) @@ -1573,7 +1546,7 @@ void verifyStore(bool checkContents) txn.commit(); } -void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths, const vector & intervals, bool allZero) +void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths, const IntVector & intervals, bool allZero) { if(!allZero && statePaths.size() != intervals.size()){ throw Error("the number of statepaths and intervals must be equal"); @@ -1587,25 +1560,25 @@ void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePath int interval=0; if(!allZero) interval = intervals.at(n); - + nixDB.setString(txn, dbStateCounters, *i, int2String(interval)); n++; } } -void LocalStore::setStatePathsInterval(const PathSet & statePaths, const vector & intervals, bool allZero) +void LocalStore::setStatePathsInterval(const PathSet & statePaths, const IntVector & intervals, bool allZero) { Transaction txn(nixDB); nix::setStatePathsIntervalTxn(txn, statePaths, intervals, allZero); txn.commit(); } -vector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths) +IntVector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths) { string data; Paths referers; - vector intervals; + IntVector intervals; for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i) { nixDB.queryString(txn, dbStateCounters, *i, data); @@ -1620,7 +1593,7 @@ vector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & st return intervals; } -vector LocalStore::getStatePathsInterval(const PathSet & statePaths) +IntVector LocalStore::getStatePathsInterval(const PathSet & statePaths) { return nix::getStatePathsIntervalTxn(noTxn, statePaths); } @@ -1645,12 +1618,12 @@ vector LocalStore::getStatePathsInterval(const PathSet & statePaths) TODO Change comment, this can also take state paths */ -void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) +void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision) { nix::storePathRequisitesTxn(noTxn, storeOrstatePath, includeOutputs, paths, withComponents, withState, revision); } -void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) +void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision) { computeFSClosureTxn(txn, storeOrstatePath, paths, withComponents, withState, revision); @@ -1667,7 +1640,7 @@ void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePa } } -void LocalStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) +void LocalStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision) { nix::storePathRequisites(storeOrstatePath, includeOutputs, paths, withComponents, withState, revision); } @@ -1848,7 +1821,7 @@ PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePa } -void LocalStore::revertToRevision(Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive) +void LocalStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive) { Transaction txn(nixDB); revertToRevisionTxn(txn, componentPath, derivationPath, statePath, revision_arg, recursive); diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 193241f52..61ebf85de 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -55,8 +55,6 @@ public: void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision); - void queryAllReferences(const Path & path, PathSet & allReferences, const int revision); - void queryReferrers(const Path & path, PathSet & referrers, const int revision); void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision); @@ -90,17 +88,13 @@ public: ///////////////////////////// - void setStatePathsInterval(const PathSet & statePath, const vector & intervals, bool allZero = false); + void setStatePathsInterval(const PathSet & statePath, const IntVector & intervals, bool allZero = false); - vector getStatePathsInterval(const PathSet & statePaths); + IntVector getStatePathsInterval(const PathSet & statePaths); bool isStateComponent(const Path & storePath); - bool isStateDrvPath(const Path & drvpath); - - bool isStateDrv(const Derivation & drv); - - void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); + void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision); void setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment); @@ -110,7 +104,7 @@ public: Snapshots commitStatePath(const Path & statePath); - Path queryDeriver(const Path & path); //should these be in here ???? + Path queryDeriver(const Path & path); PathSet queryDerivers(const Path & storePath, const string & identifier, const string & user); //should these be in here ???? @@ -118,7 +112,7 @@ public: PathSet toNonSharedPathSet(const PathSet & statePaths); - void revertToRevision(Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive); + void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive); }; @@ -219,7 +213,7 @@ bool isStateComponentTxn(const Transaction & txn, const Path & path); bool isStateDrvPathTxn(const Transaction & txn, const Path & drvPath); -bool isStateDrvTxn(const Transaction & txn, const Derivation & drv); +bool isStateDrv(const Derivation & drv); //TODO can this ????? void queryAllValidPathsTxn(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths); @@ -235,7 +229,7 @@ void queryReferrersTxn(const Transaction & txn, const Path & storePath, PathSet void queryStateReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & stateReferrers, const int revision); Path queryStatePathDrvTxn(const Transaction & txn, const Path & statePath); -void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); +void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision); void setStateRevisionsTxn(const Transaction & txn, const RevisionClosure & revisions, const Path & rootStatePath, const string & comment); bool isValidPathTxn(const Transaction & txn, const Path & path); @@ -250,10 +244,10 @@ Path toNonSharedPathTxn(const Transaction & txn, const Path & statePath); PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePath); void ensurePathTxn(const Transaction & txn, const Path & path); -vector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths); +IntVector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths); bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision); -void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePath, const vector & intervals, bool allZero = false); +void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePath, const IntVector & intervals, bool allZero = false); } diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 48381eff4..6fc73cda5 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -212,8 +212,7 @@ Path RemoteStore::queryStatePathDrv(const Path & statePath) writeInt(wopQueryStatePathDrv, to); writeString(statePath, to); processStderr(); - Path p = readString(from); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! check wheter from is the state path ???? - return p; + return readString(from); } void RemoteStore::queryReferences(const Path & path, @@ -221,10 +220,10 @@ void RemoteStore::queryReferences(const Path & path, { writeInt(wopQueryReferences, to); writeString(path, to); + writeInt(revision, to); processStderr(); PathSet references2 = readStorePaths(from); references.insert(references2.begin(), references2.end()); - //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! include revision? } void RemoteStore::queryStateReferences(const Path & path, @@ -232,29 +231,23 @@ void RemoteStore::queryStateReferences(const Path & path, { writeInt(wopQueryStateReferences, to); writeString(path, to); + writeInt(revision, to); processStderr(); PathSet stateReferences2 = readStorePaths(from); stateReferences.insert(stateReferences2.begin(), stateReferences2.end()); - //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! include revision? } -void RemoteStore::queryAllReferences(const Path & path, - PathSet & allReferences, const int revision) -{ - //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -} - void RemoteStore::queryReferrers(const Path & path, PathSet & referrers, const int revision) { writeInt(wopQueryReferrers, to); writeString(path, to); + writeInt(revision, to); processStderr(); PathSet referrers2 = readStorePaths(from); referrers.insert(referrers2.begin(), referrers2.end()); - //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! include revision? + } void RemoteStore::queryStateReferrers(const Path & path, @@ -262,10 +255,10 @@ void RemoteStore::queryStateReferrers(const Path & path, { writeInt(wopQueryStateReferrers, to); writeString(path, to); + writeInt(revision, to); processStderr(); PathSet stateReferrers2 = readStorePaths(from); stateReferrers.insert(stateReferrers2.begin(), stateReferrers2.end()); - //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! include revision? } @@ -319,7 +312,7 @@ Path RemoteStore::importPath(bool requireSignature, Source & source) anyway. */ processStderr(0, &source); - Path path = readStorePath(from); + //Path path = readStorePath(from); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove return readStorePath(from); } @@ -403,6 +396,136 @@ void RemoteStore::collectGarbage(GCAction action, const PathSet & pathsToDelete, bytesFreed = (((unsigned long long) hi) << 32) | lo; } +PathSet RemoteStore::queryDerivers(const Path & storePath, const string & identifier, const string & user) +{ + writeInt(wopQueryDerivers, to); + writeString(storePath, to); + writeString(identifier, to); + writeString(user, to); + processStderr(); + return readStorePaths(from); //TODO is this ok ?? +} + +void RemoteStore::setStatePathsInterval(const PathSet & statePaths, const IntVector & intervals, bool allZero) +{ + writeInt(wopSetStatePathsInterval, to); + writeStringSet(statePaths, to); + writeIntVector(intervals, to); + writeInt(allZero ? 1 : 0, to); + processStderr(); + readInt(from); +} + +IntVector RemoteStore::getStatePathsInterval(const PathSet & statePaths) +{ + writeInt(wopGetStatePathsInterval, to); + writeStringSet(statePaths, to); + processStderr(); + return readIntVector(from); +} + +bool RemoteStore::isStateComponent(const Path & path) +{ + writeInt(wopIsStateComponent, to); + writeString(path, to); + processStderr(); + unsigned int reply = readInt(from); + return reply != 0; +} + +void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision) +{ + writeInt(wopStorePathRequisites, to); + writeString(storeOrstatePath, to); + writeInt(includeOutputs ? 1 : 0, to); + writeStringSet(paths, to); + writeInt(withComponents ? 1 : 0, to); + writeInt(withState ? 1 : 0, to); + writeInt(revision, to); + processStderr(); + readInt(from); +} + +void RemoteStore::setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment) +{ + writeInt(wopSetStateRevisions, to); + writeRevisionClosure(revisions, to); + writeString(rootStatePath, to); + writeString(comment, to); + processStderr(); + readInt(from); +} + +bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision) +{ + writeInt(wopQueryStateRevisions, to); + writeString(statePath, to); + writeInt(revision, to); + RevisionClosure revisions2 = readRevisionClosure(from); + RevisionClosureTS timestamps2 = readRevisionClosureTS(from); + revisions = revisions2; //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + timestamps = timestamps2; //TODO !!!!!!!!!!!!!!!!!!!! COPY BY VALUE I THINK + processStderr(); + unsigned int reply = readInt(from); + return reply != 0; +} + +bool RemoteStore::queryAvailableStateRevisions(const Path & statePath, RevisionInfos & revisions) +{ + writeInt(wopQueryAvailableStateRevisions, to); + writeString(statePath, to); + RevisionInfos revisions2 = readRevisionInfos(from); + revisions = revisions2; //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + processStderr(); + unsigned int reply = readInt(from); + return reply != 0; +} + +Snapshots RemoteStore::commitStatePath(const Path & statePath) +{ + writeInt(wopCommitStatePath, to); + writeString(statePath, to); + processStderr(); + return readSnapshots(from); +} + +void RemoteStore::scanAndUpdateAllReferences(const Path & statePath, const bool recursive) +{ + writeInt(wopScanAndUpdateAllReferences, to); + writeString(statePath, to); + writeInt(recursive ? 1 : 0, to); + processStderr(); + readInt(from); +} + +Path RemoteStore::queryDeriver(const Path & path) +{ + writeInt(wopQueryDeriver, to); + writeString(path, to); + processStderr(); + return readStorePath(from); +} + +PathSet RemoteStore::toNonSharedPathSet(const PathSet & statePaths) +{ + writeInt(wopToNonSharedPathSet, to); + writeStringSet(statePaths, to); + processStderr(); + return readStringSet(from); //TODO !!!!!!!!!!!!!!! create a readStatePaths just like readStorePaths +} + +void RemoteStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive) +{ + writeInt(wopRevertToRevision, to); + writeString(componentPath, to); + writeString(derivationPath, to); + writeString(statePath, to); + writeInt(revision_arg, to); + writeInt(recursive ? 1 : 0, to); + processStderr(); + readInt(from); +} + void RemoteStore::processStderr(Sink * sink, Source * source) { @@ -433,100 +556,6 @@ void RemoteStore::processStderr(Sink * sink, Source * source) throw Error("protocol error processing standard error"); } -//TODO -void RemoteStore::setStatePathsInterval(const PathSet & statePaths, const vector & intervals, bool allZero) -{ - -} -//TODO -vector RemoteStore::getStatePathsInterval(const PathSet & statePaths) -{ - vector intervals; - return intervals; -} - -//TODO -bool RemoteStore::isStateComponent(const Path & path) -{ - return false; -} - -//TODO -bool RemoteStore::isStateDrvPath(const Path & drvpath) -{ - return false; -} - -//TODO -bool RemoteStore::isStateDrv(const Derivation & drv) -{ - return false; -} - -//TODO -void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) -{ - -} - -//TODO -void RemoteStore::setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment) -{ - -} - -//TODO -bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision) -{ - return false; -} - -//TODO -bool RemoteStore::queryAvailableStateRevisions(const Path & statePath, RevisionInfos & revisions) -{ - return false; -} - -//TODO -Snapshots RemoteStore::commitStatePath(const Path & statePath) -{ - Snapshots ss; - return ss; -} - -void RemoteStore::scanAndUpdateAllReferences(const Path & statePath, const bool recursive) -{ - -} - -Path RemoteStore::queryDeriver(const Path & path) -{ - writeInt(wopQueryDeriver, to); - writeString(path, to); - processStderr(); - return readStorePath(from); -} - -PathSet RemoteStore::queryDerivers(const Path & storePath, const string & identifier, const string & user) -{ - writeInt(wopQueryDerivers, to); - writeString(storePath, to); - writeString(identifier, to); - writeString(user, to); - processStderr(); - return readStorePaths(from); //TODO is this ok ?? -} - -PathSet RemoteStore::toNonSharedPathSet(const PathSet & statePaths) -{ - PathSet p; - return p; -} - -void RemoteStore::revertToRevision(Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive) -{ - -} } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index beb63a04c..54e953d74 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -43,8 +43,6 @@ public: void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision); - void queryAllReferences(const Path & path, PathSet & allReferences, const int revision); - void queryReferrers(const Path & path, PathSet & referrers, const int revision); void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision); @@ -76,17 +74,13 @@ public: void collectGarbage(GCAction action, const PathSet & pathsToDelete, bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed); - void setStatePathsInterval(const PathSet & statePath, const vector & intervals, bool allZero = false); + void setStatePathsInterval(const PathSet & statePath, const IntVector & intervals, bool allZero = false); - vector getStatePathsInterval(const PathSet & statePaths); + IntVector getStatePathsInterval(const PathSet & statePaths); bool isStateComponent(const Path & path); - bool isStateDrvPath(const Path & drvpath); - - bool isStateDrv(const Derivation & drv); - - void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); + void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision); void setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment); @@ -104,7 +98,7 @@ public: PathSet toNonSharedPathSet(const PathSet & statePaths); - void revertToRevision(Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive); + void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive); private: AutoCloseFD fdSocket; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 59f3d8054..6399a4e71 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -87,8 +87,6 @@ public: The result is not cleared. */ virtual void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision) = 0; - virtual void queryAllReferences(const Path & path, PathSet & allReferences, const int revision) = 0; - /* Queries the set of incoming FS references for a store path. The result is not cleared. */ virtual void queryReferrers(const Path & path, @@ -202,22 +200,16 @@ public: bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0; /* TODO */ - virtual void setStatePathsInterval(const PathSet & statePath, const vector & intervals, bool allZero = false) = 0; + virtual void setStatePathsInterval(const PathSet & statePath, const IntVector & intervals, bool allZero = false) = 0; /* TODO */ - virtual vector getStatePathsInterval(const PathSet & statePaths) = 0; + virtual IntVector getStatePathsInterval(const PathSet & statePaths) = 0; /* Checks whether a path is a component path that has a statePath. */ virtual bool isStateComponent(const Path & path) = 0; /* TODO */ - virtual bool isStateDrvPath(const Path & drvpath) = 0; - - /* TODO */ - virtual bool isStateDrv(const Derivation & drv) = 0; - - /* TODO */ - virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) = 0; + virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision) = 0; /* TODO */ virtual void setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment) = 0; @@ -234,14 +226,18 @@ public: /* Query the deriver of a store path. Return the empty string if no deriver has been set. */ virtual Path queryDeriver(const Path & path) = 0; - + + /* TODO */ virtual PathSet queryDerivers(const Path & storePath, const string & identifier, const string & user) = 0; - + + /* TODO */ virtual void scanAndUpdateAllReferences(const Path & statePath, const bool recursive) = 0; + /* TODO */ virtual PathSet toNonSharedPathSet(const PathSet & statePaths) = 0; - virtual void revertToRevision(Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive) = 0; + /* TODO */ + virtual void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive) = 0; }; diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index 43013727e..5e00171bf 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -65,7 +65,7 @@ void createStateDirsTxn(const Transaction & txn, const DerivationStateOutputDirs } //Initialize the counters for the statePaths that have an interval to 0 - vector empty; + IntVector empty; setStatePathsIntervalTxn(txn, intervalPaths, empty, true); } @@ -90,7 +90,7 @@ PathSet getAllStateDerivationsRecursivelyTxn(const Transaction & txn, const Path -void revertToRevisionTxn(const Transaction & txn, Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive) +void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive) { PathSet statePaths; @@ -222,7 +222,7 @@ Snapshots commitStatePathTxn(const Transaction & txn, const Path & statePath) intervalPaths.insert(fullstatedir); } } - vector intervals = getStatePathsIntervalTxn(txn, intervalPaths); + IntVector intervals = getStatePathsIntervalTxn(txn, intervalPaths); Snapshots revisions_list; diff --git a/src/libstore/store-state.hh b/src/libstore/store-state.hh index dbde130d3..9891e8b75 100644 --- a/src/libstore/store-state.hh +++ b/src/libstore/store-state.hh @@ -25,7 +25,7 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path & statePath); -void revertToRevisionTxn(const Transaction & txn, Path & componentPath, Path & derivationPath, Path & statePath, int revision_arg, bool recursive); +void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive); } diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index b6dfff486..807b0a093 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -34,7 +34,19 @@ typedef enum { wopExportPath, wopImportPath, wopQueryDeriver, + wopQueryDerivers, + wopSetStatePathsInterval, + wopGetStatePathsInterval, + wopIsStateComponent, + wopStorePathRequisites, + wopSetStateRevisions, + wopQueryStateRevisions, + wopQueryAvailableStateRevisions, + wopCommitStatePath, + wopScanAndUpdateAllReferences, + wopToNonSharedPathSet, + wopRevertToRevision, } WorkerOp; diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index c0e1c17af..635e90e97 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -55,6 +55,50 @@ void writeStringSet(const StringSet & ss, Sink & sink) writeString(*i, sink); } +void writeIntVector(const IntVector & iv, Sink & sink) +{ + writeInt(iv.size(), sink); + for(int i=0;i < iv.size(); i++) + writeString(int2String(iv.at(i)), sink); +} + +void writeRevisionClosure(const RevisionClosure & rc, Sink & sink) +{ + writeInt(rc.size(), sink); + for (RevisionClosure::const_iterator i = rc.begin(); i != rc.end(); ++i){ + writeString((*i).first, sink); + writeSnapshots((*i).second, sink); + } +} + +void writeSnapshots(const Snapshots & ss, Sink & sink) +{ + writeInt(ss.size(), sink); + for (Snapshots::const_iterator i = ss.begin(); i != ss.end(); ++i){ + writeString((*i).first, sink); + writeInt((*i).second, sink); //TODO MUST BE UNSGINED INT + } +} + +void writeRevisionClosureTS(const RevisionClosureTS & rc, Sink & sink) +{ + writeInt(rc.size(), sink); + for (RevisionClosureTS::const_iterator i = rc.begin(); i != rc.end(); ++i){ + writeString((*i).first, sink); + writeInt((*i).second, sink); + } +} + +void writeRevisionInfos(const RevisionInfos & ri, Sink & sink) +{ + writeInt(ri.size(), sink); + for (RevisionInfos::const_iterator i = ri.begin(); i != ri.end(); ++i){ + writeInt((*i).first, sink); + RevisionInfo rvi = (*i).second; + writeString(rvi.comment, sink); + writeInt(rvi.timestamp, sink); //TODO MUST BE UNSGINED INT + } +} void readPadding(unsigned int len, Source & source) { @@ -102,5 +146,86 @@ StringSet readStringSet(Source & source) return ss; } +/* +//IntVector +//RevisionClosure +//RevisionClosureTS +//RevisionInfos + +struct RevisionInfo +{ + string comment; + unsigned int timestamp; +}; +typedef map RevisionInfos; +typedef map Snapshots; //Automatically sorted on Path :) +typedef map RevisionClosure; +typedef map RevisionClosureTS; + +*/ + +IntVector readIntVector(Source & source) +{ + unsigned int count = readInt(source); + IntVector iv; + while (count--){ + string s = readString(source); + int i; + if (!string2Int(s, i)) + throw Error(format("`%1%' is corrupt in readIntVector") % s); + iv.push_back(i); + } + return iv; +} + +RevisionClosure readRevisionClosure(Source & source) +{ + unsigned int count = readInt(source); + RevisionClosure rc; + while (count--){ + string path = readString(source); + Snapshots ss = readSnapshots(source); + rc[path] = ss; + } + return rc; +} + + +Snapshots readSnapshots(Source & source) +{ + unsigned int count = readInt(source); + Snapshots ss; + while (count--){ + string path = readString(source); + unsigned int ri = readInt(source); //TODO MUST BE UNSGINED INT + ss[path] = ri; + } + return ss; +} + + +RevisionClosureTS readRevisionClosureTS(Source & source) +{ + unsigned int count = readInt(source); + RevisionClosureTS rc; + while (count--){ + string path = readString(source); + int ri = readInt(source); + rc[path] = ri; + } + return rc; +} + +RevisionInfos readRevisionInfos(Source & source) +{ + unsigned int count = readInt(source); + RevisionInfos ri; + while (count--){ + readInt(source); + RevisionInfo rvi; + rvi.comment = readString(source); + rvi.timestamp = readInt(source); + } +} } diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index c18e82463..5864ce6b0 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -98,11 +98,22 @@ void writeInt(unsigned int n, Sink & sink); void writeString(const string & s, Sink & sink); void writeStringSet(const StringSet & ss, Sink & sink); +void writeIntVector(const IntVector & iv, Sink & sink); +void writeRevisionClosure(const RevisionClosure & rc, Sink & sink); +void writeSnapshots(const Snapshots & ss, Sink & sink); +void writeRevisionClosureTS(const RevisionClosureTS & rc, Sink & sink); +void writeRevisionInfos(const RevisionInfos & ri, Sink & sink); + void readPadding(unsigned int len, Source & source); unsigned int readInt(Source & source); string readString(Source & source); StringSet readStringSet(Source & source); +IntVector readIntVector(Source & source); +RevisionClosure readRevisionClosure(Source & source); +Snapshots readSnapshots(Source & source); +RevisionClosureTS readRevisionClosureTS(Source & source); +RevisionInfos readRevisionInfos(Source & source); } diff --git a/src/libutil/types.hh b/src/libutil/types.hh index 520fced0d..fc63315e6 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -59,7 +59,7 @@ typedef list Paths; typedef set PathSet; //state types -typedef list RevisionNumbers; //the Strings (list) of StateReferences and this list are connected by position +typedef vector IntVector; //the Strings (list) of StateReferences and this list are connected by position struct RevisionInfo { string comment; diff --git a/src/libutil/util.cc b/src/libutil/util.cc index b12d4298e..f19c80277 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -919,22 +919,22 @@ Strings unpackStrings(const string & s) return strings; } -string packRevisionNumbers(const RevisionNumbers & revs) +string packRevisionNumbers(const IntVector & revs) { string seperator = "|"; string d = ""; - for (RevisionNumbers::const_iterator i = revs.begin(); + for (IntVector::const_iterator i = revs.begin(); i != revs.end(); ++i){ d += int2String(*i) + seperator; } return d; } -RevisionNumbers unpackRevisionNumbers(const string & packed) +IntVector unpackRevisionNumbers(const string & packed) { string seperator = "|"; Strings ss = tokenizeString(packed, seperator); - RevisionNumbers revs; + IntVector revs; for (Strings::const_iterator i = ss.begin(); i != ss.end(); ++i){ diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index fdbd1d65b..6e15bc519 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -497,7 +497,7 @@ static void installDerivations(Globals & globals, //Set the state indentifier if it is a state-component printMsg(lvlError, format("New component to install DRV: '%1%'") % i->queryDrvPath(globals.state)); Derivation drv = derivationFromPathTxn(noTxn, i->queryDrvPath(globals.state)); - if(store->isStateDrv(drv)) + if(isStateDrv(drv)) { DerivationStateOutputs stateOutputs = drv.stateOutputs; string stateIdentifier = stateOutputs.find("state")->second.stateIdentifier; diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index 5eaf13335..06a050dc8 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -213,7 +213,7 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs) } //Sort ourselfes to create a nice output - vector revisions_sort; + IntVector revisions_sort; int highestrev; for (RevisionInfos::iterator i = revisions.begin(); i != revisions.end(); ++i){ int rev = (*i).first; @@ -224,7 +224,7 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs) sort(revisions_sort.begin(), revisions_sort.end()); int max_size = int2String(highestrev).length(); - for (vector::iterator i = revisions_sort.begin(); i != revisions_sort.end(); ++i) + for (IntVector::iterator i = revisions_sort.begin(); i != revisions_sort.end(); ++i) { int rev = *i; string rev_s = padd(int2String(rev), '0' , max_size, true); //pad revisions with a 0 diff --git a/src/nix-store/dotgraph.cc b/src/nix-store/dotgraph.cc index 1b4910a20..7b8f1aab1 100644 --- a/src/nix-store/dotgraph.cc +++ b/src/nix-store/dotgraph.cc @@ -111,9 +111,13 @@ void printDotGraph(const PathSet & roots) cout << makeNode(path, symbolicName(path), "#ff0000"); - PathSet allReferences; - store->queryAllReferences(path, allReferences, -1); + //Lookup all references + PathSet references; + PathSet stateReferences; + store->queryReferences(path, references, -1); + store->queryStateReferences(path, stateReferences, -1); + PathSet allReferences = pathSets_union(references, stateReferences); for (PathSet::iterator i = allReferences.begin(); i != allReferences.end(); ++i) diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 4f79c5b8a..86d4c1ed6 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -211,8 +211,12 @@ static void printTree(const Path & path, cout << format("%1%%2%\n") % firstPad % path; - PathSet allReferences; - store->queryAllReferences(path, allReferences, -1); + //Lookup all references + PathSet references; + PathSet stateReferences; + store->queryReferences(path, references, -1); + store->queryStateReferences(path, stateReferences, -1); + PathSet allReferences = pathSets_union(references, stateReferences); #if 0 for (PathSet::iterator i = drv.inputSrcs.begin(); diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index b237bb22a..eb6876119 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -284,7 +284,7 @@ static void performOp(Source & from, Sink & to, unsigned int op) } case wopQueryStatePathDrv: { - Path path = readStorePath(from); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! needs to be the state path + Path path = readString(from); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! make a readStatePath... startWork(); Path p = store->queryStatePathDrv(path); stopWork(); @@ -295,12 +295,13 @@ static void performOp(Source & from, Sink & to, unsigned int op) case wopQueryReferences: case wopQueryReferrers: { Path path = readStorePath(from); + int revision = readInt(from); startWork(); PathSet paths; if (op == wopQueryReferences) - store->queryReferences(path, paths, -1); + store->queryReferences(path, paths, revision); else - store->queryReferrers(path, paths, -1); + store->queryReferrers(path, paths, revision); stopWork(); writeStringSet(paths, to); break; @@ -309,12 +310,13 @@ static void performOp(Source & from, Sink & to, unsigned int op) case wopQueryStateReferences: case wopQueryStateReferrers: { Path path = readStorePath(from); + int revision = readInt(from); startWork(); PathSet paths; if (op == wopQueryStateReferences) - store->queryStateReferences(path, paths, -1); + store->queryStateReferences(path, paths, revision); else - store->queryStateReferrers(path, paths, -1); //TODO Does this work???, how about the state path????????? + store->queryStateReferrers(path, paths, revision); //TODO Does this work???, how about the state path????????? stopWork(); writeStringSet(paths, to); break; @@ -329,17 +331,6 @@ static void performOp(Source & from, Sink & to, unsigned int op) break; } - case wopQueryDerivers: { - Path path = readStorePath(from); - string identifier = readString(from); - string user = readString(from); - startWork(); - PathSet derivers = store->queryDerivers(path, identifier, user); - stopWork(); - writeStringSet(derivers, to); - break; - } - case wopAddToStore: { string baseName = readString(from); bool fixed = readInt(from) == 1; @@ -474,6 +465,72 @@ static void performOp(Source & from, Sink & to, unsigned int op) break; } + + case wopQueryDerivers: { + Path path = readStorePath(from); + string identifier = readString(from); + string user = readString(from); + startWork(); + PathSet derivers = store->queryDerivers(path, identifier, user); + stopWork(); + writeStringSet(derivers, to); + break; + } + + case wopSetStatePathsInterval: { + + break; + } + + case wopGetStatePathsInterval: { + + break; + } + + case wopIsStateComponent: { + + break; + } + + case wopStorePathRequisites: { + + break; + } + + case wopSetStateRevisions: { + + break; + } + + case wopQueryStateRevisions: { + + break; + } + + case wopQueryAvailableStateRevisions: { + + break; + } + + case wopCommitStatePath: { + + break; + } + + case wopScanAndUpdateAllReferences: { + + break; + } + + case wopToNonSharedPathSet: { + + break; + } + + case wopRevertToRevision: { + + break; + } default: throw Error(format("invalid operation %1%") % op);