From 8614cf13344eca75074cd4af20fd90238571b0b6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 16 Aug 2021 20:03:32 +0200 Subject: Non-blocking garbage collector The garbage collector no longer blocks other processes from adding/building store paths or adding GC roots. To prevent the collector from deleting store paths just added by another process, processes need to connect to the garbage collector via a Unix domain socket to register new temporary roots. --- src/libstore/local-store.hh | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/libstore/local-store.hh') diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 3b3f26162..85c6c4495 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -58,9 +58,15 @@ private: struct Stmts; std::unique_ptr stmts; + /* The global GC lock */ + AutoCloseFD fdGCLock; + /* The file to which we write our temporary roots. */ AutoCloseFD fdTempRoots; + /* Connection to the garbage collector. */ + AutoCloseFD fdRootsSocket; + /* The last time we checked whether to do an auto-GC, or an auto-GC finished. */ std::chrono::time_point lastGCCheck; @@ -150,10 +156,7 @@ public: private: - typedef std::shared_ptr FDPtr; - typedef list FDs; - - void findTempRoots(FDs & fds, Roots & roots, bool censor); + void findTempRoots(Roots & roots, bool censor); public: @@ -235,18 +238,11 @@ private: struct GCState; - void deleteGarbage(GCState & state, const Path & path); - - void tryToDelete(GCState & state, const Path & path); - - bool canReachRoot(GCState & state, StorePathSet & visited, const StorePath & path); - - void deletePathRecursive(GCState & state, const Path & path); - - bool isActiveTempFile(const GCState & state, - const Path & path, const string & suffix); - - AutoCloseFD openGCLock(LockType lockType); + bool tryToDelete( + GCState & state, + StorePathSet & visited, + const Path & path, + bool recursive); void findRoots(const Path & path, unsigned char type, Roots & roots); -- cgit v1.2.3