mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-12-01 12:32:13 +01:00
Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef5f832b0f | ||
|
|
91fe76dbe1 | ||
|
|
4ff217c721 | ||
|
|
620c3fd10f | ||
|
|
6bcef1281d | ||
|
|
b9f18180fe | ||
|
|
70259b5163 | ||
|
|
c1718b13a7 | ||
|
|
acf3bd40a5 | ||
|
|
e90979eb05 | ||
|
|
d3f6f0b155 | ||
|
|
4e96ae8c61 | ||
|
|
bba74b5e65 | ||
|
|
fd0fb66448 | ||
|
|
7614ed6731 | ||
|
|
c44c1bccb5 |
No files matched your search
Generated
+10
@@ -3727,6 +3727,7 @@ dependencies = [
|
||||
"parking_lot 0.13.0",
|
||||
"pdfs-core",
|
||||
"pdfs-drive",
|
||||
"pdfs-sched",
|
||||
"pdfs-store",
|
||||
"pdfs-sync",
|
||||
"pdfs-vfs",
|
||||
@@ -3770,6 +3771,14 @@ dependencies = [
|
||||
"webkit6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdfs-sched"
|
||||
version = "3.10.0"
|
||||
dependencies = [
|
||||
"parking_lot 0.13.0",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdfs-store"
|
||||
version = "3.10.0"
|
||||
@@ -3794,6 +3803,7 @@ dependencies = [
|
||||
"parking_lot 0.13.0",
|
||||
"pdfs-core",
|
||||
"pdfs-drive",
|
||||
"pdfs-sched",
|
||||
"pdfs-store",
|
||||
"proton-drive-rs",
|
||||
"sha1 0.11.0",
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = ["crates/pdfs-core", "crates/pdfs-store", "crates/pdfs-drive", "crates/pdfs-sync", "crates/pdfs-vfs", "crates/pdfs-fuse", "crates/pdfs-daemon", "crates/pdfs-cli", "crates/pdfs-gui"]
|
||||
members = ["crates/pdfs-core", "crates/pdfs-store", "crates/pdfs-drive", "crates/pdfs-sync", "crates/pdfs-sched", "crates/pdfs-vfs", "crates/pdfs-fuse", "crates/pdfs-daemon", "crates/pdfs-cli", "crates/pdfs-gui"]
|
||||
|
||||
[workspace.package]
|
||||
version = "3.10.0"
|
||||
@@ -28,6 +28,7 @@ pdfs-store = { path = "crates/pdfs-store" }
|
||||
pdfs-drive = { path = "crates/pdfs-drive" }
|
||||
pdfs-sync = { path = "crates/pdfs-sync" }
|
||||
pdfs-vfs = { path = "crates/pdfs-vfs" }
|
||||
pdfs-sched = { path = "crates/pdfs-sched" }
|
||||
pdfs-fuse = { path = "crates/pdfs-fuse" }
|
||||
pdfs-daemon = { path = "crates/pdfs-daemon" }
|
||||
|
||||
|
||||
@@ -270,6 +270,34 @@ pub(super) fn sync_engine_line(sync: &pdfs_core::control::SyncEngineState) -> St
|
||||
line
|
||||
}
|
||||
|
||||
/// One class of background step in `pdfs diagnostics`: `mirror: 8 running,
|
||||
/// 3 waiting (oldest 2s); 120 admitted, waited 14s in total, 950ms at most`.
|
||||
pub(super) fn admission_line(load: &pdfs_core::control::AdmissionLoad) -> String {
|
||||
let mut line = format!(
|
||||
"{}: {} running, {} waiting",
|
||||
load.class, load.running, load.waiting
|
||||
);
|
||||
if let Some(ms) = load.oldest_wait_ms {
|
||||
line.push_str(&format!(" (oldest {})", wait_ms(ms)));
|
||||
}
|
||||
line.push_str(&format!(
|
||||
"; {} admitted, waited {} in total, {} at most",
|
||||
load.admitted,
|
||||
wait_ms(load.waited_ms),
|
||||
wait_ms(load.longest_wait_ms),
|
||||
));
|
||||
line
|
||||
}
|
||||
|
||||
/// A wait, in ms below a second, where most admission waits fall.
|
||||
fn wait_ms(ms: u64) -> String {
|
||||
if ms < 1000 {
|
||||
format!("{ms}ms")
|
||||
} else {
|
||||
human_secs(ms / 1000)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn cmd_diagnostics() -> Result<()> {
|
||||
let response = control_request(CtlRequest::Diagnostics)?;
|
||||
if emit_json(&response)? {
|
||||
@@ -346,6 +374,12 @@ pub(super) fn cmd_diagnostics() -> Result<()> {
|
||||
);
|
||||
}
|
||||
}
|
||||
if !d.admission.is_empty() {
|
||||
println!("admission of background steps:");
|
||||
for load in &d.admission {
|
||||
println!(" {}", admission_line(load));
|
||||
}
|
||||
}
|
||||
if !d.drive_calls.is_empty() {
|
||||
println!("calls to Drive since start:");
|
||||
for call in &d.drive_calls {
|
||||
@@ -480,3 +514,37 @@ pub(super) fn cmd_cache_inspect(deep: bool) -> Result<()> {
|
||||
other => bail!("unexpected response: {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pdfs_core::control::AdmissionLoad;
|
||||
|
||||
use super::admission_line;
|
||||
|
||||
#[test]
|
||||
fn an_admission_line_says_who_waits_and_for_how_long() {
|
||||
let load = AdmissionLoad {
|
||||
class: "mirror".into(),
|
||||
running: 8,
|
||||
waiting: 3,
|
||||
oldest_wait_ms: Some(2_400),
|
||||
admitted: 120,
|
||||
waited_ms: 14_000,
|
||||
longest_wait_ms: 950,
|
||||
};
|
||||
assert_eq!(
|
||||
admission_line(&load),
|
||||
"mirror: 8 running, 3 waiting (oldest 2s); 120 admitted, waited 14s in total, 950ms at most"
|
||||
);
|
||||
let idle = AdmissionLoad {
|
||||
oldest_wait_ms: None,
|
||||
waiting: 0,
|
||||
running: 0,
|
||||
..load
|
||||
};
|
||||
assert_eq!(
|
||||
admission_line(&idle),
|
||||
"mirror: 0 running, 0 waiting; 120 admitted, waited 14s in total, 950ms at most"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2382,6 +2382,31 @@ pub struct Diagnostics {
|
||||
/// folder pin, oldest first. Empty from a daemon that predates the field.
|
||||
#[serde(default)]
|
||||
pub jobs: Vec<ServiceState>,
|
||||
/// What the admission of background work is doing, per class of step.
|
||||
/// Empty from a daemon that predates the field.
|
||||
#[serde(default)]
|
||||
pub admission: Vec<AdmissionLoad>,
|
||||
}
|
||||
|
||||
/// One class of background step in the daemon's admission, in
|
||||
/// [`Diagnostics::admission`]. Steps waiting here have not reached the
|
||||
/// network yet, so a stall with steps waiting and none running is in the
|
||||
/// daemon, not at Proton.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct AdmissionLoad {
|
||||
/// The class of step, such as `mirror`.
|
||||
pub class: String,
|
||||
/// Steps admitted and still running.
|
||||
pub running: usize,
|
||||
/// Steps waiting to be admitted.
|
||||
pub waiting: usize,
|
||||
/// How long the step that has waited longest has waited so far, in ms.
|
||||
pub oldest_wait_ms: Option<u64>,
|
||||
/// Steps admitted since start.
|
||||
pub admitted: u64,
|
||||
/// The time those steps spent waiting, in total and at most, in ms.
|
||||
pub waited_ms: u64,
|
||||
pub longest_wait_ms: u64,
|
||||
}
|
||||
|
||||
/// One long-lived daemon thread, in [`Diagnostics::services`], or one
|
||||
|
||||
@@ -13,6 +13,7 @@ description = "FUSE on-demand filesystem for Proton Drive"
|
||||
pdfs-core.workspace = true
|
||||
pdfs-drive.workspace = true
|
||||
pdfs-sync.workspace = true
|
||||
pdfs-sched.workspace = true
|
||||
pdfs-vfs.workspace = true
|
||||
pdfs-store.workspace = true
|
||||
zip.workspace = true
|
||||
|
||||
@@ -18,7 +18,9 @@ use std::sync::{Arc, LazyLock};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use pdfs_core::control::{Diagnostics, DriveCallStat, InflightRequest, ServiceState, WorkerState};
|
||||
use pdfs_core::control::{
|
||||
AdmissionLoad, Diagnostics, DriveCallStat, InflightRequest, ServiceState, WorkerState,
|
||||
};
|
||||
|
||||
use pdfs_core::lifecycle::ServiceBoard;
|
||||
|
||||
@@ -198,6 +200,21 @@ impl Core {
|
||||
longest_ms: u64::try_from(stat.longest.as_millis()).unwrap_or(u64::MAX),
|
||||
})
|
||||
.collect(),
|
||||
admission: self
|
||||
.sync
|
||||
.admission
|
||||
.load()
|
||||
.into_iter()
|
||||
.map(|load| AdmissionLoad {
|
||||
class: load.class.name().to_owned(),
|
||||
running: load.running,
|
||||
waiting: load.waiting,
|
||||
oldest_wait_ms: load.oldest_wait.map(millis),
|
||||
admitted: load.admitted,
|
||||
waited_ms: millis(load.waited),
|
||||
longest_wait_ms: millis(load.longest_wait),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +238,10 @@ impl Core {
|
||||
}
|
||||
}
|
||||
|
||||
fn millis(took: Duration) -> u64 {
|
||||
u64::try_from(took.as_millis()).unwrap_or(u64::MAX)
|
||||
}
|
||||
|
||||
/// Run `probe` on a thread of its own and wait up to `deadline` for it.
|
||||
///
|
||||
/// `None` when it did not answer in time, or when the previous probe sharing
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Core {
|
||||
if is_local_uid_str(&op.uid) {
|
||||
match self.withdrawn_twin(op)? {
|
||||
Some(twin) => {
|
||||
self.writes.hide(&twin);
|
||||
self.withdraw_landed(&twin);
|
||||
match self
|
||||
.block_on_bounded(self.drive.trash_nodes(std::slice::from_ref(&twin)))
|
||||
.and_then(batch::into_unit)
|
||||
@@ -61,12 +61,28 @@ 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");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Take a node a withdrawn create made on Drive out of every listing.
|
||||
///
|
||||
/// Hiding keeps it out of listings from now on, not out of one taken while
|
||||
/// Drive listed it and the drain still waited for the answer. A file made
|
||||
/// under the name then opened the node being trashed, and every write to
|
||||
/// it was refused with EACCES (`docs/BUGS.md` B303).
|
||||
fn withdraw_landed(&self, uid: &NodeUid) {
|
||||
self.writes.hide(uid);
|
||||
self.for_each_mount(|st, notify| {
|
||||
if let Some((parent, name)) = st.forget_or_unlink(uid) {
|
||||
notify.inval_entry(parent, name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Remove a trash op that landed, and the blob of a create it withdrew.
|
||||
pub(crate) fn retire_trash_op(
|
||||
&self,
|
||||
@@ -191,7 +207,7 @@ impl Core {
|
||||
real: &NodeUid,
|
||||
name: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
self.writes.hide(real);
|
||||
self.withdraw_landed(real);
|
||||
self.note_self_change(real);
|
||||
let trash = PendingOp {
|
||||
id: trash,
|
||||
|
||||
@@ -932,6 +932,9 @@ struct Core {
|
||||
/// Set while a diagnostics report's database probe is still out, so a
|
||||
/// database that does not answer costs one stuck thread, not one per report.
|
||||
pending_probe: Arc<AtomicBool>,
|
||||
/// Cold listings in flight, by folder, so callers that find the same
|
||||
/// folder unlisted at once share one listing ([`Core::list_children`]).
|
||||
listing_flights: Arc<pdfs_sched::flights::Flights<NodeUid>>,
|
||||
/// Secondary FUSE sessions for `ondemand` sync folders, keyed by sync-folder
|
||||
/// id. Each is a `ProtonFs` rooted at the folder's remote
|
||||
/// node, mounted over its local path, sharing this Core's client/cache/db and
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
/// How many folders the mount lists on Drive at once, in the daemon's
|
||||
/// admission ([`pdfs_sched::Class::Listing`]).
|
||||
///
|
||||
/// Above what the mount's workers ([`workers::FUSE_WORKERS`]) and a burst
|
||||
/// of commands list at once, so for now the admission counts cold listings
|
||||
/// in `pdfs diagnostics` and rarely makes one wait. A lookup must not queue
|
||||
/// behind a pin walking a large tree; a lower limit waits for a policy that
|
||||
/// tells the two apart.
|
||||
pub(crate) const COLD_LISTINGS: usize = 32;
|
||||
|
||||
impl Core {
|
||||
/// Whether [`Core::ensure_children`] would answer for `ino` without
|
||||
/// touching the network. Lets a handler decide between answering inline
|
||||
@@ -265,6 +275,22 @@ impl Core {
|
||||
if !self.is_online() {
|
||||
return self.adopt_stale_listing(ino, &folder_uid, cached, primary_root);
|
||||
}
|
||||
// Single flight: callers that find the folder unlisted at the same
|
||||
// time share one listing. Each used to ask Drive itself, and all but
|
||||
// the first threw the answer away. A follower waits for the leader and
|
||||
// takes what it published; when the leader failed, the follower lists
|
||||
// the folder itself, so each caller still gets its own answer. A
|
||||
// shared folder's refresh is left out: its generation check answers a
|
||||
// caller EAGAIN on its own.
|
||||
let _lead = if foreign {
|
||||
None
|
||||
} else {
|
||||
match self.listing_flights.join(&folder_uid) {
|
||||
Some(lead) => Some(lead),
|
||||
None if self.state().children.contains_key(&ino) => return Ok(()),
|
||||
None => None,
|
||||
}
|
||||
};
|
||||
|
||||
let refresh_generation =
|
||||
refresh_foreign.then(|| self.shared.shared_generation.load(Ordering::SeqCst));
|
||||
@@ -274,6 +300,15 @@ impl Core {
|
||||
let queued_before = (!foreign)
|
||||
.then(|| self.db.queued_children(&folder_uid).ok())
|
||||
.flatten();
|
||||
// Asking Drive waits for the daemon's admission of cold listings,
|
||||
// which counts it in `pdfs diagnostics`. The permit covers the two
|
||||
// calls to Drive and goes before the listing is published.
|
||||
let admitted = self
|
||||
.rt
|
||||
.block_on(self.sync.admission.admit(pdfs_sched::Step {
|
||||
class: pdfs_sched::Class::Listing,
|
||||
root: 0,
|
||||
}));
|
||||
let uids = match self
|
||||
.rt
|
||||
.block_on(self.drive.enumerate_folder_children_node_uids(&folder_uid))
|
||||
@@ -306,6 +341,7 @@ impl Core {
|
||||
return Err(Errno::EIO);
|
||||
}
|
||||
};
|
||||
drop(admitted);
|
||||
// Drive shows none of what is still queued for the folder (B132).
|
||||
// A shared folder's listing is published as Drive has it.
|
||||
if !foreign {
|
||||
|
||||
@@ -520,6 +520,10 @@ pub(crate) fn mount_with(
|
||||
unscanned: Arc::default(),
|
||||
abandon: Arc::default(),
|
||||
events_read_at: Arc::new(AtomicI64::new(0)),
|
||||
admission: Arc::new(pdfs_sched::Classes::new(|class| match class {
|
||||
pdfs_sched::Class::Mirror => sync::SYNC_CONCURRENCY,
|
||||
pdfs_sched::Class::Listing => super::listing::COLD_LISTINGS,
|
||||
})),
|
||||
};
|
||||
let state = Arc::new(Ranked::new(
|
||||
Rank::State,
|
||||
@@ -571,6 +575,7 @@ pub(crate) fn mount_with(
|
||||
events,
|
||||
indexing: Arc::new(AtomicBool::new(false)),
|
||||
pending_probe: Arc::default(),
|
||||
listing_flights: Arc::default(),
|
||||
mounts: Arc::new(Mutex::new(SecondaryMountRegistry::default())),
|
||||
states: Arc::new(StateRegistry::default()),
|
||||
};
|
||||
|
||||
@@ -539,6 +539,81 @@ mod tests {
|
||||
assert!(uploads.count >= 1);
|
||||
}
|
||||
|
||||
/// How often the daemon has asked Drive for the children of a folder.
|
||||
fn children_listed(daemon: &Daemon) -> u64 {
|
||||
let Ok(Response::Diagnostics { diagnostics }) = daemon.request(&Request::Diagnostics)
|
||||
else {
|
||||
panic!("no diagnostics");
|
||||
};
|
||||
diagnostics
|
||||
.drive_calls
|
||||
.iter()
|
||||
.find(|stat| stat.call == "enumerate_folder_children_node_uids")
|
||||
.map_or(0, |stat| stat.count)
|
||||
}
|
||||
|
||||
fn listing_load(daemon: &Daemon) -> control::AdmissionLoad {
|
||||
let Ok(Response::Diagnostics { diagnostics }) = daemon.request(&Request::Diagnostics)
|
||||
else {
|
||||
panic!("no diagnostics");
|
||||
};
|
||||
diagnostics
|
||||
.admission
|
||||
.into_iter()
|
||||
.find(|load| load.class == "listing")
|
||||
.expect("the admission reports cold listings")
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn callers_that_find_a_folder_unlisted_at_once_share_one_listing() {
|
||||
// Each caller used to ask Drive for the folder itself, and all but
|
||||
// the first threw the answer away. Now the first lists it, through
|
||||
// the daemon's admission, and the others wait for that listing.
|
||||
let drive = FakeDrive::new();
|
||||
let cold = drive.device().mkdir("cold");
|
||||
for name in ["a.txt", "b.txt", "c.txt"] {
|
||||
drive
|
||||
.device()
|
||||
.write(&format!("cold/{name}"), name.as_bytes());
|
||||
}
|
||||
let dir = scratch("cold-listing-flight");
|
||||
let daemon = Daemon::start(&dir, drive.client(1, Faults::lan())).unwrap();
|
||||
let listed = |daemon: &Daemon| match daemon.request(&Request::ListDir {
|
||||
path: "cold".into(),
|
||||
}) {
|
||||
Ok(Response::Entries { entries }) => {
|
||||
let mut names: Vec<String> = entries.into_iter().map(|e| e.name).collect();
|
||||
names.sort();
|
||||
names
|
||||
}
|
||||
other => panic!("listing cold: {other:?}"),
|
||||
};
|
||||
// The mount root is listed first, so the only listing held is cold's.
|
||||
let _ = std::fs::read_dir(&daemon.mountpoint).unwrap().count();
|
||||
|
||||
let before = children_listed(&daemon);
|
||||
let held = daemon.client.hold_next_children_of(&cold);
|
||||
std::thread::scope(|scope| {
|
||||
let callers: Vec<_> = (0..4).map(|_| scope.spawn(|| listed(&daemon))).collect();
|
||||
assert!(wait_until(Duration::from_secs(10), || held.reached()));
|
||||
// Give the others time to find the folder unlisted too.
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
let load = listing_load(&daemon);
|
||||
assert_eq!((load.running, load.waiting), (1, 0), "{load:?}");
|
||||
drop(held);
|
||||
for caller in callers {
|
||||
assert_eq!(caller.join().unwrap(), ["a.txt", "b.txt", "c.txt"]);
|
||||
}
|
||||
});
|
||||
assert_eq!(children_listed(&daemon) - before, 1);
|
||||
let load = listing_load(&daemon);
|
||||
assert_eq!(load.running, 0, "{load:?}");
|
||||
assert!(load.admitted >= 1, "{load:?}");
|
||||
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 a_daemon_on_the_fake_drive_syncs_both_ways() {
|
||||
@@ -1904,6 +1979,9 @@ mod tests {
|
||||
let first = traced_pass(&daemon, folder, |t| calls(t, "upload") > 0)
|
||||
.expect("the first pass is traced");
|
||||
assert_eq!(calls(&first, "upload"), 3);
|
||||
// Each upload waited for the daemon's admission first, and the time
|
||||
// in line is its own entry, apart from the time on the network.
|
||||
assert_eq!(calls(&first, "admission wait"), 3, "{first}");
|
||||
assert_eq!(counted(&first, "local entries"), 3);
|
||||
assert!(counted(&first, "remote folders") >= 1);
|
||||
for phase in ["baseline", "local walk", "remote walk", "apply"] {
|
||||
@@ -1917,6 +1995,17 @@ mod tests {
|
||||
.iter()
|
||||
.any(|line| line.contains("sync: pass trace"))
|
||||
);
|
||||
let Ok(Response::Diagnostics { diagnostics }) = daemon.request(&Request::Diagnostics)
|
||||
else {
|
||||
panic!("no diagnostics");
|
||||
};
|
||||
let mirror = diagnostics
|
||||
.admission
|
||||
.iter()
|
||||
.find(|load| load.class == "mirror")
|
||||
.expect("the admission reports mirror steps");
|
||||
assert!(mirror.admitted >= 3, "{mirror:?}");
|
||||
assert_eq!((mirror.running, mirror.waiting), (0, 0), "{mirror:?}");
|
||||
|
||||
// Drive does not list a node it has just made at once, so the read
|
||||
// back after an upload has no revision id to record. The next pass
|
||||
@@ -2875,6 +2964,67 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn a_listing_taken_while_a_withdrawn_create_lands_does_not_keep_it() {
|
||||
// A file deleted while its create was on the wire. Drive made the node
|
||||
// and listed it before the drain had its answer, and a refresh then put
|
||||
// it in the tree. The drain hid it and trashed it, but the entry stayed:
|
||||
// a new file made under the name opened the trashed node, and every
|
||||
// write and rename of it was refused with EACCES (B303).
|
||||
let drive = FakeDrive::new();
|
||||
let dir = scratch("withdrawn-create-listed");
|
||||
let daemon = Daemon::start(&dir, drive.client(1, Faults::lan())).unwrap();
|
||||
let mnt = daemon.mountpoint.clone();
|
||||
let file = |bytes: &[u8]| Some(Entry::File(Arc::new(bytes.to_vec())));
|
||||
|
||||
let held = daemon.client.hold_reply_to_next_create();
|
||||
daemon.write_new(&mnt.join("d"), b"first").unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || held.reached()));
|
||||
std::fs::remove_file(mnt.join("d")).unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || {
|
||||
drive.tree().get("d").cloned() == file(b"first")
|
||||
}));
|
||||
// Past the listing lag, so the refresh finds the node Drive made.
|
||||
std::thread::sleep(Duration::from_millis(300));
|
||||
let refresh = Request::Refresh {
|
||||
scope: RefreshScope::Dir {
|
||||
path: mnt.to_string_lossy().into_owned(),
|
||||
},
|
||||
};
|
||||
assert!(matches!(daemon.request(&refresh), Ok(Response::Ok { .. })));
|
||||
let _ = std::fs::read_dir(&mnt).unwrap().count();
|
||||
drop(held);
|
||||
assert!(
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& !drive.tree().contains_key("d")
|
||||
}),
|
||||
"{:?} {:?}",
|
||||
daemon.pending(),
|
||||
drive.tree()
|
||||
);
|
||||
assert!(
|
||||
!mnt.join("d").exists(),
|
||||
"the trashed create is still listed"
|
||||
);
|
||||
|
||||
std::fs::write(mnt.join("d"), b"second").unwrap();
|
||||
std::fs::rename(mnt.join("d"), mnt.join("c.bin")).unwrap();
|
||||
assert!(
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& drive.tree().get("c.bin").cloned() == file(b"second")
|
||||
}),
|
||||
"{:?} {:?}",
|
||||
daemon.pending(),
|
||||
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 a_file_made_under_the_name_of_a_create_on_the_wire_waits_for_it() {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "pdfs-sched"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
rust-version.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
description = "Admission of background work for the Proton Drive Linux client"
|
||||
|
||||
[dependencies]
|
||||
tokio.workspace = true
|
||||
parking_lot.workspace = true
|
||||
@@ -0,0 +1,154 @@
|
||||
//! Single flight: one caller does a piece of work, the others asking for the
|
||||
//! same thing at the same time wait for it.
|
||||
//!
|
||||
//! The first caller for a key leads and gets a [`Lead`]; it does the work and
|
||||
//! drops the lead when done, whether it succeeded, failed or panicked. A
|
||||
//! caller that finds a lead out for its key follows: [`Flights::join`] blocks
|
||||
//! until that lead is dropped and returns `None`. The follower then looks
|
||||
//! again at what the leader left behind; when the leader failed it does the
|
||||
//! work itself, so every caller still gets an answer of its own.
|
||||
//!
|
||||
//! The wait is a blocking one, for the threads that serve the mount. A
|
||||
//! follower must hold nothing its leader needs.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::hash::Hash;
|
||||
use std::sync::Arc;
|
||||
|
||||
use parking_lot::{Condvar, Mutex};
|
||||
|
||||
/// The work in flight, by key.
|
||||
pub struct Flights<K: Eq + Hash + Clone> {
|
||||
out: Mutex<HashMap<K, Arc<Flight>>>,
|
||||
}
|
||||
|
||||
/// One piece of work in flight, which its followers wait on.
|
||||
#[derive(Default)]
|
||||
struct Flight {
|
||||
landed: Mutex<bool>,
|
||||
wake: Condvar,
|
||||
}
|
||||
|
||||
/// The right and the duty to do the work for one key. Dropping it lets the
|
||||
/// followers go.
|
||||
pub struct Lead<'a, K: Eq + Hash + Clone> {
|
||||
flights: &'a Flights<K>,
|
||||
key: K,
|
||||
flight: Arc<Flight>,
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash + Clone> Default for Flights<K> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
out: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash + Clone> Flights<K> {
|
||||
/// Lead the work for `key`, or, when another caller leads it already,
|
||||
/// wait until that caller is done and return `None`.
|
||||
pub fn join(&self, key: &K) -> Option<Lead<'_, K>> {
|
||||
let flight = {
|
||||
let mut out = self.out.lock();
|
||||
match out.get(key) {
|
||||
Some(flight) => flight.clone(),
|
||||
None => {
|
||||
let flight = Arc::new(Flight::default());
|
||||
out.insert(key.clone(), flight.clone());
|
||||
return Some(Lead {
|
||||
flights: self,
|
||||
key: key.clone(),
|
||||
flight,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
let mut landed = flight.landed.lock();
|
||||
while !*landed {
|
||||
flight.wake.wait(&mut landed);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// How many keys have work in flight.
|
||||
pub fn len(&self) -> usize {
|
||||
self.out.lock().len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash + Clone> Drop for Lead<'_, K> {
|
||||
fn drop(&mut self) {
|
||||
// Out of the map first, so a caller that comes after the followers
|
||||
// wake leads anew rather than following a flight that has landed.
|
||||
self.flights.out.lock().remove(&self.key);
|
||||
*self.flight.landed.lock() = true;
|
||||
self.flight.wake.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn callers_that_ask_at_once_share_one_flight() {
|
||||
let flights = Arc::new(Flights::<u32>::default());
|
||||
let worked = Arc::new(AtomicUsize::new(0));
|
||||
let lead = flights.join(&7).expect("the first caller leads");
|
||||
let followers: Vec<_> = (0..4)
|
||||
.map(|_| {
|
||||
let (flights, worked) = (flights.clone(), worked.clone());
|
||||
thread::spawn(move || {
|
||||
if flights.join(&7).is_some() {
|
||||
worked.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
thread::sleep(Duration::from_millis(30));
|
||||
assert!(followers.iter().all(|f| !f.is_finished()));
|
||||
drop(lead);
|
||||
for follower in followers {
|
||||
follower.join().unwrap();
|
||||
}
|
||||
assert_eq!(worked.load(Ordering::SeqCst), 0);
|
||||
assert!(flights.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_keys_do_not_wait_for_each_other() {
|
||||
let flights = Flights::<u32>::default();
|
||||
let _a = flights.join(&1).expect("leads 1");
|
||||
let _b = flights.join(&2).expect("leads 2");
|
||||
assert_eq!(flights.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_leader_that_panics_still_lets_its_followers_go() {
|
||||
let flights = Arc::new(Flights::<u32>::default());
|
||||
let (led, lead_now) = std::sync::mpsc::channel();
|
||||
let leader = {
|
||||
let flights = flights.clone();
|
||||
thread::spawn(move || {
|
||||
let _lead = flights.join(&3).expect("leads");
|
||||
led.send(()).unwrap();
|
||||
thread::sleep(Duration::from_millis(20));
|
||||
panic!("the work failed");
|
||||
})
|
||||
};
|
||||
lead_now.recv().unwrap();
|
||||
assert!(flights.join(&3).is_none());
|
||||
assert!(leader.join().is_err());
|
||||
// The next caller leads again.
|
||||
assert!(flights.join(&3).is_some());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
//! Admission: when a runnable step of background work may start.
|
||||
//!
|
||||
//! Step 6 of the 4.0 plan in `docs/ARCHITECTURE.md` gives the daemon one
|
||||
//! account-wide admission policy for mirrors, reads and writeback
|
||||
//! (`SCHEDULER_AND_WORKERS.md`). This crate is its port. A service describes
|
||||
//! each step it is about to run as a [`Step`] and waits for a [`Permit`]
|
||||
//! from an [`Admission`]; dropping the permit gives the capacity back.
|
||||
//!
|
||||
//! The sync engine is the first caller: every upload, download and folder
|
||||
//! creation of a mirror pass is admitted here. [`Bounded`] is the policy the
|
||||
//! daemon supplies for now, a fixed number of steps at once, which is what the
|
||||
//! engine did on its own before. An account-wide controller that weighs
|
||||
//! mirrors against mounted reads and the drain plugs in behind the same trait
|
||||
//! later, without the engine changing.
|
||||
//!
|
||||
//! [`flights`] holds the single flight that lets callers asking for the same
|
||||
//! thing at once share one piece of work.
|
||||
//!
|
||||
//! An admission decides only; it runs no step and does no I/O. It does say
|
||||
//! what it is doing: [`Admission::load`] reports, per class, how many steps
|
||||
//! run, how many wait and for how long, so a stall report can tell a step
|
||||
//! waiting in line from one already on the network.
|
||||
|
||||
pub mod flights;
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
/// The kind of work a step is, which a policy weighs against the others.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Class {
|
||||
/// One effect of a mirror pass: an upload, a download, or a folder made
|
||||
/// on Drive.
|
||||
Mirror,
|
||||
/// Listing a folder on Drive that the mount has not listed yet, for a
|
||||
/// lookup, a `readdir` or a command that resolves a path.
|
||||
Listing,
|
||||
}
|
||||
|
||||
impl Class {
|
||||
/// Every class, in the order a report lists them.
|
||||
pub const ALL: [Class; 2] = [Class::Mirror, Class::Listing];
|
||||
|
||||
/// The class's name in diagnostics.
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
Class::Mirror => "mirror",
|
||||
Class::Listing => "listing",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A step that is ready to run and asks to be admitted.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Step {
|
||||
pub class: Class,
|
||||
/// The root the step works for, such as the id of a synced folder, so a
|
||||
/// policy can be fair across roots. `0` for work of the mount itself.
|
||||
pub root: i64,
|
||||
}
|
||||
|
||||
/// The capacity a step was admitted with. Dropping it gives the capacity
|
||||
/// back.
|
||||
pub struct Permit {
|
||||
_held: Box<dyn Send + Sync>,
|
||||
}
|
||||
|
||||
impl Permit {
|
||||
/// A permit that holds `capacity` until it is dropped.
|
||||
pub fn new(capacity: impl Send + Sync + 'static) -> Self {
|
||||
Self {
|
||||
_held: Box::new(capacity),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The future an admission answers with: it resolves once the step may run.
|
||||
pub type Admitting<'a> = Pin<Box<dyn Future<Output = Permit> + Send + 'a>>;
|
||||
|
||||
/// What an admission is doing for one class of step, in [`Admission::load`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Load {
|
||||
pub class: Class,
|
||||
/// Steps admitted and still holding their permit.
|
||||
pub running: usize,
|
||||
/// Steps that asked and have not been admitted yet.
|
||||
pub waiting: usize,
|
||||
/// How long the step that has waited longest has waited so far.
|
||||
pub oldest_wait: Option<Duration>,
|
||||
/// Steps admitted since the policy was made.
|
||||
pub admitted: u64,
|
||||
/// The time those steps spent waiting, in total and at most.
|
||||
pub waited: Duration,
|
||||
pub longest_wait: Duration,
|
||||
}
|
||||
|
||||
/// A policy that decides when a step may start.
|
||||
pub trait Admission: Send + Sync {
|
||||
/// Wait until `step` may run, and return the capacity it runs with.
|
||||
fn admit(&self, step: Step) -> Admitting<'_>;
|
||||
|
||||
/// What the policy is doing now, one entry per class it has seen. It must
|
||||
/// answer without waiting on a step, so a stall report can ask it while
|
||||
/// every step is stuck.
|
||||
fn load(&self) -> Vec<Load> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// The counters behind [`Load`], for one class.
|
||||
#[derive(Default)]
|
||||
struct Counters {
|
||||
running: usize,
|
||||
/// When each waiting step asked, by ticket.
|
||||
waiting: Vec<(u64, Instant)>,
|
||||
admitted: u64,
|
||||
waited: Duration,
|
||||
longest_wait: Duration,
|
||||
}
|
||||
|
||||
/// The counters of every class, shared by a policy and the permits and
|
||||
/// pending admissions it handed out. Each lock is held for a few field
|
||||
/// updates and never across an await.
|
||||
#[derive(Default)]
|
||||
struct Meter {
|
||||
classes: Mutex<[Counters; Class::ALL.len()]>,
|
||||
next_ticket: std::sync::atomic::AtomicU64,
|
||||
}
|
||||
|
||||
impl Meter {
|
||||
fn ask(self: &Arc<Self>, class: Class) -> Asking {
|
||||
let ticket = self
|
||||
.next_ticket
|
||||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let asked = Instant::now();
|
||||
self.classes.lock()[class as usize]
|
||||
.waiting
|
||||
.push((ticket, asked));
|
||||
Asking {
|
||||
meter: self.clone(),
|
||||
class,
|
||||
ticket,
|
||||
asked,
|
||||
admitted: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn load(&self) -> Vec<Load> {
|
||||
let now = Instant::now();
|
||||
let classes = self.classes.lock();
|
||||
Class::ALL
|
||||
.iter()
|
||||
.map(|class| {
|
||||
let c = &classes[*class as usize];
|
||||
Load {
|
||||
class: *class,
|
||||
running: c.running,
|
||||
waiting: c.waiting.len(),
|
||||
oldest_wait: c
|
||||
.waiting
|
||||
.iter()
|
||||
.map(|(_, asked)| now.saturating_duration_since(*asked))
|
||||
.max(),
|
||||
admitted: c.admitted,
|
||||
waited: c.waited,
|
||||
longest_wait: c.longest_wait,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// A step that has asked and not been admitted yet. Dropped unadmitted, as
|
||||
/// when the caller gives up waiting, it leaves the queue without counting.
|
||||
struct Asking {
|
||||
meter: Arc<Meter>,
|
||||
class: Class,
|
||||
ticket: u64,
|
||||
asked: Instant,
|
||||
admitted: bool,
|
||||
}
|
||||
|
||||
impl Asking {
|
||||
/// The step was admitted: it stops waiting and starts running.
|
||||
fn admitted(mut self) -> Running {
|
||||
let waited = self.asked.elapsed();
|
||||
{
|
||||
let mut classes = self.meter.classes.lock();
|
||||
let c = &mut classes[self.class as usize];
|
||||
c.waiting.retain(|(t, _)| *t != self.ticket);
|
||||
c.running += 1;
|
||||
c.admitted += 1;
|
||||
c.waited += waited;
|
||||
c.longest_wait = c.longest_wait.max(waited);
|
||||
}
|
||||
self.admitted = true;
|
||||
Running {
|
||||
meter: self.meter.clone(),
|
||||
class: self.class,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Asking {
|
||||
fn drop(&mut self) {
|
||||
if !self.admitted {
|
||||
self.meter.classes.lock()[self.class as usize]
|
||||
.waiting
|
||||
.retain(|(t, _)| *t != self.ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A step that runs; dropping it counts the step as done.
|
||||
struct Running {
|
||||
meter: Arc<Meter>,
|
||||
class: Class,
|
||||
}
|
||||
|
||||
impl Drop for Running {
|
||||
fn drop(&mut self) {
|
||||
let mut classes = self.meter.classes.lock();
|
||||
let c = &mut classes[self.class as usize];
|
||||
c.running = c.running.saturating_sub(1);
|
||||
}
|
||||
}
|
||||
|
||||
/// At most a fixed number of steps at once, whatever their class or root,
|
||||
/// admitted in the order they asked.
|
||||
pub struct Bounded {
|
||||
slots: Arc<Semaphore>,
|
||||
meter: Arc<Meter>,
|
||||
}
|
||||
|
||||
impl Bounded {
|
||||
/// A policy that runs at most `limit` steps at once. `limit` must be at
|
||||
/// least 1.
|
||||
pub fn new(limit: usize) -> Self {
|
||||
assert!(limit > 0, "an admission that admits nothing never finishes");
|
||||
Self {
|
||||
slots: Arc::new(Semaphore::new(limit)),
|
||||
meter: Arc::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// How many more steps could start now.
|
||||
pub fn available(&self) -> usize {
|
||||
self.slots.available_permits()
|
||||
}
|
||||
}
|
||||
|
||||
impl Admission for Bounded {
|
||||
fn admit(&self, step: Step) -> Admitting<'_> {
|
||||
let slots = self.slots.clone();
|
||||
let asking = self.meter.ask(step.class);
|
||||
Box::pin(async move {
|
||||
// The semaphore is never closed, so the acquire cannot fail.
|
||||
let slot = slots.acquire_owned().await.expect("semaphore never closed");
|
||||
// A tuple drops its fields in order: the step stops counting as
|
||||
// running before its slot goes back, so
|
||||
// a report never shows more running than the limit.
|
||||
Permit::new((asking.admitted(), slot))
|
||||
})
|
||||
}
|
||||
|
||||
fn load(&self) -> Vec<Load> {
|
||||
self.meter.load()
|
||||
}
|
||||
}
|
||||
|
||||
/// A limit of its own for each class: steps of one class never wait for
|
||||
/// steps of another. Within a class, steps are admitted in the order they
|
||||
/// asked.
|
||||
pub struct Classes {
|
||||
slots: [Arc<Semaphore>; Class::ALL.len()],
|
||||
meter: Arc<Meter>,
|
||||
}
|
||||
|
||||
impl Classes {
|
||||
/// A policy with the limit `limit(class)` for each class. Every limit must
|
||||
/// be at least 1.
|
||||
pub fn new(limit: impl Fn(Class) -> usize) -> Self {
|
||||
Self {
|
||||
slots: Class::ALL.map(|class| {
|
||||
let n = limit(class);
|
||||
assert!(n > 0, "an admission that admits nothing never finishes");
|
||||
Arc::new(Semaphore::new(n))
|
||||
}),
|
||||
meter: Arc::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// How many more steps of `class` could start now.
|
||||
pub fn available(&self, class: Class) -> usize {
|
||||
self.slots[class as usize].available_permits()
|
||||
}
|
||||
}
|
||||
|
||||
impl Admission for Classes {
|
||||
fn admit(&self, step: Step) -> Admitting<'_> {
|
||||
let slots = self.slots[step.class as usize].clone();
|
||||
let asking = self.meter.ask(step.class);
|
||||
Box::pin(async move {
|
||||
// The semaphore is never closed, so the acquire cannot fail.
|
||||
let slot = slots.acquire_owned().await.expect("semaphore never closed");
|
||||
Permit::new((asking.admitted(), slot))
|
||||
})
|
||||
}
|
||||
|
||||
fn load(&self) -> Vec<Load> {
|
||||
self.meter.load()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn step(root: i64) -> Step {
|
||||
Step {
|
||||
class: Class::Mirror,
|
||||
root,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_bounded_admission_never_runs_more_than_its_limit() {
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(4)
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
let admission = Arc::new(Bounded::new(3));
|
||||
let running = Arc::new(AtomicUsize::new(0));
|
||||
let peak = Arc::new(AtomicUsize::new(0));
|
||||
rt.block_on(async {
|
||||
let mut set = tokio::task::JoinSet::new();
|
||||
for root in 0..20 {
|
||||
let (admission, running, peak) = (admission.clone(), running.clone(), peak.clone());
|
||||
set.spawn(async move {
|
||||
let _permit = admission.admit(step(root)).await;
|
||||
let now = running.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
peak.fetch_max(now, Ordering::SeqCst);
|
||||
tokio::time::sleep(Duration::from_millis(5)).await;
|
||||
running.fetch_sub(1, Ordering::SeqCst);
|
||||
});
|
||||
}
|
||||
while set.join_next().await.is_some() {}
|
||||
});
|
||||
assert_eq!(peak.load(Ordering::SeqCst), 3);
|
||||
assert_eq!(admission.available(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dropping_a_permit_gives_its_capacity_back() {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.build()
|
||||
.unwrap();
|
||||
let admission = Bounded::new(1);
|
||||
rt.block_on(async {
|
||||
let first = admission.admit(step(1)).await;
|
||||
assert_eq!(admission.available(), 0);
|
||||
drop(first);
|
||||
assert_eq!(admission.available(), 1);
|
||||
let _second = admission.admit(step(2)).await;
|
||||
assert_eq!(admission.available(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_load_counts_running_and_waiting_steps() {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
let admission = Bounded::new(1);
|
||||
rt.block_on(async {
|
||||
let first = admission.admit(step(1)).await;
|
||||
let mut second = admission.admit(step(2));
|
||||
// Polled once, the second step is in line behind the first.
|
||||
assert!(
|
||||
tokio::time::timeout(Duration::from_millis(20), &mut second)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let load = &admission.load()[0];
|
||||
assert_eq!((load.running, load.waiting, load.admitted), (1, 1, 1));
|
||||
assert!(load.oldest_wait.unwrap() >= Duration::from_millis(20));
|
||||
|
||||
drop(first);
|
||||
let second = second.await;
|
||||
let load = &admission.load()[0];
|
||||
assert_eq!((load.running, load.waiting, load.admitted), (1, 0, 2));
|
||||
assert_eq!(load.oldest_wait, None);
|
||||
assert!(load.longest_wait >= Duration::from_millis(20));
|
||||
assert!(load.waited >= load.longest_wait);
|
||||
|
||||
drop(second);
|
||||
assert_eq!(admission.load()[0].running, 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_step_that_stops_waiting_leaves_the_line() {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
let admission = Bounded::new(1);
|
||||
rt.block_on(async {
|
||||
let _first = admission.admit(step(1)).await;
|
||||
let gave_up =
|
||||
tokio::time::timeout(Duration::from_millis(5), admission.admit(step(2))).await;
|
||||
assert!(gave_up.is_err());
|
||||
let load = &admission.load()[0];
|
||||
assert_eq!((load.running, load.waiting, load.admitted), (1, 0, 1));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_class_at_its_limit_does_not_hold_up_another() {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
let admission = Classes::new(|class| match class {
|
||||
Class::Mirror => 1,
|
||||
Class::Listing => 2,
|
||||
});
|
||||
rt.block_on(async {
|
||||
let _mirror = admission.admit(step(1)).await;
|
||||
let blocked = tokio::time::timeout(Duration::from_millis(5), admission.admit(step(1)));
|
||||
assert!(blocked.await.is_err());
|
||||
let listing = Step {
|
||||
class: Class::Listing,
|
||||
root: 0,
|
||||
};
|
||||
let _a = admission.admit(listing).await;
|
||||
let _b = admission.admit(listing).await;
|
||||
assert_eq!(admission.available(Class::Listing), 0);
|
||||
let load = admission.load();
|
||||
assert_eq!(load[Class::Mirror as usize].running, 1);
|
||||
assert_eq!(load[Class::Listing as usize].running, 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "admits nothing")]
|
||||
fn a_class_limit_of_nothing_is_refused() {
|
||||
let _ = Classes::new(|class| usize::from(class == Class::Mirror));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "admits nothing")]
|
||||
fn a_bounded_admission_of_nothing_is_refused() {
|
||||
let _ = Bounded::new(0);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ homepage.workspace = true
|
||||
description = "The mirror engine's planner and pass model for the Proton Drive Linux client"
|
||||
|
||||
[dependencies]
|
||||
pdfs-sched.workspace = true
|
||||
pdfs-core.workspace = true
|
||||
pdfs-drive.workspace = true
|
||||
pdfs-store.workspace = true
|
||||
|
||||
@@ -41,8 +41,8 @@ impl Syncer {
|
||||
.map_err(|e| format!("baseline dir {rel}: {e:?}"))
|
||||
}
|
||||
|
||||
/// Run a batch of queued [`Pending`] ops concurrently (bounded by
|
||||
/// [`SYNC_CONCURRENCY`]) and fold their results back into the reconcile's
|
||||
/// Run a batch of queued [`Pending`] ops concurrently, each once the
|
||||
/// engine's admission lets it start, and fold their results back into the reconcile's
|
||||
/// shared state on the engine thread: created folders are registered in
|
||||
/// `remote_dirs` (so deeper paths resolve their parent), and what each op did
|
||||
/// is tallied into `outcome`. Driven by `block_on` from the (non-runtime) sync
|
||||
@@ -67,14 +67,20 @@ impl Syncer {
|
||||
let core = self.clone();
|
||||
let root = local_root.to_path_buf();
|
||||
let results = self.rt.block_on(async move {
|
||||
let sem = Arc::new(tokio::sync::Semaphore::new(SYNC_CONCURRENCY));
|
||||
let mut set = tokio::task::JoinSet::new();
|
||||
for op in batch {
|
||||
let core = core.clone();
|
||||
let sem = sem.clone();
|
||||
let root = root.clone();
|
||||
set.spawn(async move {
|
||||
let _permit = sem.acquire_owned().await.expect("semaphore not closed");
|
||||
let asked = Instant::now();
|
||||
let _permit = core
|
||||
.admission
|
||||
.admit(pdfs_sched::Step {
|
||||
class: pdfs_sched::Class::Mirror,
|
||||
root: folder_id,
|
||||
})
|
||||
.await;
|
||||
core.trace_call(Call::Admission, asked.elapsed());
|
||||
// An op still waiting for its turn when the stop comes is
|
||||
// not started; the ones already sending finish.
|
||||
if core.shutdown.is_stopping() {
|
||||
|
||||
@@ -30,7 +30,7 @@ const POLL_INTERVAL: Duration = Duration::from_secs(120);
|
||||
/// How many uploads/downloads/folder-creations a reconcile runs at once. The
|
||||
/// per-item work is a network round-trip, so a folder with thousands of files is
|
||||
/// unusable done one-at-a-time; this bounds concurrency like the bulk-upload
|
||||
/// engine does.
|
||||
/// engine does. The daemon's admission (`SyncParts::admission`) enforces it.
|
||||
pub const SYNC_CONCURRENCY: usize = 8;
|
||||
/// How long after a failed watch the engine tries the watches again. Each try
|
||||
/// walks the folder's whole tree, so not on every burst.
|
||||
|
||||
@@ -86,6 +86,9 @@ pub struct SyncParts {
|
||||
/// first read. A pass trusts the feed's dirty folders only while it is
|
||||
/// being read.
|
||||
pub events_read_at: Arc<AtomicI64>,
|
||||
/// When each step of a pass may start: its uploads, downloads and folder
|
||||
/// creations.
|
||||
pub admission: Arc<dyn pdfs_sched::Admission>,
|
||||
}
|
||||
|
||||
impl SyncParts {
|
||||
|
||||
@@ -58,6 +58,10 @@ impl Phase {
|
||||
/// A kind of call to Drive, or of work applied for one path.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Call {
|
||||
/// Waiting for the daemon's admission before an upload, download or
|
||||
/// folder creation could start. Time here is time in line, not on the
|
||||
/// network.
|
||||
Admission,
|
||||
/// The child uids of one folder.
|
||||
ListChildren,
|
||||
/// Names and kinds of one folder's children, without unlocking file keys.
|
||||
@@ -76,7 +80,8 @@ pub enum Call {
|
||||
}
|
||||
|
||||
impl Call {
|
||||
const ALL: [Call; 10] = [
|
||||
const ALL: [Call; 11] = [
|
||||
Call::Admission,
|
||||
Call::ListChildren,
|
||||
Call::ReadNodes,
|
||||
Call::ReadNodesFull,
|
||||
@@ -91,6 +96,7 @@ impl Call {
|
||||
|
||||
fn name(self) -> &'static str {
|
||||
match self {
|
||||
Call::Admission => "admission wait",
|
||||
Call::ListChildren => "list children",
|
||||
Call::ReadNodes => "read nodes",
|
||||
Call::ReadNodesFull => "read nodes full",
|
||||
|
||||
@@ -51,6 +51,7 @@ graph TD
|
||||
| [`pdfs-store`](../crates/pdfs-store) | The SQLite schema and queries (`db/`), the content cache (`cache`) |
|
||||
| [`pdfs-drive`](../crates/pdfs-drive) | The `DriveApi` seam over the SDK, the call counter (`counted`), and `FakeDrive` for the simulations |
|
||||
| [`pdfs-sync`](../crates/pdfs-sync) | The mirror engine: its passes (`mirror`), split into the walks (`mirror::walk`), applying a plan (`mirror::apply`) and the push pass (`mirror::push`), its engine thread (`mirror::engine`), its reads and writes of the local disk in one module (`mirror::local`), and the parts with no I/O: planner, pass model and pass trace. It owns its state (`SyncParts`), reads and writes its tables only through `SyncStore`, and reaches the daemon only through `SyncHost` |
|
||||
| [`pdfs-sched`](../crates/pdfs-sched) | The admission port: a service describes each step of background work it is about to run (`Step`: its class and its root) and waits for a `Permit` from an `Admission`. `Bounded` admits a fixed number at once. The mirror engine admits every upload, download and folder creation of a pass through it |
|
||||
| [`pdfs-vfs`](../crates/pdfs-vfs) | The mounted-files service, with no kernel adapter: the tree (`tree`: nodes, stable inodes, per-mount roots), the reserved inodes (`ids`), the open files (`open`: write handles and their authored ranges, released writes waiting for upload, directory handles, `fallocate` rules), the open-file service (`files`: open, write, resize, fsync and close, behind the `FilesHost` port), the namespace service (`namespace`: create, mkdir, unlink, rmdir and rename behind the `NamespaceHost` port, and the settling of a cut-off replacing rename), a headless adapter that serves both by path (`headless`) and the scenarios every adapter has to pass (`conformance`), and what the mount accepted but has not sent yet (`writes`: queued revisions, nodes removed here, echoes of our own changes). Errors are typed; the FUSE adapter maps them to errno |
|
||||
| [`pdfs-fuse`](../crates/pdfs-fuse) | The daemon: FUSE handlers (`filesystem`), finding nodes (`resolve`), folder listings and file sizes (`listing`, `sizes`), reads (`reads`), queueing and the drain (`enqueue`, `queue`, `drain`, `upload`), calls sent straight to Drive (`remote`), requests by path (`requests`), startup recovery (`recovery`), pins, search, trash, the shared tree (`shared`), the link state (`link`), remote events (`background`), the daemon's side of the sync engine (`sync`, which implements `SyncHost`), moves between locations (`relocate`), control handlers (`control`), push events (`events`), photos, sharing, devices, the supervisor, and the simulation tests (`sim/`) |
|
||||
| [`pdfs-daemon`](../crates/pdfs-daemon) | The daemon's composition root: waits for a session, opens the database and the content cache, resumes the session and mounts, then remounts or retries with a backoff and records each failure |
|
||||
@@ -721,6 +722,7 @@ apps pdfs-cli, pdfs-gui talk to the daemon over the co
|
||||
daemon pdfs-daemon builds the services, supervisor, diagnostics, control server
|
||||
adapters pdfs-fuse (Linux FUSE), pdfs-local (watch, scan, place), pdfs-drive (SDK adapter, fake Drive)
|
||||
services pdfs-sync (mirrors), pdfs-vfs (mounted files: objects, handles, generations), photos, ...
|
||||
pdfs-sched (admission: which step of background work may start)
|
||||
base pdfs-store (SQLite, migrations), pdfs-core (config, protocol, ids, errors)
|
||||
```
|
||||
|
||||
@@ -879,6 +881,29 @@ and removals with their POSIX refusals; an unlinked open file) run through it in
|
||||
through a FUSE mount, online and offline, in `pdfs-fuse`'s simulations, and both see the same
|
||||
outcomes. `cargo tree -p pdfs-vfs` still shows no kernel or GUI crate.
|
||||
|
||||
Step 6 has started. `pdfs-sched` holds the admission port: an `Admission` decides when a `Step`
|
||||
may start, and its `Permit` gives the capacity back when dropped. The mirror engine asks it
|
||||
before every upload, download and folder creation of a pass, through `SyncParts::admission`,
|
||||
instead of a semaphore of its own. The daemon supplies `Bounded` with the engine's old limit of
|
||||
8 (`SYNC_CONCURRENCY`); passes run one at a time, so the behaviour is the one from before. An
|
||||
account-wide controller that weighs mirror steps against mounted reads and the drain plugs in
|
||||
behind the same trait.
|
||||
|
||||
An admission also reports its load (`Admission::load`): per class of step, how many run, how
|
||||
many wait, how long the oldest has waited, and the total and longest wait so far. `pdfs
|
||||
diagnostics` prints it, and each pass trace counts the time its steps spent in line
|
||||
(`admission wait`) apart from the time they spent on the network. This is the first item of the
|
||||
scheduler's delivery order: measure before any policy changes.
|
||||
|
||||
The second item moves one cold path behind admission: a folder the mount has not listed yet. The
|
||||
daemon's admission is now `Classes`, a limit of its own per class of step, so mirror steps (8) and
|
||||
cold listings (32, above what the mount lists at once today) never wait for each other. Callers
|
||||
that find the same folder unlisted at once share one listing through a single flight
|
||||
(`pdfs_sched::flights`): the first lists it, the others wait and take what it published, and a
|
||||
follower whose leader failed lists the folder itself, so each caller still gets its own answer.
|
||||
A shared folder's refresh stays out of the flight, since its generation check settles races of
|
||||
its own.
|
||||
|
||||
Steps 0 to 3 are 4.0.0. Steps 4 to 6 follow in 4.x, one service at a time. Out of scope for
|
||||
now: an encrypted local vault (full-disk encryption covers a copied disk today), Windows and
|
||||
macOS adapters, and a separate repository for the sync engine.
|
||||
|
||||
@@ -108,6 +108,8 @@ 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 |
|
||||
| [B300](#b300--a-read-during-a-release-can-be-served-the-revision-the-write-replaced) | A read during a release can be served the revision the write replaced |
|
||||
@@ -405,6 +407,63 @@ 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)
|
||||
**Found:** 2026-11-27, from a CI failure of the `one_client_on_a_slow_link` simulation (seed 3):
|
||||
`rename y/d -> y/c.bin` answered EACCES, and the daemon log had two "access changed before the
|
||||
write could be queued" errors for the node.
|
||||
**Where:** `Core::trash_withdrawn_create` and `Core::drain_trash` in
|
||||
`crates/pdfs-fuse/src/drain/trash.rs`
|
||||
|
||||
**Repro:** Make a file and delete it while its create is on the wire, on a slow link. Drive makes
|
||||
the node and lists it before the drain has the answer. Refresh the folder in that window. Once the
|
||||
drain has trashed the node, make a file under the same name, write to it and rename it. The write
|
||||
is kept in staging with "access changed before the write could be queued", and the rename fails
|
||||
with EACCES.
|
||||
|
||||
**Cause.** The drain hid the node Drive made, so later listings left it out, but it did not take
|
||||
it out of a listing already in the tree. The refresh had put the node there under the deleted
|
||||
file's name. A new file under that name opened the existing entry, which was the node being
|
||||
trashed. Once the trash landed its row was gone, the node had no write authority, and every
|
||||
write and rename of it was refused.
|
||||
|
||||
**Fix.** `Core::withdraw_landed` hides the node and also removes it from every mount, and drops
|
||||
the kernel's entry for its name. Both places that trash a withdrawn create's node call it.
|
||||
|
||||
**Verified:** `a_listing_taken_while_a_withdrawn_create_lands_does_not_keep_it` holds the answer to
|
||||
a create, deletes the file, refreshes the folder, then lets the answer through. It fails without
|
||||
the fix and passes with it.
|
||||
### B302 — A stop during a replacing rename leaves the replaced file in the trash
|
||||
|
||||
**Status:** Fixed (unverified)
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ commands are for scripts and for cases where the mount is not available.
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `pdfs diagnose` | Check the installation and print a report. Works without the service. When the service does not answer, also asks Proton which of your keys open. Exits non-zero if a check fails. |
|
||||
| `pdfs diagnostics` | What a running service is doing now: worker threads, queues, requests in flight, memory, and where each synced folder's last pass spent its time. For a service that has stopped answering, or a synced folder that never finishes. |
|
||||
| `pdfs diagnostics` | What a running service is doing now: worker threads, queues, requests in flight, memory, how many background steps run and wait, and where each synced folder's last pass spent its time. For a service that has stopped answering, or a synced folder that never finishes. |
|
||||
| `pdfs cache inspect [--deep]` | Database size, reclaimable space, row counts, cache use against the limit. `--deep` also runs SQLite's integrity check (slow). |
|
||||
| `pdfs cache vacuum` | Compact the database. Needs free space for a second copy of it while it runs. |
|
||||
| `pdfs cache clear` | Delete cached file content. Files kept available offline stay. |
|
||||
|
||||
@@ -298,6 +298,11 @@ What the parts mean:
|
||||
recorded. A high count here on a folder that has not changed is the slow case from B294. Each
|
||||
pass records what it read, so the count falls on the next pass even if this one is cut short.
|
||||
- **`slowest listing`** names the folder on Proton Drive that took longest to list.
|
||||
- **`admission wait`** is the time uploads, downloads and folder creations spent waiting for
|
||||
their turn before they started. The service runs at most 8 of them at once. A large
|
||||
`admission wait` next to a small `upload` total means the work queued inside the service and
|
||||
did not wait on Proton Drive. The `admission of background steps` lines in `pdfs diagnostics`
|
||||
show how many steps run and wait right now, and how long the oldest one has waited.
|
||||
- **`reused`** and **`dirty folders`:** once a pass has listed the whole folder on Proton Drive,
|
||||
later passes start from that listing (`reused` paths) and list only the folders Proton Drive
|
||||
reported a change in (`dirty folders`). A pass with no `reused` count listed everything. That
|
||||
|
||||
Reference in new issue
Block a user