fix(lsm): store data len in db; fix bug

This commit is contained in:
Jef Roosens 2023-11-08 16:04:21 +01:00
parent ef33825b7b
commit 9c03a36aa2
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 25 additions and 3 deletions

View file

@ -30,6 +30,8 @@ lsm_error lsm_store_init(lsm_store **ptr) {
return lsm_error_ok;
}
uint64_t lsm_store_size(lsm_store *store) { return lsm_trie_size(store->trie); }
lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store,
lsm_str *key) {
lsm_entry_wrapper *wrapper;

View file

@ -105,6 +105,8 @@ static lsm_error lsm_entry_read_str(lsm_str **out, uint64_t *sum, FILE *f) {
return lsm_error_failed_alloc;
}
buf[len] = '\0';
uint64_t read = 0;
while (read < len) {
@ -158,6 +160,8 @@ lsm_error lsm_store_load_db(lsm_store *store) {
return lsm_error_failed_io;
}
LSM_RES(lsm_fread(&handle->wrapper->entry->data_len, NULL, store->db_file,
sizeof(uint64_t), 1));
LSM_RES(lsm_entry_read_attrs(NULL, handle, store->db_file));
lsm_entry_close(handle);

View file

@ -37,10 +37,11 @@ lsm_error lsm_entry_write_db(uint64_t *size, FILE *db_file, lsm_entry *entry,
uint64_t pos) {
LSM_RES(lsm_seek(db_file, pos));
// First we write how many attributes follow
LSM_RES(lsm_entry_write_uint64_t(db_file, entry->data_len));
LSM_RES(
lsm_entry_write_single(db_file, sizeof(uint8_t), &entry->attrs.count));
*size = sizeof(uint8_t);
*size = sizeof(uint64_t) + sizeof(uint8_t);
for (uint8_t i = 0; i < entry->attrs.count; i++) {
// Write attribute type, length & value