This commit is contained in:
nvrl committed 2026-06-30 06:23:00 +02:00
1 parent 81a0ecce54
commit ec4f5ea32f
2 files changed
+36 -10

No files matched your search

+10 -3
View File
@@ -206,7 +206,8 @@ impl ContentCache {
} }
fn block_meta(&self, uid: &NodeUid, idx: u64) -> PathBuf { fn block_meta(&self, uid: &NodeUid, idx: u64) -> PathBuf {
self.block_dir.join(format!("{}.b{idx}.meta", Self::key(uid))) self.block_dir
.join(format!("{}.b{idx}.meta", Self::key(uid)))
} }
/// Serve cached block `idx` (a [`BLOCK_SIZE`]-aligned chunk) of `uid`, or /// Serve cached block `idx` (a [`BLOCK_SIZE`]-aligned chunk) of `uid`, or
@@ -244,7 +245,10 @@ impl ContentCache {
.join(format!("{}.b{idx}.tmp", Self::key(uid))); .join(format!("{}.b{idx}.tmp", Self::key(uid)));
std::fs::write(&tmp, bytes)?; std::fs::write(&tmp, bytes)?;
std::fs::rename(&tmp, &blob)?; std::fs::rename(&tmp, &blob)?;
std::fs::write(self.block_meta(uid, idx), serde_json::to_vec(&Meta { mtime, size })?)?; std::fs::write(
self.block_meta(uid, idx),
serde_json::to_vec(&Meta { mtime, size })?,
)?;
self.enforce_block_budget(); self.enforce_block_budget();
Ok(()) Ok(())
} }
@@ -744,7 +748,10 @@ mod tests {
assert!(c.cached_block(&u, 1, 12, 0).is_some()); assert!(c.cached_block(&u, 1, 12, 0).is_some());
std::thread::sleep(std::time::Duration::from_millis(10)); std::thread::sleep(std::time::Duration::from_millis(10));
c.store_block(&u, 1, 12, 2, b"cccc").unwrap(); c.store_block(&u, 1, 12, 2, b"cccc").unwrap();
assert!(c.cached_block(&u, 1, 12, 0).is_some(), "recently-read survives"); assert!(
c.cached_block(&u, 1, 12, 0).is_some(),
"recently-read survives"
);
assert!(c.cached_block(&u, 1, 12, 1).is_none(), "LRU block evicted"); assert!(c.cached_block(&u, 1, 12, 1).is_none(), "LRU block evicted");
assert!(c.cached_block(&u, 1, 12, 2).is_some(), "newest survives"); assert!(c.cached_block(&u, 1, 12, 2).is_some(), "newest survives");
} }
+26 -7
View File
@@ -450,7 +450,13 @@ impl Core {
} else { } else {
let bend = e.min(base_size); let bend = e.min(base_size);
if s < bend { if s < bend {
out.extend_from_slice(&self.read_range(uid, base_mtime, base_size, s, bend - s)?); out.extend_from_slice(&self.read_range(
uid,
base_mtime,
base_size,
s,
bend - s,
)?);
} }
// Anything past the base is a hole: zero-fill. // Anything past the base is a hole: zero-fill.
let zeros = e.saturating_sub(s.max(base_size)); let zeros = e.saturating_sub(s.max(base_size));
@@ -510,10 +516,13 @@ impl Core {
Errno::EIO Errno::EIO
})?; })?;
self.rt self.rt
.block_on( .block_on(self.client.upload_new_revision_from(
self.client &uid,
.upload_new_revision_from(&uid, reader, len as i64, Vec::new(), None), reader,
) len as i64,
Vec::new(),
None,
))
.map_err(|e| { .map_err(|e| {
error!(%uid, error = %e, "upload new revision failed"); error!(%uid, error = %e, "upload new revision failed");
Errno::EIO Errno::EIO
@@ -1123,7 +1132,14 @@ impl Filesystem for ProtonFs {
}; };
if let Some((file, len, uid, base_mtime, base_size, written)) = handle { if let Some((file, len, uid, base_mtime, base_size, written)) = handle {
match self.core.serve_open_read( match self.core.serve_open_read(
&file, len, &uid, base_mtime, base_size, &written, offset, size as u64, &file,
len,
&uid,
base_mtime,
base_size,
&written,
offset,
size as u64,
) { ) {
Ok(bytes) => reply.data(&bytes), Ok(bytes) => reply.data(&bytes),
Err(e) => reply.error(e), Err(e) => reply.error(e),
@@ -1146,7 +1162,10 @@ impl Filesystem for ProtonFs {
} }
} }
}; };
match self.core.read_range(&uid, mtime, fsize, offset, size as u64) { match self
.core
.read_range(&uid, mtime, fsize, offset, size as u64)
{
Ok(bytes) => reply.data(&bytes), Ok(bytes) => reply.data(&bytes),
Err(e) => reply.error(e), Err(e) => reply.error(e),
} }