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();
138 std::optional<AssociatedCredentials> association;
146 const Path schemaPath;
147 const Path tempRootsDir;
148 const Path fnTempRoots;
158 void associateWithCredentials(uid_t user, gid_t group)
160 association = {user, group};
165 const PublicKeys & getPublicKeys();
176 LocalStore(std::string scheme, std::string path, LocalStoreConfig config);
187 static std::set<std::string> uriSchemes()
193 static ref<LocalStore>
makeLocalStore(
const StoreConfig::Params & params);
199 std::string
getUri()
override;
201 kj::Promise<Result<bool>> isValidPathUncached(
const StorePath & path)
override;
203 kj::Promise<Result<StorePathSet>>
queryValidPaths(
const StorePathSet & paths,
204 SubstituteFlag maybeSubstitute = NoSubstitute)
override;
208 kj::Promise<Result<std::shared_ptr<const ValidPathInfo>>>
211 kj::Promise<Result<void>>
212 queryReferrers(
const StorePath & path, StorePathSet & referrers)
override;
214 kj::Promise<Result<StorePathSet>>
queryValidDerivers(
const StorePath & path)
override;
216 kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
219 kj::Promise<Result<std::optional<StorePath>>>
225 bool realisationIsUntrusted(
const Realisation & )
override;
227 kj::Promise<Result<void>>
addToStore(
const ValidPathInfo & info, AsyncInputStream & source,
228 RepairFlag repair, CheckSigsFlag checkSigs)
override;
231 AsyncInputStream & dump,
232 std::string_view name,
233 FileIngestionMethod method,
236 const StorePathSet & references
240 std::string_view name,
242 const StorePathSet & references,
243 RepairFlag repair)
override;
245 kj::Promise<Result<void>>
addTempRoot(
const StorePath & path)
override;
249 void createTempRootsFile();
254 Sync<AutoCloseFD> _fdTempRoots;
259 Sync<AutoCloseFD> _fdGCLock;
264 Sync<AutoCloseFD> _fdRootsSocket;
278 void findTempRoots(Roots & roots,
bool censor);
280 AutoCloseFD openGCLock();
284 kj::Promise<Result<Roots>>
findRoots(
bool censor)
override;
286 kj::Promise<Result<void>>
287 collectGarbage(
const GCOptions & options, GCResults & results)
override;
293 kj::Promise<Result<void>>
optimiseStore(OptimiseStats & stats);
301 void optimisePath(
const Path & path, RepairFlag repair);
303 kj::Promise<Result<bool>>
verifyStore(
bool checkContents, RepairFlag repair)
override;
315 kj::Promise<Result<void>> registerValidPaths(
const ValidPathInfos & infos);
317 kj::Promise<Result<unsigned int>>
getProtocol()
override;
319 kj::Promise<Result<std::optional<TrustedFlag>>>
isTrustedClient()
override;
321 kj::Promise<Result<void>>
322 addSignatures(
const StorePath & storePath,
const StringSet & sigs)
override;
328 kj::Promise<Result<void>>
autoGC(
bool sync =
true);
335 kj::Promise<Result<void>>
337 void cacheDrvOutputMapping(
339 const uint64_t deriver,
340 const std::string & outputName,
341 const StorePath & output);
343 std::optional<const Realisation> queryRealisation_(DBState & state,
const DrvOutput &
id);
344 std::optional<std::pair<int64_t, Realisation>> queryRealisationCore_(DBState & state,
const DrvOutput &
id);
345 kj::Promise<Result<std::shared_ptr<const Realisation>>>
346 queryRealisationUncached(
const DrvOutput&)
override;
348 kj::Promise<Result<std::optional<std::string>>> getVersion()
override;
358 void initDB(DBState & state);
359 void openDB(DBState & state,
bool create);
360 void prepareStatements(DBState & state);
362 void makeStoreWritable();
364 uint64_t queryValidPathId(DBState & state,
const StorePath & path);
366 kj::Promise<Result<uint64_t>>
367 addValidPath(DBState & state,
const ValidPathInfo & info,
bool checkOutputs =
true);
369 kj::Promise<Result<void>> invalidatePath(DBState & state,
const StorePath & path);
374 kj::Promise<Result<void>> invalidatePathChecked(
const StorePath & path);
376 kj::Promise<Result<void>> verifyPath(
const StorePath & path,
const StorePathSet & store,
377 StorePathSet & done, StorePathSet & validPaths, RepairFlag repair,
bool & errors);
379 std::shared_ptr<const ValidPathInfo> queryPathInfoInternal(DBState & state,
const StorePath & path);
381 void updatePathInfo(DBState & state,
const ValidPathInfo & info);
383 PathSet queryValidPathsOld();
384 ValidPathInfo queryPathInfoOld(
const Path & path);
386 kj::Promise<Result<void>>
findRoots(
const Path & path,
unsigned char type, Roots & roots);
388 kj::Promise<Result<void>> findRootsNoTemp(Roots & roots,
bool censor);
394 virtual void findPlatformRoots(UncheckedRoots & unchecked);
396 kj::Promise<Result<void>> findRuntimeRoots(Roots & roots,
bool censor);
398 std::pair<Path, AutoCloseFD> createTempDirInStore();
400 typedef std::unordered_set<ino_t> InodeHash;
402 InodeHash loadInodeHash();
403 Strings readDirectoryIgnoringInodes(
const Path & path,
const InodeHash & inodeHash);
404 void optimisePath_(Activity * act, OptimiseStats & stats,
const Path & path, InodeHash & inodeHash, RepairFlag repair);
407 bool isValidPath_(DBState & state,
const StorePath & path);
408 void queryReferrers(DBState & state,
const StorePath & path, StorePathSet & referrers);
414 void signPathInfo(ValidPathInfo & info);
415 void signRealisation(Realisation &);
418 ContentAddress hashCAPath(
419 const ContentAddressMethod & method,
420 const HashType & hashType,
421 const StorePath & path);
423 ContentAddress hashCAPath(
424 const ContentAddressMethod & method,
425 const HashType & hashType,
427 const std::string_view pathHash
430 kj::Promise<Result<void>> addBuildLog(
const StorePath & drvPath, std::string_view log)
override;
432 friend struct LocalDerivationGoal;
433 friend struct PathSubstitutionGoal;
434 friend struct SubstitutionGoal;
435 friend struct DerivationGoal;