feat(lsm): sync database when closing handle

This commit is contained in:
Jef Roosens 2023-11-09 22:40:06 +01:00
parent eb0ce16f78
commit 9b223d04a0
Signed by: Jef Roosens
GPG key ID: 02D4C0997E74717B
8 changed files with 33 additions and 28 deletions

View file

@ -88,4 +88,25 @@ struct lsm_store {
*/
lsm_error lsm_store_load_db(lsm_store *store);
/**
* Close & free the handle without updating the database
*
* @param handle handle to close
*/
void lsm_entry_close_no_disk(lsm_entry_handle *handle);
/**
* Write a new insert to the database.
*
* @param handle handle to added entry
*/
lsm_error lsm_entry_disk_insert(lsm_entry_handle *handle);
/**
* Remove an entry from the database
*
* @param handle handle to the removed entry
*/
lsm_error lsm_entry_disk_remove(lsm_entry_handle *handle);
#endif

View file

@ -172,7 +172,7 @@ lsm_error lsm_store_load_db(lsm_store *store) {
LSM_RES(lsm_entry_read_attrs(NULL, handle, store->db_file));
handle->wrapper->entry->idx_file_offset = idx_file_offset;
lsm_entry_close(handle);
lsm_entry_close_no_disk(handle);
store->db_file_size += db_dim[1];
}

View file

@ -75,7 +75,7 @@ lsm_error lsm_write_idx_entry(uint64_t *size, FILE *idx_file, lsm_entry *entry,
return lsm_error_ok;
}
lsm_error lsm_entry_sync(lsm_entry_handle *handle) {
lsm_error lsm_entry_disk_insert(lsm_entry_handle *handle) {
lsm_store *store = handle->store;
pthread_mutex_lock(&store->db_lock);

View file

@ -47,13 +47,19 @@ lsm_error lsm_entry_handle_init(lsm_entry_handle **out) {
return lsm_error_ok;
}
void lsm_entry_close_no_disk(lsm_entry_handle *handle) {
pthread_rwlock_unlock(&handle->wrapper->lock);
free(handle);
}
void lsm_entry_close(lsm_entry_handle *handle) {
if (handle->f != NULL) {
fclose(handle->f);
}
pthread_rwlock_unlock(&handle->wrapper->lock);
free(handle);
// TODO handle errors here
lsm_entry_disk_insert(handle);
lsm_entry_close_no_disk(handle);
}
bool lsm_entry_attr_present(lsm_entry_handle *handle, uint8_t type) {