1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 07:11:47 +02: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

@ -306,6 +306,9 @@ struct RestoreSink : ParseSink
{
Path dstPath;
AutoCloseFD fd;
bool startFsync;
explicit RestoreSink(bool startFsync) : startFsync{startFsync} {}
void createDirectory(const Path & path) override
{
@ -323,6 +326,10 @@ struct RestoreSink : ParseSink
void closeRegularFile() override
{
/* Initiate an fsync operation without waiting for the result. The real fsync should be run before registering
a store path, but this is a performance optimization to allow the disk write to start early. */
if (startFsync)
fd.startFsync();
/* Call close explicitly to make sure the error is checked */
fd.close();
}
@ -367,9 +374,9 @@ struct RestoreSink : ParseSink
};
void restorePath(const Path & path, Source & source)
void restorePath(const Path & path, Source & source, bool startFsync)
{
RestoreSink sink;
RestoreSink sink { startFsync };
sink.dstPath = path;
parseDump(sink, source);
}