diff --git a/scripts/base/frameworks/storage/main.zeek b/scripts/base/frameworks/storage/main.zeek index 7a11a6c25a..5c05503c33 100644 --- a/scripts/base/frameworks/storage/main.zeek +++ b/scripts/base/frameworks/storage/main.zeek @@ -1,7 +1,5 @@ ##! The storage framework provides a way to store long-term data to disk. -@load base/bif/storage.bif - module Storage; export { diff --git a/src/storage/Backend.cc b/src/storage/Backend.cc index f47e29eeea..53dd4c0335 100644 --- a/src/storage/Backend.cc +++ b/src/storage/Backend.cc @@ -5,7 +5,7 @@ #include "zeek/Trigger.h" #include "zeek/broker/Data.h" #include "zeek/storage/ReturnCode.h" -#include "zeek/storage/storage.bif.h" +#include "zeek/storage/storage-events.bif.h" namespace zeek::storage { diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index d1401a3ee1..b64c7d6016 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -6,6 +6,8 @@ zeek_add_subdir_library( Component.cc ReturnCode.cc BIFS - storage.bif) + storage-async.bif + storage-events.bif + storage-sync.bif) add_subdirectory(backend) diff --git a/src/storage/backend/redis/Redis.cc b/src/storage/backend/redis/Redis.cc index 5d357239d2..f597a1370f 100644 --- a/src/storage/backend/redis/Redis.cc +++ b/src/storage/backend/redis/Redis.cc @@ -8,7 +8,6 @@ #include "zeek/Val.h" #include "zeek/iosource/Manager.h" #include "zeek/storage/ReturnCode.h" -#include "zeek/storage/storage.bif.h" #include "hiredis/adapters/poll.h" #include "hiredis/async.h" diff --git a/src/storage/storage-async.bif b/src/storage/storage-async.bif new file mode 100644 index 0000000000..5afca4feec --- /dev/null +++ b/src/storage/storage-async.bif @@ -0,0 +1,190 @@ +##! Functions related to asynchronous storage operations. + +%%{ +#include "zeek/Frame.h" +#include "zeek/Trigger.h" +#include "zeek/storage/Backend.h" +#include "zeek/storage/Manager.h" +#include "zeek/storage/ReturnCode.h" + +using namespace zeek; +using namespace zeek::storage; + +// Utility method for initializing a trigger from a Frame passed into a BIF. This is +// used by the asynchronous methods to make sure the trigger is setup before starting +// the operations. It also does some sanity checking to ensure the trigger is valid. + +static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame) { + auto trigger = frame->GetTrigger(); + + 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("Asynchronous storage operations must specify a timeout block"); + return nullptr; + } + + frame->SetDelayed(); + trigger->Hold(); + + return {NewRef{}, trigger}; +} + +// Utility method to cast the handle val passed into BIF methods into a form that can +// be used to start storage operations. The method is also used by the BIFs in sync.bif. +static zeek::expected cast_handle(Val* handle) { + auto b = static_cast(handle); + + if ( ! b ) + return zeek::unexpected( + OperationResult{ReturnCode::OPERATION_FAILED, "Invalid storage handlle"}); + else if ( ! b->backend->IsOpen() ) + return zeek::unexpected(OperationResult{ReturnCode::NOT_CONNECTED, "Backend is closed"}); + + return b; +} + +static void handle_async_result(const IntrusivePtr& backend, ResultCallback* cb, + const OperationResult& op_result) { + if ( op_result.code != ReturnCode::IN_PROGRESS || ! backend->SupportsAsync() ) { + // We need to complete the callback early if: + // 1. The operation didn't start up successfully. For async operations, this means + // it didn't report back IN_PROGRESS. + // 2. The backend doesn't support async. This means we already blocked in order + // to get here already. + cb->Complete(op_result); + delete cb; + } + else if ( run_state::reading_traces ) { + // If the backend is truly async and we're reading traces, we need to fake being + // in sync mode because otherwise time doesn't move forward correctly. + backend->Poll(); + } +} + +%%} + +module Storage::Async; + +function Storage::Async::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any%): Storage::OperationResult + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return nullptr; + + auto btype_val = IntrusivePtr{NewRef{}, btype->AsEnumVal()}; + Tag tag{btype_val}; + + auto b = storage_mgr->Instantiate(tag); + + if ( ! b.has_value() ) { + trigger->Cache( + frame->GetTriggerAssoc(), + new StringVal(util::fmt("Failed to instantiate backend: %s", b.error().c_str()))); + trigger->Release(); + return nullptr; + } + + auto bh = make_intrusive(b.value()); + + auto cb = new OpenResultCallback(trigger, frame->GetTriggerAssoc(), bh); + auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); + auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); + auto options_val = IntrusivePtr{NewRef{}, options->AsRecordVal()}; + auto op_result = storage_mgr->OpenBackend(b.value(), cb, options_val, kt, vt); + + handle_async_result(b.value(), cb, op_result); + + return nullptr; + %} + +function Storage::Async::__close_backend%(backend: opaque of Storage::BackendHandle%) : Storage::OperationResult + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return nullptr; + + auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); + auto b = cast_handle(backend); + if ( ! b ) { + cb->Complete(b.error()); + delete cb; + return nullptr; + } + + auto op_result = storage_mgr->CloseBackend((*b)->backend, cb); + handle_async_result((*b)->backend, cb, op_result); + + return nullptr; + %} + +function Storage::Async::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, + overwrite: bool, expire_time: interval%): Storage::OperationResult + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return nullptr; + + auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); + auto b = cast_handle(backend); + if ( ! b ) { + cb->Complete(b.error()); + delete cb; + return nullptr; + } + + if ( expire_time > 0.0 ) + expire_time += run_state::network_time; + + auto key_v = IntrusivePtr{NewRef{}, key}; + auto val_v = IntrusivePtr{NewRef{}, value}; + auto op_result = (*b)->backend->Put(cb, key_v, val_v, overwrite, expire_time); + handle_async_result((*b)->backend, cb, op_result); + + return nullptr; + %} + +function Storage::Async::__get%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return nullptr; + + auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); + auto b = cast_handle(backend); + if ( ! b ) { + cb->Complete(b.error()); + delete cb; + return nullptr; + } + + auto key_v = IntrusivePtr{NewRef{}, key}; + auto op_result = (*b)->backend->Get(cb, key_v); + handle_async_result((*b)->backend, cb, op_result); + + return nullptr; + %} + +function Storage::Async::__erase%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult + %{ + auto trigger = init_trigger(frame); + if ( ! trigger ) + return nullptr; + + auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); + auto b = cast_handle(backend); + if ( ! b ) { + cb->Complete(b.error()); + delete cb; + return nullptr; + } + + auto key_v = IntrusivePtr{NewRef{}, key}; + auto op_result = (*b)->backend->Erase(cb, key_v); + handle_async_result((*b)->backend, cb, op_result); + + return nullptr; + %} diff --git a/src/storage/storage-events.bif b/src/storage/storage-events.bif new file mode 100644 index 0000000000..b0aa5c4f72 --- /dev/null +++ b/src/storage/storage-events.bif @@ -0,0 +1,31 @@ +##! Events related to storage operations. + +module Storage; + +## Generated automatically when a new backend connection is opened successfully. +## +## tag: A string describing the backend that enqueued this event. This is typically +## generated by the ``Tag()`` method in the backend plugin. +## +## options: A copy of the configuration options passed to +## :zeek:see:`Storage::Async::open_backend` or +## :zeek:see:`Storage::Sync::open_backend` when the backend was initially opened. +## +## .. zeek:see:: Storage::backend_lost +event Storage::backend_opened%(tag: string, options: any%); + +## May be generated when a backend connection is lost, both normally and +## unexpectedly. This event depends on the backends implementing handling for +## it, and is not generated automatically by the storage framework. +## +## tag: A string describing the backend that enqueued this event. This is typically +## generated by the ``Tag()`` method in the backend plugin. +## +## options: A copy of the configuration options passed to +## :zeek:see:`Storage::Async::open_backend` or +## :zeek:see:`Storage::Sync::open_backend` when the backend was initially opened. +## +## reason: A string describing why the connection was lost. +## +## .. zeek:see:: Storage::backend_opened +event Storage::backend_lost%(tag: string, options: any, reason: string%); diff --git a/src/storage/storage-sync.bif b/src/storage/storage-sync.bif new file mode 100644 index 0000000000..24ad138ee3 --- /dev/null +++ b/src/storage/storage-sync.bif @@ -0,0 +1,165 @@ +##! Functions related to synchronous storage operations. + +%%{ +#include "zeek/storage/Backend.h" +#include "zeek/storage/Manager.h" +#include "zeek/storage/ReturnCode.h" + +using namespace zeek; +using namespace zeek::storage; + +// Utility method to cast the handle val passed into BIF methods into a form that can +// be used to start storage operations. This is a duplicate of the method in sync.bif +// due to how utility methods are built by bifcl. +/* +static zeek::expected cast_handle(Val* handle) { + auto b = static_cast(handle); + + if ( ! b ) + return zeek::unexpected( + OperationResult{ReturnCode::OPERATION_FAILED, "Invalid storage handlle"}); + else if ( ! b->backend->IsOpen() ) + return zeek::unexpected(OperationResult{ReturnCode::NOT_CONNECTED, "Backend is closed"}); + + return b; +} +*/ +%%} + +module Storage::Sync; + +function Storage::Sync::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any%): Storage::OperationResult + %{ + 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 val_mgr->Bool(false); + } + + auto bh = make_intrusive(b.value()); + + auto cb = new OpenResultCallback(bh); + auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); + auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); + auto options_val = IntrusivePtr{NewRef{}, options->AsRecordVal()}; + auto op_result = storage_mgr->OpenBackend(b.value(), cb, options_val, kt, vt); + + // If the backend only supports async, block until it's ready and then pull the result out of + // the callback. + if ( ! b.value()->SupportsSync() ) { + b.value()->Poll(); + op_result = cb->Result(); + } + + delete cb; + + return op_result.BuildVal(); + %} + +function Storage::Sync::__close_backend%(backend: opaque of Storage::BackendHandle%) : Storage::OperationResult + %{ + OperationResult op_result; + + auto b = cast_handle(backend); + if ( ! b ) + op_result = b.error(); + else { + auto cb = new OperationResultCallback(); + op_result = storage_mgr->CloseBackend((*b)->backend, cb); + + // If the backend only supports async, block until it's ready and then pull the result out of + // the callback. + if ( ! (*b)->backend->SupportsSync() ) { + (*b)->backend->Poll(); + op_result = cb->Result(); + } + + delete cb; + } + + return op_result.BuildVal(); + %} + +function Storage::Sync::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, + overwrite: bool, expire_time: interval%): Storage::OperationResult + %{ + OperationResult op_result; + + auto b = cast_handle(backend); + if ( ! b ) + op_result = b.error(); + else { + if ( expire_time > 0.0 ) + expire_time += run_state::network_time; + + auto cb = new OperationResultCallback(); + auto key_v = IntrusivePtr{NewRef{}, key}; + auto val_v = IntrusivePtr{NewRef{}, value}; + op_result = (*b)->backend->Put(cb, key_v, val_v, overwrite, expire_time); + + // If the backend only supports async, block until it's ready and then pull the result out of + // the callback. + if ( ! (*b)->backend->SupportsSync() ) { + (*b)->backend->Poll(); + op_result = cb->Result(); + } + + delete cb; + } + + return op_result.BuildVal(); + %} + +function Storage::Sync::__get%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult + %{ + OperationResult op_result; + + auto b = cast_handle(backend); + if ( ! b ) + op_result = b.error(); + else { + auto cb = new OperationResultCallback(); + auto key_v = IntrusivePtr{NewRef{}, key}; + op_result = (*b)->backend->Get(cb, key_v); + + // If the backend only supports async, block until it's ready and then pull the result out of + // the callback. + if ( ! (*b)->backend->SupportsSync() ) { + (*b)->backend->Poll(); + op_result = cb->Result(); + } + + delete cb; + } + + return op_result.BuildVal(); + %} + +function Storage::Sync::__erase%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult + %{ + OperationResult op_result; + + auto b = cast_handle(backend); + if ( ! b ) + op_result = b.error(); + else { + auto cb = new OperationResultCallback(); + auto key_v = IntrusivePtr{NewRef{}, key}; + op_result = (*b)->backend->Erase(cb, key_v); + + // If the backend only supports async, block until it's ready and then pull the result out of + // the callback. + if ( ! (*b)->backend->SupportsSync() ) { + (*b)->backend->Poll(); + op_result = cb->Result(); + } + + delete cb; + } + + return op_result.BuildVal(); + %} diff --git a/src/storage/storage.bif b/src/storage/storage.bif deleted file mode 100644 index b32818734e..0000000000 --- a/src/storage/storage.bif +++ /dev/null @@ -1,343 +0,0 @@ -%%{ -#include "zeek/Trigger.h" -#include "zeek/Frame.h" -#include "zeek/storage/Backend.h" -#include "zeek/storage/Manager.h" -#include "zeek/storage/ReturnCode.h" - -using namespace zeek; -using namespace zeek::storage; - -static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame) { - auto trigger = frame->GetTrigger(); - - 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"); - return nullptr; - } - - frame->SetDelayed(); - trigger->Hold(); - - 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()); -} - -static zeek::expected cast_handle(Val* handle) { - auto b = static_cast(handle); - - if ( ! b ) - return zeek::unexpected(OperationResult{ReturnCode::OPERATION_FAILED, "Invalid storage handlle"}); - else if ( ! b->backend->IsOpen() ) - return zeek::unexpected(OperationResult{ReturnCode::NOT_CONNECTED, "Backend is closed"}); - - return b; -} - -static void handle_async_result(const IntrusivePtr& backend, ResultCallback* cb, - const OperationResult& op_result) { - if ( op_result.code != ReturnCode::IN_PROGRESS || ! backend->SupportsAsync() ) { - // We need to complete the callback early if: - // 1. The operation didn't start up successfully. For async operations, this means - // it didn't report back IN_PROGRESS. - // 2. The backend doesn't support async. This means we already blocked in order - // to get here already. - cb->Complete(op_result); - delete cb; - } - else if ( run_state::reading_traces ) { - // If the backend is truly async and we're reading traces, we need to fake being in sync mode - // because otherwise time doesn't move forward correctly. - backend->Poll(); - } -} - -%%} - -module Storage; - -## Generated automatically when a new backend connection is opened successfully. -event Storage::backend_opened%(tag: string, options: any%); - -## May be generated when a backend connection is lost, both normally and -## unexpectedly. This event depends on the backends implementing handling for -## it, and is not generated automatically by the storage framework. -event Storage::backend_lost%(tag: string, options: any, reason: string%); - -module Storage::Async; - -function Storage::Async::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any%): Storage::OperationResult - %{ - auto trigger = init_trigger(frame); - if ( ! trigger ) - return nullptr; - - auto btype_val = IntrusivePtr{NewRef{}, btype->AsEnumVal()}; - Tag tag{btype_val}; - - auto b = storage_mgr->Instantiate(tag); - - if ( ! b.has_value() ) { - trigger->Cache( - frame->GetTriggerAssoc(), - new StringVal(util::fmt("Failed to instantiate backend: %s", b.error().c_str()))); - trigger->Release(); - return nullptr; - } - - auto bh = make_intrusive(b.value()); - - auto cb = new OpenResultCallback(trigger, frame->GetTriggerAssoc(), bh); - auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); - auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); - auto options_val = IntrusivePtr{NewRef{}, options->AsRecordVal()}; - auto op_result = storage_mgr->OpenBackend(b.value(), cb, options_val, kt, vt); - - handle_async_result(b.value(), cb, op_result); - - return nullptr; - %} - -function Storage::Async::__close_backend%(backend: opaque of Storage::BackendHandle%) : Storage::OperationResult - %{ - auto trigger = init_trigger(frame); - if ( ! trigger ) - return nullptr; - - auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); - auto b = cast_handle(backend); - if ( ! b ) { - cb->Complete(b.error()); - delete cb; - return nullptr; - } - - auto op_result = storage_mgr->CloseBackend((*b)->backend, cb); - handle_async_result((*b)->backend, cb, op_result); - - return nullptr; - %} - -function Storage::Async::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, - overwrite: bool, expire_time: interval%): Storage::OperationResult - %{ - auto trigger = init_trigger(frame); - if ( ! trigger ) - return nullptr; - - auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); - auto b = cast_handle(backend); - if ( ! b ) { - cb->Complete(b.error()); - delete cb; - return nullptr; - } - - if ( expire_time > 0.0 ) - expire_time += run_state::network_time; - - auto key_v = IntrusivePtr{NewRef{}, key}; - auto val_v = IntrusivePtr{NewRef{}, value}; - auto op_result = (*b)->backend->Put(cb, key_v, val_v, overwrite, expire_time); - handle_async_result((*b)->backend, cb, op_result); - - return nullptr; - %} - -function Storage::Async::__get%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult - %{ - auto trigger = init_trigger(frame); - if ( ! trigger ) - return nullptr; - - auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); - auto b = cast_handle(backend); - if ( ! b ) { - cb->Complete(b.error()); - delete cb; - return nullptr; - } - - auto key_v = IntrusivePtr{NewRef{}, key}; - auto op_result = (*b)->backend->Get(cb, key_v); - handle_async_result((*b)->backend, cb, op_result); - - return nullptr; - %} - -function Storage::Async::__erase%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult - %{ - auto trigger = init_trigger(frame); - if ( ! trigger ) - return nullptr; - - auto cb = new OperationResultCallback(trigger, frame->GetTriggerAssoc()); - auto b = cast_handle(backend); - if ( ! b ) { - cb->Complete(b.error()); - delete cb; - return nullptr; - } - - auto key_v = IntrusivePtr{NewRef{}, key}; - auto op_result = (*b)->backend->Erase(cb, key_v); - handle_async_result((*b)->backend, cb, op_result); - - return nullptr; - %} - -module Storage::Sync; - -function Storage::Sync::__open_backend%(btype: Storage::Backend, options: any, key_type: any, val_type: any%): Storage::OperationResult - %{ - 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 val_mgr->Bool(false); - } - - auto bh = make_intrusive(b.value()); - - auto cb = new OpenResultCallback(bh); - auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); - auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType(); - auto options_val = IntrusivePtr{NewRef{}, options->AsRecordVal()}; - auto op_result = storage_mgr->OpenBackend(b.value(), cb, options_val, kt, vt); - - // If the backend only supports async, block until it's ready and then pull the result out of - // the callback. - if ( ! b.value()->SupportsSync() ) { - b.value()->Poll(); - op_result = cb->Result(); - } - - delete cb; - - return op_result.BuildVal(); - %} - -function Storage::Sync::__close_backend%(backend: opaque of Storage::BackendHandle%) : Storage::OperationResult - %{ - OperationResult op_result; - - auto b = cast_handle(backend); - if ( ! b ) - op_result = b.error(); - else { - auto cb = new OperationResultCallback(); - op_result = storage_mgr->CloseBackend((*b)->backend, cb); - - // If the backend only supports async, block until it's ready and then pull the result out of - // the callback. - if ( ! (*b)->backend->SupportsSync() ) { - (*b)->backend->Poll(); - op_result = cb->Result(); - } - - delete cb; - } - - return op_result.BuildVal(); - %} - -function Storage::Sync::__put%(backend: opaque of Storage::BackendHandle, key: any, value: any, - overwrite: bool, expire_time: interval%): Storage::OperationResult - %{ - OperationResult op_result; - - auto b = cast_handle(backend); - if ( ! b ) - op_result = b.error(); - else { - if ( expire_time > 0.0 ) - expire_time += run_state::network_time; - - auto cb = new OperationResultCallback(); - auto key_v = IntrusivePtr{NewRef{}, key}; - auto val_v = IntrusivePtr{NewRef{}, value}; - op_result = (*b)->backend->Put(cb, key_v, val_v, overwrite, expire_time); - - // If the backend only supports async, block until it's ready and then pull the result out of - // the callback. - if ( ! (*b)->backend->SupportsSync() ) { - (*b)->backend->Poll(); - op_result = cb->Result(); - } - - delete cb; - } - - return op_result.BuildVal(); - %} - -function Storage::Sync::__get%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult - %{ - OperationResult op_result; - - auto b = cast_handle(backend); - if ( ! b ) - op_result = b.error(); - else { - auto cb = new OperationResultCallback(); - auto key_v = IntrusivePtr{NewRef{}, key}; - op_result = (*b)->backend->Get(cb, key_v); - - // If the backend only supports async, block until it's ready and then pull the result out of - // the callback. - if ( ! (*b)->backend->SupportsSync() ) { - (*b)->backend->Poll(); - op_result = cb->Result(); - } - - delete cb; - } - - return op_result.BuildVal(); - %} - -function Storage::Sync::__erase%(backend: opaque of Storage::BackendHandle, key: any%): Storage::OperationResult - %{ - OperationResult op_result; - - auto b = cast_handle(backend); - if ( ! b ) - op_result = b.error(); - else { - auto cb = new OperationResultCallback(); - auto key_v = IntrusivePtr{NewRef{}, key}; - op_result = (*b)->backend->Erase(cb, key_v); - - // If the backend only supports async, block until it's ready and then pull the result out of - // the callback. - if ( ! (*b)->backend->SupportsSync() ) { - (*b)->backend->Poll(); - op_result = cb->Result(); - } - - delete cb; - } - - return op_result.BuildVal(); - %} diff --git a/testing/btest/Baseline/coverage.bare-load-baseline/canonified_loaded_scripts.log b/testing/btest/Baseline/coverage.bare-load-baseline/canonified_loaded_scripts.log index dedda53b20..e08c150e8d 100644 --- a/testing/btest/Baseline/coverage.bare-load-baseline/canonified_loaded_scripts.log +++ b/testing/btest/Baseline/coverage.bare-load-baseline/canonified_loaded_scripts.log @@ -160,7 +160,9 @@ scripts/base/init-frameworks-and-bifs.zeek build/scripts/base/bif/bloom-filter.bif.zeek build/scripts/base/bif/cardinality-counter.bif.zeek build/scripts/base/bif/top-k.bif.zeek - build/scripts/base/bif/storage.bif.zeek + build/scripts/base/bif/storage-async.bif.zeek + build/scripts/base/bif/storage-events.bif.zeek + build/scripts/base/bif/storage-sync.bif.zeek build/scripts/base/bif/spicy.bif.zeek build/scripts/base/bif/plugins/__load__.zeek build/scripts/base/bif/plugins/Zeek_BitTorrent.events.bif.zeek 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 c6a813054b..febd84103a 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 @@ -160,7 +160,9 @@ scripts/base/init-frameworks-and-bifs.zeek build/scripts/base/bif/bloom-filter.bif.zeek build/scripts/base/bif/cardinality-counter.bif.zeek build/scripts/base/bif/top-k.bif.zeek - build/scripts/base/bif/storage.bif.zeek + build/scripts/base/bif/storage-async.bif.zeek + build/scripts/base/bif/storage-events.bif.zeek + build/scripts/base/bif/storage-sync.bif.zeek build/scripts/base/bif/spicy.bif.zeek build/scripts/base/bif/plugins/__load__.zeek build/scripts/base/bif/plugins/Zeek_BitTorrent.events.bif.zeek diff --git a/testing/btest/Baseline/plugins.hooks/output b/testing/btest/Baseline/plugins.hooks/output index b66bf362d9..9f6e9b79be 100644 --- a/testing/btest/Baseline/plugins.hooks/output +++ b/testing/btest/Baseline/plugins.hooks/output @@ -505,7 +505,9 @@ 0.000000 MetaHookPost LoadFile(0, ./sftp, <...>/sftp.zeek) -> -1 0.000000 MetaHookPost LoadFile(0, ./spicy.bif.zeek, <...>/spicy.bif.zeek) -> -1 0.000000 MetaHookPost LoadFile(0, ./stats.bif.zeek, <...>/stats.bif.zeek) -> -1 -0.000000 MetaHookPost LoadFile(0, ./storage.bif.zeek, <...>/storage.bif.zeek) -> -1 +0.000000 MetaHookPost LoadFile(0, ./storage-async.bif.zeek, <...>/storage-async.bif.zeek) -> -1 +0.000000 MetaHookPost LoadFile(0, ./storage-events.bif.zeek, <...>/storage-events.bif.zeek) -> -1 +0.000000 MetaHookPost LoadFile(0, ./storage-sync.bif.zeek, <...>/storage-sync.bif.zeek) -> -1 0.000000 MetaHookPost LoadFile(0, ./store, <...>/store.zeek) -> -1 0.000000 MetaHookPost LoadFile(0, ./store.bif.zeek, <...>/store.bif.zeek) -> -1 0.000000 MetaHookPost LoadFile(0, ./strings.bif.zeek, <...>/strings.bif.zeek) -> -1 @@ -816,7 +818,9 @@ 0.000000 MetaHookPost LoadFileExtended(0, ./sftp, <...>/sftp.zeek) -> (-1, ) 0.000000 MetaHookPost LoadFileExtended(0, ./spicy.bif.zeek, <...>/spicy.bif.zeek) -> (-1, ) 0.000000 MetaHookPost LoadFileExtended(0, ./stats.bif.zeek, <...>/stats.bif.zeek) -> (-1, ) -0.000000 MetaHookPost LoadFileExtended(0, ./storage.bif.zeek, <...>/storage.bif.zeek) -> (-1, ) +0.000000 MetaHookPost LoadFileExtended(0, ./storage-async.bif.zeek, <...>/storage-async.bif.zeek) -> (-1, ) +0.000000 MetaHookPost LoadFileExtended(0, ./storage-events.bif.zeek, <...>/storage-events.bif.zeek) -> (-1, ) +0.000000 MetaHookPost LoadFileExtended(0, ./storage-sync.bif.zeek, <...>/storage-sync.bif.zeek) -> (-1, ) 0.000000 MetaHookPost LoadFileExtended(0, ./store, <...>/store.zeek) -> (-1, ) 0.000000 MetaHookPost LoadFileExtended(0, ./store.bif.zeek, <...>/store.bif.zeek) -> (-1, ) 0.000000 MetaHookPost LoadFileExtended(0, ./strings.bif.zeek, <...>/strings.bif.zeek) -> (-1, ) @@ -1460,7 +1464,9 @@ 0.000000 MetaHookPre LoadFile(0, ./sftp, <...>/sftp.zeek) 0.000000 MetaHookPre LoadFile(0, ./spicy.bif.zeek, <...>/spicy.bif.zeek) 0.000000 MetaHookPre LoadFile(0, ./stats.bif.zeek, <...>/stats.bif.zeek) -0.000000 MetaHookPre LoadFile(0, ./storage.bif.zeek, <...>/storage.bif.zeek) +0.000000 MetaHookPre LoadFile(0, ./storage-async.bif.zeek, <...>/storage-async.bif.zeek) +0.000000 MetaHookPre LoadFile(0, ./storage-events.bif.zeek, <...>/storage-events.bif.zeek) +0.000000 MetaHookPre LoadFile(0, ./storage-sync.bif.zeek, <...>/storage-sync.bif.zeek) 0.000000 MetaHookPre LoadFile(0, ./store, <...>/store.zeek) 0.000000 MetaHookPre LoadFile(0, ./store.bif.zeek, <...>/store.bif.zeek) 0.000000 MetaHookPre LoadFile(0, ./strings.bif.zeek, <...>/strings.bif.zeek) @@ -1771,7 +1777,9 @@ 0.000000 MetaHookPre LoadFileExtended(0, ./sftp, <...>/sftp.zeek) 0.000000 MetaHookPre LoadFileExtended(0, ./spicy.bif.zeek, <...>/spicy.bif.zeek) 0.000000 MetaHookPre LoadFileExtended(0, ./stats.bif.zeek, <...>/stats.bif.zeek) -0.000000 MetaHookPre LoadFileExtended(0, ./storage.bif.zeek, <...>/storage.bif.zeek) +0.000000 MetaHookPre LoadFileExtended(0, ./storage-async.bif.zeek, <...>/storage-async.bif.zeek) +0.000000 MetaHookPre LoadFileExtended(0, ./storage-events.bif.zeek, <...>/storage-events.bif.zeek) +0.000000 MetaHookPre LoadFileExtended(0, ./storage-sync.bif.zeek, <...>/storage-sync.bif.zeek) 0.000000 MetaHookPre LoadFileExtended(0, ./store, <...>/store.zeek) 0.000000 MetaHookPre LoadFileExtended(0, ./store.bif.zeek, <...>/store.bif.zeek) 0.000000 MetaHookPre LoadFileExtended(0, ./strings.bif.zeek, <...>/strings.bif.zeek) @@ -2426,7 +2434,9 @@ 0.000000 | HookLoadFile ./sftp <...>/sftp.zeek 0.000000 | HookLoadFile ./spicy.bif.zeek <...>/spicy.bif.zeek 0.000000 | HookLoadFile ./stats.bif.zeek <...>/stats.bif.zeek -0.000000 | HookLoadFile ./storage.bif.zeek <...>/storage.bif.zeek +0.000000 | HookLoadFile ./storage-async.bif.zeek <...>/storage-async.bif.zeek +0.000000 | HookLoadFile ./storage-events.bif.zeek <...>/storage-events.bif.zeek +0.000000 | HookLoadFile ./storage-sync.bif.zeek <...>/storage-sync.bif.zeek 0.000000 | HookLoadFile ./store <...>/store.zeek 0.000000 | HookLoadFile ./store.bif.zeek <...>/store.bif.zeek 0.000000 | HookLoadFile ./strings.bif.zeek <...>/strings.bif.zeek @@ -2737,7 +2747,9 @@ 0.000000 | HookLoadFileExtended ./sftp <...>/sftp.zeek 0.000000 | HookLoadFileExtended ./spicy.bif.zeek <...>/spicy.bif.zeek 0.000000 | HookLoadFileExtended ./stats.bif.zeek <...>/stats.bif.zeek -0.000000 | HookLoadFileExtended ./storage.bif.zeek <...>/storage.bif.zeek +0.000000 | HookLoadFileExtended ./storage-async.bif.zeek <...>/storage-async.bif.zeek +0.000000 | HookLoadFileExtended ./storage-events.bif.zeek <...>/storage-events.bif.zeek +0.000000 | HookLoadFileExtended ./storage-sync.bif.zeek <...>/storage-sync.bif.zeek 0.000000 | HookLoadFileExtended ./store <...>/store.zeek 0.000000 | HookLoadFileExtended ./store.bif.zeek <...>/store.bif.zeek 0.000000 | HookLoadFileExtended ./strings.bif.zeek <...>/strings.bif.zeek