From c65c296ce09bc8725ad3ab55844fef25442c7332 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Tue, 3 Jul 2007 13:50:16 +0000 Subject: [PATCH] Before trying to install STLdb4 .... --- src/libstore/build.cc | 6 +++-- src/libstore/db.cc | 48 +++++++++++++++++++++++++++++++++++++ src/libstore/db.hh | 20 ++++++++++++++++ src/libstore/local-store.cc | 29 ++++++++++++---------- src/libutil/types.hh | 12 +++++++++- 5 files changed, 100 insertions(+), 15 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 3203b26bf..25af0dda4 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1642,10 +1642,12 @@ void DerivationGoal::computeClosure() if(!drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall()) createStateDirs(drv.stateOutputDirs, drv.stateOutputs, drv.env); + /* for (PathSet::iterator i = allPaths.begin(); i != allPaths.end(); ++i) - printMsg(lvlError, format("allPaths: %1%") % *i); + printMsg(lvlError, format("scanning for allPaths: %1%") % *i); for (PathSet::iterator i = allStatePaths.begin(); i != allStatePaths.end(); ++i) - printMsg(lvlError, format("allStatePaths: %1%") % *i); + printMsg(lvlError, format("scanning for allStatePaths: %1%") % *i); + */ /* Check whether the output paths were created, and grep each output path to determine what other paths it references. Also make all diff --git a/src/libstore/db.cc b/src/libstore/db.cc index f0c520985..8fc298931 100644 --- a/src/libstore/db.cc +++ b/src/libstore/db.cc @@ -444,5 +444,53 @@ void Database::enumTable(const Transaction & txn, TableId table, } catch (DbException e) { rethrow(e); } } +void Database::setStateReferences(const Transaction & txn, TableId table, + const Path & statePath, const int revision, const Strings & references) +{ + //get all previous StateReferences + StateReferences newReferences; + + //Merge + newReferences[revision] = references; + + + + //Insert + string data = ""; + checkInterrupt(); + try { + Db * db = getDb(table); + Dbt kt((void *) statePath.c_str(), statePath.length()); + Dbt dt((void *) data.c_str(), data.length()); + db->put(txn.txn, &kt, &dt, 0); + } catch (DbException e) { rethrow(e); } +} + +bool Database::queryStateReferences(const Transaction & txn, TableId table, + const Path & statePath, Strings & references, int revision) +{ + //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + return false; +} + +void Database::setStateRevisions(const Transaction & txn, TableId table, + const Path & statePath, const int revision, const RevisionNumbers & revisions) +{ + //TODO +} +/* +bool Database::queryStateRevisions(const Transaction & txn, TableId table, + const Path & statePath, RevisionNumbers & revisions, int revision = -1) +{ + //TODO + return false; +}*/ + +bool Database::queryAllStateRevisions(const Transaction & txn, TableId table, + const Path & statePath, RevisionNumbers & revisions) +{ + //TODO + return false; +} } diff --git a/src/libstore/db.hh b/src/libstore/db.hh index 54f490f88..120fe9a87 100644 --- a/src/libstore/db.hh +++ b/src/libstore/db.hh @@ -89,6 +89,26 @@ public: void enumTable(const Transaction & txn, TableId table, Strings & keys, const string & keyPrefix = ""); + + /* Set the stateReferences for a specific revision (and older until the next higher revision number in the table) */ + void setStateReferences(const Transaction & txn, TableId table, + const Path & statePath, const int revision, const Strings & references); + + /* Returns the references for a specific revision (and older until the next higher revision number in the table) */ + bool queryStateReferences(const Transaction & txn, TableId table, + const Path & statePath, Strings & references, int revision = -1); + + /* 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 int revision, const RevisionNumbers & 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); + + /* Returns all available revision numbers of the given state path */ + bool queryAllStateRevisions(const Transaction & txn, TableId table, + const Path & statePath, RevisionNumbers & revisions); }; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index d295d4aeb..45e2c8fcf 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -398,7 +398,12 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath, if (references.size() > 0 && !isRealisableComponentOrStatePath(txn, store_or_statePath)) throw Error(format("cannot set references for path `%1%' which is invalid and has no substitutes") % store_or_statePath); - //printMsg(lvlError, format("REGISTER: %1%") % store_or_statePath); + /* + for (PathSet::iterator i = references.begin(); i != references.end(); ++i) + printMsg(lvlError, format("'%2%' has references: %1%") % *i % store_or_statePath); + for (PathSet::iterator i = stateReferences.begin(); i != stateReferences.end(); ++i) + printMsg(lvlError, format("'%2%' has stateReferences: %1%") % *i % store_or_statePath); + */ Paths oldReferences; nixDB.queryStrings(txn, dbReferences, store_or_statePath, oldReferences); @@ -446,7 +451,7 @@ void queryReferences(const Transaction & txn, Paths references2; if (!isRealisableComponentOrStatePath(txn, storePath)) - throw Error(format("path `%1%' is not valid 1") % storePath); + throw Error(format("path `%1%' is not valid") % storePath); nixDB.queryStrings(txn, dbReferences, storePath, references2); references.insert(references2.begin(), references2.end()); } @@ -459,19 +464,19 @@ void LocalStore::queryReferences(const Path & storePath, } void queryStateReferences(const Transaction & txn, - const Path & storePath, PathSet & stateReferences) + const Path & componentOrstatePath, PathSet & stateReferences) { Paths stateReferences2; - if (!isRealisableComponentOrStatePath(txn, storePath)) - throw Error(format("path `%1%' is not valid 2") % storePath); - nixDB.queryStrings(txn, dbStateReferences, storePath, stateReferences2); + if (!isRealisableComponentOrStatePath(txn, componentOrstatePath)) + throw Error(format("path `%1%' is not valid") % componentOrstatePath); + nixDB.queryStrings(txn, dbStateReferences, componentOrstatePath, stateReferences2); stateReferences.insert(stateReferences2.begin(), stateReferences2.end()); } -void LocalStore::queryStateReferences(const Path & storePath, PathSet & stateReferences) +void LocalStore::queryStateReferences(const Path & componentOrstatePath, PathSet & stateReferences) { - nix::queryStateReferences(noTxn, storePath, stateReferences); + nix::queryStateReferences(noTxn, componentOrstatePath, stateReferences); } void queryReferrers(const Transaction & txn, @@ -1644,11 +1649,10 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa (remember we need to keep the old as the basis, and things can change, the db is not consistent anymore then ....) But we also dont want useless refereces ...... - TODO: solution, - ALSO: + Update the 2 references tables: all state paths get: Path statepath --> List(int revnumber, List(References)) + TODO EDIT TABLES references,references_state,referrers,referrers_state - Update the 2 references tables: - all state paths get: run number + state references + revision numbers) THIS ONE !!!!!! + New table stateRevisionClosure: Path StatePath + int revision --> List(int revnumbers) A1(STATEPATH) --> UPDATE ALL STATE REFERENCES IN DB (TRANSACTION) A2(STATEPATH [+ REV]) --> GIVE ALL STATE REFERENCES IN DB @@ -1658,6 +1662,7 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa + //update all revision numbers (transaction) NEW FUN THAT UPDATES THE REVISIONS //update all revision numbers + references (transaction) //update all references diff --git a/src/libutil/types.hh b/src/libutil/types.hh index 0ea6990e8..7634ccd16 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -15,6 +16,7 @@ namespace nix { using std::string; using std::list; using std::set; +using std::map; using std::vector; using boost::format; @@ -50,12 +52,20 @@ typedef list Strings; typedef set StringSet; typedef set SetStringSet; - /* Paths are just strings. */ typedef string Path; typedef list Paths; typedef set PathSet; +//state types +struct RevisionNumbersKey { Path statePath; int revision; } ; +typedef list RevisionNumbers; //the Strings (list) of StateReferences and this list are connected by position +typedef map StateReferences; + +//typedef std::map StateReferencesKey; +//typedef std::map StateReferencesKey2; + + typedef enum { lvlError,