libstore: mark all non-local stores as thread-unsafe
this pretty much only impacts store verification via the nix3 cli. no other thread pools are left, and the verification pool may *actually* be important for throughput since verification involves much hashing. Change-Id: I32152e6169a82a1268a790e333f21a0430ede7f4
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "lix/libstore/derivations.hh"
|
||||
#include "lix/libstore/profiles.hh"
|
||||
#include "lix/libcmd/repl.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
|
||||
extern char * * environ __attribute__((weak));
|
||||
|
||||
@@ -39,14 +40,15 @@ StoreCommand::StoreCommand()
|
||||
|
||||
ref<Store> StoreCommand::getStore()
|
||||
{
|
||||
if (!_store)
|
||||
_store = createStore();
|
||||
if (!_store) {
|
||||
_store = createStore(aio());
|
||||
}
|
||||
return *_store;
|
||||
}
|
||||
|
||||
ref<Store> StoreCommand::createStore()
|
||||
ref<Store> StoreCommand::createStore(AsyncIoRoot & in)
|
||||
{
|
||||
return aio().blockOn(openStore());
|
||||
return in.blockOn(openStore());
|
||||
}
|
||||
|
||||
void StoreCommand::run()
|
||||
@@ -71,9 +73,9 @@ CopyCommand::CopyCommand()
|
||||
});
|
||||
}
|
||||
|
||||
ref<Store> CopyCommand::createStore()
|
||||
ref<Store> CopyCommand::createStore(AsyncIoRoot & in)
|
||||
{
|
||||
return srcUri.empty() ? StoreCommand::createStore() : aio().blockOn(openStore(srcUri));
|
||||
return srcUri.empty() ? StoreCommand::createStore(in) : in.blockOn(openStore(srcUri));
|
||||
}
|
||||
|
||||
ref<Store> CopyCommand::getDstStore()
|
||||
|
||||
@@ -39,7 +39,7 @@ struct StoreCommand : virtual Command
|
||||
StoreCommand();
|
||||
void run() override;
|
||||
ref<Store> getStore();
|
||||
virtual ref<Store> createStore();
|
||||
virtual ref<Store> createStore(AsyncIoRoot & in);
|
||||
/**
|
||||
* Main entry point, with a `Store` provided
|
||||
*/
|
||||
@@ -59,7 +59,7 @@ struct CopyCommand : virtual StoreCommand
|
||||
|
||||
CopyCommand();
|
||||
|
||||
ref<Store> createStore() override;
|
||||
ref<Store> createStore(AsyncIoRoot & in) override;
|
||||
|
||||
ref<Store> getDstStore();
|
||||
};
|
||||
|
||||
@@ -160,6 +160,11 @@ public:
|
||||
association = {user, group};
|
||||
}
|
||||
|
||||
bool isThreadSafe() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
const PublicKeys & getPublicKeys();
|
||||
|
||||
@@ -266,6 +266,18 @@ public:
|
||||
|
||||
virtual std::string getUri() = 0;
|
||||
|
||||
/**
|
||||
* whether this store can safely be used by multiple threads. Stores with
|
||||
* async state (such as network connections) cannot be thread-safe due to
|
||||
* kj async objects' thread binding. realistically only stores using only
|
||||
* file system state can be thread-safe, i.e. only our local stores. even
|
||||
* daemon stores can't be safe as they hold onto unix socket connections.
|
||||
*/
|
||||
virtual bool isThreadSafe() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
StorePath parseStorePath(std::string_view path) const;
|
||||
|
||||
std::optional<StorePath> maybeParseStorePath(std::string_view path) const;
|
||||
|
||||
@@ -85,6 +85,8 @@ struct CmdVerify : StorePathsCommand
|
||||
ThreadPool pool{"Verify pool"};
|
||||
|
||||
auto doPath = [&](AsyncIoRoot & aio, const StorePath & storePath) {
|
||||
thread_local auto store = getStore()->isThreadSafe() ? getStore() : createStore(aio);
|
||||
|
||||
try {
|
||||
MaintainCount<std::atomic<size_t>> mcActive(active);
|
||||
update();
|
||||
|
||||
Reference in New Issue
Block a user