Skip to content

Commit

Permalink
skip CRC when initializing TDBStore
Browse files Browse the repository at this point in the history
Problem: The build_ram_table() function of TDBStore loops over every entry, calculates the checksum and compares them to the stored checksum in the entry header to ensure integrity. For larger TDBStores (e.g. 8 MiB or more) in external single-SPI flash devices this check can take very long, thus rendering it unusable in some cases.

Solution: The suggested solution skips the time consuming CRC of the data. After reading the key and calculating its CRC, it sets next_offset to the beginning of the next entry, thereby skipping the data. While this skips the integrity check, it significantly reduces the initial building of the RAM table.

The data CRC can be enabled or disabled with a compiler flag.

Contribution is provided on behalf of BIOTRONIK.
  • Loading branch information
mattgbio committed May 22, 2024
1 parent 95fee2f commit 3082c28
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions storage/kvstore/tdbstore/source/TDBStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ int TDBStore::read_record(uint8_t area, uint32_t offset, char *key,

if (calc_hash) {
hash = calc_crc(hash, chunk_size, dest_buf);
#ifdef KVSTORE_RAM_TABLE_NO_CRC_CHECK
next_offset = align_up(offset + total_size, _prog_size);
return ret;
#endif /* KVSTORE_RAM_TABLE_NO_CRC_CHECK */
}

user_key_ptr += chunk_size;
Expand Down

0 comments on commit 3082c28

Please sign in to comment.