1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 09:19:36 +01:00

Add fsync-store-paths option

- Add recursiveSync function to flush a directory tree to disk

- Add AutoCloseFD::startFsync to initiate an asynchronous fsync
  without waiting for the result

- Initiate an asynchronous fsync while extracting NAR files

- Implement the fsync-store-paths option in LocalStore
This commit is contained in:
squalus 2022-10-04 00:47:43 -07:00
parent 1437582ccd
commit 5987fb7459
7 changed files with 102 additions and 10 deletions

View file

@ -1299,7 +1299,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
TeeSource wrapperSource { source, hashSink };
restorePath(realPath, wrapperSource);
restorePath(realPath, wrapperSource, settings.fsyncStorePaths);
auto hashResult = hashSink.finish();
@ -1342,6 +1342,11 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
optimisePath(realPath, repair); // FIXME: combine with hashPath()
if (settings.fsyncStorePaths) {
recursiveSync(realPath);
syncParent(realPath);
}
registerValidPath(info);
}
@ -1402,7 +1407,7 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
tempPath = tempDir + "/x";
if (method == FileIngestionMethod::Recursive)
restorePath(tempPath, bothSource);
restorePath(tempPath, bothSource, settings.fsyncStorePaths);
else
writeFile(tempPath, bothSource);
@ -1434,7 +1439,7 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
StringSource dumpSource { dump };
/* Restore from the NAR in memory. */
if (method == FileIngestionMethod::Recursive)
restorePath(realPath, dumpSource);
restorePath(realPath, dumpSource, settings.fsyncStorePaths);
else
writeFile(realPath, dumpSource);
} else {
@ -1459,6 +1464,12 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
info.narSize = narHash.second;
info.references = references;
info.ca = FixedOutputHash { .method = method, .hash = hash };
if (settings.fsyncStorePaths) {
recursiveSync(realPath);
syncParent(realPath);
}
registerValidPath(info);
}
@ -1491,7 +1502,7 @@ StorePath LocalStore::addTextToStore(
autoGC();
writeFile(realPath, s);
writeFile(realPath, s, 0666, settings.fsyncStorePaths);
canonicalisePathMetaData(realPath, {});
@ -1505,6 +1516,10 @@ StorePath LocalStore::addTextToStore(
info.narSize = sink.s.size();
info.references = references;
info.ca = TextHash { .hash = hash };
if (settings.fsyncStorePaths)
syncParent(realPath);
registerValidPath(info);
}