Skip to content

Commit

Permalink
feat: add log support (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <[email protected]>
  • Loading branch information
MrCroxx authored Jun 1, 2023
1 parent 8e80c6c commit 79610aa
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions foyer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tokio = { version = "1", features = [
"time",
"signal",
] }
tracing = "0.1"
twox-hash = "1"

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions foyer/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ where
config: Config<I, P, H, S>,
registry: prometheus::Registry,
) -> Result<Self> {
tracing::info!("open foyer with config: \n{:#?}", config);

let pool_count = 1 << config.pool_count_bits;
let capacity = config.capacity >> config.pool_count_bits;

Expand Down
43 changes: 29 additions & 14 deletions foyer/src/store/read_only_file_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,18 @@ where
.read(location.offset as u64, location.len as usize)
.await?
} else {
files
.frozens
.get(&fid)
.expect("frozen file not found")
.cache_file
.read(location.offset as u64, location.len as usize)
.await?
match files.frozens.get(&fid) {
Some(frozen) => {
frozen
.cache_file
.read(location.offset as u64, location.len as usize)
.await?
}
None => {
tracing::error!("frozen file {} not found", fid);
return Ok(None);
}
}
}
};

Expand Down Expand Up @@ -325,13 +330,17 @@ where
.write(sid as u64 * Self::meta_entry_size() as u64, empty_entry)
.await?;
} else {
files
.frozens
.get(&fid)
.expect("frozen file not found")
.meta_file
.write(sid as u64 * Self::meta_entry_size() as u64, empty_entry)
.await?;
match files.frozens.get(&fid) {
Some(frozen) => {
frozen
.meta_file
.write(sid as u64 * Self::meta_entry_size() as u64, empty_entry)
.await?;
}
None => {
tracing::error!("frozen file {} not found", fid);
}
}
}
}

Expand Down Expand Up @@ -369,10 +378,14 @@ where
// update frozen map
files.frozens.insert(id, frozen);

tracing::info!("active file rotated: {} => {}", id, id + 1);

Ok(())
}

async fn reclaim_frozen_file(&self, id: FileId) -> Result<()> {
tracing::info!("reclaiming frozen file {}", id);

let (fid, meta_file, cache_file) = {
let mut files = self.files.write().await;

Expand Down Expand Up @@ -404,6 +417,8 @@ where
meta_file.reclaim().await?;
cache_file.reclaim().await?;

tracing::info!("frozen file {} reclaimed", id);

Ok(())
}

Expand Down

0 comments on commit 79610aa

Please sign in to comment.