feat(lsm): data streaming, random other stuff, locks

This commit is contained in:
Jef Roosens 2023-10-28 15:48:28 +02:00
parent aab93d9741
commit 0e4e18da6c
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 137 additions and 24 deletions

View file

@ -3,11 +3,11 @@
#include <stdint.h>
#define LSM_RES(x) \
{ \
lsm_error res = x; \
if (res != lsm_error_ok) \
return res; \
#define LSM_RES(x) \
{ \
lsm_error res = x; \
if (res != lsm_error_ok) \
return res; \
}
typedef enum lsm_error {
@ -15,7 +15,9 @@ typedef enum lsm_error {
lsm_error_failed_alloc = 1,
lsm_error_not_found = 2,
lsm_error_already_present = 3,
lsm_error_null_value = 4
lsm_error_null_value = 4,
lsm_error_failed_io = 5,
lsm_error_lock_busy = 6,
} lsm_error;
/*typedef struct lsm_string { */

View file

@ -104,7 +104,7 @@ lsm_error lsm_store_init(lsm_store **ptr);
* @param db_path path to the database file
* @param data_path path to the data directory
*/
lsm_error lsm_store_open(lsm_store **ptr, char *db_path, char *data_path);
lsm_error lsm_store_open(lsm_store **ptr, lsm_str *db_path, lsm_str *data_path);
/**
* Dealocate an existing lsm_store object.
@ -114,16 +114,37 @@ lsm_error lsm_store_open(lsm_store **ptr, char *db_path, char *data_path);
void lsm_store_free(lsm_store *store);
/**
* Search for an entry in the store.
* Retrieve an entry from the store, preparing & locking it for the purpose of
* reading.
*
* @param out pointer to store entry pointer in
* @param store store to search in
* @param key key to look with
* @param out pointer to store entry pointer
* @param store store to retrieve entry from
* @param key key to search
*/
lsm_error lsm_store_search(lsm_entry **out, lsm_store *store, lsm_str *key);
lsm_error lsm_store_get_read(lsm_entry **out, lsm_store *store, lsm_str *key);
/**
* Allocate a new entry in the store with the specified key.
* Retrieve an entry from the store for the purposes of writing. This
* write-locks the entry.
*
* @param out pointer to store entry pointer
* @param store store to retrieve entry from
* @param key key to search
*/
lsm_error lsm_store_get_write(lsm_entry **out, lsm_store *store, lsm_str *key);
/**
* Unlock a locked entry.
*
* @param store store to unlock entry in
* @param entry entry to unlock
*/
lsm_error lsm_store_unlock(lsm_store *store, lsm_entry *entry);
/**
* Allocate a new entry in the store with the specified key. The entry returned
* will be write-locked, and should be unlocked after streaming the necessary
* data.
*
* @param out pointer to store new entry pointer in
* @param store store to modify
@ -141,6 +162,7 @@ lsm_error lsm_store_insert(lsm_entry **out, lsm_store *store, lsm_str *key);
* @param entry entry to append data to
* @param data data to append
*/
lsm_error lsm_store_data_append(lsm_store *store, lsm_entry *entry, lsm_str *data);
lsm_error lsm_store_data_write(lsm_store *store, lsm_entry *entry,
lsm_str *data);
#endif