From 0377271084039ae99978f5be14e220dd37924cc6 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Sun, 11 Feb 2024 00:01:19 +0100 Subject: [PATCH] Fix migration cache issue --- src/map.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/map.rs b/src/map.rs index 5eba9ac..a404f07 100644 --- a/src/map.rs +++ b/src/map.rs @@ -177,7 +177,7 @@ async fn fetch_item_with_location( 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; @@ -190,7 +190,7 @@ async fn fetch_item_with_location( 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? @@ -604,9 +604,14 @@ async fn migrate_items( 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::(flash, flash_range.clone(), cache, data_buffer, key.clone()) - .await? + let Some((_, found_address, _)) = fetch_item_with_location::( + flash, + flash_range.clone(), + cache, + data_buffer, + key.clone(), + ) + .await? else { // We couldn't even find our own item? return Err(MapError::Corrupted { @@ -622,7 +627,7 @@ async fn migrate_items( .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::(next_page_write_address);