Replace hasSubstitutes() with querySubstitutablePaths()

querySubstitutablePaths() takes a set of paths, so this greatly
reduces daemon <-> client latency.
This commit is contained in:
Eelco Dolstra 2012-07-11 17:52:18 -04:00
parent 58ef4d9a95
commit 09a6321aeb
8 changed files with 52 additions and 24 deletions

View File

@ -932,16 +932,24 @@ template<class T> T getIntLine(int fd)
} }
bool LocalStore::hasSubstitutes(const Path & path) PathSet LocalStore::querySubstitutablePaths(const PathSet & paths)
{ {
PathSet res;
foreach (Paths::iterator, i, substituters) { foreach (Paths::iterator, i, substituters) {
if (res.size() == paths.size()) break;
RunningSubstituter & run(runningSubstituters[*i]); RunningSubstituter & run(runningSubstituters[*i]);
startSubstituter(*i, run); startSubstituter(*i, run);
writeLine(run.to, "have\n" + path); string s = "have ";
if (getIntLine<int>(run.from)) return true; foreach (PathSet::const_iterator, i, paths)
if (res.find(*i) == res.end()) { s += *i; s += " "; }
writeLine(run.to, s);
while (true) {
Path path = readLine(run.from);
if (path == "") break;
res.insert(path);
}
} }
return res;
return false;
} }

View File

@ -123,9 +123,7 @@ public:
StringSet queryDerivationOutputNames(const Path & path); StringSet queryDerivationOutputNames(const Path & path);
PathSet querySubstitutablePaths(); PathSet querySubstitutablePaths(const PathSet & paths);
bool hasSubstitutes(const Path & path);
void querySubstitutablePathInfos(const Path & substituter, void querySubstitutablePathInfos(const Path & substituter,
PathSet & paths, SubstitutablePathInfos & infos); PathSet & paths, SubstitutablePathInfos & infos);

View File

@ -219,13 +219,13 @@ bool RemoteStore::isValidPath(const Path & path)
PathSet RemoteStore::queryValidPaths(const PathSet & paths) PathSet RemoteStore::queryValidPaths(const PathSet & paths)
{ {
openConnection();
if (GET_PROTOCOL_MINOR(daemonVersion) < 12) { if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
PathSet res; PathSet res;
foreach (PathSet::const_iterator, i, paths) foreach (PathSet::const_iterator, i, paths)
if (isValidPath(*i)) res.insert(*i); if (isValidPath(*i)) res.insert(*i);
return res; return res;
} else { } else {
openConnection();
writeInt(wopQueryValidPaths, to); writeInt(wopQueryValidPaths, to);
writeStrings(paths, to); writeStrings(paths, to);
processStderr(); processStderr();
@ -243,14 +243,24 @@ PathSet RemoteStore::queryAllValidPaths()
} }
bool RemoteStore::hasSubstitutes(const Path & path) PathSet RemoteStore::querySubstitutablePaths(const PathSet & paths)
{ {
openConnection(); openConnection();
writeInt(wopHasSubstitutes, to); if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
writeString(path, to); PathSet res;
processStderr(); foreach (PathSet::const_iterator, i, paths) {
unsigned int reply = readInt(from); writeInt(wopHasSubstitutes, to);
return reply != 0; writeString(*i, to);
processStderr();
if (readInt(from)) res.insert(*i);
}
return res;
} else {
writeInt(wopQuerySubstitutablePaths, to);
writeStrings(paths, to);
processStderr();
return readStorePaths<PathSet>(from);
}
} }

View File

@ -45,7 +45,7 @@ public:
StringSet queryDerivationOutputNames(const Path & path); StringSet queryDerivationOutputNames(const Path & path);
bool hasSubstitutes(const Path & path); PathSet querySubstitutablePaths(const PathSet & paths);
void querySubstitutablePathInfos(const PathSet & paths, void querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos); SubstitutablePathInfos & infos);

View File

@ -145,8 +145,8 @@ public:
/* Query the output names of the derivation denoted by `path'. */ /* Query the output names of the derivation denoted by `path'. */
virtual StringSet queryDerivationOutputNames(const Path & path) = 0; virtual StringSet queryDerivationOutputNames(const Path & path) = 0;
/* Query whether a path has substitutes. */ /* Query which of the given paths have substitutes. */
virtual bool hasSubstitutes(const Path & path) = 0; virtual PathSet querySubstitutablePaths(const PathSet & paths) = 0;
/* Query substitute info (i.e. references, derivers and download /* Query substitute info (i.e. references, derivers and download
sizes) of a set of paths. If a path does not have substitute sizes) of a set of paths. If a path does not have substitute

View File

@ -42,6 +42,7 @@ typedef enum {
wopQueryDerivationOutputNames = 28, wopQueryDerivationOutputNames = 28,
wopQuerySubstitutablePathInfos = 29, wopQuerySubstitutablePathInfos = 29,
wopQueryValidPaths = 30, wopQueryValidPaths = 30,
wopQuerySubstitutablePaths = 31,
} WorkerOp; } WorkerOp;

View File

@ -211,9 +211,12 @@ static int comparePriorities(EvalState & state,
static bool isPrebuilt(EvalState & state, const DrvInfo & elem) static bool isPrebuilt(EvalState & state, const DrvInfo & elem)
{ {
assert(false);
#if 0
return return
store->isValidPath(elem.queryOutPath(state)) || store->isValidPath(elem.queryOutPath(state)) ||
store->hasSubstitutes(elem.queryOutPath(state)); store->hasSubstitutes(elem.queryOutPath(state));
#endif
} }
@ -931,8 +934,7 @@ static void opQuery(Globals & globals,
/* Query which paths have substitutes. */ /* Query which paths have substitutes. */
SubstitutablePathInfos subs; PathSet validPaths, substitutablePaths;
PathSet validPaths;
if (printStatus) { if (printStatus) {
PathSet paths; PathSet paths;
foreach (vector<DrvInfo>::iterator, i, elems2) foreach (vector<DrvInfo>::iterator, i, elems2)
@ -943,7 +945,7 @@ static void opQuery(Globals & globals,
i->setFailed(); i->setFailed();
} }
validPaths = store->queryValidPaths(paths); validPaths = store->queryValidPaths(paths);
store->querySubstitutablePathInfos(paths, subs); substitutablePaths = store->querySubstitutablePaths(paths);
} }
@ -969,7 +971,7 @@ static void opQuery(Globals & globals,
if (printStatus) { if (printStatus) {
Path outPath = i->queryOutPath(globals.state); Path outPath = i->queryOutPath(globals.state);
bool hasSubs = subs.find(outPath) != subs.end(); bool hasSubs = substitutablePaths.find(outPath) != substitutablePaths.end();
bool isInstalled = installed.find(outPath) != installed.end(); bool isInstalled = installed.find(outPath) != installed.end();
bool isValid = validPaths.find(outPath) != validPaths.end(); bool isValid = validPaths.find(outPath) != validPaths.end();
if (xmlOutput) { if (xmlOutput) {

View File

@ -309,12 +309,21 @@ static void performOp(unsigned int clientVersion,
case wopHasSubstitutes: { case wopHasSubstitutes: {
Path path = readStorePath(from); Path path = readStorePath(from);
startWork(); startWork();
bool result = store->hasSubstitutes(path); PathSet res = store->querySubstitutablePaths(singleton<PathSet>(path));
stopWork(); stopWork();
writeInt(result, to); writeInt(res.find(path) != res.end(), to);
break; break;
} }
case wopQuerySubstitutablePaths: {
PathSet paths = readStorePaths<PathSet>(from);
startWork();
PathSet res = store->querySubstitutablePaths(paths);
stopWork();
writeStrings(res, to);
break;
}
case wopQueryPathHash: { case wopQueryPathHash: {
Path path = readStorePath(from); Path path = readStorePath(from);
startWork(); startWork();