Skip to content

Commit

Permalink
Fix migration cache issue
Browse files Browse the repository at this point in the history
  • Loading branch information
diondokter committed Feb 10, 2024
1 parent bc378d2 commit 0377271
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async fn fetch_item_with_location<I: StorageItem, S: NorFlash>(
else {
// The cache points to a non-existing item?
if cfg!(feature = "_test") {
panic!("Wrong cache value");
panic!("Wrong cache value. Addr: {cached_location}");
}
cache.invalidate_cache_state();
break 'cache;
Expand All @@ -190,7 +190,7 @@ async fn fetch_item_with_location<I: StorageItem, S: NorFlash>(
match item {
item::MaybeItem::Corrupted(_, _) | item::MaybeItem::Erased(_, _) => {
if cfg!(feature = "_test") {
panic!("Wrong cache value");
panic!("Wrong cache value. Addr: {cached_location}");
}

// The cache points to a corrupted or erased item?
Expand Down Expand Up @@ -604,9 +604,14 @@ async fn migrate_items<I: StorageItem, S: NorFlash>(
let (item_header, data_buffer) = item.destruct();

// Search for the newest item with the key we found
let Some((_, found_address, _)) =
fetch_item_with_location::<I, S>(flash, flash_range.clone(), cache, data_buffer, key.clone())
.await?
let Some((_, found_address, _)) = fetch_item_with_location::<I, S>(
flash,
flash_range.clone(),
cache,
data_buffer,
key.clone(),
)
.await?
else {
// We couldn't even find our own item?
return Err(MapError::Corrupted {
Expand All @@ -622,7 +627,7 @@ async fn migrate_items<I: StorageItem, S: NorFlash>(
.read_item(flash, data_buffer, item_address, u32::MAX)
.await?
.unwrap()?;
cache.notice_key_location(key, item_address, true);
cache.notice_key_location(key, next_page_write_address, true);
item.write(flash, flash_range.clone(), cache, next_page_write_address)
.await?;
next_page_write_address = item.header.next_item_address::<S>(next_page_write_address);
Expand Down

0 comments on commit 0377271

Please sign in to comment.