Compare commits

..
Author SHA1 Message Date
nvrl ea29a260b0 Merge pull request #180 from narrrl/fix/echo-false-conflict
fix(fuse): read a write based on a landed create's placeholder as the create's revision
2026-11-27 19:31:10 +01:00
nvrl 8e9816919d Merge pull request #184 from narrrl/feat/sync-root-reducer
feat(sync): run a root reducer per mirror folder alongside the engine
2026-11-27 19:30:48 +01:00
nvrl ef5f832b0f fix(fuse): read a write based on a landed create's placeholder as the create's revision
A write released while its file's create landed could keep the
placeholder's base, a local mtime and no revision id: the release takes
its handle out of the tree before it queues, so neither the rebase of
open handles nor the rebase of queued writes reached it. The drain then
compared mtimes, Drive had stamped the create a second later, and the
write went up as a conflict copy of the file's own create (B304).

Landing a create now remembers the placeholder's stamp with the revision
the create sealed, and the drain reads a revision-less base with that
stamp as that revision.
2026-11-27 18:56:13 +01:00
5 changed files with 115 additions and 0 deletions

No files matched your search

+52
View File
@@ -80,6 +80,13 @@ pub(crate) struct DrainState {
/// The node an upload has just put on Drive, from when the drain lets go
/// of its blob until the tree has the node (`docs/BUGS.md` B170).
pub(crate) landed: Arc<Mutex<HashMap<NodeUid, Node>>>,
/// A landed create's placeholder stamp, by the uid Drive gave it, with the
/// revision the create sealed. A write released while the create landed
/// can be based on the placeholder: a local mtime and no revision id. Its
/// bytes are the ones the create sent, so the drain reads that base as the
/// sealed revision ([`placeholder_base`]). Dropped once a later upload of
/// the file lands.
pub(crate) placeholders: Arc<Mutex<HashMap<NodeUid, Baseline>>>,
/// How long this node's last upload actually took, in milliseconds, with
/// the time it was measured for eviction. Feeds
/// [`Core::revision_debounce`]: a file that takes 30 seconds to send needs
@@ -110,6 +117,7 @@ impl DrainState {
unadopted: Arc::new(Mutex::new(HashMap::new())),
sealed_unread: Arc::new(Mutex::new(HashMap::new())),
landed: Arc::new(Mutex::new(HashMap::new())),
placeholders: Arc::new(Mutex::new(HashMap::new())),
upload_times: Arc::new(Mutex::new(HashMap::new())),
upload_cancel: Arc::new(Mutex::new(HashMap::new())),
landing_uploads: Arc::new(AtomicU64::new(0)),
@@ -874,6 +882,29 @@ fn revision_changed(base: &Baseline, node: &Node) -> Option<String> {
})
}
/// `base` as the revision it was made against, for [`revision_changed`].
///
/// A base with no revision id whose stamp is a landed create's placeholder
/// (`placeholder`) was taken from that placeholder by a write released while
/// the create landed: the release had taken its handle out of the tree, so the
/// rebase onto the landed node missed it, and it queued after the queued writes
/// were rebased. The placeholder's bytes are the ones the create sent, so the
/// base is the revision the create sealed. Compared by its local mtime instead,
/// the write was a conflict copy of the file's own create whenever the server
/// stamped the create a second later than the placeholder.
fn placeholder_base(base: &Baseline, placeholder: Option<&Baseline>) -> Baseline {
match placeholder {
Some(created)
if base.revision_id.is_none()
&& created.mtime == base.mtime
&& created.size == base.size =>
{
created.clone()
}
_ => base.clone(),
}
}
/// Whether a queued write that found the remote moved on ([`revision_changed`]
/// fired) is nonetheless a single-writer self-supersede rather than a foreign
/// conflict — the remote sits at a revision this daemon sealed itself, so
@@ -1808,6 +1839,27 @@ mod tests {
assert!(revision_changed(&base, &remote).is_some());
}
/// A write released while its file's create landed keeps the
/// placeholder's base: the local mtime, a second before the server's
/// stamp, and no revision id.
#[test]
fn a_write_based_on_a_landed_create_placeholder_is_not_a_conflict() {
let placeholder = baseline(1_795_799_834, 28, None);
let created = baseline(1_795_799_834, 28, Some("rev-create"));
let landed = file_node(1_795_799_835, 28, Some("rev-create"));
assert!(revision_changed(&placeholder, &landed).is_some());
let base = placeholder_base(&placeholder, Some(&created));
assert_eq!(revision_changed(&base, &landed), None);
// Another device writing over the create is still a conflict.
let edited = file_node(1_795_799_835, 28, Some("theirs"));
assert!(revision_changed(&base, &edited).is_some());
// A base with a revision of its own, or another stamp, is left alone.
let other = baseline(1_795_799_830, 28, None);
assert_eq!(placeholder_base(&other, Some(&created)), other);
let revised = baseline(1_795_799_834, 28, Some("older"));
assert_eq!(placeholder_base(&revised, Some(&created)), revised);
}
/// The reported shape (docs/BUGS.md B113): a downloader creates a file
/// through the mount, and the file is moved before its write drains. The
/// move re-stamps the node's mtime on the server (1790955809 -> 1790956593),
+27
View File
@@ -651,6 +651,9 @@ impl Core {
// B123).
let remote = node.clone();
self.stamp_pending_sizes(std::slice::from_mut(&mut node));
// The placeholder as the tree has it, before the landed node replaces
// it: the base of a write that opened over it (`placeholder_base`).
let mut placeholder = None;
// The rows and queued ops already follow the node: `retire_create`
// moved its row to the real uid, and ops find it by local id.
@@ -673,6 +676,11 @@ impl Core {
node.parent_uid = e.node.parent_uid.clone();
}
st.write_through(node.clone());
if let Some(e) = st.entries.get(&ino)
&& node_revision_id(&e.node).is_none()
{
placeholder.get_or_insert((e.node.modification_time, node_size(&e.node)));
}
let mut landed = node.clone();
st.keep_open_write_size(ino, &mut landed);
if let Some(e) = st.entries.get_mut(&ino) {
@@ -719,6 +727,25 @@ impl Core {
{
warn!(%real, error = %e, "persisting our sealed revision failed");
}
// A release that took its handle out of the tree before the rebase
// below and queues after `rebaseline_pending` is caught by neither,
// and an incomplete write does not chain onto our own revision. Its
// base is the placeholder, whose bytes the create sent.
if let Some((mtime, size)) = placeholder
&& mtime != remote.modification_time
&& size == node_size(&remote)
&& let Some(rev) = node_revision_id(&remote)
{
self.drain.placeholders.lock().insert(
real.clone(),
Baseline {
mtime,
size,
hash: None,
revision_id: Some(rev),
},
);
}
self.rebase_open_writes(real, &remote);
// A write carried over from the create was made against no revision at
// all; the one just created is what it now replaces.
+4
View File
@@ -116,6 +116,8 @@ impl Core {
if node.trashed {
return Ok(Some("the file was trashed remotely".into()));
}
let placeholder = self.drain.placeholders.lock().get(uid).cloned();
let base = &placeholder_base(base, placeholder.as_ref());
let Some(reason) = revision_changed(base, &node) else {
return Ok(None);
};
@@ -511,6 +513,8 @@ impl Core {
if fetched.is_ok() {
self.drain.sealed_unread.lock().remove(uid);
}
// This upload went after any write based on the create's placeholder.
self.drain.placeholders.lock().remove(uid);
let node = match fetched {
Ok(Some(node)) => node,
// Trashed or deleted under us: the tree will hear it from the event
+1
View File
@@ -61,6 +61,7 @@ impl Core {
if let Err(e) = self.db.clear_own_sealed_rev(&uid.to_string()) {
debug!(%uid, error = %e, "clearing the sealed-revision record failed");
}
self.drain.placeholders.lock().remove(&uid);
self.invalidate_trash();
self.log_activity(ActivityKind::Trash, &name, "trashed", true);
info!(%uid, name, "pending trash landed");
+31
View File
@@ -108,6 +108,7 @@ a live account since.
| Entry | Title |
|---|---|
| [B304](#b304--a-write-released-while-its-files-create-lands-is-kept-as-a-conflict-copy) | A write released while its file's create lands is kept as a conflict copy |
| [B303](#b303--a-file-made-where-a-withdrawn-create-was-listed-refuses-every-write) | A file made where a withdrawn create was listed refuses every write |
| [B302](#b302--a-stop-during-a-replacing-rename-leaves-the-replaced-file-in-the-trash) | A stop during a replacing rename leaves the replaced file in the trash |
| [B301](#b301--two-overlapping-fsyncs-can-leave-the-older-ones-record-on-disk) | Two overlapping fsyncs can leave the older one's record on disk |
@@ -406,6 +407,36 @@ a live account since.
Newest first.
### B304 — A write released while its file's create lands is kept as a conflict copy
**Status:** Fixed (unverified)
**Found:** 2026-11-27, from a CI failure of the `one_client_with_stale_hashes_and_reordered_echoes`
simulation (seed 5): the queues did not drain in time, and Drive held a conflict copy of `e.md`.
The daemon log said "the remote revision changed under the queued write (expected 28 bytes at
mtime 1795799834, found 28 at 1795799835)".
**Where:** `Core::adopt_real_uid` in `crates/pdfs-fuse/src/drain/create.rs` and
`Core::revision_conflict` in `crates/pdfs-fuse/src/drain/revision.rs`
**Repro:** Make a file with some content, and let its create reach Drive in a later second than
the file was made locally. As the create lands, write part of the file and close it. Rare: the
close has to fall in a window of a few milliseconds.
**Cause.** The write opened over the create's placeholder, whose base is the local mtime and no
revision id. Landing the create rebases the handles open on the file and the writes queued for
it onto the node Drive made. A release takes its handle out of the tree before it queues the
write, so a release that started before the rebase and queued after it was caught by neither.
The drain then had no revision id to compare and fell back to the mtime, which Drive had stamped
a second later. The write was not complete, so the check that chains a write onto a revision this
daemon sealed did not apply either, and the write went up as a conflict copy of the file's own
create.
**Fix.** Landing a create remembers the placeholder's mtime and size with the revision the create
sealed. A base with no revision id and that stamp is read as that revision: its bytes are the ones
the create sent. The record goes once a later upload of the file lands, or the file is trashed.
**Verified:** `a_write_based_on_a_landed_create_placeholder_is_not_a_conflict` checks the
comparison. The race itself is not reproduced on demand; 40 local replays of the seed passed.
### B303 — A file made where a withdrawn create was listed refuses every write
**Status:** Fixed (unverified)