Fix invalid oldest address assignment (#255)

* fix: fix invalid oldest address assignment after gc the last traversed sector.
* feat: always update oldest address after sector GC.

---------

Co-authored-by: shihang zhang <shihang.zhang.ext@siemens.com>
This commit is contained in:
shihang-zhang 2023-10-30 21:13:55 -05:00 committed by GitHub
parent 7bdef5eab7
commit a208b1555b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 2 deletions

View File

@ -1078,7 +1078,6 @@ static bool do_gc(kv_sec_info_t sector, void *arg1, void *arg2)
struct gc_cb_args *gc = (struct gc_cb_args *)arg1;
fdb_kvdb_t db = gc->db;
gc->traversed_len += db_sec_size(db);
if (sector->check_ok && (sector->status.dirty == FDB_SECTOR_DIRTY_TRUE || sector->status.dirty == FDB_SECTOR_DIRTY_GC)) {
uint8_t status_table[FDB_DIRTY_STATUS_TABLE_SIZE];
/* change the sector status to GC */
@ -1098,7 +1097,7 @@ static bool do_gc(kv_sec_info_t sector, void *arg1, void *arg2)
gc->cur_free_size += db_sec_size(db) - SECTOR_HDR_DATA_SIZE;
FDB_DEBUG("Collect a sector @0x%08" PRIX32 "\n", sector->addr);
/* update oldest_addr for next GC sector format */
db_oldest_addr(db) = get_next_sector_addr(db, sector, gc->traversed_len);
db_oldest_addr(db) = get_next_sector_addr(db, sector, 0);
if (gc->cur_free_size >= gc->setting_free_size)
return true;
}