Skip to content

当在垃圾回收过程中掉电,重新上电初始化时 db_oldest_addr(db) = 0,导致无法正常恢复垃圾回收的特殊情况 #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Gin3068 opened this issue Feb 11, 2025 · 1 comment

Comments

@Gin3068
Copy link

Gin3068 commented Feb 11, 2025

/* The oldest address is 0 by default.
 * The new oldest sector is found when sector status change from empty to full or using.
 */
if (*last_sector_status == FDB_SECTOR_STORE_EMPTY
        && (sector->status.store == FDB_SECTOR_STORE_FULL || sector->status.store == FDB_SECTOR_STORE_USING)) {
    *sector_oldest_addr = sector->addr;
}

测试情况说明:
1)数据库挂载了4个扇区,一扇区写入本条数据后满(0x1F,且脏),二扇区为空(0x7F),三扇区状态满(0x1F,且脏;最旧),四扇区状态满(0x1F,且脏);
2)触发垃圾回收并进行,此时4个扇区存储状态分别为:满(0x1F)、使用中(0x3F)、满(0x1F,迁移中)、满(0x1F);
3)掉电;
4)上电后4个扇区的存储状态仍为:满(0x1F)、使用中(0x3F)、满(0x1F,迁移中)、满(0x1F),上述if条件不满足,db_oldest_addr(db) = 0;
5)检测到存在垃圾回收被中断的扇区,恢复垃圾回收,对最旧扇区即一扇区进行数据迁移;
6)由于掉电前垃圾回收的扇区为三扇区,掉电后被更改为一扇区,导致二扇区无法完成一扇区的全部数据迁移;
7)一扇区被擦除,有效数据丢失。

以上情况发生会导致有效数据被擦除。
是不是可以在if条件里增加是否处于恢复性检查状态的判断?db->in_recovery_check == true

@armink
Copy link
Owner

armink commented Feb 12, 2025

能否在测试用例里面测一下你说的情况呢?

位于 tests/fdb_kvdb_tc.c ,执行方法可以看下 CI 里面的流程

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants