diff --git a/CHANGES b/CHANGES index 1f8800343b..4e02b55909 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +8.1.0-dev.555 | 2025-09-17 08:44:43 -0700 + + * Avoid starting up storage expiration thread with zero backends (Tim Wojtulewicz, Corelight) + + * Remove a couple of obsolete TODOs in storage manager (Tim Wojtulewicz, Corelight) + 8.1.0-dev.552 | 2025-09-16 13:31:39 -0700 * Reword comment about when ZeroMQ is required for the build (Tim Wojtulewicz, Corelight) diff --git a/VERSION b/VERSION index d9dc82e0fd..61d9136c9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.1.0-dev.552 +8.1.0-dev.555 diff --git a/src/storage/Manager.cc b/src/storage/Manager.cc index d07764238d..95cc48d3cc 100644 --- a/src/storage/Manager.cc +++ b/src/storage/Manager.cc @@ -22,7 +22,7 @@ void detail::ExpirationTimer::Dispatch(double t, bool is_expire) { // start another one running. If this causes us to skip a cycle, that's not // a big deal as the next cycle will catch anything that should be expired // in the interim. - if ( ! expire_running.test_and_set() ) { + if ( ! expire_running.test_and_set() && storage_mgr->BackendCount() > 0 ) { DBG_LOG(DBG_STORAGE, "Starting new expiration thread"); storage_mgr->expiration_thread = zeek::jthread([t]() { storage_mgr->Expire(t); }); } @@ -100,8 +100,6 @@ OperationResult Manager::OpenBackend(BackendPtr backend, OpenResultCallback* cb, RegisterBackend(std::move(backend)); - // TODO: post Storage::backend_opened event - return res; } @@ -116,11 +114,7 @@ OperationResult Manager::CloseBackend(BackendPtr backend, ResultCallback* cb) { backends.erase(it); } - auto res = backend->Close(cb); - - // TODO: post Storage::backend_lost event - - return res; + return backend->Close(cb); } void Manager::Expire(double t) { @@ -152,4 +146,11 @@ void Manager::RegisterBackend(BackendPtr backend) { DBG_LOG(DBG_STORAGE, "Registered backends: %zu", backends.size()); } +size_t Manager::BackendCount() { + // Expiration runs on a separate thread and loops over the vector of backends. The mutex + // here ensures exclusive access. + std::unique_lock lk(backends_mtx); + return backends.size(); +} + } // namespace zeek::storage diff --git a/src/storage/Manager.h b/src/storage/Manager.h index f918f5b215..25d7554a75 100644 --- a/src/storage/Manager.h +++ b/src/storage/Manager.h @@ -113,6 +113,7 @@ protected: friend class storage::detail::ExpirationTimer; void RunExpireThread(); void StartExpirationTimer(); + size_t BackendCount(); zeek::jthread expiration_thread; friend class storage::OpenResultCallback; diff --git a/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek b/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek index 7be028e0e8..6931d1fe51 100644 --- a/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek +++ b/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek @@ -4,7 +4,7 @@ # @TEST-PORT: REDIS_PORT # @TEST-EXEC: btest-bg-run redis-server run-redis-server ${REDIS_PORT%/tcp} -# @TEST-EXEC: zcat <$TRACES/echo-connections.pcap.gz | zeek -B storage -b -r - %INPUT > out +# @TEST-EXEC: zeek -B storage -b %INPUT > out # @TEST-EXEC: btest-bg-wait -k 1 # @TEST-EXEC: btest-diff out