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

Clear FSDB materialization cache when removeing a file #18747

Merged
merged 4 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions src/rust/engine/fs/store/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ impl UnderlyingByteStore for ShardedFSDB {
}

async fn remove(&self, fingerprint: Fingerprint) -> Result<bool, String> {
Ok(
tokio::fs::remove_file(self.get_path(fingerprint))
.await
.is_ok(),
)
let removed = tokio::fs::remove_file(self.get_path(fingerprint))
.await
.is_ok();
let _ = self.dest_initializer.lock().remove(&fingerprint);
thejcannon marked this conversation as resolved.
Show resolved Hide resolved
thejcannon marked this conversation as resolved.
Show resolved Hide resolved
Ok(removed)
}

async fn store_bytes_batch(
Expand Down
51 changes: 51 additions & 0 deletions src/rust/engine/fs/store/src/local_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,57 @@ async fn garbage_collect_and_compact() {
);
}

async fn write_1mb(store: &ByteStore, byte: u8) -> Digest {
let mut bytes = BytesMut::with_capacity(1024 * 1024);
for _ in 0..1024 * 1024 {
bytes.put_u8(byte);
}
let digest = Digest::of_bytes(&bytes);
store
.store_bytes(EntryType::File, digest.hash, bytes.freeze(), false)
.await
.expect("Error storing");
digest
}

#[tokio::test]
async fn remove_big_file_and_store_again() {
let dir = TempDir::new().unwrap();
let store = new_store(dir.path());

let digest1 = write_1mb(&store, b'0').await;
let digest2 = write_1mb(&store, b'1').await;

let size = get_directory_size(dir.path());
assert!(
size >= 2 * 1024 * 1024,
"Expect size to be at least 2MB but was {size}"
);

store
.remove(EntryType::File, digest1)
.await
.expect("Error removing");
store
.remove(EntryType::File, digest2)
.await
.expect("Error removing");

let size = get_directory_size(dir.path());
assert!(
size < 2 * 1024 * 1024,
"Expect size to be less than 2MB but was {size}"
);

write_1mb(&store, b'0').await;
write_1mb(&store, b'1').await;
let size = get_directory_size(dir.path());
assert!(
size >= 2 * 1024 * 1024,
"Expect size to be at least 2MB but was {size}"
);
}

#[tokio::test]
async fn entry_type_for_file() {
let testdata = TestData::roland();
Expand Down