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_post_redirect_body_to_attr(event_loop_conn *conn);
|
||||||
|
|
||||||
bool lander_entry_sync(event_loop_conn *conn);
|
|
||||||
|
|
||||||
#endif
|
#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_error lsm_entry_data_read(uint64_t *out, char *buf,
|
||||||
lsm_entry_handle *handle, uint64_t len);
|
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.
|
* Return the length of the entry's data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -88,4 +88,25 @@ struct lsm_store {
|
||||||
*/
|
*/
|
||||||
lsm_error lsm_store_load_db(lsm_store *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
|
#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));
|
LSM_RES(lsm_entry_read_attrs(NULL, handle, store->db_file));
|
||||||
|
|
||||||
handle->wrapper->entry->idx_file_offset = idx_file_offset;
|
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];
|
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;
|
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;
|
lsm_store *store = handle->store;
|
||||||
|
|
||||||
pthread_mutex_lock(&store->db_lock);
|
pthread_mutex_lock(&store->db_lock);
|
||||||
|
|
|
@ -47,13 +47,19 @@ lsm_error lsm_entry_handle_init(lsm_entry_handle **out) {
|
||||||
return lsm_error_ok;
|
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) {
|
void lsm_entry_close(lsm_entry_handle *handle) {
|
||||||
if (handle->f != NULL) {
|
if (handle->f != NULL) {
|
||||||
fclose(handle->f);
|
fclose(handle->f);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_rwlock_unlock(&handle->wrapper->lock);
|
// TODO handle errors here
|
||||||
free(handle);
|
lsm_entry_disk_insert(handle);
|
||||||
|
lsm_entry_close_no_disk(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lsm_entry_attr_present(lsm_entry_handle *handle, uint8_t type) {
|
bool lsm_entry_attr_present(lsm_entry_handle *handle, uint8_t type) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ http_route lander_routes[] = {
|
||||||
.path = "^/s(l?)/([^/]*)$",
|
.path = "^/s(l?)/([^/]*)$",
|
||||||
.steps = {http_loop_step_auth, lander_post_redirect_lsm,
|
.steps = {http_loop_step_auth, lander_post_redirect_lsm,
|
||||||
http_loop_step_body_to_buf, lander_post_redirect_body_to_attr,
|
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,
|
.steps_res = {http_loop_step_write_header, http_loop_step_write_body,
|
||||||
NULL},
|
NULL},
|
||||||
},
|
},
|
||||||
|
@ -33,8 +33,7 @@ http_route lander_routes[] = {
|
||||||
.method = http_post,
|
.method = http_post,
|
||||||
.path = "^/p(l?)/([^/]*)$",
|
.path = "^/p(l?)/([^/]*)$",
|
||||||
.steps = {http_loop_step_auth, http_loop_step_parse_content_length,
|
.steps = {http_loop_step_auth, http_loop_step_parse_content_length,
|
||||||
lander_post_paste_lsm, lander_stream_body_to_entry,
|
lander_post_paste_lsm, lander_stream_body_to_entry, NULL},
|
||||||
lander_entry_sync, NULL},
|
|
||||||
.steps_res = {http_loop_step_write_header, http_loop_step_write_body,
|
.steps_res = {http_loop_step_write_header, http_loop_step_write_body,
|
||||||
NULL}},
|
NULL}},
|
||||||
};
|
};
|
||||||
|
|
|
@ -149,17 +149,6 @@ bool lander_post_redirect_body_to_attr(event_loop_conn *conn) {
|
||||||
return true;
|
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) {
|
bool lander_post_paste_lsm(event_loop_conn *conn) {
|
||||||
http_loop_ctx *ctx = conn->ctx;
|
http_loop_ctx *ctx = conn->ctx;
|
||||||
lander_ctx *c_ctx = ctx->c;
|
lander_ctx *c_ctx = ctx->c;
|
||||||
|
|
Loading…
Reference in New Issue