mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Add infrastructure for automated expiration of storage entries
This is used for backends that don't support expiration natively.
This commit is contained in:
parent
8dee733a7d
commit
d07d27453a
12 changed files with 96 additions and 21 deletions
|
@ -4,11 +4,24 @@
|
|||
|
||||
#include "zeek/Desc.h"
|
||||
|
||||
#include "const.bif.netvar_h"
|
||||
|
||||
namespace zeek::storage {
|
||||
|
||||
void detail::ExpirationTimer::Dispatch(double t, bool is_expire) {
|
||||
if ( is_expire )
|
||||
return;
|
||||
|
||||
storage_mgr->Expire();
|
||||
storage_mgr->StartExpirationTimer();
|
||||
}
|
||||
|
||||
Manager::Manager() : plugin::ComponentManager<storage::Component>("Storage", "Backend") {}
|
||||
|
||||
void Manager::InitPostScript() { detail::backend_opaque = make_intrusive<OpaqueType>("Storage::Backend"); }
|
||||
void Manager::InitPostScript() {
|
||||
detail::backend_opaque = make_intrusive<OpaqueType>("Storage::Backend");
|
||||
StartExpirationTimer();
|
||||
}
|
||||
|
||||
zeek::expected<BackendPtr, std::string> Manager::OpenBackend(const Tag& type, RecordValPtr options, TypePtr key_type,
|
||||
TypePtr val_type) {
|
||||
|
@ -40,20 +53,39 @@ zeek::expected<BackendPtr, std::string> Manager::OpenBackend(const Tag& type, Re
|
|||
|
||||
// TODO: post Storage::backend_opened event
|
||||
|
||||
backends.push_back(bp);
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(backends_mtx);
|
||||
backends.push_back(bp);
|
||||
}
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
void Manager::CloseBackend(BackendPtr backend) {
|
||||
auto it = std::find(backends.begin(), backends.end(), backend);
|
||||
if ( it == backends.end() )
|
||||
return;
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(backends_mtx);
|
||||
auto it = std::find(backends.begin(), backends.end(), backend);
|
||||
if ( it == backends.end() )
|
||||
return;
|
||||
|
||||
backends.erase(it);
|
||||
}
|
||||
|
||||
backends.erase(it);
|
||||
backend->Close();
|
||||
|
||||
// TODO: post Storage::backend_lost event
|
||||
}
|
||||
|
||||
void Manager::Expire() {
|
||||
DBG_LOG(DBG_STORAGE, "Expire running, have %zu backends to check", backends.size());
|
||||
std::unique_lock<std::mutex> lk(backends_mtx);
|
||||
for ( const auto& b : backends )
|
||||
b->Expire();
|
||||
}
|
||||
|
||||
void Manager::StartExpirationTimer() {
|
||||
zeek::detail::timer_mgr->Add(
|
||||
new detail::ExpirationTimer(run_state::network_time + zeek::BifConst::Storage::expire_interval));
|
||||
}
|
||||
|
||||
} // namespace zeek::storage
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue