Skip to content

Commit 10c8d79

Browse files
authored
Merge pull request NixOS#12336 from NaN-git/fix-progress
libstore: Fix progress bars
2 parents 9837aff + be97dc1 commit 10c8d79

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/libstore/remote-store.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,21 @@ void RemoteStore::addMultipleToStore(
539539
RepairFlag repair,
540540
CheckSigsFlag checkSigs)
541541
{
542+
// `addMultipleToStore` is single threaded
543+
size_t bytesExpected = 0;
544+
for (auto & [pathInfo, _] : pathsToCopy) {
545+
bytesExpected += pathInfo.narSize;
546+
}
547+
act.setExpected(actCopyPath, bytesExpected);
548+
542549
auto source = sinkToSource([&](Sink & sink) {
543-
sink << pathsToCopy.size();
550+
size_t nrTotal = pathsToCopy.size();
551+
sink << nrTotal;
544552
// Reverse, so we can release memory at the original start
545553
std::reverse(pathsToCopy.begin(), pathsToCopy.end());
546554
while (!pathsToCopy.empty()) {
555+
act.progress(nrTotal - pathsToCopy.size(), nrTotal, size_t(1), size_t(0));
556+
547557
auto & [pathInfo, pathSource] = pathsToCopy.back();
548558
WorkerProto::Serialise<ValidPathInfo>::write(*this,
549559
WorkerProto::WriteConn {

src/libstore/store-api.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ void Store::addMultipleToStore(
242242
storePathsToAdd.insert(thingToAdd.first.path);
243243
}
244244

245-
auto showProgress = [&]() {
246-
act.progress(nrDone, pathsToCopy.size(), nrRunning, nrFailed);
245+
auto showProgress = [&, nrTotal = pathsToCopy.size()]() {
246+
act.progress(nrDone, nrTotal, nrRunning, nrFailed);
247247
};
248248

249249
processGraph<StorePath>(
@@ -1104,9 +1104,6 @@ std::map<StorePath, StorePath> copyPaths(
11041104
return storePathForDst;
11051105
};
11061106

1107-
// total is accessed by each copy, which are each handled in separate threads
1108-
std::atomic<uint64_t> total = 0;
1109-
11101107
for (auto & missingPath : sortedMissing) {
11111108
auto info = srcStore.queryPathInfo(missingPath);
11121109

@@ -1116,9 +1113,10 @@ std::map<StorePath, StorePath> copyPaths(
11161113
ValidPathInfo infoForDst = *info;
11171114
infoForDst.path = storePathForDst;
11181115

1119-
auto source = sinkToSource([&](Sink & sink) {
1116+
auto source = sinkToSource([&, narSize = info->narSize](Sink & sink) {
11201117
// We can reasonably assume that the copy will happen whenever we
11211118
// read the path, so log something about that at that point
1119+
uint64_t total = 0;
11221120
auto srcUri = srcStore.getUri();
11231121
auto dstUri = dstStore.getUri();
11241122
auto storePathS = srcStore.printStorePath(missingPath);
@@ -1129,13 +1127,13 @@ std::map<StorePath, StorePath> copyPaths(
11291127

11301128
LambdaSink progressSink([&](std::string_view data) {
11311129
total += data.size();
1132-
act.progress(total, info->narSize);
1130+
act.progress(total, narSize);
11331131
});
11341132
TeeSink tee { sink, progressSink };
11351133

11361134
srcStore.narFromPath(missingPath, tee);
11371135
});
1138-
pathsToCopy.push_back(std::pair{infoForDst, std::move(source)});
1136+
pathsToCopy.emplace_back(std::move(infoForDst), std::move(source));
11391137
}
11401138

11411139
dstStore.addMultipleToStore(std::move(pathsToCopy), act, repair, checkSigs);

0 commit comments

Comments
 (0)