Cache connection failures
This commit is contained in:
parent
8490ee37a6
commit
d1158bb816
2 changed files with 18 additions and 1 deletions
|
@ -44,13 +44,26 @@ RemoteStore::RemoteStore(const Params & params)
|
|||
: Store(params)
|
||||
, connections(make_ref<Pool<Connection>>(
|
||||
std::max(1, std::stoi(get(params, "max-connections", "1"))),
|
||||
[this]() { return openConnection(); },
|
||||
[this]() { return openConnectionWrapper(); },
|
||||
[](const ref<Connection> & r) { return r->to.good() && r->from.good(); }
|
||||
))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper()
|
||||
{
|
||||
if (failed)
|
||||
throw Error("opening a connection to remote store ‘%s’ previously failed", getUri());
|
||||
try {
|
||||
return openConnection();
|
||||
} catch (...) {
|
||||
failed = true;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UDSRemoteStore::UDSRemoteStore(const Params & params)
|
||||
: Store(params)
|
||||
, LocalFSStore(params)
|
||||
|
|
|
@ -98,6 +98,8 @@ protected:
|
|||
void processStderr(Sink * sink = 0, Source * source = 0);
|
||||
};
|
||||
|
||||
ref<Connection> openConnectionWrapper();
|
||||
|
||||
virtual ref<Connection> openConnection() = 0;
|
||||
|
||||
void initConnection(Connection & conn);
|
||||
|
@ -106,6 +108,8 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
std::atomic_bool failed{false};
|
||||
|
||||
void setOptions(Connection & conn);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue