fix(core,fuse): a node written under its stand-in after landing updates its landed row

This commit is contained in:
nvrl committed 2026-10-04 13:38:54 +02:00
1 parent 9c93860cd8
commit dbc4d9a8c5
4 files changed
+66 -30

No files matched your search

+18 -1
View File
@@ -900,8 +900,25 @@ fn adopt_children_tx(tx: &Transaction<'_>, uid: &str, lid: i64) -> Result<()> {
}
fn upsert_node_tx(tx: &Transaction<'_>, node: &Node) -> Result<()> {
let json = serde_json::to_string(node)?;
let uid = node.uid.to_string();
// A node written under its stand-in after it landed is its row, which has
// the uid Drive gave it by now: written under the stand-in, it would bring
// the placeholder row back beside it.
if let Some(lid) = local_lid(&uid) {
let landed: Option<String> = tx
.query_row(
"SELECT uid FROM nodes WHERE lid = ?1 AND uid IS NOT ?2",
params![lid, uid],
|row| row.get(0),
)
.optional()?;
if let Some(real) = landed.as_deref().and_then(parse_node_uid) {
let mut node = node.clone();
node.uid = real;
return upsert_node_tx(tx, &node);
}
}
let json = serde_json::to_string(node)?;
let parent_uid = node.parent_uid.as_ref().map(|u| u.to_string());
let prior: Option<PriorRow> = tx
+37
View File
@@ -3964,6 +3964,43 @@ fn a_landed_folder_rewrites_no_row_or_op_below_it() {
);
}
/// A node the mount still holds under its stand-in, written after it landed,
/// updates the landed row: written under the stand-in, it brought the
/// placeholder row back beside it.
#[test]
fn a_stand_in_written_after_landing_updates_the_landed_row() {
let db = Db::open_in_memory().unwrap();
db.upsert_node(&folder("root", None, "My Files")).unwrap();
let lid = db
.add_local_row(&uid("root").to_string(), "a.txt", false, 1)
.unwrap();
let local = local_uid(lid);
let mut node = file("x", "root", "a.txt", 3);
node.uid = NodeUid::new(VolumeId::from("local"), LinkId::from(lid.to_string()));
db.upsert_node(&node).unwrap();
db.land_placeholder_row(&local, &uid("a").to_string())
.unwrap();
node.name = "b.txt".into();
db.upsert_node(&node).unwrap();
let rows: Vec<(i64, String, String)> = {
let conn = db.conn.lock();
let mut stmt = conn
.prepare("SELECT lid, uid, name FROM nodes WHERE uid != ?1")
.unwrap();
stmt.query_map([uid("root").to_string()], |r| {
Ok((r.get(0)?, r.get(1)?, r.get(2)?))
})
.unwrap()
.collect::<rusqlite::Result<_>>()
.unwrap()
};
assert_eq!(rows, [(lid, uid("a").to_string(), "b.txt".to_string())]);
let landed = db.node_by_uid(&uid("a").to_string()).unwrap().unwrap();
assert_eq!((landed.uid, landed.name), (uid("a"), "b.txt".to_string()));
}
/// A create queued inside a folder made here is sent under the folder's real
/// uid once it lands. Landing where it was sent is no move.
#[test]
+3 -24
View File
@@ -169,10 +169,6 @@ const DRAIN_BACKOFF_MAX: Duration = Duration::from_secs(300);
/// directly on a new write or a reconnect, so this only bounds how late a
/// backoff can fire.
const DRAIN_IDLE_POLL: Duration = Duration::from_secs(30);
/// How long a write whose create just landed waits for the drain to repoint
/// its inode (`Core::landed_uid`): 200 polls of 10 ms, two seconds in all.
const LANDED_UID_POLLS: u32 = 200;
const LANDED_UID_POLL: Duration = Duration::from_millis(10);
/// How long the mount waits before asking again for a node it has just created
/// when Drive does not list it yet (`Core::fetch_minted_node`).
const MINTED_READ_BACK_DELAYS: [Duration; 2] = [Duration::from_millis(250), Duration::from_secs(1)];
@@ -3430,9 +3426,9 @@ impl Core {
break 'queued attached.superseded;
}
drop(pending);
// The create landed while this handle was open. Its uid is the
// one the drain has just given the inode.
let Some(real) = self.landed_uid(ino) else {
// The create landed while this handle was open, and its row
// already has the uid Drive gave it.
let Some(real) = self.landed_row_uid(ino) else {
error!(%uid, staged = %path.display(),
"queued create vanished under a write; bytes kept in staging");
return Err(Errno::EIO);
@@ -3511,23 +3507,6 @@ impl Core {
Ok(())
}
/// The real uid the drain gave `ino` when its queued create landed.
///
/// Called by a write that found the create already retired. The drain
/// repoints the inode right after it drops `pending`, with no network in
/// between, so a short wait covers the gap; `None` means the inode is gone
/// or never stopped being a placeholder.
fn landed_uid(&self, ino: u64) -> Option<NodeUid> {
for _ in 0..LANDED_UID_POLLS {
let uid = self.state().entries.get(&ino).map(|e| e.uid.clone())?;
if !is_local_uid(&uid) {
return Some(uid);
}
std::thread::sleep(LANDED_UID_POLL);
}
None
}
/// Queue the new content of a path-based truncate — `> file`, or any
/// `setattr(size=…)` arriving without a write handle.
///