#include <key_value_store.h>
Classes | |
class | Item |
Representation of a key-value entry during iteration. More... | |
class | iterator |
Supported iteration methods. More... | |
struct | StorageStats |
Public Types | |
using | const_iterator = iterator |
Public Member Functions | |
Status | Init () |
bool | initialized () const |
StatusWithSize | Get (std::string_view key, span< std::byte > value, size_t offset_bytes=0) const |
template<typename Pointer , typename = std::enable_if_t<std::is_pointer<Pointer>::value>> | |
Status | Get (const std::string_view &key, const Pointer &pointer) const |
template<typename T , typename std::enable_if_t< ConvertsToSpan< T >::value > * = nullptr> | |
Status | Put (const std::string_view &key, const T &value) |
template<typename T , typename std::enable_if_t<!ConvertsToSpan< T >::value > * = nullptr> | |
Status | Put (const std::string_view &key, const T &value) |
Status | Delete (std::string_view key) |
StatusWithSize | ValueSize (std::string_view key) const |
Status | HeavyMaintenance () |
Status | FullMaintenance () |
Status | PartialMaintenance () |
void | LogDebugInfo () const |
iterator | begin () const |
iterator | end () const |
size_t | size () const |
size_t | total_entries_with_deleted () const |
size_t | max_size () const |
size_t | empty () const |
uint32_t | transaction_count () const |
StorageStats | GetStorageStats () const |
size_t | redundancy () const |
bool | error_detected () const |
size_t | max_key_value_size_bytes () const |
bool | CheckForErrors () |
Static Public Member Functions | |
static constexpr size_t | max_key_value_size_bytes (size_t partition_sector_size_bytes) |
Protected Types | |
using | Address = FlashPartition::Address |
using | Entry = internal::Entry |
using | KeyDescriptor = internal::KeyDescriptor |
using | SectorDescriptor = internal::SectorDescriptor |
Protected Member Functions | |
KeyValueStore (FlashPartition *partition, span< const EntryFormat > formats, const Options &options, size_t redundancy, Vector< SectorDescriptor > §or_descriptor_list, const SectorDescriptor **temp_sectors_to_skip, Vector< KeyDescriptor > &key_descriptor_list, Address *addresses) | |
Flash-backed persistent key-value store (KVS) with integrated wear-leveling.
Instances are declared as instances of pw::kvs::KeyValueStoreBuffer<MAX_ENTRIES, MAX_SECTORS>
, which allocates buffers for tracking entries and flash sectors.
iterator pw::kvs::KeyValueStore::begin | ( | ) | const |
bool pw::kvs::KeyValueStore::CheckForErrors | ( | ) |
Checks the KVS for any error conditions and returns true
if any errors are present. Primarily intended for test and internal use.
Status pw::kvs::KeyValueStore::Delete | ( | std::string_view | key | ) |
Removes a key-value entry from the KVS.
[in] | key | - The name of the key-value entry to delete. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The entry was successfully deleted. * * NOT_FOUND: ``key`` is not present in the KVS. * * DATA_LOSS: Checksum validation failed after recording the * erase. * * RESOURCE_EXHAUSTED: Insufficient space to mark the entry as deleted. * * FAILED_PRECONDITION: The KVS is not initialized. Call ``Init()`` * before calling this method. * * INVALID_ARGUMENT: ``key`` is empty or too long. * *
|
inline |
true
if the KVS is empty.
|
inline |
|
inline |
true
if the KVS has any unrepaired errors.
|
inline |
Perform all maintenance possible, including all needed repairing of corruption and garbage collection of reclaimable space in the KVS. When configured for manual recovery, this (along with HeavyMaintenance()
) is the only way KVS repair is triggered.
Does not garbage collect sectors with valid data unless the KVS is mostly full.
|
inline |
StatusWithSize pw::kvs::KeyValueStore::Get | ( | std::string_view | key, |
span< std::byte > | value, | ||
size_t | offset_bytes = 0 |
||
) | const |
Reads the value of an entry in the KVS. The value is read into the provided buffer and the number of bytes read is returned. Reads can be started at an offset.
[in] | key | The name of the key. |
[out] | value | The buffer to read the key's value into. |
[in] | offset_bytes | The byte offset to start the read at. Optional. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The entry was successfully read. * * NOT_FOUND: The key is not present in the KVS. * * DATA_LOSS: Found the entry, but the data was corrupted. * * RESOURCE_EXHAUSTED: The buffer could not fit the entire * value, but as many bytes as possible were written to it. The number of * of bytes read is returned. The remainder of the value can be read by * calling ``Get()`` again with an offset. * * FAILED_PRECONDITION: The KVS is not initialized. Call ``Init()`` * before calling this method. * * INVALID_ARGUMENT: ``key`` is empty or too long, or ``value`` * is too large. * *
StorageStats pw::kvs::KeyValueStore::GetStorageStats | ( | ) | const |
StorageStats
struct with details about the current and past state of the KVS.
|
inline |
Performs all maintenance possible, including all needed repairing of corruption and garbage collection of reclaimable space in the KVS. When configured for manual recovery, this (along with FullMaintenance()
) is the only way KVS repair is triggered.
Status pw::kvs::KeyValueStore::Init | ( | ) |
Initializes the KVS. Must be called before calling other functions.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The KVS successfully initialized. * * DATA_LOSS: The KVS initialized and is usable, but contains corrupt * data. * * UNKNOWN: Unknown error. The KVS is not initialized. * *
|
inline |
|
inlinestaticconstexpr |
|
inline |
Status pw::kvs::KeyValueStore::PartialMaintenance | ( | ) |
Performs a portion of KVS maintenance. If configured for at least lazy recovery, will do any needed repairing of corruption. Does garbage collection of part of the KVS, typically a single sector or similar unit that makes sense for the KVS implementation.
|
inline |
Adds a key-value entry to the KVS. If the key was already present, its value is overwritten.
[in] | key | The name of the key. All keys in the KVS must have a unique hash. If the hash of your key matches an existing key, nothing is added and embed:rst:inline :c:enumerator:`ALREADY_EXISTS`is returned. |
[in] | value | The value for the key. This can be a span of bytes or a trivially copyable object. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The entry was successfully added or updated. * * DATA_LOSS: Checksum validation failed after writing data. * * RESOURCE_EXHAUSTED: Not enough space to add the entry. * * ALREADY_EXISTS: The entry could not be added because a different * key with the same hash is already in the KVS. * * FAILED_PRECONDITION: The KVS is not initialized. Call ``Init()`` * before calling this method. * * INVALID_ARGUMENT: ``key`` is empty or too long, or ``value`` * is too large. * *
|
inline |
|
inline |
|
inline |
|
inline |
StatusWithSize pw::kvs::KeyValueStore::ValueSize | ( | std::string_view | key | ) | const |
Returns the size of the value corresponding to the key.
[in] | key | - The name of the key. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The size was returned successfully. * * NOT_FOUND: ``key`` is not present in the KVS. * * DATA_LOSS: Checksum validation failed after reading the entry. * * FAILED_PRECONDITION: The KVS is not initialized. Call ``Init()`` * before calling this method. * * INVALID_ARGUMENT: ``key`` is empty or too long. * *