mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-19 01:55:04 +01:00
fix(fuse): cache an upload whose read-back failed, and know it as ours (B157)
When the read-back after an upload went unanswered, the drain let go of the staged blob without caching it. A partial write opened next had nothing to fill its gaps from and queued an incomplete revision, so the write open after it was refused with EIO. The bytes are now cached under the size and mtime the tree still has, which is the base the next write takes. Their SHA-1 stands in for the revision id the read-back did not bring, so that write chains onto the upload and does not fork a conflict copy of itself.
This commit is contained in:
1 parent
16fca10e6c
commit
4676a4e32b
8 files changed
+165
-17
No files matched your search
@@ -358,6 +358,46 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn a_file_whose_upload_was_not_read_back_takes_two_writes_at_once() {
|
||||
// The read-back after an upload went unanswered, and the drain let go of
|
||||
// the uploaded bytes without caching them. A partial write had nothing
|
||||
// to fill its gaps from, and the next open was refused with EIO (B157).
|
||||
let drive = FakeDrive::new();
|
||||
let dir = scratch("upload-not-read-back");
|
||||
let daemon = Daemon::start(&dir, drive.client(1, Faults::lan())).unwrap();
|
||||
let path = daemon.mountpoint.join("f.txt");
|
||||
let file = |bytes: &[u8]| Some(Entry::File(Arc::new(bytes.to_vec())));
|
||||
|
||||
std::fs::write(&path, b"first").unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& drive.tree().get("f.txt").cloned() == file(b"first")
|
||||
}));
|
||||
daemon.client.lose_read_back_of_next_revision();
|
||||
std::fs::write(&path, b"0123456789").unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& drive.tree().get("f.txt").cloned() == file(b"0123456789")
|
||||
}));
|
||||
write_at(&path, 2, b"ab").unwrap();
|
||||
write_at(&path, 6, b"cd").unwrap();
|
||||
assert!(
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& drive.tree().get("f.txt").cloned() == file(b"01ab45cd89")
|
||||
}),
|
||||
"{:?} {:?}",
|
||||
daemon.pending(),
|
||||
drive.tree()
|
||||
);
|
||||
assert_eq!(drive.tree().len(), 1, "{:?}", drive.tree());
|
||||
|
||||
assert!(matches!(daemon.stop(), Ok(MountOutcome::Shutdown)));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn the_echo_of_our_own_rename_keeps_the_cached_bytes() {
|
||||
|
||||
@@ -334,6 +334,8 @@ impl FakeDrive {
|
||||
lose_create_reply: AtomicBool::new(false),
|
||||
hold_create_reply: Mutex::new(None),
|
||||
lose_revision_reply: AtomicBool::new(false),
|
||||
lose_revision_read_back: AtomicBool::new(false),
|
||||
lose_read: Mutex::new(None),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -589,6 +591,10 @@ struct ClientInner {
|
||||
hold_create_reply: Mutex<Option<Arc<HoldState>>>,
|
||||
/// Set by [`FakeClient::lose_reply_to_next_revision`].
|
||||
lose_revision_reply: AtomicBool,
|
||||
/// Set by [`FakeClient::lose_read_back_of_next_revision`].
|
||||
lose_revision_read_back: AtomicBool,
|
||||
/// The file whose next read goes unanswered, once its revision is made.
|
||||
lose_read: Mutex<Option<NodeUid>>,
|
||||
}
|
||||
|
||||
struct HoldState {
|
||||
@@ -678,6 +684,13 @@ impl FakeClient {
|
||||
self.0.lose_revision_reply.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// Make the next revision of a file on Drive and answer it, then lose the
|
||||
/// answer to the next read of that file alone, as the read-back after an
|
||||
/// upload meets on a link that drops it.
|
||||
pub(crate) fn lose_read_back_of_next_revision(&self) {
|
||||
self.0.lose_revision_read_back.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// Wait here if `uids` is the read a [`Held`] is for.
|
||||
async fn wait_if_held(&self, uids: &[NodeUid]) {
|
||||
let state = {
|
||||
@@ -916,6 +929,16 @@ impl DriveApi for FakeClient {
|
||||
|
||||
async fn enumerate_nodes(&self, uids: &[NodeUid]) -> Result<Vec<Node>> {
|
||||
self.wait_if_held(uids).await;
|
||||
{
|
||||
let mut lose = self.0.lose_read.lock();
|
||||
if lose
|
||||
.as_ref()
|
||||
.is_some_and(|uid| uids == std::slice::from_ref(uid))
|
||||
{
|
||||
*lose = None;
|
||||
return Err(no_answer());
|
||||
}
|
||||
}
|
||||
let lag = self.lag();
|
||||
let nodes: Vec<Node> = self
|
||||
.request(false, |server| {
|
||||
@@ -1168,6 +1191,9 @@ impl DriveApi for FakeClient {
|
||||
if self.0.lose_revision_reply.swap(false, Ordering::SeqCst) {
|
||||
return Err(no_answer());
|
||||
}
|
||||
if self.0.lose_revision_read_back.swap(false, Ordering::SeqCst) {
|
||||
*self.0.lose_read.lock() = Some(file_uid.clone());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user