mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 01:58:20 +00:00
Always register backend for expiration, check for open during loop
This commit is contained in:
parent
28951dccf1
commit
64f3969434
3 changed files with 9 additions and 11 deletions
|
@ -62,13 +62,10 @@ OpenResultCallback::OpenResultCallback(IntrusivePtr<zeek::detail::trigger::Trigg
|
||||||
void OpenResultCallback::Complete(const ErrorResult& res) {
|
void OpenResultCallback::Complete(const ErrorResult& res) {
|
||||||
zeek::Val* result;
|
zeek::Val* result;
|
||||||
|
|
||||||
if ( res ) {
|
if ( res )
|
||||||
result = new StringVal(res.value());
|
result = new StringVal(res.value());
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
storage_mgr->AddBackendToMap(backend->backend);
|
|
||||||
result = backend;
|
result = backend;
|
||||||
}
|
|
||||||
|
|
||||||
ValComplete(result);
|
ValComplete(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,7 @@ ErrorResult Manager::OpenBackend(BackendPtr backend, RecordValPtr options, TypeP
|
||||||
return util::fmt("Failed to open backend %s: %s", backend->Tag(), res.value().c_str());
|
return util::fmt("Failed to open backend %s: %s", backend->Tag(), res.value().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! cb )
|
RegisterBackend(std::move(backend));
|
||||||
AddBackendToMap(std::move(backend));
|
|
||||||
|
|
||||||
// TODO: post Storage::backend_opened event
|
// TODO: post Storage::backend_opened event
|
||||||
|
|
||||||
|
@ -83,8 +82,10 @@ ErrorResult Manager::CloseBackend(BackendPtr backend, ErrorResultCallback* cb) {
|
||||||
void Manager::Expire() {
|
void Manager::Expire() {
|
||||||
DBG_LOG(DBG_STORAGE, "Expire running, have %zu backends to check", backends.size());
|
DBG_LOG(DBG_STORAGE, "Expire running, have %zu backends to check", backends.size());
|
||||||
std::unique_lock<std::mutex> lk(backends_mtx);
|
std::unique_lock<std::mutex> lk(backends_mtx);
|
||||||
for ( const auto& b : backends )
|
for ( const auto& b : backends ) {
|
||||||
b->Expire();
|
if ( b->IsOpen() )
|
||||||
|
b->Expire();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::StartExpirationTimer() {
|
void Manager::StartExpirationTimer() {
|
||||||
|
@ -92,7 +93,7 @@ void Manager::StartExpirationTimer() {
|
||||||
new detail::ExpirationTimer(run_state::network_time + zeek::BifConst::Storage::expire_interval));
|
new detail::ExpirationTimer(run_state::network_time + zeek::BifConst::Storage::expire_interval));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::AddBackendToMap(BackendPtr backend) {
|
void Manager::RegisterBackend(BackendPtr backend) {
|
||||||
std::unique_lock<std::mutex> lk(backends_mtx);
|
std::unique_lock<std::mutex> lk(backends_mtx);
|
||||||
backends.push_back(std::move(backend));
|
backends.push_back(std::move(backend));
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ protected:
|
||||||
void StartExpirationTimer();
|
void StartExpirationTimer();
|
||||||
|
|
||||||
friend class storage::OpenResultCallback;
|
friend class storage::OpenResultCallback;
|
||||||
void AddBackendToMap(BackendPtr backend);
|
void RegisterBackend(BackendPtr backend);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<BackendPtr> backends;
|
std::vector<BackendPtr> backends;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue