Skip to content

Commit 09a6321

Browse files
committed
Replace hasSubstitutes() with querySubstitutablePaths()
querySubstitutablePaths() takes a set of paths, so this greatly reduces daemon <-> client latency.
1 parent 58ef4d9 commit 09a6321

File tree

8 files changed

+52
-24
lines changed

8 files changed

+52
-24
lines changed

src/libstore/local-store.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -932,16 +932,24 @@ template<class T> T getIntLine(int fd)
932932
}
933933

934934

935-
bool LocalStore::hasSubstitutes(const Path & path)
935+
PathSet LocalStore::querySubstitutablePaths(const PathSet & paths)
936936
{
937+
PathSet res;
937938
foreach (Paths::iterator, i, substituters) {
939+
if (res.size() == paths.size()) break;
938940
RunningSubstituter & run(runningSubstituters[*i]);
939941
startSubstituter(*i, run);
940-
writeLine(run.to, "have\n" + path);
941-
if (getIntLine<int>(run.from)) return true;
942+
string s = "have ";
943+
foreach (PathSet::const_iterator, i, paths)
944+
if (res.find(*i) == res.end()) { s += *i; s += " "; }
945+
writeLine(run.to, s);
946+
while (true) {
947+
Path path = readLine(run.from);
948+
if (path == "") break;
949+
res.insert(path);
950+
}
942951
}
943-
944-
return false;
952+
return res;
945953
}
946954

947955

src/libstore/local-store.hh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ public:
123123

124124
StringSet queryDerivationOutputNames(const Path & path);
125125

126-
PathSet querySubstitutablePaths();
127-
128-
bool hasSubstitutes(const Path & path);
126+
PathSet querySubstitutablePaths(const PathSet & paths);
129127

130128
void querySubstitutablePathInfos(const Path & substituter,
131129
PathSet & paths, SubstitutablePathInfos & infos);

src/libstore/remote-store.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ bool RemoteStore::isValidPath(const Path & path)
219219

220220
PathSet RemoteStore::queryValidPaths(const PathSet & paths)
221221
{
222+
openConnection();
222223
if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
223224
PathSet res;
224225
foreach (PathSet::const_iterator, i, paths)
225226
if (isValidPath(*i)) res.insert(*i);
226227
return res;
227228
} else {
228-
openConnection();
229229
writeInt(wopQueryValidPaths, to);
230230
writeStrings(paths, to);
231231
processStderr();
@@ -243,14 +243,24 @@ PathSet RemoteStore::queryAllValidPaths()
243243
}
244244

245245

246-
bool RemoteStore::hasSubstitutes(const Path & path)
246+
PathSet RemoteStore::querySubstitutablePaths(const PathSet & paths)
247247
{
248248
openConnection();
249-
writeInt(wopHasSubstitutes, to);
250-
writeString(path, to);
251-
processStderr();
252-
unsigned int reply = readInt(from);
253-
return reply != 0;
249+
if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
250+
PathSet res;
251+
foreach (PathSet::const_iterator, i, paths) {
252+
writeInt(wopHasSubstitutes, to);
253+
writeString(*i, to);
254+
processStderr();
255+
if (readInt(from)) res.insert(*i);
256+
}
257+
return res;
258+
} else {
259+
writeInt(wopQuerySubstitutablePaths, to);
260+
writeStrings(paths, to);
261+
processStderr();
262+
return readStorePaths<PathSet>(from);
263+
}
254264
}
255265

256266

src/libstore/remote-store.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public:
4545

4646
StringSet queryDerivationOutputNames(const Path & path);
4747

48-
bool hasSubstitutes(const Path & path);
48+
PathSet querySubstitutablePaths(const PathSet & paths);
4949

5050
void querySubstitutablePathInfos(const PathSet & paths,
5151
SubstitutablePathInfos & infos);

src/libstore/store-api.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public:
145145
/* Query the output names of the derivation denoted by `path'. */
146146
virtual StringSet queryDerivationOutputNames(const Path & path) = 0;
147147

148-
/* Query whether a path has substitutes. */
149-
virtual bool hasSubstitutes(const Path & path) = 0;
148+
/* Query which of the given paths have substitutes. */
149+
virtual PathSet querySubstitutablePaths(const PathSet & paths) = 0;
150150

151151
/* Query substitute info (i.e. references, derivers and download
152152
sizes) of a set of paths. If a path does not have substitute

src/libstore/worker-protocol.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef enum {
4242
wopQueryDerivationOutputNames = 28,
4343
wopQuerySubstitutablePathInfos = 29,
4444
wopQueryValidPaths = 30,
45+
wopQuerySubstitutablePaths = 31,
4546
} WorkerOp;
4647

4748

src/nix-env/nix-env.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ static int comparePriorities(EvalState & state,
211211

212212
static bool isPrebuilt(EvalState & state, const DrvInfo & elem)
213213
{
214+
assert(false);
215+
#if 0
214216
return
215217
store->isValidPath(elem.queryOutPath(state)) ||
216218
store->hasSubstitutes(elem.queryOutPath(state));
219+
#endif
217220
}
218221

219222

@@ -931,8 +934,7 @@ static void opQuery(Globals & globals,
931934

932935

933936
/* Query which paths have substitutes. */
934-
SubstitutablePathInfos subs;
935-
PathSet validPaths;
937+
PathSet validPaths, substitutablePaths;
936938
if (printStatus) {
937939
PathSet paths;
938940
foreach (vector<DrvInfo>::iterator, i, elems2)
@@ -943,7 +945,7 @@ static void opQuery(Globals & globals,
943945
i->setFailed();
944946
}
945947
validPaths = store->queryValidPaths(paths);
946-
store->querySubstitutablePathInfos(paths, subs);
948+
substitutablePaths = store->querySubstitutablePaths(paths);
947949
}
948950

949951

@@ -969,7 +971,7 @@ static void opQuery(Globals & globals,
969971

970972
if (printStatus) {
971973
Path outPath = i->queryOutPath(globals.state);
972-
bool hasSubs = subs.find(outPath) != subs.end();
974+
bool hasSubs = substitutablePaths.find(outPath) != substitutablePaths.end();
973975
bool isInstalled = installed.find(outPath) != installed.end();
974976
bool isValid = validPaths.find(outPath) != validPaths.end();
975977
if (xmlOutput) {

src/nix-worker/nix-worker.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,21 @@ static void performOp(unsigned int clientVersion,
309309
case wopHasSubstitutes: {
310310
Path path = readStorePath(from);
311311
startWork();
312-
bool result = store->hasSubstitutes(path);
312+
PathSet res = store->querySubstitutablePaths(singleton<PathSet>(path));
313313
stopWork();
314-
writeInt(result, to);
314+
writeInt(res.find(path) != res.end(), to);
315315
break;
316316
}
317317

318+
case wopQuerySubstitutablePaths: {
319+
PathSet paths = readStorePaths<PathSet>(from);
320+
startWork();
321+
PathSet res = store->querySubstitutablePaths(paths);
322+
stopWork();
323+
writeStrings(res, to);
324+
break;
325+
}
326+
318327
case wopQueryPathHash: {
319328
Path path = readStorePath(from);
320329
startWork();

0 commit comments

Comments
 (0)