feat(lsm): add valid entry marker to idx entries
parent
2f58d1ee48
commit
d4b21fb84d
|
@ -142,6 +142,7 @@ lsm_error lsm_store_load_db(lsm_store *store) {
|
|||
uint64_t db_dim[2];
|
||||
lsm_str *key;
|
||||
lsm_entry_handle *handle;
|
||||
bool valid_entry;
|
||||
|
||||
rewind(store->idx_file);
|
||||
|
||||
|
@ -152,6 +153,10 @@ lsm_error lsm_store_load_db(lsm_store *store) {
|
|||
for (uint64_t i = 0; i < store->idx_file_block_count; i++) {
|
||||
uint64_t idx_file_offset = store->idx_file_size;
|
||||
|
||||
LSM_RES(lsm_fread(&valid_entry, &store->idx_file_size, store->idx_file,
|
||||
sizeof(bool), 1));
|
||||
|
||||
if (valid_entry) {
|
||||
LSM_RES(lsm_entry_read_str(&key, &store->idx_file_size, store->idx_file));
|
||||
LSM_RES(lsm_fread(&db_dim, &store->idx_file_size, store->idx_file,
|
||||
sizeof(uint64_t), 2));
|
||||
|
@ -171,6 +176,21 @@ lsm_error lsm_store_load_db(lsm_store *store) {
|
|||
|
||||
store->db_file_size += db_dim[1];
|
||||
}
|
||||
// Simply skip the invalid entry
|
||||
else {
|
||||
uint64_t key_len;
|
||||
LSM_RES(lsm_fread(&key_len, &store->idx_file_size, store->idx_file,
|
||||
sizeof(uint64_t), 1));
|
||||
|
||||
uint64_t remaining = key_len + 2 * sizeof(uint64_t);
|
||||
|
||||
if (fseek(store->idx_file, remaining, SEEK_CUR) != 0) {
|
||||
return lsm_error_failed_io;
|
||||
}
|
||||
|
||||
store->idx_file_size += remaining;
|
||||
}
|
||||
}
|
||||
|
||||
return lsm_error_ok;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ lsm_error lsm_write_idx_entry(uint64_t *size, FILE *idx_file, lsm_entry *entry,
|
|||
|
||||
LSM_RES(lsm_fseek(idx_file, pos));
|
||||
|
||||
bool valid_entry_marker = true;
|
||||
LSM_RES(lsm_fwrite(size, idx_file, sizeof(bool), 1, &valid_entry_marker));
|
||||
|
||||
LSM_RES(lsm_write_str(size, idx_file, entry->key));
|
||||
LSM_RES(lsm_fwrite(size, idx_file, sizeof(uint64_t), 1, &offset));
|
||||
LSM_RES(lsm_fwrite(size, idx_file, sizeof(uint64_t), 1, &len));
|
||||
|
|
Loading…
Reference in New Issue