From a208b1555b9805c4fb13336b0c1529d2df8d5641 Mon Sep 17 00:00:00 2001 From: shihang-zhang <77595854+shihang-zhang@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:13:55 -0500 Subject: [PATCH] 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 --- src/fdb_kvdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fdb_kvdb.c b/src/fdb_kvdb.c index 4f06654..132323b 100644 --- a/src/fdb_kvdb.c +++ b/src/fdb_kvdb.c @@ -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; }