Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
wasm-forge committed Sep 3, 2024
1 parent 5db414d commit edad33e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
17 changes: 3 additions & 14 deletions src/storage/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub struct CacheJournal<M: Memory> {

impl<M: Memory> CacheJournal<M> {
pub fn new(journal: VirtualMemory<M>) -> Result<CacheJournal<M>, Error> {


let cache_journal = if journal.size() == 0 {
journal.grow(1);

Expand All @@ -31,7 +29,6 @@ impl<M: Memory> CacheJournal<M> {
cache_journal.reset_mounted_meta();

cache_journal

} else {
// check the marker
let mut b = [0u8; 4];
Expand All @@ -42,16 +39,13 @@ impl<M: Memory> CacheJournal<M> {
return Err(Error::InvalidMagicMarker);
}

let cache_journal = CacheJournal { journal };

cache_journal
CacheJournal { journal }
};

Ok(cache_journal)
}

pub fn read_mounted_meta_node(&self) -> Option<Node>
{
pub fn read_mounted_meta_node(&self) -> Option<Node> {
let mut ret = 0u64;
read_obj(&self.journal, MOUNTED_META_PTR, &mut ret);
if ret == u64::MAX {
Expand Down Expand Up @@ -124,15 +118,13 @@ mod tests {
assert_eq!(meta, meta2);
}


#[test]
fn fsj1_marker_is_written() {
let mem = new_vector_memory();
let memory_manager = MemoryManager::init(mem);
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];

Expand All @@ -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];

Expand Down Expand Up @@ -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);

}
}
12 changes: 2 additions & 10 deletions src/storage/stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ impl<M: Memory> StableStorage<M> {
}

fn flush_mounted_meta(&mut self) {

let node = self.cache_journal.read_mounted_meta_node();

if let Some(node) = node {
Expand Down Expand Up @@ -468,20 +467,16 @@ impl<M: Memory> Storage for StableStorage<M> {
// Get the metadata associated with the node.
fn get_metadata(&self, node: Node) -> Result<Metadata, Error> {
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);

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());
}

Expand All @@ -494,16 +489,13 @@ impl<M: Memory> Storage for StableStorage<M> {
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);
}
Expand Down Expand Up @@ -668,7 +660,7 @@ impl<M: Memory> Storage for StableStorage<M> {
// 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
Expand Down

0 comments on commit edad33e

Please sign in to comment.