Fix: fdb_kv_iterate() now return and stats only active kvs (kv->status are FDB_KV_WRITE)

This commit is contained in:
eggcar 2020-07-05 01:58:35 +08:00
parent f4bbeedac7
commit a2a2f53d8a
1 changed files with 22 additions and 20 deletions

View File

@ -1645,26 +1645,28 @@ bool fdb_kv_iterate(fdb_kvdb_t db, fdb_kv_iterator_t itr)
struct kvdb_sec_info sector; struct kvdb_sec_info sector;
fdb_kv_t kv = &(itr->curr_kv); fdb_kv_t kv = &(itr->curr_kv);
do { do {
if (read_sector_info(db, itr->sector_addr, &sector, false) != FDB_NO_ERR) { if (read_sector_info(db, itr->sector_addr, &sector, false) == FDB_NO_ERR) {
continue; if (sector.status.store == FDB_SECTOR_STORE_USING || sector.status.store == FDB_SECTOR_STORE_FULL) {
} if (kv->addr.start == 0) {
else if (sector.status.store == FDB_SECTOR_STORE_USING || sector.status.store == FDB_SECTOR_STORE_FULL) { kv->addr.start = sector.addr + SECTOR_HDR_DATA_SIZE;
if (kv->addr.start == 0) { }
kv->addr.start = sector.addr + SECTOR_HDR_DATA_SIZE; else if ((kv->addr.start = get_next_kv_addr(db, &sector, kv)) == FAILED_ADDR) {
} kv->addr.start = 0;
else if ((kv->addr.start = get_next_kv_addr(db, &sector, kv)) == FAILED_ADDR) { continue;
kv->addr.start = 0; }
continue; do {
} read_kv(db, kv);
/* If iterator statistics is needed */ if (kv->status == FDB_KV_WRITE) {
itr->iterated_cnt++; /* We got a valid kv here. */
itr->iterated_obj_bytes += kv->len; /* If iterator statistics is needed */
itr->iterated_value_bytes += kv->value_len; itr->iterated_cnt++;
itr->iterated_obj_bytes += kv->len;
/* We got a valid kv here. */ itr->iterated_value_bytes += kv->value_len;
read_kv(db, kv); return true;
return true; }
} } while((kv->addr.start = get_next_kv_addr(db, &sector, kv)) != FAILED_ADDR);
}
}
/** Set kv->addr.start to 0 when we get into a new sector so that if we successfully get the next sector info, /** Set kv->addr.start to 0 when we get into a new sector so that if we successfully get the next sector info,
* the kv->addr.start is set to the new sector.addr + SECTOR_HDR_DATA_SIZE. * the kv->addr.start is set to the new sector.addr + SECTOR_HDR_DATA_SIZE.
*/ */