mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Pass network time down to Expire()
This commit is contained in:
parent
c7503654e8
commit
ebefb21c53
6 changed files with 14 additions and 11 deletions
|
@ -160,8 +160,11 @@ protected:
|
|||
/**
|
||||
* Removes any entries in the backend that have expired. Can be overridden by
|
||||
* derived classes.
|
||||
*
|
||||
* @param current_network_time The network time as of the start of the
|
||||
* expiration operation.
|
||||
*/
|
||||
void Expire() { DoExpire(); }
|
||||
void Expire(double current_network_time) { DoExpire(current_network_time); }
|
||||
|
||||
/**
|
||||
* Enqueues the Storage::backend_opened event. This is called automatically
|
||||
|
@ -192,7 +195,7 @@ private:
|
|||
virtual OperationResult DoGet(ValPtr key, OperationResultCallback* cb = nullptr) = 0;
|
||||
virtual OperationResult DoErase(ValPtr key, OperationResultCallback* cb = nullptr) = 0;
|
||||
virtual void DoPoll() {}
|
||||
virtual void DoExpire() {}
|
||||
virtual void DoExpire(double current_network_time) {}
|
||||
|
||||
uint8_t modes;
|
||||
};
|
||||
|
|
|
@ -113,9 +113,10 @@ void Manager::Expire() {
|
|||
|
||||
DBG_LOG(DBG_STORAGE, "Expiration running, have %zu backends to check", backends.size());
|
||||
|
||||
double current_network_time = run_state::network_time;
|
||||
for ( auto it = backends.begin(); it != backends.end() && ! run_state::terminating; ++it ) {
|
||||
if ( (*it)->IsOpen() )
|
||||
(*it)->Expire();
|
||||
(*it)->Expire(current_network_time);
|
||||
}
|
||||
|
||||
expire_running.clear();
|
||||
|
|
|
@ -351,7 +351,7 @@ OperationResult Redis::DoErase(ValPtr key, OperationResultCallback* cb) {
|
|||
return {ReturnCode::IN_PROGRESS};
|
||||
}
|
||||
|
||||
void Redis::DoExpire() {
|
||||
void Redis::DoExpire(double current_network_time) {
|
||||
// Expiration is handled natively by Redis if not reading traces.
|
||||
if ( ! connected || ! zeek::run_state::reading_traces )
|
||||
return;
|
||||
|
@ -361,7 +361,7 @@ void Redis::DoExpire() {
|
|||
during_expire = true;
|
||||
|
||||
int status = redisAsyncCommand(async_ctx, redisGeneric, NULL, "ZRANGEBYSCORE %s_expire -inf %f", key_prefix.data(),
|
||||
run_state::network_time);
|
||||
current_network_time);
|
||||
|
||||
if ( status == REDIS_ERR ) {
|
||||
// TODO: do something with the error?
|
||||
|
@ -407,7 +407,7 @@ void Redis::DoExpire() {
|
|||
|
||||
// Remove all of the elements from the range-set that match the time range.
|
||||
redisAsyncCommand(async_ctx, redisGeneric, NULL, "ZREMRANGEBYSCORE %s_expire -inf %f", key_prefix.data(),
|
||||
run_state::network_time);
|
||||
current_network_time);
|
||||
|
||||
++active_ops;
|
||||
Poll();
|
||||
|
|
|
@ -54,7 +54,7 @@ private:
|
|||
OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoGet(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoErase(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
void DoExpire() override;
|
||||
void DoExpire(double current_network_time) override;
|
||||
void DoPoll() override;
|
||||
|
||||
OperationResult ParseGetReply(redisReply* reply) const;
|
||||
|
|
|
@ -234,11 +234,10 @@ OperationResult SQLite::DoErase(ValPtr key, OperationResultCallback* cb) {
|
|||
* Removes any entries in the backend that have expired. Can be overridden by
|
||||
* derived classes.
|
||||
*/
|
||||
void SQLite::DoExpire() {
|
||||
void SQLite::DoExpire(double current_network_time) {
|
||||
auto stmt = expire_stmt.get();
|
||||
|
||||
if ( auto res = CheckError(sqlite3_bind_double(stmt, 1, run_state::network_time));
|
||||
res.code != ReturnCode::SUCCESS ) {
|
||||
if ( auto res = CheckError(sqlite3_bind_double(stmt, 1, current_network_time)); res.code != ReturnCode::SUCCESS ) {
|
||||
sqlite3_reset(stmt);
|
||||
// TODO: do something with the error here?
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ private:
|
|||
OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoGet(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoErase(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
void DoExpire() override;
|
||||
void DoExpire(double current_network_time) override;
|
||||
|
||||
/**
|
||||
* Checks whether a status code returned by an sqlite call is a success.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue