fix(restore): keep the legacy restore snapshot when filing it under its node fails
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust, sqlite
- Lĩnh vực
- backend, databases, testing-qa
Hướng nghiên cứu
Start with rust/src/api/orders.rs, especially migrate_unnamed_restore_snapshot and file_unnamed_restore_snapshot, then inspect the existing orders tests using throwaway_store(). Add failure-path coverage for get_setting and set_setting, verify the legacy key survives and is retried, and update specs/004-mostro-p2p-client/contracts/identity.md. Run cargo test and cargo clippy -- -D warnings.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Follow-up to #812 / PR #841, found in its round-2 review. The code below is introduced by #841 (commit 44520537), so this can only be done once #841 is merged.
Context
Before #812, a restore stored a single snapshot (floor + live order ids) under the settings key restore_snapshot, and that snapshot did not say which node answered. #841 keeps one snapshot per node (restore_snapshot:<node>) and migrates the old one with migrate_unnamed_restore_snapshot (rust/src/api/orders.rs):
- every row of its
liveorders names the same node →file_unnamed_restore_snapshotstores it under that node's key, unless the node already has its own; - otherwise → it is dropped;
- in both cases the legacy
restore_snapshotkey is then deleted.
The migration runs at start, in _run_order_subscription before seed_global_dm_coverage() opens the kind-14 feed, so the feed's replay finds the snapshot already filed and rebuilds nothing it hid. The history pass (reconcile_restored_history, 60 s after start, then every 30 min) runs it too if the legacy key is still there.
Problem
file_unnamed_restore_snapshot returns false in two cases the caller cannot tell apart:
| Case | Today | Should the legacy key go? |
|---|---|---|
The node already has its own snapshot (get_setting → Ok(Some(_))) |
false |
Yes, the node's own snapshot is newer |
The node's key cannot be read (get_setting → Err) |
false |
No |
serde_json::to_string fails |
false |
No |
set_setting fails |
false |
No |
migrate_unnamed_restore_snapshot deletes restore_snapshot whatever filed is:
let filed = match named {
Some(snapshot) => file_unnamed_restore_snapshot(db, &snapshot).await,
None => false,
};
match db.delete_setting(key).await {
Ok(()) if !filed => /* logs "restore snapshot without its node dropped" */,
...
}
So after a database error during the one start that migrates, the only copy of the snapshot is lost:
- The kind-14 feed opens right after and replays the whole history. With no snapshot for that node,
unwritten_row_statereads those orders as never written, andrebuild_trade_from_dmrebuilds their rows. visible_tradesdoes not hide them and the history pass does not drop them, because no snapshot exists for their node.- Nothing retries: the history pass looks for the legacy key and no longer finds it.
My Trades fills back up with the history #614 hid. That lasts until the user runs Account → Refresh on that node, and nothing tells the user to do it. On top of that, the log is misleading: a failed write logs the warning and then restore snapshot without its node dropped, which reads like a deliberate decision.
This also breaks the rule restore_snapshot_to_settle follows a few lines below: "One that cannot be read is left for the next pass."
Likelihood: low. It needs a storage error at exactly that start, for example SQLite with a full disk or a locked database, or IndexedDB over quota or with an aborted transaction on web. But the loss is permanent and silent, and it brings back the exact outcome the migration exists to prevent.
Proposed fix
Let file_unnamed_restore_snapshot tell "not filed" from "failed", and keep the legacy key on failure:
/// Store the legacy `snapshot`, now naming its node, under that node's key,
/// unless the node already has a snapshot of its own (`Ok(false)`). An
/// error leaves the legacy key for the next pass.
async fn file_unnamed_restore_snapshot(
db: &impl Storage,
snapshot: &crate::mostro::restore_history::RestoreSnapshot,
) -> anyhow::Result<bool> {
let Some(node) = snapshot.node.as_deref() else {
return Ok(false);
};
let key = crate::db::settings_keys::restore_snapshot(node);
if db.get_setting(&key).await?.is_some() {
return Ok(false);
}
db.set_setting(&key, &serde_json::to_string(snapshot)?).await?;
crate::api::logging::blog_info(
"restore",
format!(
"restore snapshot without its node filed under node={}",
crate::api::logging::short_id(node)
),
);
Ok(true)
}
let filed = match named {
Some(snapshot) => match file_unnamed_restore_snapshot(db, &snapshot).await {
Ok(filed) => filed,
// Deleted now, it would be lost: kept for the next pass.
Err(e) => {
log::warn!("[restore] restore snapshot without its node not filed, kept: {e}");
return;
}
},
None => false,
};
With the key kept, recovery is automatic:
- The history pass, 60 s later, runs the migration again (it is called from
reconcile_restored_history). If filing now works, the same pass settles that node's rows with the filed snapshot, and the rows the replay rebuilt are dropped as history. - The next start retries too, before the feed opens.
An unreadable legacy snapshot (serde_json::from_str fails) or one whose live rows do not name a single node can still be dropped: nothing can ever file it, so keeping it would only retry forever.
Tests
Following the quality bar: a test: commit that fails before the fix.
a_legacy_snapshot_is_kept_when_it_cannot_be_filed: aStoragethat wraps the throwaway SQLite store (throwaway_store()in theorders.rstests) and fails forRESTORE_SNAPSHOT_PREFIXkeys. Cover both a failingset_settingand a failingget_setting, or add a variant toPersistProbe. Aftermigrate_unnamed_restore_snapshot, assert:- the legacy
restore_snapshotkey is still there; - no
restore_snapshot:<node>key was written.
- the legacy
- Then, with the failure removed, a second
migrate_unnamed_restore_snapshotfiles it under the node and deletes the legacy key, asa_legacy_snapshot_is_filed_under_the_node_of_its_live_rowsexpects. a_legacy_snapshot_never_replaces_a_nodes_ownanda_legacy_snapshot_of_an_unknown_node_is_droppedkeep passing unchanged: a node with its own snapshot, or an unknown node, still drops the legacy key.
Acceptance criteria
- A storage error while filing the legacy snapshot leaves
restore_snapshotin place, and the log says it was kept, not dropped. - The next history pass or start files it once storage works, and settles that node's rows the same pass.
- A node that already has its own snapshot, an unknown node and an unreadable snapshot behave as today (legacy key dropped).
- Red test first, then the fix;
cargo testandcargo clippy -- -D warningspass. -
specs/004-mostro-p2p-client/contracts/identity.md(the legacy snapshot paragraph) says that a failed migration keeps the snapshot for the next pass.
- Ngôn ngữ chính
- Dart
- Star
- 11
- Fork
- 9
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 16
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MostroP2P/app
-
documentation priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: ui bug priority: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
NWC: the pay and buyer-invoice readouts are zero-size, so no accessibility tree carries themĐang mởarea: ui bug priority: high
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Button "Share logs" does nothingCó thể đã có người làm @Luquitasjeffrey đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: rust-core bug priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MostroP2P/app
Issue tương tự
-
Python example: list a model's scenes and their camerasCó thể đã có người làm @rudraparmar76 đã nhận hôm nay. Đang mởdocumentation good first issue python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
iamahsanmehmood/openskp#796 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
Plural rendering: first matching part wins, but gen-l10n lets the last one win (=1 shadows one)Đang mởbug help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
crowdin/flutter-sdk#97 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
MrSpideyNihal/lockfeed#16 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
InlitX/GymMane#529 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày