* Wrap calls to registerSubstitute() in a single transaction to

improve throughput.
* Don't build the `substitute-rev' table for now, since it caused
  Theta(N^2) time and log file consumption when adding N substitutes.
  Maybe we can do without it.
This commit is contained in:
Eelco Dolstra 2004-06-21 07:38:17 +00:00
parent 15c60ca1b6
commit daf0a923c7
3 changed files with 13 additions and 11 deletions

View file

@ -302,19 +302,16 @@ static void writeSubstitutes(const Transaction & txn,
} }
void registerSubstitute(const Path & srcPath, void registerSubstitute(const Transaction & txn,
const Substitute & sub) const Path & srcPath, const Substitute & sub)
{ {
assertStorePath(srcPath); assertStorePath(srcPath);
assertStorePath(sub.storeExpr); assertStorePath(sub.storeExpr);
Transaction txn(nixDB);
Substitutes subs = readSubstitutes(txn, srcPath); Substitutes subs = readSubstitutes(txn, srcPath);
if (find(subs.begin(), subs.end(), sub) != subs.end()) { if (find(subs.begin(), subs.end(), sub) != subs.end()) {
/* Nothing to do if the substitute is already known. */ /* Nothing to do if the substitute is already known. */
txn.abort();
return; return;
} }
subs.push_front(sub); /* new substitutes take precedence */ subs.push_front(sub); /* new substitutes take precedence */
@ -325,10 +322,9 @@ void registerSubstitute(const Path & srcPath,
nixDB.queryStrings(txn, dbSubstitutesRev, sub.storeExpr, revs); nixDB.queryStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
if (find(revs.begin(), revs.end(), srcPath) == revs.end()) if (find(revs.begin(), revs.end(), srcPath) == revs.end())
revs.push_back(srcPath); revs.push_back(srcPath);
nixDB.setStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
txn.commit(); // !!! O(n^2) complexity in building this
// nixDB.setStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
} }

View file

@ -63,8 +63,8 @@ bool querySuccessor(const Path & srcPath, Path & sucPath);
Paths queryPredecessors(const Path & sucPath); Paths queryPredecessors(const Path & sucPath);
/* Register a substitute. */ /* Register a substitute. */
void registerSubstitute(const Path & srcPath, void registerSubstitute(const Transaction & txn,
const Substitute & sub); const Path & srcPath, const Substitute & sub);
/* Return the substitutes expression for the given path. */ /* Return the substitutes expression for the given path. */
Substitutes querySubstitutes(const Path & srcPath); Substitutes querySubstitutes(const Path & srcPath);

View file

@ -170,6 +170,9 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
if (!opArgs.empty()) if (!opArgs.empty())
throw UsageError("no arguments expected"); throw UsageError("no arguments expected");
Transaction txn;
createStoreTransaction(txn);
while (1) { while (1) {
Path srcPath; Path srcPath;
Substitute sub; Substitute sub;
@ -188,8 +191,11 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
sub.args.push_back(s); sub.args.push_back(s);
} }
if (!cin || cin.eof()) throw Error("missing input"); if (!cin || cin.eof()) throw Error("missing input");
registerSubstitute(srcPath, sub); cerr << ".";
registerSubstitute(txn, srcPath, sub);
} }
txn.commit();
} }