feat(lsm): store pointer to store in entry handle
This commit is contained in:
parent
d4b21fb84d
commit
eb0ce16f78
7 changed files with 23 additions and 59 deletions
|
|
@ -58,6 +58,7 @@ void lsm_entry_wrapper_free(lsm_entry_wrapper *wrapper);
|
|||
|
||||
struct lsm_entry_handle {
|
||||
lsm_entry_wrapper *wrapper;
|
||||
lsm_store *store;
|
||||
FILE *f;
|
||||
uint64_t pos;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,24 +62,8 @@ lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store,
|
|||
return res;
|
||||
}
|
||||
|
||||
/* // Open a new file descriptor if needed */
|
||||
/* if (entry->data_len > 0) { */
|
||||
/* char path[store->data_path->len + entry->key->len + 2]; */
|
||||
/* sprintf(path, "%s/%s", lsm_str_ptr(store->data_path), */
|
||||
/* lsm_str_ptr(entry->key)); */
|
||||
|
||||
/* FILE *f = fopen(path, "rb"); */
|
||||
|
||||
/* if (f == NULL) { */
|
||||
/* free(handle); */
|
||||
|
||||
/* return lsm_error_failed_io; */
|
||||
/* } */
|
||||
|
||||
/* handle->f = f; */
|
||||
/* } */
|
||||
|
||||
handle->wrapper = wrapper;
|
||||
handle->store = store;
|
||||
*out = handle;
|
||||
|
||||
return lsm_error_ok;
|
||||
|
|
@ -116,24 +100,8 @@ lsm_error lsm_store_open_write(lsm_entry_handle **out, lsm_store *store,
|
|||
return res;
|
||||
}
|
||||
|
||||
/* // Open a new file descriptor if needed */
|
||||
/* if (entry->data_len > 0) { */
|
||||
/* char path[store->data_path->len + entry->key->len + 2]; */
|
||||
/* sprintf(path, "%s/%s", lsm_str_ptr(store->data_path), */
|
||||
/* lsm_str_ptr(entry->key)); */
|
||||
|
||||
/* FILE *f = fopen(path, "ab"); */
|
||||
|
||||
/* if (f == NULL) { */
|
||||
/* free(handle); */
|
||||
|
||||
/* return lsm_error_failed_io; */
|
||||
/* } */
|
||||
|
||||
/* handle->f = f; */
|
||||
/* } */
|
||||
|
||||
handle->wrapper = wrapper;
|
||||
handle->store = store;
|
||||
*out = handle;
|
||||
|
||||
return lsm_error_ok;
|
||||
|
|
@ -180,14 +148,14 @@ lsm_error lsm_store_insert(lsm_entry_handle **out, lsm_store *store,
|
|||
|
||||
// No need to set the handle's file, as the entry doesn't have any data yet
|
||||
handle->wrapper = wrapper;
|
||||
handle->store = store;
|
||||
|
||||
*out = handle;
|
||||
|
||||
return lsm_error_ok;
|
||||
}
|
||||
|
||||
lsm_error lsm_entry_data_append(lsm_store *store, lsm_entry_handle *handle,
|
||||
lsm_str *data) {
|
||||
lsm_error lsm_entry_data_append(lsm_entry_handle *handle, lsm_str *data) {
|
||||
if (lsm_str_len(data) == 0) {
|
||||
return lsm_error_ok;
|
||||
}
|
||||
|
|
@ -199,8 +167,8 @@ lsm_error lsm_entry_data_append(lsm_store *store, lsm_entry_handle *handle,
|
|||
|
||||
// Entries don't open their file unless needed
|
||||
if (handle->f == NULL) {
|
||||
char path[store->data_path->len + entry->key->len + 2];
|
||||
sprintf(path, "%s/%s", lsm_str_ptr(store->data_path),
|
||||
char path[handle->store->data_path->len + entry->key->len + 2];
|
||||
sprintf(path, "%s/%s", lsm_str_ptr(handle->store->data_path),
|
||||
lsm_str_ptr(entry->key));
|
||||
|
||||
FILE *f = fopen(path, "ab");
|
||||
|
|
@ -225,7 +193,7 @@ lsm_error lsm_entry_data_append(lsm_store *store, lsm_entry_handle *handle,
|
|||
return lsm_error_ok;
|
||||
}
|
||||
|
||||
lsm_error lsm_entry_data_read(uint64_t *out, char *buf, lsm_store *store,
|
||||
lsm_error lsm_entry_data_read(uint64_t *out, char *buf,
|
||||
lsm_entry_handle *handle, uint64_t len) {
|
||||
lsm_entry *entry = handle->wrapper->entry;
|
||||
|
||||
|
|
@ -237,8 +205,8 @@ lsm_error lsm_entry_data_read(uint64_t *out, char *buf, lsm_store *store,
|
|||
|
||||
// Entries don't open their file unless needed
|
||||
if (handle->f == NULL) {
|
||||
char path[store->data_path->len + entry->key->len + 2];
|
||||
sprintf(path, "%s/%s", lsm_str_ptr(store->data_path),
|
||||
char path[handle->store->data_path->len + entry->key->len + 2];
|
||||
sprintf(path, "%s/%s", lsm_str_ptr(handle->store->data_path),
|
||||
lsm_str_ptr(entry->key));
|
||||
|
||||
FILE *f = fopen(path, "rb");
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ static lsm_error lsm_entry_read_attrs(uint64_t *sum, lsm_entry_handle *handle,
|
|||
for (uint64_t i = 0; i < attr_count; i++) {
|
||||
LSM_RES(lsm_fread(&attr_type, sum, db_file, sizeof(uint8_t), 1));
|
||||
LSM_RES(lsm_entry_read_str(&val, sum, db_file));
|
||||
lsm_entry_attr_insert(handle, attr_type, val);
|
||||
LSM_RES(lsm_entry_attr_insert(handle, attr_type, val));
|
||||
}
|
||||
|
||||
return lsm_error_ok;
|
||||
|
|
|
|||
|
|
@ -75,7 +75,9 @@ 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_store *store, lsm_entry_handle *handle) {
|
||||
lsm_error lsm_entry_sync(lsm_entry_handle *handle) {
|
||||
lsm_store *store = handle->store;
|
||||
|
||||
pthread_mutex_lock(&store->db_lock);
|
||||
|
||||
uint64_t db_entry_index = store->db_file_size;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue