95 std::unique_ptr<const PublicKeys> publicKeys =
nullptr;
96 std::once_flag publicKeysFlag;
106 std::unique_ptr<Stmts> stmts;
117 std::chrono::time_point<std::chrono::steady_clock> lastGCCheck;
123 bool gcRunning =
false;
124 std::future<void> gcFuture;
125 std::list<kj::Own<kj::CrossThreadPromiseFulfiller<void>>> gcWaiters;
133 uint64_t availAfterGC = std::numeric_limits<uint64_t>::max();
144 const Path schemaPath;
145 const Path tempRootsDir;
146 const Path fnTempRoots;
153 const PublicKeys & getPublicKeys();
164 LocalStore(std::string scheme, std::string path, LocalStoreConfig config);
175 static std::set<std::string> uriSchemes()
181 static std::shared_ptr<LocalStore>
makeLocalStore(
const StoreConfig::Params & params);
187 std::string
getUri()
override;
189 kj::Promise<Result<bool>> isValidPathUncached(
const StorePath & path)
override;
191 kj::Promise<Result<StorePathSet>>
queryValidPaths(
const StorePathSet & paths,
192 SubstituteFlag maybeSubstitute = NoSubstitute)
override;
196 kj::Promise<Result<std::shared_ptr<const ValidPathInfo>>>
199 kj::Promise<Result<void>>
200 queryReferrers(
const StorePath & path, StorePathSet & referrers)
override;
202 kj::Promise<Result<StorePathSet>>
queryValidDerivers(
const StorePath & path)
override;
204 kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
207 kj::Promise<Result<std::optional<StorePath>>>
213 bool realisationIsUntrusted(
const Realisation & )
override;
215 kj::Promise<Result<void>>
addToStore(
const ValidPathInfo & info, AsyncInputStream & source,
216 RepairFlag repair, CheckSigsFlag checkSigs)
override;
219 AsyncInputStream & dump,
220 std::string_view name,
221 FileIngestionMethod method,
224 const StorePathSet & references
228 std::string_view name,
230 const StorePathSet & references,
231 RepairFlag repair)
override;
233 kj::Promise<Result<void>>
addTempRoot(
const StorePath & path)
override;
237 void createTempRootsFile();
242 Sync<AutoCloseFD> _fdTempRoots;
247 Sync<AutoCloseFD> _fdGCLock;
252 Sync<AutoCloseFD> _fdRootsSocket;
266 void findTempRoots(Roots & roots,
bool censor);
268 AutoCloseFD openGCLock();
272 kj::Promise<Result<Roots>>
findRoots(
bool censor)
override;
274 kj::Promise<Result<void>>
275 collectGarbage(
const GCOptions & options, GCResults & results)
override;
281 kj::Promise<Result<void>>
optimiseStore(OptimiseStats & stats);
289 void optimisePath(
const Path & path, RepairFlag repair);
291 kj::Promise<Result<bool>>
verifyStore(
bool checkContents, RepairFlag repair)
override;
303 kj::Promise<Result<void>> registerValidPaths(
const ValidPathInfos & infos);
305 kj::Promise<Result<unsigned int>>
getProtocol()
override;
307 kj::Promise<Result<std::optional<TrustedFlag>>>
isTrustedClient()
override;
309 kj::Promise<Result<void>>
310 addSignatures(
const StorePath & storePath,
const StringSet & sigs)
override;
316 kj::Promise<Result<void>>
autoGC(
bool sync =
true);
323 kj::Promise<Result<void>>
325 void cacheDrvOutputMapping(
327 const uint64_t deriver,
328 const std::string & outputName,
329 const StorePath & output);
331 std::optional<const Realisation> queryRealisation_(DBState & state,
const DrvOutput &
id);
332 std::optional<std::pair<int64_t, Realisation>> queryRealisationCore_(DBState & state,
const DrvOutput &
id);
333 kj::Promise<Result<std::shared_ptr<const Realisation>>>
334 queryRealisationUncached(
const DrvOutput&)
override;
336 kj::Promise<Result<std::optional<std::string>>> getVersion()
override;
346 void initDB(DBState & state);
347 void openDB(DBState & state,
bool create);
348 void prepareStatements(DBState & state);
350 void makeStoreWritable();
352 uint64_t queryValidPathId(DBState & state,
const StorePath & path);
354 kj::Promise<Result<uint64_t>>
355 addValidPath(DBState & state,
const ValidPathInfo & info,
bool checkOutputs =
true);
357 kj::Promise<Result<void>> invalidatePath(DBState & state,
const StorePath & path);
362 kj::Promise<Result<void>> invalidatePathChecked(
const StorePath & path);
364 kj::Promise<Result<void>> verifyPath(
const StorePath & path,
const StorePathSet & store,
365 StorePathSet & done, StorePathSet & validPaths, RepairFlag repair,
bool & errors);
367 std::shared_ptr<const ValidPathInfo> queryPathInfoInternal(DBState & state,
const StorePath & path);
369 void updatePathInfo(DBState & state,
const ValidPathInfo & info);
371 PathSet queryValidPathsOld();
372 ValidPathInfo queryPathInfoOld(
const Path & path);
374 kj::Promise<Result<void>>
findRoots(
const Path & path,
unsigned char type, Roots & roots);
376 kj::Promise<Result<void>> findRootsNoTemp(Roots & roots,
bool censor);
382 virtual void findPlatformRoots(UncheckedRoots & unchecked);
384 kj::Promise<Result<void>> findRuntimeRoots(Roots & roots,
bool censor);
386 std::pair<Path, AutoCloseFD> createTempDirInStore();
388 typedef std::unordered_set<ino_t> InodeHash;
390 InodeHash loadInodeHash();
391 Strings readDirectoryIgnoringInodes(
const Path & path,
const InodeHash & inodeHash);
392 void optimisePath_(Activity * act, OptimiseStats & stats,
const Path & path, InodeHash & inodeHash, RepairFlag repair);
395 bool isValidPath_(DBState & state,
const StorePath & path);
396 void queryReferrers(DBState & state,
const StorePath & path, StorePathSet & referrers);
402 void signPathInfo(ValidPathInfo & info);
403 void signRealisation(Realisation &);
406 ContentAddress hashCAPath(
407 const ContentAddressMethod & method,
408 const HashType & hashType,
409 const StorePath & path);
411 ContentAddress hashCAPath(
412 const ContentAddressMethod & method,
413 const HashType & hashType,
415 const std::string_view pathHash
418 kj::Promise<Result<void>> addBuildLog(
const StorePath & drvPath, std::string_view log)
override;
420 friend struct LocalDerivationGoal;
421 friend struct PathSubstitutionGoal;
422 friend struct SubstitutionGoal;
423 friend struct DerivationGoal;