feat(lsm): sync database when closing handle
parent
eb0ce16f78
commit
9b223d04a0
|
@ -57,6 +57,4 @@ bool lander_get_entry_lsm(event_loop_conn *conn);
|
|||
|
||||
bool lander_post_redirect_body_to_attr(event_loop_conn *conn);
|
||||
|
||||
bool lander_entry_sync(event_loop_conn *conn);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -213,14 +213,6 @@ lsm_error lsm_entry_data_append_raw(lsm_entry_handle *handle, char *data,
|
|||
lsm_error lsm_entry_data_read(uint64_t *out, char *buf,
|
||||
lsm_entry_handle *handle, uint64_t len);
|
||||
|
||||
/**
|
||||
* Persist the entry's data to disk.
|
||||
*
|
||||
* @param store store to persist entry in
|
||||
* @param handle handle to entry to persist
|
||||
*/
|
||||
lsm_error lsm_entry_sync(lsm_entry_handle *handle);
|
||||
|
||||
/**
|
||||
* Return the length of the entry's data.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -25,7 +25,7 @@ http_route lander_routes[] = {
|
|||
.path = "^/s(l?)/([^/]*)$",
|
||||
.steps = {http_loop_step_auth, lander_post_redirect_lsm,
|
||||
http_loop_step_body_to_buf, lander_post_redirect_body_to_attr,
|
||||
lander_entry_sync, NULL},
|
||||
NULL},
|
||||
.steps_res = {http_loop_step_write_header, http_loop_step_write_body,
|
||||
NULL},
|
||||
},
|
||||
|
@ -33,8 +33,7 @@ http_route lander_routes[] = {
|
|||
.method = http_post,
|
||||
.path = "^/p(l?)/([^/]*)$",
|
||||
.steps = {http_loop_step_auth, http_loop_step_parse_content_length,
|
||||
lander_post_paste_lsm, lander_stream_body_to_entry,
|
||||
lander_entry_sync, NULL},
|
||||
lander_post_paste_lsm, lander_stream_body_to_entry, NULL},
|
||||
.steps_res = {http_loop_step_write_header, http_loop_step_write_body,
|
||||
NULL}},
|
||||
};
|
||||
|
|
|
@ -149,17 +149,6 @@ bool lander_post_redirect_body_to_attr(event_loop_conn *conn) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool lander_entry_sync(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
lander_ctx *c_ctx = ctx->c;
|
||||
|
||||
if (lsm_entry_sync(c_ctx->entry) != lsm_error_ok) {
|
||||
ctx->res.status = http_internal_server_error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lander_post_paste_lsm(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
lander_ctx *c_ctx = ctx->c;
|
||||
|
|
Loading…
Reference in New Issue