Add infrastructure for asynchronous storage operations

This commit is contained in:
Tim Wojtulewicz 2024-12-06 16:05:23 -07:00
parent d07d27453a
commit 7ad6a05f5b
8 changed files with 251 additions and 49 deletions

View file

@ -13,13 +13,19 @@ export {
# The value to store associated with the key.
value: any;
# Indicates whether this value should overwrite an existing entry
# for the key.
# Indicates whether this value should overwrite an existing entry for the
# key.
overwrite: bool &default=T;
# 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.
@ -58,7 +64,7 @@ export {
##
## 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 false 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;
@ -68,11 +74,18 @@ export {
##
## 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 false to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned.
global get: function(backend: opaque of Storage::BackendHandle, key: any): any;
global get: function(backend: opaque of Storage::BackendHandle, key: any,
async_mode: bool &default=T): any;
## Erases an entry from the backend.
##
@ -80,11 +93,18 @@ export {
##
## 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 false 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;
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): opaque of Storage::BackendHandle
@ -99,15 +119,15 @@ function close_backend(backend: opaque of Storage::BackendHandle): bool
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool
{
return Storage::__put(backend, args$key, args$value, args$overwrite, args$expire_time);
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): any
function get(backend: opaque of Storage::BackendHandle, key: any, async_mode: bool &default=T): any
{
return Storage::__get(backend, key);
return Storage::__get(backend, key, async_mode);
}
function erase(backend: opaque of Storage::BackendHandle, key: any): bool
function erase(backend: opaque of Storage::BackendHandle, key: any, async_mode: bool &default=T): bool
{
return Storage::__erase(backend, key);
return Storage::__erase(backend, key, async_mode);
}