mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-04 16:56:59 +01:00
some performance optimizations
This commit is contained in:
1 parent
a90cf83ff5
commit
1d5fdfb6b9
7 files changed
+601
-85
No files matched your search
@@ -35,7 +35,7 @@ use super::transfers::CountingReader;
|
||||
use super::{
|
||||
Core, DRAIN_BACKOFF_MAX, DRAIN_BACKOFF_MIN, DRAIN_IDLE_POLL, ROOT_INO, conflict_name,
|
||||
is_already_exists, is_gone, is_local_uid_str, media_type_for, node_size, now_millis, now_secs,
|
||||
op_is_ready, parse_node_uid,
|
||||
parse_node_uid,
|
||||
};
|
||||
|
||||
impl Core {
|
||||
@@ -55,12 +55,10 @@ impl Core {
|
||||
pub(crate) fn run_pending_drain(&self) {
|
||||
loop {
|
||||
let now = now_millis();
|
||||
let due = self
|
||||
.db
|
||||
.pending_ops()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.find(|op| op.next_attempt_at <= now && op_is_ready(op));
|
||||
// One row, chosen by the database. Reading the whole queue to pick
|
||||
// one op made a long queue quadratic to drain, and held the shared
|
||||
// connection — and so every FUSE metadata call — for the duration.
|
||||
let due = self.db.next_due_op(now).unwrap_or_default();
|
||||
|
||||
let Some(op) = due.filter(|_| self.online.load(Ordering::Relaxed)) else {
|
||||
self.wait_for_drain_work();
|
||||
|
||||
@@ -3097,17 +3097,6 @@ fn conflict_name(name: &str, stamp: i64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether an op can be attempted now, as opposed to waiting on another op.
|
||||
///
|
||||
/// A node created inside a folder that was itself created offline cannot be sent
|
||||
/// anywhere until that folder is real — the API has never heard of `local~…`.
|
||||
/// Ops replay in queue order, so the parent normally drains first and rewrites
|
||||
/// this one; the check matters when the parent is instead backing off after a
|
||||
/// failure, where the child must wait rather than burn its own retries.
|
||||
fn op_is_ready(op: &PendingOp) -> bool {
|
||||
!op.parent_uid.as_deref().is_some_and(is_local_uid_str)
|
||||
}
|
||||
|
||||
/// Fabricate the node the server would have returned, for a `create`/`mkdir`
|
||||
/// that could not reach it. Everything the kernel asks about a fresh node —
|
||||
/// name, kind, size, times — is knowable locally; the uid is the only invention,
|
||||
@@ -4784,28 +4773,6 @@ mod local_uid_tests {
|
||||
assert!(!is_local_uid_str("vol1~local"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_op_waits_for_a_parent_that_is_still_a_placeholder() {
|
||||
let op = |parent: Option<&str>| PendingOp {
|
||||
id: 0,
|
||||
kind: OP_CREATE.to_string(),
|
||||
uid: "local~child".to_string(),
|
||||
parent_uid: parent.map(str::to_string),
|
||||
name: Some("f.txt".to_string()),
|
||||
blob_path: None,
|
||||
meta_json: None,
|
||||
created_at: 0,
|
||||
attempts: 0,
|
||||
last_error: None,
|
||||
next_attempt_at: 0,
|
||||
};
|
||||
// Sending this to the API would 404: the folder does not exist yet.
|
||||
assert!(!op_is_ready(&op(Some("local~dir"))));
|
||||
assert!(op_is_ready(&op(Some("vol1~dir"))));
|
||||
// A revision op names no parent and is always ready.
|
||||
assert!(op_is_ready(&op(None)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_placeholder_file_reports_itself_as_empty_and_unsealed() {
|
||||
let parent = NodeUid::new(VolumeId::from("vol1"), LinkId::from("dir"));
|
||||
|
||||
Reference in new issue
Block a user