pw_kvs: Add KVS error repair/recovery
- Add repair of detected errors in the KVS.
- Add additional error detection in KVS init
- KVS initialization has a new "needs maintenance" state. This is a
read-only mode because not all of the required KVS system invariants
have been met.
Change-Id: If13094855d8da03d59011891c8ed5af2ad38ad2d
diff --git a/pw_kvs/entry_cache.cc b/pw_kvs/entry_cache.cc
index 447417d..1f4dfa8 100644
--- a/pw_kvs/entry_cache.cc
+++ b/pw_kvs/entry_cache.cc
@@ -31,6 +31,23 @@
} // namespace
+void EntryMetadata::RemoveAddress(Address address_to_remove) {
+ // Find the index of the address to remove.
+ for (Address& address : addresses_) {
+ if (address == address_to_remove) {
+ // Move the address at the back of the list to the slot of the address
+ // being removed. Do this unconditionally, even if the address to remove
+ // is the last slot since the logic still works.
+ address = addresses_.back();
+
+ // Remove the back entry of the address list.
+ addresses_.back() = kNoAddress;
+ addresses_ = span(addresses_.begin(), addresses_.size() - 1);
+ break;
+ }
+ }
+}
+
void EntryMetadata::Reset(const KeyDescriptor& descriptor, Address address) {
*descriptor_ = descriptor;