Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improved missing chunk iterator #18

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog

## [unreleased]

- Upgrade Pocket-ic client version to V5.0
- Filename cache added (faster repeated opening of the same file)
## [v0.6.4]

- Upgrade Pocket-ic client version to V5.0.
- Filename cache added (faster repeated opening of the same file).
- Refactor v2 chunks reading and writing (reuse the same iteration mechanism).
- Medatada cache for regular files (faster overwriting in small segments).
- Dependency updates to the latest versions

## [v0.6.3]

Expand All @@ -30,7 +32,6 @@
- add V2 chunks support.
- *API change:* mounted memory file support.


## [v0.5.1]

- use newer ic-cdk version.
Expand All @@ -42,7 +43,8 @@
- *API change:* init with memory manager using memory index range rather than first memory index.


[unreleased]: https://github.com/wasm-forge/stable-fs/compare/v0.6.3...main
[unreleased]: https://github.com/wasm-forge/stable-fs/compare/v0.6.4...main
[v0.6.4]: https://github.com/wasm-forge/stable-fs/compare/v0.6.3...v0.6.4
[v0.6.3]: https://github.com/wasm-forge/stable-fs/compare/v0.6.2...v0.6.3
[v0.6.2]: https://github.com/wasm-forge/stable-fs/compare/v0.6.1...v0.6.2
[v0.6.1]: https://github.com/wasm-forge/stable-fs/compare/v0.6.0...v0.6.1
Expand Down
48 changes: 29 additions & 19 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "stable-fs"
version = "0.6.3"
version = "0.6.4"
edition = "2021"
description = "A Simple File system implementing WASI endpoints and using the stable structures of the Internet Computer"
keywords = ["ic", "internet-computer", "file-system"]
license = "MIT"
repository = "https://github.com/wasm-forge/stable-fs"

[dependencies]
bitflags = "2.3.1"
bitflags = "2.6.0"
ic-cdk = "0.16"
ic-stable-structures = "0.6.5"
serde = "1.0.164"
serde = "1.0.210"
serde_bytes = "0.11"
ciborium = "0.2.1"
ciborium = "0.2.2"

[dev-dependencies]
candid = "0.10.8"
candid = "0.10.10"
pocket-ic = "5.0.0"
5 changes: 2 additions & 3 deletions src/filename_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ impl FilenameCache {

// add new cache pointer
pub fn add(&mut self, key: (Node, String), value: Node) {

if self.nodes.len() + 1 > CACHE_CAPACITY {
self.clear();
}

self.nodes.insert(key, value);
}

Expand Down Expand Up @@ -62,7 +61,7 @@ mod tests {
let filename = "test_file".to_string();
let node = 35 as Node;

cache.add((fd, filename.clone()), node.clone());
cache.add((fd, filename.clone()), node);

let retrieved_node = cache.get(&(fd, filename));
assert_eq!(retrieved_node, Some(node));
Expand Down
24 changes: 9 additions & 15 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl FileSystem {
if !flags.contains(OpenFlags::CREATE) {
return Err(Error::NotFound);
}

if flags.contains(OpenFlags::DIRECTORY) {
return Err(Error::InvalidFileType);
}
Expand Down Expand Up @@ -1327,8 +1327,6 @@ mod tests {
let content = format!("{i}");
let times = SIZE_OF_FILE / content.len();

println!("Writing to {filename}");

write_text_file(&mut fs, root_fd, filename.as_str(), content.as_str(), times)
.unwrap();
}
Expand All @@ -1338,8 +1336,6 @@ mod tests {
let filename = format!("{}/my_file_{}.txt", dir_name, i);
let expected_content = format!("{i}{i}{i}");

println!("Reading {}", filename);

let text_read = read_text_file(
&mut fs,
root_fd,
Expand Down Expand Up @@ -1589,14 +1585,12 @@ mod tests {
let content = read_text_file(&mut fs, root_fd, filename, 0, 100);

assert_eq!(content, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
println!("{:?}", content);

write_text_at_offset(&mut fs, fd, "abc", 3, 3).unwrap();

let content = read_text_file(&mut fs, root_fd, filename, 1, 100);

assert_eq!(content, "\0\0abcabcabc\0\0\0");
println!("{:?}", content);
}
}

Expand All @@ -1613,14 +1607,18 @@ mod tests {
let content = read_text_file(&mut fs, root_fd, filename, 0, chunk_size * 10);

let vec = vec![0; chunk_size * 2 + 500];

let expected = String::from_utf8(vec).unwrap();

// expect all zeroes at first
assert_eq!(content, expected);

// write some text to the first chunk
write_text_at_offset(&mut fs, fd, "abc", 33, 3).unwrap();

// write some text to the 100th position of the third chunk
write_text_at_offset(&mut fs, fd, "abc", 33, chunk_size as FileSize * 2 + 100).unwrap();

// read what we have now
let content = read_text_file(&mut fs, root_fd, filename, 0, chunk_size * 10);

let mut expected = vec![0u8; chunk_size * 2 + 500];
Expand Down Expand Up @@ -1668,13 +1666,11 @@ mod tests {
}
}


#[test]
fn filename_cached_on_open_or_create() {
let filename = "test.txt";

for mut fs in test_fs_setups("") {

let root_fd = fs.root_fd();
let fd = fs
.open_or_create(root_fd, filename, FdStat::default(), OpenFlags::CREATE, 12)
Expand All @@ -1683,7 +1679,6 @@ mod tests {
fs.close(fd).unwrap();

assert_eq!(fs.names_cache.get_nodes().len(), 1);

}
}

Expand All @@ -1692,20 +1687,19 @@ mod tests {
let filename = "test.txt";

for mut fs in test_fs_setups("") {

let root_fd = fs.root_fd();
let fd = fs
.open_or_create(root_fd, filename, FdStat::default(), OpenFlags::CREATE, 12)
.unwrap();
fs.close(fd).unwrap();

fs.remove_file(root_fd, filename).unwrap();

assert_eq!(fs.names_cache.get_nodes().len(), 0);

// check we don't increase cache when the file is opened but not created
let fd2 = fs
.open_or_create(root_fd, filename, FdStat::default(), OpenFlags::empty(), 12);
let fd2 =
fs.open_or_create(root_fd, filename, FdStat::default(), OpenFlags::empty(), 12);

assert_eq!(fd2, Err(Error::NotFound));
assert_eq!(fs.names_cache.get_nodes().len(), 0);
Expand Down
9 changes: 4 additions & 5 deletions src/runtime/structure_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@ pub fn find_node(

match find_result {
Ok(result) => {

names_cache.add(key, result.node);

return Ok(result.node);
},
Err(e) => {
return Err(e);
Ok(result.node)
}
Err(e) => Err(e),
}
}

Expand Down Expand Up @@ -473,8 +470,10 @@ pub fn get_chunk_infos(start: FileSize, end: FileSize, chunk_size: usize) -> Vec
let mut result = vec![];
let start_index = offset_to_file_chunk_index(start, chunk_size);
let end_index = offset_to_file_chunk_index(end, chunk_size);

for index in start_index..=end_index {
let start_of_chunk = file_chunk_index_to_offset(index, chunk_size);

assert!(start_of_chunk <= end);
let start_in_chunk = start_of_chunk.max(start) - start_of_chunk;
let end_in_chunk = (start_of_chunk + chunk_size as FileSize).min(end) - start_of_chunk;
Expand Down
1 change: 1 addition & 0 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod allocator;
mod chunk_iterator;
pub mod dummy;
mod journal;
mod metadata_cache;
mod ptr_cache;
pub mod stable;
pub mod transient;
Expand Down
Loading
Loading