mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Split storage.bif file into events/sync/async, add more comments
This commit is contained in:
parent
f40947f6ac
commit
c7015e8250
11 changed files with 414 additions and 356 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
190
src/storage/storage-async.bif
Normal file
190
src/storage/storage-async.bif
Normal file
|
@ -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<storage::detail::BackendHandleVal*, OperationResult> cast_handle(Val* handle) {
|
||||
auto b = static_cast<storage::detail::BackendHandleVal*>(handle);
|
||||
|
||||
if ( ! b )
|
||||
return zeek::unexpected<OperationResult>(
|
||||
OperationResult{ReturnCode::OPERATION_FAILED, "Invalid storage handlle"});
|
||||
else if ( ! b->backend->IsOpen() )
|
||||
return zeek::unexpected<OperationResult>(OperationResult{ReturnCode::NOT_CONNECTED, "Backend is closed"});
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static void handle_async_result(const IntrusivePtr<Backend>& 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<EnumVal>{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<storage::detail::BackendHandleVal>(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<RecordVal>{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<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{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<Val>{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<Val>{NewRef{}, key};
|
||||
auto op_result = (*b)->backend->Erase(cb, key_v);
|
||||
handle_async_result((*b)->backend, cb, op_result);
|
||||
|
||||
return nullptr;
|
||||
%}
|
31
src/storage/storage-events.bif
Normal file
31
src/storage/storage-events.bif
Normal file
|
@ -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%);
|
165
src/storage/storage-sync.bif
Normal file
165
src/storage/storage-sync.bif
Normal file
|
@ -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<storage::detail::BackendHandleVal*, OperationResult> cast_handle(Val* handle) {
|
||||
auto b = static_cast<storage::detail::BackendHandleVal*>(handle);
|
||||
|
||||
if ( ! b )
|
||||
return zeek::unexpected<OperationResult>(
|
||||
OperationResult{ReturnCode::OPERATION_FAILED, "Invalid storage handlle"});
|
||||
else if ( ! b->backend->IsOpen() )
|
||||
return zeek::unexpected<OperationResult>(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<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 val_mgr->Bool(false);
|
||||
}
|
||||
|
||||
auto bh = make_intrusive<storage::detail::BackendHandleVal>(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<RecordVal>{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<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{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<Val>{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<Val>{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();
|
||||
%}
|
|
@ -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<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());
|
||||
}
|
||||
|
||||
static zeek::expected<storage::detail::BackendHandleVal*, OperationResult> cast_handle(Val* handle) {
|
||||
auto b = static_cast<storage::detail::BackendHandleVal*>(handle);
|
||||
|
||||
if ( ! b )
|
||||
return zeek::unexpected<OperationResult>(OperationResult{ReturnCode::OPERATION_FAILED, "Invalid storage handlle"});
|
||||
else if ( ! b->backend->IsOpen() )
|
||||
return zeek::unexpected<OperationResult>(OperationResult{ReturnCode::NOT_CONNECTED, "Backend is closed"});
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static void handle_async_result(const IntrusivePtr<Backend>& 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<EnumVal>{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<storage::detail::BackendHandleVal>(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<RecordVal>{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<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{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<Val>{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<Val>{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<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 val_mgr->Bool(false);
|
||||
}
|
||||
|
||||
auto bh = make_intrusive<storage::detail::BackendHandleVal>(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<RecordVal>{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<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{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<Val>{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<Val>{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();
|
||||
%}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./spicy.bif.zeek, <...>/spicy.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./stats.bif.zeek, <...>/stats.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./storage.bif.zeek, <...>/storage.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./storage-async.bif.zeek, <...>/storage-async.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./storage-events.bif.zeek, <...>/storage-events.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./storage-sync.bif.zeek, <...>/storage-sync.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./store, <...>/store.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./store.bif.zeek, <...>/store.bif.zeek) -> (-1, <no content>)
|
||||
0.000000 MetaHookPost LoadFileExtended(0, ./strings.bif.zeek, <...>/strings.bif.zeek) -> (-1, <no content>)
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue