1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 12:10:59 +01:00

before removing referrer code

This commit is contained in:
Wouter den Breejen 2007-08-03 10:30:39 +00:00
parent 4fb9070fbd
commit 7d91f62b71
3 changed files with 7 additions and 133 deletions

View file

@ -632,55 +632,6 @@ bool Database::queryStateReferrers(const Transaction & txn, TableId referrers_ta
return queryStateReferences(txn, referrers_table, revisions_table, statePath, referrers, revision, timestamp); return queryStateReferences(txn, referrers_table, revisions_table, statePath, referrers, revision, timestamp);
} }
//PRIVATE !!!!!!
//Update the referrers of some path because the store_or_statePath got new references
void Database::updateReferredPath(const Transaction & txn, TableId revisions_table, TableId referrers_X_s_table,
const Path & referred_state_or_store_Path, const Path & statePath, const int revision)
{
//referred_state_or_store_Path --> statePath
//you dont know what referred_state_or_store_Path is !!!!!!!!!!!! add a bool !!!!!!
if(revision != -1){
//Get timestamp of revision
int timestamp;
bool succeed = revisionToTimeStamp(txn, revisions_table, referred_state_or_store_Path, revision, timestamp);
if(!succeed)
throw Error(format("Couldnt find timestamp for revision '%1%' at update referrers mapping for '%2%'") % revision % referred_state_or_store_Path);
//remove all dynamic (that have a ts) referrers of that revision first (except if it is the latest, eg. -1)
delPair(txn, referrers_X_s_table, mergeToDBKey(referred_state_or_store_Path, timestamp));
}
//now get the referrers at timestamp (or just the latest if revision is -1)
PathSet referrers;
//TODO
//if( ! state)
//getReferrers...............
//dbStateComponentReferrers
//else
//getStateReferrers...............
//dbStateStateReferrers
//string kkkk = nixDB.mergeToDBKey(store_or_statePath, revision);
//Add store_or_statePath in .... if nessacary (if in references)
//TODO
//referredPath - TS --> store_or_statePath ADD
//Set Remove store_or_statePath in .... if nessacary (if not in references)
//TODO
//referredPath - TS --> store_or_statePath DEL
//set the new referrers of revision (-1 insert as a new timestamp)
//nixDB.setStateReferrers(txn, table, dbStateRevisions, referredPath, ........, revision);
}
void Database::setStateRevisions(const Transaction & txn, TableId revisions_table, TableId snapshots_table, void Database::setStateRevisions(const Transaction & txn, TableId revisions_table, TableId snapshots_table,
const RevisionClosure & revisions) const RevisionClosure & revisions)
{ {

View file

@ -121,10 +121,6 @@ public:
bool queryStateReferrers(const Transaction & txn, TableId referrers_table, TableId revisions_table, bool queryStateReferrers(const Transaction & txn, TableId referrers_table, TableId revisions_table,
const Path & statePath, Strings & referrers, int revision = -1, int timestamp = -1); const Path & statePath, Strings & referrers, int revision = -1, int timestamp = -1);
/* TODO */
void updateReferredPath(const Transaction & txn, TableId revisions_table, TableId referrers_X_s_table,
const Path & referred_state_or_store_Path, const Path & statePath, const int revision);
/* 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 revisions_table, TableId snapshots_table, void setStateRevisions(const Transaction & txn, TableId revisions_table, TableId snapshots_table,
const RevisionClosure & revisions); const RevisionClosure & revisions);

View file

@ -452,24 +452,11 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
nixDB.setStrings(txn, dbComponentComponentReferences, store_or_statePath, Paths(references.begin(), references.end())); nixDB.setStrings(txn, dbComponentComponentReferences, store_or_statePath, Paths(references.begin(), references.end()));
nixDB.setStrings(txn, dbComponentStateReferences, store_or_statePath, Paths(stateReferences.begin(), stateReferences.end())); nixDB.setStrings(txn, dbComponentStateReferences, store_or_statePath, Paths(stateReferences.begin(), stateReferences.end()));
//Handle referrers like the old way, because references (and so referrers) referrers never change (So these do not have a timestamp)
//dbComponentComponentReferrers
//dbComponentStateReferrers
/*
references c -> c
oldReferences
stateReferences c -> s
oldStateReferences
*/
//TODO
} }
else if(isRealisableStatePath(txn, store_or_statePath)) else if(isRealisableStatePath(txn, store_or_statePath))
{ {
//Write references and referrers to a special revision (since there are multiple revisions of a statePath) //Write references to a special revision (since there are multiple revisions of a statePath)
//query the references of revision (-1 is query the latest references) //query the references of revision (-1 is query the latest references)
Paths oldStateReferences_s_c; Paths oldStateReferences_s_c;
@ -483,19 +470,6 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
//set the references of revision (-1 insert as a new timestamp) //set the references of revision (-1 insert as a new timestamp)
nixDB.setStateReferences(txn, dbStateComponentReferences, dbStateRevisions, store_or_statePath, Paths(references.begin(), references.end()), revision); nixDB.setStateReferences(txn, dbStateComponentReferences, dbStateRevisions, store_or_statePath, Paths(references.begin(), references.end()), revision);
nixDB.setStateReferences(txn, dbStateStateReferences, dbStateRevisions, store_or_statePath, Paths(stateReferences.begin(), stateReferences.end()), revision); nixDB.setStateReferences(txn, dbStateStateReferences, dbStateRevisions, store_or_statePath, Paths(stateReferences.begin(), stateReferences.end()), revision);
//REFERRERS
//for all references old and new, state and component
PathSet all_references = pathSets_union(references, oldReferences);
PathSet all_stateReferences = pathSets_union(oldStateReferences, stateReferences);
for (PathSet::const_iterator i = all_references.begin(); i != all_references.end(); ++i)
nixDB.updateReferredPath(txn, dbStateRevisions, dbComponentStateReferrers, *i, store_or_statePath, revision);
for (PathSet::const_iterator i = all_stateReferences.begin(); i != all_stateReferences.end(); ++i)
nixDB.updateReferredPath(txn, dbStateRevisions, dbStateStateReferrers, *i, store_or_statePath, revision);
} }
else else
throw Error(format("Path '%1%' is not a valid component or state path") % store_or_statePath); throw Error(format("Path '%1%' is not a valid component or state path") % store_or_statePath);
@ -585,59 +559,12 @@ static PathSet getXReferrers(const Transaction & txn, const Path & store_or_stat
PathSet referrers; PathSet referrers;
if(isValidPathTxn(txn, store_or_statePath) || isValidStatePathTxn(txn, store_or_statePath)){ if(isValidPathTxn(txn, store_or_statePath)){
//Lookup its where it points to if its shared
Path store_or_statePath_ns;
if(isValidStatePathTxn(txn, store_or_statePath))
store_or_statePath_ns = toNonSharedPathTxn(txn, store_or_statePath);
map<string, int> possible_referrers; //referrer at timestamp
Strings keys;
nixDB.enumTable(txn, table, keys);
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i){
if( (*i).substr(0, store_or_statePath_ns.length()) == store_or_statePath_ns){
if( (*i).length() == store_or_statePath_ns.length() )
referrers.insert(*i); //referrers from components
else{
//now filter the latest of each value
Path empty;
int timestamp;
nixDB.splitDBKey(*i, empty, timestamp);
string data;
nixDB.queryString(txn, table, *i, data);
Path statePath;
int added_or_removed;
nixDB.splitDBKey(data, statePath, added_or_removed);
if(possible_referrers[statePath] != 0) //if not yet set
if(timestamp > possible_referrers[statePath])
possible_referrers[statePath] = timestamp;
else
possible_referrers[statePath] = timestamp;
}
}
} }
else if(isValidStatePathTxn(txn, store_or_statePath)){
Path statePath_ns = toNonSharedPathTxn(txn, store_or_statePath); //Lookup its where it points to if its shared
//Check wheter the latest was added or deleted
for (map<string, int>::iterator i = possible_referrers.begin(); i != possible_referrers.end(); ++i){
string data;
nixDB.queryString(txn, table, nixDB.mergeToDBKey(store_or_statePath_ns, (*i).second), data);
Path statePath;
int added_or_removed;
nixDB.splitDBKey(data, statePath, added_or_removed);
if(added_or_removed == 1) //now filter on -0 (removed) or -1 (added)
referrers.insert(statePath);
}
return referrers;
} }
else else
throw Error(format("Path '%1%' is not a valid component or state path") % store_or_statePath); throw Error(format("Path '%1%' is not a valid component or state path") % store_or_statePath);