diff --git a/include/lander.h b/include/lander.h index 9ebbdf2..7b418bc 100644 --- a/include/lander.h +++ b/include/lander.h @@ -51,8 +51,6 @@ lnm_http_step_err lander_post_paste_secure(lnm_http_conn *conn); lnm_http_step_err lander_stream_body_to_entry(lnm_http_conn *conn); -lnm_http_step_err lander_commit_entry(lnm_http_conn *conn); - lnm_http_step_err lander_post_redirect_body_to_attr(lnm_http_conn *conn); lnm_http_step_err lander_remove_entry(lnm_http_conn *conn); diff --git a/lsm/include/lsm/store.h b/lsm/include/lsm/store.h index e2d7d86..c680c43 100644 --- a/lsm/include/lsm/store.h +++ b/lsm/include/lsm/store.h @@ -159,15 +159,6 @@ lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store, lsm_error lsm_store_open_write(lsm_entry_handle **out, lsm_store *store, const lsm_str *key); -/** - * Commit any changes to the persistent storage. Any changes, insertions or - * deletions that occured without a commit are reverted when the handle is - * closed. - * - * @param handle handle to the entry - */ -lsm_error lsm_entry_commit(lsm_entry_handle *handle); - /** * Close an open entry handle. * diff --git a/lsm/src/_include/lsm/store_internal.h b/lsm/src/_include/lsm/store_internal.h index 1b84b60..e446a0d 100644 --- a/lsm/src/_include/lsm/store_internal.h +++ b/lsm/src/_include/lsm/store_internal.h @@ -156,12 +156,4 @@ lsm_error lsm_entry_data_open_read(lsm_entry_handle *handle); */ lsm_error lsm_entry_data_open_write(lsm_entry_handle *handle); -/** - * Remove the entry's data file if present and close its handle. Any uncommitted - * changes will be reverted. - * - * @param handle handle to the entry - */ -lsm_error lsm_entry_data_remove(lsm_entry_handle *handle); - #endif diff --git a/lsm/src/store/lsm_store_disk_write.c b/lsm/src/store/lsm_store_disk_write.c index 51e9be8..31f907b 100644 --- a/lsm/src/store/lsm_store_disk_write.c +++ b/lsm/src/store/lsm_store_disk_write.c @@ -153,7 +153,20 @@ lsm_error lsm_entry_disk_remove(lsm_entry_handle *handle) { fflush(store->idx.f); - LSM_RES(lsm_entry_data_remove(handle)); + // Remove data file if present + if (entry->data_len > 0) { + if (handle->f != NULL) { + fclose(handle->f); + handle->f = NULL; + } + + char data_path[lsm_entry_data_path_len(handle) + 1]; + lsm_entry_data_path(data_path, handle); + + if (remove(data_path) != 0) { + return lsm_error_failed_io; + } + } return lsm_error_ok; } diff --git a/lsm/src/store/lsm_store_entry.c b/lsm/src/store/lsm_store_entry.c index 7d33d30..63d90a7 100644 --- a/lsm/src/store/lsm_store_entry.c +++ b/lsm/src/store/lsm_store_entry.c @@ -58,45 +58,23 @@ lsm_error lsm_entry_handle_init(lsm_entry_handle **out) { return lsm_error_ok; } -lsm_error lsm_entry_commit(lsm_entry_handle *handle) { - uint8_t state_new = handle->states & lsm_entry_handle_state_new; - uint8_t state_removed = handle->states & lsm_entry_handle_state_removed; - - // Clean new entry - if (state_new && !state_removed) { - LSM_RES(lsm_entry_disk_insert(handle)); - } - // Previously stored entry that needs to be removed; should be removed from db - // file as well - else if (state_removed && !state_new) { - LSM_RES(lsm_entry_disk_remove(handle)); - - lsm_entry_free(handle->wrapper->entry); - handle->wrapper->entry = NULL; - } - - // Reset states after committing current changes - handle->states = 0; - - return lsm_error_ok; -} - void lsm_entry_close(lsm_entry_handle *handle) { if (handle->f != NULL) { fclose(handle->f); - handle->f = NULL; } - uint8_t state_new = handle->states & lsm_entry_handle_state_new; - /* bool state_updated = handle->states & lsm_entry_handle_state_updated; */ - - // New entries create a wrapper in the trie that should be removed if not - // committed - if (state_new) { - lsm_entry_data_remove(handle); + // TODO handle errors here + if ((handle->states & lsm_entry_handle_state_new) && + !(handle->states & lsm_entry_handle_state_removed)) { + lsm_entry_disk_insert(handle); + } else if ((handle->states & lsm_entry_handle_state_removed) && + !(handle->states & lsm_entry_handle_state_new)) { + lsm_entry_disk_remove(handle); lsm_entry_free(handle->wrapper->entry); handle->wrapper->entry = NULL; + } else if (handle->states & lsm_entry_handle_state_updated) { + /* lsm_entry_disk_update(handle); */ } pthread_rwlock_unlock(&handle->wrapper->lock); @@ -338,23 +316,3 @@ lsm_error lsm_entry_data_open_read(lsm_entry_handle *handle) { return lsm_error_ok; } - -lsm_error lsm_entry_data_remove(lsm_entry_handle *handle) { - const lsm_entry *entry = handle->wrapper->entry; - - if (entry->data_len > 0) { - if (handle->f != NULL) { - fclose(handle->f); - handle->f = NULL; - } - - char data_path[lsm_entry_data_path_len(handle) + 1]; - lsm_entry_data_path(data_path, handle); - - if (remove(data_path) != 0) { - return lsm_error_failed_io; - } - } - - return lsm_error_ok; -} diff --git a/src/lander/lander_steps.c b/src/lander/lander_steps.c index 8e2d702..00c86ba 100644 --- a/src/lander/lander_steps.c +++ b/src/lander/lander_steps.c @@ -1,7 +1,6 @@ #include #include "lnm/http/loop.h" -#include "lnm/log.h" #include "lnm/loop.h" #include "lander.h" @@ -26,12 +25,3 @@ lnm_http_step_err lander_stream_body_to_entry(lnm_http_conn *conn) { ? lnm_http_step_err_done : lnm_http_step_err_io_needed; } - -lnm_http_step_err lander_commit_entry(lnm_http_conn *conn) { - lnm_http_loop_ctx *ctx = conn->ctx; - lander_ctx *c_ctx = ctx->c; - - lsm_entry_commit(c_ctx->entry); - - return lnm_http_step_err_done; -}