WIP: lsm handle read-write separation
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
Jef Roosens 2024-08-29 12:40:51 +02:00
parent 7c938d592e
commit 80281c702b
Signed by: Jef Roosens
GPG key ID: 02D4C0997E74717B
6 changed files with 417 additions and 223 deletions

View file

@ -9,96 +9,22 @@
#define LSM_STORE_DATA_LEVELS 3
/**
* Read-only handle to an entry in the store
*/
typedef struct lsm_read_handle lsm_read_handle;
/**
* Writeable handle to an entry in the store
*/
typedef struct lsm_write_handle lsm_write_handle;
/**
* A handle referencing an entry inside a store. Read/write operations from/to
* the entry go through this handle.
*/
typedef struct lsm_entry_handle lsm_entry_handle;
/**
* Checks whether the entry has an attribute with the specified type.
*
* @param entry entry to check
* @param type type of attribute to check for
*/
bool lsm_entry_attr_present(lsm_entry_handle *handle, uint8_t type);
/**
* Retrieve the contents of an attribute from an entry, if present
*
* @param out where to store pointer to attribute data
* @param entry entry to search for
* @param type type of attribute to return
*/
lsm_error lsm_entry_attr_get(lsm_str **out, lsm_entry_handle *handle,
uint8_t type);
/**
* Convenience wrapper around `lsm_entry_attr_get` that can be used if we know
* beforehand the attribute value is a 64-bit number.
*
* @param out where to store attribute data
* @param entry entry to search for
* @param type type of attribute to return
*/
lsm_error lsm_entry_attr_get_uint64_t(uint64_t *out, lsm_entry_handle *handle,
uint8_t type);
/**
* Convenience wrapper around `lsm_entry_attr_get` that can be used if we know
* beforehand the attribute value is an 8-bit number.
*
* @param out where to store attribute data
* @param entry entry to search for
* @param type type of attribute to return
*/
lsm_error lsm_entry_attr_get_uint8_t(uint8_t *out, lsm_entry_handle *handle,
uint8_t type);
/**
* Add a new attribute to the entry. This overwrites an existing version of this
* attribute.
*
* @param entry entry to modify
* @param type type of attribute to add
* @param data data of attribute; ownership of pointer is taken over
*/
lsm_error lsm_entry_attr_insert(lsm_entry_handle *handle, uint8_t type,
lsm_str *data);
/**
* Convenience wrapper around `lsm_entry_attr_insert` that can be used if the
* data to be stored is a 64-bit number.
*
* @param entry entry to modify
* @param type type of attribute to add
* @param data data of attribute
*/
lsm_error lsm_entry_attr_insert_uint64_t(lsm_entry_handle *handle, uint8_t type,
uint64_t data);
/**
* Convenience wrapper around `lsm_entry_attr_insert` that can be used if the
* data to be stored is an 8-bit number.
*
* @param entry entry to modify
* @param type type of attribute to add
* @param data data of attribute
*/
lsm_error lsm_entry_attr_insert_uint8_t(lsm_entry_handle *handle, uint8_t type,
uint8_t data);
/**
* Remove an atribute from the given entry, if present.
*
* @param out pointer to store removed data pointer in. If NULL, data pointer
* will be leaked.
* @param entry entry to remove attribute from
* @param type type of attribute to remove
*/
lsm_error lsm_entry_attr_remove(lsm_str **out, lsm_entry_handle *handle,
uint8_t type);
/**
* A store consisting of LSM entries.
*
@ -145,7 +71,7 @@ void lsm_store_free(lsm_store *store);
* @param store store to retrieve entry from
* @param key key to search
*/
lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store,
lsm_error lsm_store_open_read(lsm_read_handle **out, lsm_store *store,
const lsm_str *key);
/**
@ -157,7 +83,7 @@ lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store,
* @param store store to retrieve entry from
* @param key key to search
*/
lsm_error lsm_store_open_write(lsm_entry_handle **out, lsm_store *store,
lsm_error lsm_store_open_write(lsm_write_handle **out, lsm_store *store,
const lsm_str *key);
/**
@ -227,8 +153,8 @@ lsm_error lsm_entry_data_append_raw(lsm_entry_handle *handle, char *data,
* @param handle entry handle to read from
* @param len how many bytes to read at most
*/
lsm_error lsm_entry_data_read(uint64_t *out, char *buf,
lsm_entry_handle *handle, uint64_t len);
lsm_error lsm_entry_data_read(uint64_t *out, char *buf, lsm_read_handle *handle,
uint64_t len);
/**
* Return the length of the entry's data.