1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 12:10:59 +01:00
This commit is contained in:
Wouter den Breejen 2007-07-12 11:34:17 +00:00
parent 96a62bb7e6
commit 7bfed0c104
8 changed files with 71 additions and 103 deletions

View file

@ -466,7 +466,7 @@ void Database::splitStatePathRevision(const Path & revisionedStatePath, Path & s
int Database::getNewRevisionNumber(const Transaction & txn, TableId table, int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
const Path & statePath, bool update) const Path & statePath)
{ {
//query //query
string data; string data;
@ -482,10 +482,8 @@ int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
if(!succeed) if(!succeed)
throw Error(format("Malformed revision counter value of path '%1%'") % statePath); throw Error(format("Malformed revision counter value of path '%1%'") % statePath);
if(update){ revision++;
revision++; setString(txn, table, statePath, int2String(revision));
setString(txn, table, statePath, int2String(revision));
}
return revision; return revision;
} }
@ -591,10 +589,10 @@ bool Database::queryStateReferrers(const Transaction & txn, TableId table,
void Database::setStateRevisions(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) //get a new revision number
root_revision = getNewRevisionNumber(txn, table, statePath); int root_revision = getNewRevisionNumber(txn, table, statePath);
//Sort based on statePath to RevisionNumbersClosure //Sort based on statePath to RevisionNumbersClosure
RevisionNumbers sorted_revisions; RevisionNumbers sorted_revisions;
@ -624,38 +622,46 @@ void Database::setStateRevisions(const Transaction & txn, TableId table,
setStrings(txn, table, key, data); setStrings(txn, table, key, data);
} }
bool Database::queryStateRevisions(const Transaction & txn, TableId table, bool Database::queryStateRevisions(const Transaction & txn, TableId table, const PathSet statePath_deps,
const Path & statePath, RevisionNumbers & revisions, int revision) const Path & statePath, RevisionNumbersSet & revisions, int root_revision)
{ {
Strings keys; Strings keys;
enumTable(txn, table, keys); //get all revisions enumTable(txn, table, keys); //get all revisions
string key; string key;
if(revision == -1){ if(root_revision == -1){
bool foundsomething = lookupHighestRevivison(keys, statePath, key); bool foundsomething = lookupHighestRevivison(keys, statePath, key);
if(!foundsomething) if(!foundsomething)
return false; return false;
} }
else else
key = makeStatePathRevision(statePath, revision); key = makeStatePathRevision(statePath, root_revision);
Strings data; 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 //sort all state references recursively
for (Strings::iterator i = data.begin(); i != data.end(); ++i){ vector<Path> sortedStatePaths;
string getRevisionS = *i; 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<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i){
string getRevisionS = data.front();
data.pop_front();
int getRevision; int getRevision;
bool succeed = string2Int(getRevisionS, getRevision); bool succeed = string2Int(getRevisionS, getRevision);
if(!succeed) if(!succeed)
throw Error(format("Cannot read revision number from db of path '%1%'") % statePath); throw Error(format("Cannot read revision number from db of path '%1%'") % statePath);
revisions.push_back(getRevision); revisions[*i] = getRevision;
} }
if(!succeed) if(!notempty)
throw Error(format("Revision '%1%' not found of statePath '%2%'") % int2String(revision) % statePath); throw Error(format("Root revision '%1%' not found of statePath '%2%'") % int2String(root_revision) % statePath);
return succeed; return notempty;
} }
//TODO include comments into revisions? //TODO include comments into revisions?

View file

@ -63,6 +63,9 @@ private:
/* TODO */ /* TODO */
bool lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, int lowerthan = -1); 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: public:
Database(); Database();
~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 */ /* 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, 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 */ /* Returns all the revision numbers of the state references closure of the given state path */
bool queryStateRevisions(const Transaction & txn, TableId table, bool queryStateRevisions(const Transaction & txn, TableId table, const PathSet statePath_deps,
const Path & statePath, RevisionNumbers & revisions, int revision = -1); const Path & statePath, RevisionNumbersSet & revisions, int root_revision = -1);
/* Returns all available revision numbers of the given state path */ /* Returns all available revision numbers of the given state path */
bool queryAvailableStateRevisions(const Transaction & txn, TableId table, bool queryAvailableStateRevisions(const Transaction & txn, TableId table,
const Path & statePath, RevisionNumbers & revisions); const Path & statePath, RevisionNumbers & revisions);
/* TODO */
int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath, bool update = true);
}; };

View file

@ -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) void queryAllValidPaths(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths)
{ {
Paths allComponentPaths2; 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); return nix::queryStateRevisionsTxn(noTxn, statePath, revisions, revision);
} }
@ -1747,15 +1743,6 @@ bool LocalStore::queryAvailableStateRevisions(const Path & statePath, RevisionNu
return nix::queryAvailableStateRevisionsTxn(noTxn, statePath, revisions); 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);
}

View file

@ -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 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, RevisionNumbersSet & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions); 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); bool isStateDrvTxn(const Transaction & txn, const Derivation & drv);
//TODO //TODO can this ?????
void queryAllValidPaths(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths); void queryAllValidPaths(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths);
bool isValidStatePathTxn(const Transaction & txn, const Path & path); bool isValidStatePathTxn(const Transaction & txn, const Path & path);
void queryReferencesTxn(const Transaction & txn, const Path & path, PathSet & references, const int revision); void queryReferencesTxn(const Transaction & txn, const Path & path, PathSet & references, const int revision);

View file

@ -469,19 +469,13 @@ void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool
} }
//TODO //TODO
void RemoteStore::scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive) void RemoteStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions)
{ {
} }
//TODO //TODO
void RemoteStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision)
{
}
//TODO
bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision)
{ {
return false; return false;
} }
@ -492,10 +486,5 @@ bool RemoteStore::queryAvailableStateRevisions(const Path & statePath, RevisionN
return false; return false;
} }
//TODO
int RemoteStore::getNewRevisionNumber(const Path & statePath, bool update)
{
return 0;
}
} }

View file

@ -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 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, RevisionNumbersSet & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions); bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions);
int getNewRevisionNumber(const Path & statePath, bool update = true);
private: private:
AutoCloseFD fdSocket; AutoCloseFD fdSocket;

View file

@ -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; virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) = 0;
/* TODO */ /* TODO */
virtual void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive) = 0; virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions) = 0;
/* TODO */ /* TODO */
virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) = 0; virtual bool queryStateRevisions(const Path & statePath, RevisionNumbersSet & revisions, const int revision) = 0;
/* TODO */
virtual bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision) = 0;
/* TODO */ /* TODO */
virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0; virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0;
/* TODO */
virtual int getNewRevisionNumber(const Path & statePath, bool update = true) = 0;
}; };

View file

@ -271,25 +271,26 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
statePaths.insert(derivationPath); //Insert direct state path statePaths.insert(derivationPath); //Insert direct state path
//Get the revisions recursively to also roll them back //Get the revisions recursively to also roll them back
RevisionNumbers getRivisions; RevisionNumbersSet getRivisions;
bool b = store->queryStateRevisions(statePath, getRivisions, revision_arg); bool b = store->queryStateRevisions(statePath, getRivisions, revision_arg);
//Sort the statePaths from all drvs //Sort the statePaths from all drvs
map<Path, string> state_repos; //map<Path, string> state_repos;
vector<Path> sorted_paths; //vector<Path> sorted_paths;
for (PathSet::iterator d = statePaths.begin(); d != statePaths.end(); ++d){ //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; //state_repos[statePath] = repos;
sorted_paths.push_back(statePath); // sorted_paths.push_back(statePath);
} //}
sort(sorted_paths.begin(), sorted_paths.end()); //sort(sorted_paths.begin(), sorted_paths.end());
//string repos =
//Revert each statePath in the list //Revert each statePath in the list
for (vector<Path>::iterator i = sorted_paths.begin(); i != sorted_paths.end(); ++i){ for (RevisionNumbersSet::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){
Path statePath = *i; Path statePath = (*i).first;
string repos = state_repos[statePath]; int revision = (*i).second;
int revision = getRivisions.front(); string repos = getStateReposPath("stateOutput:staterepospath", statePath); //this is a copy from store-state.cc
getRivisions.pop_front();
printMsg(lvlError, format("Reverting statePath '%1%' to revision: %2%") % statePath % int2String(revision)); printMsg(lvlError, format("Reverting statePath '%1%' to revision: %2%") % statePath % int2String(revision));
Strings p_args; Strings p_args;
@ -399,7 +400,7 @@ void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path
//We dont need to sort since the db does that //We dont need to sort since the db does that
//call scanForAllReferences again on all statePaths //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); int revision = readRevisionNumber(*i);
//Scan, update, call recursively //Scan, update, call recursively
@ -416,9 +417,6 @@ void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path
void updateRevisionsRecursively(Path statePath) void updateRevisionsRecursively(Path statePath)
{ {
//
int newRevisionNumber = store->getNewRevisionNumber(statePath);
//Save all revisions for the call to //Save all revisions for the call to
RevisionNumbersSet rivisionMapping; RevisionNumbersSet rivisionMapping;
@ -439,7 +437,7 @@ void updateRevisionsRecursively(Path statePath)
rivisionMapping[*i] = readRevisionNumber(*i); rivisionMapping[*i] = readRevisionNumber(*i);
//Store the revision numbers in the database for this statePath with revision number //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 //Commit transaction TODO
//Debugging //Debugging
RevisionNumbers getRivisions; RevisionNumbersSet getRivisions;
bool b = store->queryStateRevisions(root_statePath, getRivisions, -1); bool b = store->queryStateRevisions(root_statePath, getRivisions, -1);
for (RevisionNumbers::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){ for (RevisionNumbersSet::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){
printMsg(lvlError, format("REV %1%") % int2String(*i)); printMsg(lvlError, format("State %1% has revision %2%") % (*i).first % int2String((*i).second));
} }