From a4ad8c246e2d59940fdbabb9db4a7e79638204dc Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sun, 12 Nov 2023 13:21:04 +0100 Subject: [PATCH] feat(lsm): remove data file when removing entry --- lsm/src/store/lsm_store_disk_write.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lsm/src/store/lsm_store_disk_write.c b/lsm/src/store/lsm_store_disk_write.c index b5081af..243c8f5 100644 --- a/lsm/src/store/lsm_store_disk_write.c +++ b/lsm/src/store/lsm_store_disk_write.c @@ -147,5 +147,24 @@ lsm_error lsm_entry_disk_remove(lsm_entry_handle *handle) { pthread_mutex_unlock(&store->idx.lock); - return res; + if (res != lsm_error_ok) { + return res; + } + + // 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; }