From edad33e38a3656bd9ad938c20a59cf9c24bf2567 Mon Sep 17 00:00:00 2001 From: wasm-forge <122647775+wasm-forge@users.noreply.github.com> Date: Wed, 4 Sep 2024 00:33:26 +0200 Subject: [PATCH] clean-up --- src/storage/journal.rs | 17 +++-------------- src/storage/stable.rs | 12 ++---------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/storage/journal.rs b/src/storage/journal.rs index 1fa4a8d..ee1efab 100644 --- a/src/storage/journal.rs +++ b/src/storage/journal.rs @@ -16,8 +16,6 @@ pub struct CacheJournal { impl CacheJournal { pub fn new(journal: VirtualMemory) -> Result, Error> { - - let cache_journal = if journal.size() == 0 { journal.grow(1); @@ -31,7 +29,6 @@ impl CacheJournal { cache_journal.reset_mounted_meta(); cache_journal - } else { // check the marker let mut b = [0u8; 4]; @@ -42,16 +39,13 @@ impl CacheJournal { return Err(Error::InvalidMagicMarker); } - let cache_journal = CacheJournal { journal }; - - cache_journal + CacheJournal { journal } }; Ok(cache_journal) } - pub fn read_mounted_meta_node(&self) -> Option - { + pub fn read_mounted_meta_node(&self) -> Option { let mut ret = 0u64; read_obj(&self.journal, MOUNTED_META_PTR, &mut ret); if ret == u64::MAX { @@ -124,7 +118,6 @@ mod tests { assert_eq!(meta, meta2); } - #[test] fn fsj1_marker_is_written() { let mem = new_vector_memory(); @@ -132,7 +125,6 @@ mod tests { let journal_memory = memory_manager.get(MemoryId::new(1)); let _journal = CacheJournal::new(journal_memory).unwrap(); - let memory = memory_manager.get(MemoryId::new(1)); let mut b = [0u8; 4]; @@ -159,7 +151,6 @@ mod tests { let journal_memory = memory_manager.get(MemoryId::new(1)); let _journal = CacheJournal::new(journal_memory).unwrap(); - let memory = memory_manager.get(MemoryId::new(1)); let b = [0u8; 1]; @@ -204,16 +195,14 @@ mod tests { }; journal.write_mounted_meta(&123, &meta); - let journal = CacheJournal::new(memory_manager.get(MemoryId::new(1))).unwrap(); assert_eq!(journal.read_mounted_meta_node(), Some(123)); - + let mut meta2 = Metadata::default(); journal.read_mounted_meta(&mut meta2); assert_eq!(meta, meta2); - } } diff --git a/src/storage/stable.rs b/src/storage/stable.rs index 71bd6f7..f73ef51 100644 --- a/src/storage/stable.rs +++ b/src/storage/stable.rs @@ -430,7 +430,6 @@ impl StableStorage { } fn flush_mounted_meta(&mut self) { - let node = self.cache_journal.read_mounted_meta_node(); if let Some(node) = node { @@ -468,7 +467,6 @@ impl Storage for StableStorage { // Get the metadata associated with the node. fn get_metadata(&self, node: Node) -> Result { if self.is_mounted(node) { - if self.cache_journal.read_mounted_meta_node() == Some(node) { let mut meta = Metadata::default(); self.cache_journal.read_mounted_meta(&mut meta); @@ -476,12 +474,9 @@ impl Storage for StableStorage { return Ok(meta); } - let res = self.mounted_meta.get(&node).ok_or(Error::NotFound); - - res + self.mounted_meta.get(&node).ok_or(Error::NotFound) } else { if self.last_metadata.0 == node { - return Ok(self.last_metadata.1.clone()); } @@ -494,16 +489,13 @@ impl Storage for StableStorage { assert_eq!(node, metadata.node, "Node does not match medatada.node!"); if self.is_mounted(node) { - // flush changes if the last node was different if self.cache_journal.read_mounted_meta_node() != Some(node) { self.flush_mounted_meta(); } self.cache_journal.write_mounted_meta(&node, &metadata) - } else { - self.last_metadata = (node, metadata.clone()); self.metadata.insert(node, metadata); } @@ -668,7 +660,7 @@ impl Storage for StableStorage { // remove metadata self.mounted_meta.remove(&node); self.metadata.remove(&node); - + let mounted_meta_node = self.cache_journal.read_mounted_meta_node(); if mounted_meta_node == Some(node) { // reset cached mounted metadata