diff --git a/src/storage/Backend.h b/src/storage/Backend.h index 23331800e0..071ce1f507 100644 --- a/src/storage/Backend.h +++ b/src/storage/Backend.h @@ -71,7 +71,8 @@ public: * @param value the value for the pair. * @param overwrite whether an existing value for a key should be overwritten. * @param expiration_time the time when this entry should be automatically - * removed. Set to zero to disable expiration. + * removed. Set to zero to disable expiration. This time is based on the current network + * time. * @param cb An optional callback object if being called via an async context. * @return An optional value potentially containing an error string if * needed Will be unset if the operation succeeded. diff --git a/src/storage/backend/redis/Redis.cc b/src/storage/backend/redis/Redis.cc index 576edd801e..5e081b821f 100644 --- a/src/storage/backend/redis/Redis.cc +++ b/src/storage/backend/redis/Redis.cc @@ -209,12 +209,10 @@ ErrorResult Redis::DoPut(ValPtr key, ValPtr value, bool overwrite, double expira format.append(" NX"); // Use built-in expiration if reading live data, since time will move - // forward consistently. If reading pcaps, we'll do something else. + // forward consistently. If reading pcaps, we'll do something else. if ( expiration_time > 0.0 && ! zeek::run_state::reading_traces ) format.append(" PXAT %d"); - double expire_time = expiration_time + run_state::network_time; - auto json_key = key->ToJSON()->ToStdString(); auto json_value = value->ToJSON()->ToStdString(); @@ -222,7 +220,7 @@ ErrorResult Redis::DoPut(ValPtr key, ValPtr value, bool overwrite, double expira int status; if ( expiration_time > 0.0 ) status = redisAsyncCommand(async_ctx, redisPut, cb, format.c_str(), key_prefix.data(), json_key.data(), - json_value.data(), static_cast(expire_time * 1e6)); + json_value.data(), static_cast(expiration_time * 1e6)); else status = redisAsyncCommand(async_ctx, redisPut, cb, format.c_str(), key_prefix.data(), json_key.data(), json_value.data()); @@ -234,7 +232,7 @@ ErrorResult Redis::DoPut(ValPtr key, ValPtr value, bool overwrite, double expira redisReply* reply; if ( expiration_time > 0.0 && ! zeek::run_state::reading_traces ) reply = (redisReply*)redisCommand(ctx, format.c_str(), key_prefix.data(), json_key.data(), - json_value.data(), static_cast(expire_time * 1e6)); + json_value.data(), static_cast(expiration_time * 1e6)); else reply = (redisReply*)redisCommand(ctx, format.c_str(), key_prefix.data(), json_key.data(), json_value.data()); @@ -254,7 +252,7 @@ ErrorResult Redis::DoPut(ValPtr key, ValPtr value, bool overwrite, double expira format += " %f %s"; redisReply* reply = - (redisReply*)redisCommand(ctx, format.c_str(), key_prefix.data(), expire_time, json_key.data()); + (redisReply*)redisCommand(ctx, format.c_str(), key_prefix.data(), expiration_time, json_key.data()); if ( ! reply ) return util::fmt("ZADD operation failed: %s", ctx->errstr); diff --git a/src/storage/backend/sqlite/SQLite.cc b/src/storage/backend/sqlite/SQLite.cc index 25b47cca0f..34f1aebcfd 100644 --- a/src/storage/backend/sqlite/SQLite.cc +++ b/src/storage/backend/sqlite/SQLite.cc @@ -162,9 +162,6 @@ ErrorResult SQLite::DoPut(ValPtr key, ValPtr value, bool overwrite, double expir return res; } - if ( expiration_time != 0 ) - expiration_time += run_state::network_time; - if ( auto res = checkError(sqlite3_bind_double(stmt, 3, expiration_time)); res.has_value() ) { sqlite3_reset(stmt); return res; diff --git a/src/storage/storage.bif b/src/storage/storage.bif index 7035260232..6c68e5f638 100644 --- a/src/storage/storage.bif +++ b/src/storage/storage.bif @@ -114,6 +114,9 @@ function Storage::Async::__put%(backend: opaque of Storage::BackendHandle, key: else if ( ! b->backend->IsOpen() ) return val_mgr->Bool(false); + if ( expire_time > 0.0 ) + expire_time += run_state::network_time; + auto cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); auto key_v = IntrusivePtr{NewRef{}, key}; auto val_v = IntrusivePtr{NewRef{}, value};