mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Split sync and async into separate script-land namespaces
This commit is contained in:
parent
e8074c40d4
commit
28951dccf1
24 changed files with 465 additions and 303 deletions
|
@ -1 +1,3 @@
|
|||
@load ./async
|
||||
@load ./main
|
||||
@load ./sync
|
100
scripts/base/frameworks/storage/async.zeek
Normal file
100
scripts/base/frameworks/storage/async.zeek
Normal file
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
98
scripts/base/frameworks/storage/sync.zeek
Normal file
98
scripts/base/frameworks/storage/sync.zeek
Normal file
|
@ -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);
|
||||
}
|
|
@ -148,11 +148,16 @@ static std::unordered_map<std::string, unsigned int> 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},
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
using namespace zeek;
|
||||
using namespace zeek::storage;
|
||||
|
||||
static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame, const BackendPtr& b) {
|
||||
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");
|
||||
emit_builtin_error("Asynchronous storage operations must be called via a when-condition");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,21 @@ static zeek::detail::trigger::TriggerPtr init_trigger(zeek::detail::Frame* frame
|
|||
|
||||
return {NewRef{}, trigger};
|
||||
}
|
||||
|
||||
static IntrusivePtr<storage::detail::BackendHandleVal> make_backend_handle(Val* btype) {
|
||||
auto btype_val = IntrusivePtr<EnumVal>{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<storage::detail::BackendHandleVal>(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<EnumVal>{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<storage::detail::BackendHandleVal>(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<RecordVal>{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<storage::detail::BackendHandleVal*>(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<storage::detail::BackendHandleVal*>(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<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{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<RecordType>("val_result");
|
||||
auto val_result = make_intrusive<RecordVal>(val_result_type);
|
||||
|
||||
auto trigger = init_trigger(frame);
|
||||
if ( ! trigger ) {
|
||||
val_result->Assign(1, make_intrusive<StringVal>("Failed to create trigger"));
|
||||
return val_result;
|
||||
}
|
||||
|
||||
auto b = dynamic_cast<storage::detail::BackendHandleVal*>(backend);
|
||||
if ( ! b ) {
|
||||
val_result->Assign(1, make_intrusive<StringVal>("Invalid storage handlle"));
|
||||
return val_result;
|
||||
}
|
||||
else if ( ! b->backend->IsOpen() ) {
|
||||
val_result->Assign(1, make_intrusive<StringVal>("Backend is closed"));
|
||||
return val_result;
|
||||
}
|
||||
|
||||
auto cb = new ValResultCallback(trigger, frame->GetTriggerAssoc());
|
||||
auto key_v = IntrusivePtr<Val>{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<storage::detail::BackendHandleVal*>(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<Val>{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<EnumVal>{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<storage::detail::BackendHandleVal>(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<RecordVal>{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<storage::detail::BackendHandleVal>(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<storage::detail::BackendHandleVal*>(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<storage::detail::BackendHandleVal*>(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<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{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<RecordType>("val_result");
|
||||
auto val_result = make_intrusive<RecordVal>(val_result_type);
|
||||
|
@ -159,23 +257,8 @@ 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<StringVal>("Failed to create trigger"));
|
||||
return val_result;
|
||||
}
|
||||
|
||||
cb = new ValResultCallback(trigger, frame->GetTriggerAssoc());
|
||||
}
|
||||
|
||||
auto key_v = IntrusivePtr<Val>{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<StringVal>(
|
||||
|
@ -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<storage::detail::BackendHandleVal*>(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<Val>{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()));
|
||||
|
|
|
@ -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/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
|
||||
|
|
|
@ -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 ()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue