From 28951dccf128d87b9dbf73a8ae9568a20916d697 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Sat, 1 Mar 2025 15:16:57 -0700 Subject: [PATCH] Split sync and async into separate script-land namespaces --- scripts/base/frameworks/storage/__load__.zeek | 4 +- scripts/base/frameworks/storage/async.zeek | 100 +++++++ scripts/base/frameworks/storage/main.zeek | 123 --------- scripts/base/frameworks/storage/sync.zeek | 98 +++++++ src/script_opt/FuncInfo.cc | 15 +- src/storage/storage.bif | 244 +++++++++++------- .../canonified_loaded_scripts.log | 4 +- .../Baseline/opt.ZAM-bif-tracking/output | 2 +- .../Baseline/plugins.storage/zeek-stderr | 4 +- .../.stderr | 4 +- testing/btest/opt/ZAM-bif-tracking.zeek | 15 +- testing/btest/plugins/storage.zeek | 24 +- .../frameworks/storage/compound-types.zeek | 8 +- .../base/frameworks/storage/erase.zeek | 10 +- .../base/frameworks/storage/expiration.zeek | 12 +- .../base/frameworks/storage/overwriting.zeek | 10 +- .../storage/redis-async-reading-pcap.zeek | 11 +- .../base/frameworks/storage/redis-async.zeek | 11 +- .../frameworks/storage/redis-cluster.zeek | 10 +- .../frameworks/storage/redis-expiration.zeek | 12 +- .../base/frameworks/storage/redis-sync.zeek | 14 +- .../storage/sqlite-basic-reading-pcap.zeek | 11 +- .../base/frameworks/storage/sqlite-basic.zeek | 10 +- .../storage/sqlite-error-handling.zeek | 12 +- 24 files changed, 465 insertions(+), 303 deletions(-) create mode 100644 scripts/base/frameworks/storage/async.zeek create mode 100644 scripts/base/frameworks/storage/sync.zeek diff --git a/scripts/base/frameworks/storage/__load__.zeek b/scripts/base/frameworks/storage/__load__.zeek index d551be57d3..0fbdc3168f 100644 --- a/scripts/base/frameworks/storage/__load__.zeek +++ b/scripts/base/frameworks/storage/__load__.zeek @@ -1 +1,3 @@ -@load ./main \ No newline at end of file +@load ./async +@load ./main +@load ./sync \ No newline at end of file diff --git a/scripts/base/frameworks/storage/async.zeek b/scripts/base/frameworks/storage/async.zeek new file mode 100644 index 0000000000..290b5fe424 --- /dev/null +++ b/scripts/base/frameworks/storage/async.zeek @@ -0,0 +1,100 @@ +##! Asynchronous operation methods for the storage framework. These methods must +##! be called as part of a :zeek:see:`when` statement. An error will be returned +##! otherwise. + +@load ./main + +module Storage::Async; + +export { + ## Opens a new backend connection based on a configuration object asynchronously. + ## + ## btype: A tag indicating what type of backend should be opened. These are + ## defined by the backend plugins loaded. + ## + ## options: A record containing the configuration for the connection. + ## + ## key_type: The script-level type of keys stored in the backend. Used for + ## validation of keys passed to other framework methods. + ## + ## val_type: The script-level type of keys stored in the backend. Used for + ## validation of values passed to :zeek:see:`Storage::Async::put` as + ## well as for type conversions for return values from + ## :zeek:see:`Storage::Async::get`. + ## + ## Returns: A handle to the new backend connection, or ``F`` if the connection + ## failed. + global open_backend: function(btype: Storage::Backend, options: any, key_type: any, + val_type: any): opaque of Storage::BackendHandle; + + ## Closes an existing backend connection asynchronously. + ## + ## backend: A handle to a backend connection. + ## + ## Returns: A boolean indicating success or failure of the operation. + global close_backend: function(backend: opaque of Storage::BackendHandle): bool; + + ## Inserts a new entry into a backend asynchronously. + ## + ## backend: A handle to a backend connection. + ## + ## args: A :zeek:see:`Storage::PutArgs` record containing the arguments for the + ## operation. + ## + ## Returns: A boolean indicating success or failure of the operation. Type + ## comparison failures against the types passed to + ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to + ## be returned. + global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool; + + ## Gets an entry from the backend asynchronously. + ## + ## backend: A handle to a backend connection. + ## + ## key: The key to look up. + ## + ## Returns: A boolean indicating success or failure of the operation. Type + ## comparison failures against the types passed to + ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to + ## be returned. The caller should check the validity of the value before + ## attempting to use it. If the value is unset, an error string may be + ## available to describe the failure. + global get: function(backend: opaque of Storage::BackendHandle, key: any): val_result; + + ## Erases an entry from the backend asynchronously. + ## + ## backend: A handle to a backend connection. + ## + ## key: The key to erase. + ## + ## Returns: A boolean indicating success or failure of the operation. Type + ## comparison failures against the types passed to + ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to + ## be returned. + global erase: function(backend: opaque of Storage::BackendHandle, key: any): bool; +} + +function open_backend(btype: Storage::Backend, options: any, key_type: any, val_type: any): opaque of Storage::BackendHandle +{ + return Storage::Async::__open_backend(btype, options, key_type, val_type); +} + +function close_backend(backend: opaque of Storage::BackendHandle): bool +{ + return Storage::Async::__close_backend(backend); +} + +function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool +{ + return Storage::Async::__put(backend, args$key, args$value, args$overwrite, args$expire_time); +} + +function get(backend: opaque of Storage::BackendHandle, key: any): val_result +{ + return Storage::Async::__get(backend, key); +} + +function erase(backend: opaque of Storage::BackendHandle, key: any): bool +{ + return Storage::Async::__erase(backend, key); +} diff --git a/scripts/base/frameworks/storage/main.zeek b/scripts/base/frameworks/storage/main.zeek index b0c725f9b2..cd46583aa9 100644 --- a/scripts/base/frameworks/storage/main.zeek +++ b/scripts/base/frameworks/storage/main.zeek @@ -20,128 +20,5 @@ export { # An interval of time until the entry is automatically removed from the # backend. expire_time: interval &default=0sec; - - # Indicates whether this operation should happen asynchronously. If this - # is true, the call to put must happen as part of a :zeek:see:`when` - # statement. This flag is overridden and set to F when reading pcaps, - # since time won't move forward the same as when caputring live traffic. - async_mode: bool &default=T; }; - - ## Opens a new backend connection based on a configuration object. - ## - ## btype: A tag indicating what type of backend should be opened. These are - ## defined by the backend plugins loaded. - ## - ## options: A record containing the configuration for the connection. - ## - ## key_type: The script-level type of keys stored in the backend. Used for - ## validation of keys passed to other framework methods. - ## - ## val_type: The script-level type of keys stored in the backend. Used for - ## validation of values passed to :zeek:see:`Storage::put` as well as - ## for type conversions for return values from :zeek:see:`Storage::get`. - ## - ## async_mode: Indicates whether this operation should happen asynchronously. If - ## this is T, the call must happen as part of a :zeek:see:`when` - ## statement. This flag is overridden and set to F when reading pcaps, - ## since time won't move forward the same as when caputring live - ## traffic. - ## - ## Returns: A handle to the new backend connection, or ``F`` if the connection - ## failed. - global open_backend: function(btype: Storage::Backend, options: any, key_type: any, - val_type: any, async_mode: bool &default=F): opaque of Storage::BackendHandle; - - ## Closes an existing backend connection. - ## - ## backend: A handle to a backend connection. - ## - ## async_mode: Indicates whether this operation should happen asynchronously. If - ## this is T, the call must happen as part of a :zeek:see:`when` - ## statement. This flag is overridden and set to F when reading pcaps, - ## since time won't move forward the same as when caputring live - ## traffic. - ## - ## Returns: A boolean indicating success or failure of the operation. - global close_backend: function(backend: opaque of Storage::BackendHandle, async_mode: bool &default=F): bool; - - ## Inserts a new entry into a backend. - ## - ## - ## backend: A handle to a backend connection. - ## - ## args: A :zeek:see:`Storage::PutArgs` record containing the arguments for the - ## operation. - ## - ## Returns: A boolean indicating success or failure of the operation. Type - ## comparison failures against the types passed to - ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to - ## be returned. - global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool; - - ## Gets an entry from the backend. - ## - ## backend: A handle to a backend connection. - ## - ## key: The key to look up. - ## - ## async_mode: Indicates whether this operation should happen asynchronously. If - ## this is T, the call must happen as part of a :zeek:see:`when` - ## statement. This flag is overridden and set to F when reading pcaps, - ## since time won't move forward the same as when caputring live - ## traffic. - ## - ## Returns: A boolean indicating success or failure of the operation. Type - ## comparison failures against the types passed to - ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to - ## be returned. The caller should check the validity of the value before - ## attempting to use it. If the value is unset, an error string may be - ## available to describe the failure. - global get: function(backend: opaque of Storage::BackendHandle, key: any, - async_mode: bool &default=T): val_result; - - ## Erases an entry from the backend. - ## - ## backend: A handle to a backend connection. - ## - ## key: The key to erase. - ## - ## async_mode: Indicates whether this operation should happen asynchronously. If - ## this is T, the call must happen as part of a :zeek:see:`when` - ## statement. This flag is overridden and set to F when reading pcaps, - ## since time won't move forward the same as when caputring live - ## traffic. - ## - ## Returns: A boolean indicating success or failure of the operation. Type - ## comparison failures against the types passed to - ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to - ## be returned. - global erase: function(backend: opaque of Storage::BackendHandle, key: any, - async_mode: bool &default=T): bool; -} - -function open_backend(btype: Storage::Backend, options: any, key_type: any, val_type: any, async_mode: bool &default=F): opaque of Storage::BackendHandle -{ - return Storage::__open_backend(btype, options, key_type, val_type, async_mode); -} - -function close_backend(backend: opaque of Storage::BackendHandle, async_mode: bool &default=F): bool -{ - return Storage::__close_backend(backend, async_mode); -} - -function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool -{ - return Storage::__put(backend, args$key, args$value, args$overwrite, args$expire_time, args$async_mode); -} - -function get(backend: opaque of Storage::BackendHandle, key: any, async_mode: bool &default=T): val_result -{ - return Storage::__get(backend, key, async_mode); -} - -function erase(backend: opaque of Storage::BackendHandle, key: any, async_mode: bool &default=T): bool -{ - return Storage::__erase(backend, key, async_mode); } diff --git a/scripts/base/frameworks/storage/sync.zeek b/scripts/base/frameworks/storage/sync.zeek new file mode 100644 index 0000000000..b50859cef0 --- /dev/null +++ b/scripts/base/frameworks/storage/sync.zeek @@ -0,0 +1,98 @@ +##! Synchronous operation methods for the storage framework. + +@load ./main + +module Storage::Sync; + +export { + ## Opens a new backend connection based on a configuration object. + ## + ## btype: A tag indicating what type of backend should be opened. These are + ## defined by the backend plugins loaded. + ## + ## options: A record containing the configuration for the connection. + ## + ## key_type: The script-level type of keys stored in the backend. Used for + ## validation of keys passed to other framework methods. + ## + ## val_type: The script-level type of keys stored in the backend. Used for + ## validation of values passed to :zeek:see:`Storage::Sync::put` as well + ## as for type conversions for return values from + ## :zeek:see:`Storage::Sync::get`. + ## + ## Returns: A handle to the new backend connection, or ``F`` if the connection + ## failed. + global open_backend: function(btype: Storage::Backend, options: any, key_type: any, + val_type: any): opaque of Storage::BackendHandle; + + ## Closes an existing backend connection. + ## + ## backend: A handle to a backend connection. + ## + ## Returns: A boolean indicating success or failure of the operation. + global close_backend: function(backend: opaque of Storage::BackendHandle): bool; + + ## Inserts a new entry into a backend. + ## + ## backend: A handle to a backend connection. + ## + ## args: A :zeek:see:`Storage::PutArgs` record containing the arguments for the + ## operation. + ## + ## Returns: A boolean indicating success or failure of the operation. Type + ## comparison failures against the types passed to + ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to + ## be returned. + global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool; + + ## Gets an entry from the backend. + ## + ## backend: A handle to a backend connection. + ## + ## key: The key to look up. + ## + ## Returns: A boolean indicating success or failure of the operation. Type + ## comparison failures against the types passed to + ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to + ## be returned. The caller should check the validity of the value before + ## attempting to use it. If the value is unset, an error string may be + ## available to describe the failure. + global get: function(backend: opaque of Storage::BackendHandle, key: any): val_result; + + ## Erases an entry from the backend. + ## + ## backend: A handle to a backend connection. + ## + ## key: The key to erase. + ## + ## Returns: A boolean indicating success or failure of the operation. Type + ## comparison failures against the types passed to + ## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to + ## be returned. + global erase: function(backend: opaque of Storage::BackendHandle, key: any): bool; +} + +function open_backend(btype: Storage::Backend, options: any, key_type: any, val_type: any): opaque of Storage::BackendHandle +{ + return Storage::Sync::__open_backend(btype, options, key_type, val_type); +} + +function close_backend(backend: opaque of Storage::BackendHandle): bool +{ + return Storage::Sync::__close_backend(backend); +} + +function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool +{ + return Storage::Sync::__put(backend, args$key, args$value, args$overwrite, args$expire_time); +} + +function get(backend: opaque of Storage::BackendHandle, key: any): val_result +{ + return Storage::Sync::__get(backend, key); +} + +function erase(backend: opaque of Storage::BackendHandle, key: any): bool +{ + return Storage::Sync::__erase(backend, key); +} diff --git a/src/script_opt/FuncInfo.cc b/src/script_opt/FuncInfo.cc index dea2ba7524..50d17440ca 100644 --- a/src/script_opt/FuncInfo.cc +++ b/src/script_opt/FuncInfo.cc @@ -148,11 +148,16 @@ static std::unordered_map func_attrs = { {"Reporter::warning", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Spicy::__resource_usage", ATTR_NO_ZEEK_SIDE_EFFECTS}, {"Spicy::__toggle_analyzer", ATTR_NO_SCRIPT_SIDE_EFFECTS}, - {"Storage::__close_backend", ATTR_NO_SCRIPT_SIDE_EFFECTS}, - {"Storage::__erase", ATTR_NO_SCRIPT_SIDE_EFFECTS}, - {"Storage::__get", ATTR_NO_SCRIPT_SIDE_EFFECTS}, - {"Storage::__open_backend", ATTR_NO_SCRIPT_SIDE_EFFECTS}, - {"Storage::__put", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Async::__close_backend", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Async::__erase", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Async::__get", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Async::__open_backend", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Async::__put", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Sync::__close_backend", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Sync::__erase", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Sync::__get", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Sync::__open_backend", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Storage::Sync::__put", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Supervisor::__create", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Supervisor::__destroy", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Supervisor::__is_supervised", ATTR_IDEMPOTENT}, diff --git a/src/storage/storage.bif b/src/storage/storage.bif index ae037378f5..7035260232 100644 --- a/src/storage/storage.bif +++ b/src/storage/storage.bif @@ -7,13 +7,13 @@ using namespace zeek; using namespace zeek::storage; -static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame, const BackendPtr& b) { - auto trigger = frame->GetTrigger(); +static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame) { + auto trigger = frame->GetTrigger(); - if ( ! trigger ) { - emit_builtin_error("Async storage operations can only be called inside when-conditions"); - return nullptr; - } + if ( ! trigger ) { + emit_builtin_error("Asynchronous storage operations must be called via a when-condition"); + return nullptr; + } if ( auto timeout = trigger->TimeoutValue(); timeout < 0 ) { emit_builtin_error("Async Storage operations must specify a timeout block"); @@ -25,6 +25,21 @@ static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame return {NewRef{}, trigger}; } + +static IntrusivePtr make_backend_handle(Val* btype) { + auto btype_val = IntrusivePtr{NewRef{}, btype->AsEnumVal()}; + Tag tag{btype_val}; + + auto b = storage_mgr->Instantiate(tag); + + if ( ! b.has_value() ) { + emit_builtin_error(b.error().c_str()); + return nullptr; + } + + return make_intrusive(b.value()); +} + %%} module Storage; @@ -35,7 +50,130 @@ event Storage::backend_opened%(%); # Generated when a backend connection is lost event Storage::backend_lost%(%); -function Storage::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any, async_mode: bool%): opaque of Storage::BackendHandle +module Storage::Async; + +function Storage::Async::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any%): opaque of Storage::BackendHandle + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return val_mgr->Bool(false); + + auto btype_val = IntrusivePtr{NewRef{}, btype->AsEnumVal()}; + Tag tag{btype_val}; + + auto b = storage_mgr->Instantiate(tag); + + if ( ! b.has_value() ) { + emit_builtin_error(b.error().c_str()); + return nullptr; + } + + auto bh = make_intrusive(b.value()); + + auto cb = new OpenResultCallback(trigger, frame->GetTriggerAssoc(), bh.release()); + auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); + auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); + auto options_val = IntrusivePtr{NewRef{}, options->AsRecordVal()}; + storage_mgr->OpenBackend(b.value(), options_val, kt, vt, cb); + + return nullptr; + %} + +function Storage::Async::__close_backend%(backend: opaque of Storage::BackendHandle%) : bool + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return val_mgr->Bool(false); + + auto b = dynamic_cast(backend); + if ( ! b ) { + emit_builtin_error("Invalid storage handle", backend); + return val_mgr->Bool(false); + } + else if ( ! b->backend->IsOpen() ) + return val_mgr->Bool(true); + + auto cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); + storage_mgr->CloseBackend(b->backend, cb); + + return nullptr; + %} + +function Storage::Async::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, + overwrite: bool, expire_time: interval%): bool + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return val_mgr->Bool(false); + + auto b = dynamic_cast(backend); + if ( ! b ) { + emit_builtin_error("Invalid storage handle", backend); + return val_mgr->Bool(false); + } + else if ( ! b->backend->IsOpen() ) + return val_mgr->Bool(false); + + auto cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); + auto key_v = IntrusivePtr{NewRef{}, key}; + auto val_v = IntrusivePtr{NewRef{}, value}; + b->backend->Put(key_v, val_v, overwrite, expire_time, cb); + + return nullptr; + %} + +function Storage::Async::__get%(backend: opaque of Storage::BackendHandle, key: any%): val_result + %{ + static auto val_result_type = id::find_type("val_result"); + auto val_result = make_intrusive(val_result_type); + + auto trigger = init_trigger(frame); + if ( ! trigger ) { + val_result->Assign(1, make_intrusive("Failed to create trigger")); + return val_result; + } + + auto b = dynamic_cast(backend); + if ( ! b ) { + val_result->Assign(1, make_intrusive("Invalid storage handlle")); + return val_result; + } + else if ( ! b->backend->IsOpen() ) { + val_result->Assign(1, make_intrusive("Backend is closed")); + return val_result; + } + + auto cb = new ValResultCallback(trigger, frame->GetTriggerAssoc()); + auto key_v = IntrusivePtr{NewRef{}, key}; + auto result = b->backend->Get(key_v, cb); + + return nullptr; + %} + +function Storage::Async::__erase%(backend: opaque of Storage::BackendHandle, key: any%): bool + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return val_mgr->Bool(false); + + auto b = dynamic_cast(backend); + if ( ! b ) { + emit_builtin_error("Invalid storage handle", backend); + return val_mgr->Bool(false); + } + else if ( ! b->backend->IsOpen() ) + return val_mgr->Bool(false); + + auto cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); + auto key_v = IntrusivePtr{NewRef{}, key}; + b->backend->Erase(key_v, cb); + + return nullptr; + %} + +module Storage::Sync; + +function Storage::Sync::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any%): opaque of Storage::BackendHandle %{ auto btype_val = IntrusivePtr{NewRef{}, btype->AsEnumVal()}; Tag tag{btype_val}; @@ -47,34 +185,20 @@ function Storage::__open_backend%(btype: Storage::Backend, options: any, key_typ return val_mgr->Bool(false); } - auto bo = make_intrusive(b.value()); - OpenResultCallback* cb = nullptr; - - if ( async_mode ) { - auto trigger = init_trigger(frame, b.value()); - if ( ! trigger ) - return val_mgr->Bool(false); - - cb = new OpenResultCallback(trigger, frame->GetTriggerAssoc(), bo.release()); - } - auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); auto options_val = IntrusivePtr{NewRef{}, options->AsRecordVal()}; - auto open_res = storage_mgr->OpenBackend(b.value(), options_val, kt, vt, cb); - - if ( async_mode ) - return nullptr; + auto open_res = storage_mgr->OpenBackend(b.value(), options_val, kt, vt, nullptr); if ( open_res.has_value() ) { emit_builtin_error(open_res.value().c_str()); return val_mgr->Bool(false); } - return bo; + return make_intrusive(b.value()); %} -function Storage::__close_backend%(backend: opaque of Storage::BackendHandle, async_mode: bool%) : bool +function Storage::Sync::__close_backend%(backend: opaque of Storage::BackendHandle%) : bool %{ auto b = dynamic_cast(backend); if ( ! b ) { @@ -85,20 +209,7 @@ function Storage::__close_backend%(backend: opaque of Storage::BackendHandle, as // Return true here since the backend is already closed return val_mgr->Bool(true); - ErrorResultCallback* cb = nullptr; - - if ( async_mode ) { - auto trigger = init_trigger(frame, b->backend); - if ( ! trigger ) - return val_mgr->Bool(false); - - cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); - } - - auto result = storage_mgr->CloseBackend(b->backend, cb); - - if ( async_mode ) - return nullptr; + auto result = storage_mgr->CloseBackend(b->backend, nullptr); if ( result.has_value() ) { emit_builtin_error(result.value().c_str()); @@ -108,8 +219,8 @@ function Storage::__close_backend%(backend: opaque of Storage::BackendHandle, as return val_mgr->Bool(true); %} -function Storage::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, - overwrite: bool, expire_time: interval, async_mode: bool &default=T%): bool +function Storage::Sync::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, + overwrite: bool, expire_time: interval%): bool %{ auto b = dynamic_cast(backend); if ( ! b ) { @@ -119,22 +230,9 @@ function Storage::__put%(backend: opaque of Storage::BackendHandle, key: any, va else if ( ! b->backend->IsOpen() ) return val_mgr->Bool(false); - ErrorResultCallback* cb = nullptr; - - if ( async_mode ) { - auto trigger = init_trigger(frame, b->backend); - if ( ! trigger ) - return val_mgr->Bool(false); - - cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); - } - auto key_v = IntrusivePtr{NewRef{}, key}; auto val_v = IntrusivePtr{NewRef{}, value}; - auto result = b->backend->Put(key_v, val_v, overwrite, expire_time, cb); - - if ( async_mode ) - return nullptr; + auto result = b->backend->Put(key_v, val_v, overwrite, expire_time, nullptr); if ( result.has_value() ) { emit_builtin_error(util::fmt("Failed to store data: %s", result.value().c_str())); @@ -144,7 +242,7 @@ function Storage::__put%(backend: opaque of Storage::BackendHandle, key: any, va return val_mgr->Bool(true); %} -function Storage::__get%(backend: opaque of Storage::BackendHandle, key: any, async_mode: bool &default=T%): val_result +function Storage::Sync::__get%(backend: opaque of Storage::BackendHandle, key: any%): val_result %{ static auto val_result_type = id::find_type("val_result"); auto val_result = make_intrusive(val_result_type); @@ -159,27 +257,12 @@ function Storage::__get%(backend: opaque of Storage::BackendHandle, key: any, as return val_result; } - ValResultCallback* cb = nullptr; - - if ( async_mode ) { - auto trigger = init_trigger(frame, b->backend); - if ( ! trigger ) { - val_result->Assign(1, make_intrusive("Failed to create trigger")); - return val_result; - } - - cb = new ValResultCallback(trigger, frame->GetTriggerAssoc()); - } - auto key_v = IntrusivePtr{NewRef{}, key}; - auto result = b->backend->Get(key_v, cb); - - if ( async_mode ) - return nullptr; + auto result = b->backend->Get(key_v, nullptr); if ( ! result.has_value() ) { val_result->Assign(1, make_intrusive( - util::fmt("Failed to retrieve data: %s", result.error().c_str()))); + util::fmt("Failed to retrieve data: %s", result.error().c_str()))); return val_result; } @@ -187,7 +270,7 @@ function Storage::__get%(backend: opaque of Storage::BackendHandle, key: any, as return val_result; %} -function Storage::__erase%(backend: opaque of Storage::BackendHandle, key: any, async_mode: bool &default=T%): bool +function Storage::Sync::__erase%(backend: opaque of Storage::BackendHandle, key: any%): bool %{ auto b = dynamic_cast(backend); if ( ! b ) { @@ -197,21 +280,8 @@ function Storage::__erase%(backend: opaque of Storage::BackendHandle, key: any, else if ( ! b->backend->IsOpen() ) return val_mgr->Bool(false); - ErrorResultCallback* cb = nullptr; - - if ( async_mode ) { - auto trigger = init_trigger(frame, b->backend); - if ( ! trigger ) - return val_mgr->Bool(false); - - cb = new ErrorResultCallback(trigger, frame->GetTriggerAssoc()); - } - auto key_v = IntrusivePtr{NewRef{}, key}; - auto result = b->backend->Erase(key_v, cb); - - if ( async_mode ) - return nullptr; + auto result = b->backend->Erase(key_v, nullptr); if ( result.has_value() ) { emit_builtin_error(util::fmt("Failed to erase data for key: %s", result.value().c_str())); diff --git a/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log b/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log index ebf298afa4..c6a813054b 100644 --- a/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log +++ b/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log @@ -369,7 +369,9 @@ scripts/base/init-default.zeek scripts/base/frameworks/telemetry/main.zeek scripts/base/misc/version.zeek scripts/base/frameworks/storage/__load__.zeek - scripts/base/frameworks/storage/main.zeek + scripts/base/frameworks/storage/async.zeek + scripts/base/frameworks/storage/main.zeek + scripts/base/frameworks/storage/sync.zeek scripts/base/frameworks/spicy/__load__.zeek scripts/base/frameworks/spicy/main.zeek scripts/base/protocols/conn/__load__.zeek diff --git a/testing/btest/Baseline/opt.ZAM-bif-tracking/output b/testing/btest/Baseline/opt.ZAM-bif-tracking/output index 4fab29b90a..972665cbdb 100644 --- a/testing/btest/Baseline/opt.ZAM-bif-tracking/output +++ b/testing/btest/Baseline/opt.ZAM-bif-tracking/output @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -551 seen BiFs, 0 unseen BiFs (), 0 new BiFs () +556 seen BiFs, 0 unseen BiFs (), 0 new BiFs () diff --git a/testing/btest/Baseline/plugins.storage/zeek-stderr b/testing/btest/Baseline/plugins.storage/zeek-stderr index 590aa27896..e114ceba55 100644 --- a/testing/btest/Baseline/plugins.storage/zeek-stderr +++ b/testing/btest/Baseline/plugins.storage/zeek-stderr @@ -1,4 +1,4 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. error in <...>/storage.zeek, line 41: Failed to retrieve data: Failed to find key -error in <...>/storage.zeek, line 53: Failed to open backend Storage::STORAGEDUMMY: open_fail was set to true, returning error (Storage::open_backend(Storage::STORAGEDUMMY, to_any_coerce opts, to_any_coerce str, to_any_coerce str, F)) -error in <...>/storage.zeek, line 54: Invalid storage handle (Storage::close_backend(b2, F) and F) +error in <...>/sync.zeek, line 74: Failed to open backend Storage::STORAGEDUMMY: open_fail was set to true, returning error (Storage::Sync::__open_backend(Storage::Sync::btype, Storage::Sync::options, Storage::Sync::key_type, Storage::Sync::val_type)) +error in <...>/sync.zeek, line 79: Invalid storage handle (Storage::Sync::__close_backend(Storage::Sync::backend) and F) diff --git a/testing/btest/Baseline/scripts.base.frameworks.storage.sqlite-error-handling/.stderr b/testing/btest/Baseline/scripts.base.frameworks.storage.sqlite-error-handling/.stderr index e590742314..e54152627d 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.storage.sqlite-error-handling/.stderr +++ b/testing/btest/Baseline/scripts.base.frameworks.storage.sqlite-error-handling/.stderr @@ -1,3 +1,3 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in <...>/sqlite-error-handling.zeek, line 20: Failed to open backend Storage::SQLITE: SQLite call failed: unable to open database file (Storage::open_backend(Storage::SQLITE, to_any_coerce opts, to_any_coerce str, to_any_coerce str, F)) -error in <...>/sqlite-error-handling.zeek, line 28: Failed to store data: type of key passed (count) does not match backend's key type (str) (Storage::put(b, (coerce [$key=bad_key, $value=value, $async_mode=F] to Storage::PutArgs))) +error in <...>/sync.zeek, line 74: Failed to open backend Storage::SQLITE: SQLite call failed: unable to open database file (Storage::Sync::__open_backend(Storage::Sync::btype, Storage::Sync::options, Storage::Sync::key_type, Storage::Sync::val_type)) +error in <...>/sync.zeek, line 84: Failed to store data: type of key passed (count) does not match backend's key type (str) (Storage::Sync::__put(Storage::Sync::backend, Storage::Sync::args$key, Storage::Sync::args$value, Storage::Sync::args$overwrite, Storage::Sync::args$expire_time)) diff --git a/testing/btest/opt/ZAM-bif-tracking.zeek b/testing/btest/opt/ZAM-bif-tracking.zeek index 2a906c365f..1d11c555c5 100644 --- a/testing/btest/opt/ZAM-bif-tracking.zeek +++ b/testing/btest/opt/ZAM-bif-tracking.zeek @@ -177,11 +177,16 @@ global known_BiFs = set( "Reporter::warning", "Spicy::__resource_usage", "Spicy::__toggle_analyzer", - "Storage::__close_backend", - "Storage::__erase", - "Storage::__get", - "Storage::__open_backend", - "Storage::__put", + "Storage::Async::__close_backend", + "Storage::Async::__erase", + "Storage::Async::__get", + "Storage::Async::__open_backend", + "Storage::Async::__put", + "Storage::Sync::__close_backend", + "Storage::Sync::__erase", + "Storage::Sync::__get", + "Storage::Sync::__open_backend", + "Storage::Sync::__put", "Supervisor::__create", "Supervisor::__destroy", "Supervisor::__is_supervised", diff --git a/testing/btest/plugins/storage.zeek b/testing/btest/plugins/storage.zeek index fd57797252..92a598586f 100644 --- a/testing/btest/plugins/storage.zeek +++ b/testing/btest/plugins/storage.zeek @@ -8,7 +8,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff zeek-stderr -@load base/frameworks/storage +@load base/frameworks/storage/sync # Create a typename here that can be passed down into get(). type str: string; @@ -26,30 +26,30 @@ event zeek_init() { # Test basic operation. The second get() should return an error # as the key should have been erased. - local b = Storage::open_backend(Storage::STORAGEDUMMY, opts, str, str); - local put_res = Storage::put(b, [$key=key, $value=value, $overwrite=F, $async_mode=F]); - local get_res = Storage::get(b, key, F); + local b = Storage::Sync::open_backend(Storage::STORAGEDUMMY, opts, str, str); + local put_res = Storage::Sync::put(b, [$key=key, $value=value, $overwrite=F]); + local get_res = Storage::Sync::get(b, key); if ( get_res is bool ) { print("Got an invalid value in response!"); } - local erase_res = Storage::erase(b, key, F); - get_res = Storage::get(b, key, F); - Storage::close_backend(b); + local erase_res = Storage::Sync::erase(b, key); + get_res = Storage::Sync::get(b, key); + Storage::Sync::close_backend(b); if ( get_res?$error ) Reporter::error(get_res$error); # Test attempting to use the closed handle. - put_res = Storage::put(b, [$key="a", $value="b", $overwrite=F]); - get_res = Storage::get(b, "a"); - erase_res = Storage::erase(b, "a"); + put_res = Storage::Sync::put(b, [$key="a", $value="b", $overwrite=F]); + get_res = Storage::Sync::get(b, "a"); + erase_res = Storage::Sync::erase(b, "a"); print(fmt("results of trying to use closed handle: get: %d, put: %d, erase: %d", get_res?$val, put_res, erase_res)); # Test failing to open the handle and test closing an invalid handle. opts$open_fail = T; - local b2 = Storage::open_backend(Storage::STORAGEDUMMY, opts, str, str); - Storage::close_backend(b2); + local b2 = Storage::Sync::open_backend(Storage::STORAGEDUMMY, opts, str, str); + Storage::Sync::close_backend(b2); } diff --git a/testing/btest/scripts/base/frameworks/storage/compound-types.zeek b/testing/btest/scripts/base/frameworks/storage/compound-types.zeek index 4a90422c87..7b37289179 100644 --- a/testing/btest/scripts/base/frameworks/storage/compound-types.zeek +++ b/testing/btest/scripts/base/frameworks/storage/compound-types.zeek @@ -3,7 +3,7 @@ # @TEST-EXEC: btest-diff out # @TEST-EXEC: btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/sqlite type Color: enum { @@ -64,11 +64,11 @@ event zeek_init() { value[2] = "b"; value[3] = "c"; - local b = Storage::open_backend(Storage::SQLITE, opts, Rec, tbl); + local b = Storage::Sync::open_backend(Storage::SQLITE, opts, Rec, tbl); - local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]); + local res = Storage::Sync::put(b, [$key=key, $value=value]); print "put result", res; - local res2 = Storage::get(b, key, F); + local res2 = Storage::Sync::get(b, key); print "get result", res2; } diff --git a/testing/btest/scripts/base/frameworks/storage/erase.zeek b/testing/btest/scripts/base/frameworks/storage/erase.zeek index b6a3e540fc..25594d9123 100644 --- a/testing/btest/scripts/base/frameworks/storage/erase.zeek +++ b/testing/btest/scripts/base/frameworks/storage/erase.zeek @@ -4,7 +4,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/sqlite # Create a typename here that can be passed down into get(). @@ -20,14 +20,14 @@ event zeek_init() { # Test inserting/retrieving a key/value pair that we know won't be in # the backend yet. - local b = Storage::open_backend(Storage::SQLITE, opts, str, str); + local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str); - local res = Storage::erase(b, key, F); + local res = Storage::Sync::erase(b, key); print "erase result", res; - local res2 = Storage::get(b, key, F); + local res2 = Storage::Sync::get(b, key); if ( res2?$error ) print "get result", res2$error; - Storage::close_backend(b); + Storage::Sync::close_backend(b); } diff --git a/testing/btest/scripts/base/frameworks/storage/expiration.zeek b/testing/btest/scripts/base/frameworks/storage/expiration.zeek index 0913468004..8332987a38 100644 --- a/testing/btest/scripts/base/frameworks/storage/expiration.zeek +++ b/testing/btest/scripts/base/frameworks/storage/expiration.zeek @@ -3,7 +3,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/sqlite redef Storage::expire_interval = 2 secs; @@ -19,11 +19,11 @@ global value: string = "value7890"; event check_removed() { # This should return an error from the sqlite backend that there aren't any more # rows available. - local res2 = Storage::get(backend, key, F); + local res2 = Storage::Sync::get(backend, key); if ( res2?$error ) print "get result", res2$error; - Storage::close_backend(backend); + Storage::Sync::close_backend(backend); terminate(); } @@ -32,12 +32,12 @@ event setup_test() { opts$database_path = "storage-test.sqlite"; opts$table_name = "testing"; - backend = Storage::open_backend(Storage::SQLITE, opts, str, str); + backend = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str); - local res = Storage::put(backend, [$key=key, $value=value, $expire_time=2 secs, $async_mode=F]); + local res = Storage::Sync::put(backend, [$key=key, $value=value, $expire_time=2 secs]); print "put result", res; - local res2 = Storage::get(backend, key, F); + local res2 = Storage::Sync::get(backend, key); print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); diff --git a/testing/btest/scripts/base/frameworks/storage/overwriting.zeek b/testing/btest/scripts/base/frameworks/storage/overwriting.zeek index 60211d1e2e..8aeabecaf6 100644 --- a/testing/btest/scripts/base/frameworks/storage/overwriting.zeek +++ b/testing/btest/scripts/base/frameworks/storage/overwriting.zeek @@ -4,7 +4,7 @@ # @TEST-EXEC: btest-diff out # @TEST-EXEC: btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/sqlite # Create a typename here that can be passed down into get(). @@ -18,15 +18,15 @@ event zeek_init() { local key = "key1234"; local value = "value7890"; - local b = Storage::open_backend(Storage::SQLITE, opts, str, str); + local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str); - local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]); + local res = Storage::Sync::put(b, [$key=key, $value=value]); print "put result", res; - local res2 = Storage::get(b, key, F); + local res2 = Storage::Sync::get(b, key); print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); - Storage::close_backend(b); + Storage::Sync::close_backend(b); } diff --git a/testing/btest/scripts/base/frameworks/storage/redis-async-reading-pcap.zeek b/testing/btest/scripts/base/frameworks/storage/redis-async-reading-pcap.zeek index 310e98fc4c..758b0e409f 100644 --- a/testing/btest/scripts/base/frameworks/storage/redis-async-reading-pcap.zeek +++ b/testing/btest/scripts/base/frameworks/storage/redis-async-reading-pcap.zeek @@ -12,7 +12,8 @@ # @TEST-EXEC: btest-diff out -@load base/frameworks/storage +@load base/frameworks/storage/sync +@load base/frameworks/storage/async @load policy/frameworks/storage/backend/redis # Create a typename here that can be passed down into open_backend() @@ -28,17 +29,17 @@ event zeek_init() { local key = "key1234"; local value = "value5678"; - local b = Storage::open_backend(Storage::REDIS, opts, str, str); + local b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str); - when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) { + when [b, key, value] ( local res = Storage::Async::put(b, [$key=key, $value=value]) ) { print "put result", res; - when [b, key, value] ( local res2 = Storage::get(b, key) ) { + when [b, key, value] ( local res2 = Storage::Async::get(b, key) ) { print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); - Storage::close_backend(b); + Storage::Sync::close_backend(b); } timeout 5 sec { print "get requeest timed out"; diff --git a/testing/btest/scripts/base/frameworks/storage/redis-async.zeek b/testing/btest/scripts/base/frameworks/storage/redis-async.zeek index ae0da73906..6d4b06383f 100644 --- a/testing/btest/scripts/base/frameworks/storage/redis-async.zeek +++ b/testing/btest/scripts/base/frameworks/storage/redis-async.zeek @@ -12,7 +12,8 @@ # @TEST-EXEC: btest-diff out -@load base/frameworks/storage +@load base/frameworks/storage/async +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/redis redef exit_only_after_terminate = T; @@ -30,17 +31,17 @@ event zeek_init() { local key = "key1234"; local value = "value5678"; - local b = Storage::open_backend(Storage::REDIS, opts, str, str); + local b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str); - when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) { + when [b, key, value] ( local res = Storage::Async::put(b, [$key=key, $value=value]) ) { print "put result", res; - when [b, key, value] ( local res2 = Storage::get(b, key) ) { + when [b, key, value] ( local res2 = Storage::Async::get(b, key) ) { print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); - Storage::close_backend(b); + Storage::Sync::close_backend(b); terminate(); } diff --git a/testing/btest/scripts/base/frameworks/storage/redis-cluster.zeek b/testing/btest/scripts/base/frameworks/storage/redis-cluster.zeek index d6e1de7af3..1fc9140cbb 100644 --- a/testing/btest/scripts/base/frameworks/storage/redis-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/storage/redis-cluster.zeek @@ -19,7 +19,7 @@ # @TEST-EXEC: btest-diff worker-2/.stdout # @TEST-EXEC: -@load base/frameworks/storage +@load base/frameworks/storage/sync @load base/frameworks/cluster @load policy/frameworks/storage/backend/redis @load policy/frameworks/cluster/experimental @@ -46,14 +46,14 @@ event zeek_init() { opts$key_prefix = "testing"; opts$async_mode = F; - backend = Storage::open_backend(Storage::REDIS, opts, str, str); + backend = Storage::Sync::open_backend(Storage::REDIS, opts, str, str); } event redis_data_written() { print "redis_data_written"; - local res = Storage::get(backend, "1234", F); + local res = Storage::Sync::get(backend, "1234"); print Cluster::node, res; - Storage::close_backend(backend); + Storage::Sync::close_backend(backend); terminate(); } @@ -77,7 +77,7 @@ event redis_data_written() { @if ( Cluster::node == "worker-1" ) event Cluster::Experimental::cluster_started() { - local res = Storage::put(backend, [$key="1234", $value="5678", $async_mode=F]); + local res = Storage::Sync::put(backend, [$key="1234", $value="5678"]); print Cluster::node, "put result", res; local e = Cluster::make_event(redis_data_written); diff --git a/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek b/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek index dbc050debf..8b813d6a36 100644 --- a/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek +++ b/testing/btest/scripts/base/frameworks/storage/redis-expiration.zeek @@ -12,7 +12,7 @@ # @TEST-EXEC: btest-diff out -@load base/frameworks/storage +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/redis redef Storage::expire_interval = 2 secs; @@ -26,10 +26,10 @@ global key: string = "key1234"; global value: string = "value7890"; event check_removed() { - local res2 = Storage::get(b, key, F); + local res2 = Storage::Sync::get(b, key); print "get result after expiration", res2; - Storage::close_backend(b); + Storage::Sync::close_backend(b); terminate(); } @@ -40,12 +40,12 @@ event setup_test() { opts$key_prefix = "testing"; opts$async_mode = F; - b = Storage::open_backend(Storage::REDIS, opts, str, str); + b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str); - local res = Storage::put(b, [$key=key, $value=value, $async_mode=F, $expire_time=2 secs]); + local res = Storage::Sync::put(b, [$key=key, $value=value, $expire_time=2 secs]); print "put result", res; - local res2 = Storage::get(b, key, F); + local res2 = Storage::Sync::get(b, key); print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); diff --git a/testing/btest/scripts/base/frameworks/storage/redis-sync.zeek b/testing/btest/scripts/base/frameworks/storage/redis-sync.zeek index d9dd372544..8579aa5a0c 100644 --- a/testing/btest/scripts/base/frameworks/storage/redis-sync.zeek +++ b/testing/btest/scripts/base/frameworks/storage/redis-sync.zeek @@ -12,7 +12,7 @@ # @TEST-EXEC: btest-diff out -@load base/frameworks/storage +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/redis # Create a typename here that can be passed down into open_backend() @@ -28,24 +28,24 @@ event zeek_init() { local key = "key1234"; local value = "value1234"; - local b = Storage::open_backend(Storage::REDIS, opts, str, str); + local b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str); - local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]); + local res = Storage::Sync::put(b, [$key=key, $value=value]); print "put result", res; - local res2 = Storage::get(b, key, F); + local res2 = Storage::Sync::get(b, key); print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); local value2 = "value5678"; - res = Storage::put(b, [$key=key, $value=value2, $overwrite=T, $async_mode=F]); + res = Storage::Sync::put(b, [$key=key, $value=value2, $overwrite=T]); print "overwrite put result", res; - res2 = Storage::get(b, key, F); + res2 = Storage::Sync::get(b, key); print "get result", res2; if ( res2?$val ) print "get result same as inserted", value2 == (res2$val as string); - Storage::close_backend(b); + Storage::Sync::close_backend(b); } diff --git a/testing/btest/scripts/base/frameworks/storage/sqlite-basic-reading-pcap.zeek b/testing/btest/scripts/base/frameworks/storage/sqlite-basic-reading-pcap.zeek index 6f2bc2d3a5..30aabfaf63 100644 --- a/testing/btest/scripts/base/frameworks/storage/sqlite-basic-reading-pcap.zeek +++ b/testing/btest/scripts/base/frameworks/storage/sqlite-basic-reading-pcap.zeek @@ -3,7 +3,8 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/async +@load base/frameworks/storage/sync @load policy/frameworks/storage/backend/sqlite redef exit_only_after_terminate = T; @@ -22,17 +23,17 @@ event zeek_init() { # Test inserting/retrieving a key/value pair that we know won't be in # the backend yet. - local b = Storage::open_backend(Storage::SQLITE, opts, str, str); + local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str); - when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) { + when [b, key, value] ( local res = Storage::Async::put(b, [$key=key, $value=value]) ) { print "put result", res; - when [b, key, value] ( local res2 = Storage::get(b, key) ) { + when [b, key, value] ( local res2 = Storage::Async::get(b, key) ) { print "get result", res2; if ( res2?$val ) print "get result same as inserted", value == (res2$val as string); - Storage::close_backend(b); + Storage::Sync::close_backend(b); terminate(); } diff --git a/testing/btest/scripts/base/frameworks/storage/sqlite-basic.zeek b/testing/btest/scripts/base/frameworks/storage/sqlite-basic.zeek index 684c86bce0..7e9e5383b9 100644 --- a/testing/btest/scripts/base/frameworks/storage/sqlite-basic.zeek +++ b/testing/btest/scripts/base/frameworks/storage/sqlite-basic.zeek @@ -3,7 +3,7 @@ # @TEST-EXEC: btest-diff out # @TEST-EXEC: btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/async @load policy/frameworks/storage/backend/sqlite redef exit_only_after_terminate = T; @@ -22,18 +22,18 @@ event zeek_init() { # Test inserting/retrieving a key/value pair that we know won't be in # the backend yet. - when [opts, key, value] ( local b = Storage::open_backend(Storage::SQLITE, opts, str, str, T) ) { + when [opts, key, value] ( local b = Storage::Async::open_backend(Storage::SQLITE, opts, str, str) ) { print "open successful"; - when [b, key, value] ( local put_res = Storage::put(b, [$key=key, $value=value]) ) { + when [b, key, value] ( local put_res = Storage::Async::put(b, [$key=key, $value=value]) ) { print "put result", put_res; - when [b, key, value] ( local get_res = Storage::get(b, key) ) { + when [b, key, value] ( local get_res = Storage::Async::get(b, key) ) { print "get result", get_res; if ( get_res?$val ) print "get result same as inserted", value == (get_res$val as string); - when [b] ( local close_res = Storage::close_backend(b, T) ) { + when [b] ( local close_res = Storage::Async::close_backend(b) ) { print "closed succesfully"; terminate(); } timeout 5 sec { diff --git a/testing/btest/scripts/base/frameworks/storage/sqlite-error-handling.zeek b/testing/btest/scripts/base/frameworks/storage/sqlite-error-handling.zeek index 4d7d248fc4..84bffa4dc3 100644 --- a/testing/btest/scripts/base/frameworks/storage/sqlite-error-handling.zeek +++ b/testing/btest/scripts/base/frameworks/storage/sqlite-error-handling.zeek @@ -3,7 +3,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr -@load base/frameworks/storage +@load base/frameworks/storage/sync @load base/frameworks/reporter @load policy/frameworks/storage/backend/sqlite @@ -17,18 +17,18 @@ event zeek_init() { opts$table_name = "testing"; # This should report an error in .stderr and reporter.log - local b = Storage::open_backend(Storage::SQLITE, opts, str, str); + local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str); # Open a valid database file opts$database_path = "test.sqlite"; - b = Storage::open_backend(Storage::SQLITE, opts, str, str); + b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str); local bad_key: count = 12345; local value = "abcde"; - Storage::put(b, [$key=bad_key, $value=value, $async_mode=F]); + Storage::Sync::put(b, [$key=bad_key, $value=value]); # Close the backend and then attempt to use the closed handle - Storage::close_backend(b); - local res = Storage::put(b, [$key="a", $value="b", $async_mode=F]); + Storage::Sync::close_backend(b); + local res = Storage::Sync::put(b, [$key="a", $value="b"]); print fmt("Put result on closed handle: %d", res); }