mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
fix(sync): robust blob handling, op validation and quarantine
- upload_blob resumes until the server confirms the blob (202/409 are not success) - missing local blob skips its PutAsset instead of blocking all later ops - failed blob downloads are counted and retried, not fatal to the cycle - server validates pushed ops (hash, hlc, clock skew) and returns per-op rejections - pulled ops that can never apply are quarantined; storage errors stay fatal - SYNAPSE_MAX_CLOCK_SKEW_MINUTES; document Arc<Mutex<Graph>> handle for the FFI Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3266ddda3a
commit
9ce35f90ff
11 files changed
+433
-52
No files matched your search
@@ -27,6 +27,13 @@ pub struct SyncState {
|
||||
/// Ops pushed / pulled(applied) in the last successful cycle.
|
||||
pub last_pushed: u64,
|
||||
pub last_pulled: u64,
|
||||
/// Ops refused by the server or skipped locally because they can never apply (this
|
||||
/// session). Details are in the log and, for pulled ops, in table `sync_quarantine`.
|
||||
pub quarantined_ops: u64,
|
||||
/// Local assets whose blob is missing: their `PutAsset` op was not pushed.
|
||||
pub skipped_assets: u64,
|
||||
/// Blobs that could not be downloaded in the last cycle (retried next cycle).
|
||||
pub failed_blobs: u64,
|
||||
}
|
||||
|
||||
impl Default for SyncState {
|
||||
@@ -38,6 +45,9 @@ impl Default for SyncState {
|
||||
last_sync_ms: None,
|
||||
last_pushed: 0,
|
||||
last_pulled: 0,
|
||||
quarantined_ops: 0,
|
||||
skipped_assets: 0,
|
||||
failed_blobs: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,10 +62,32 @@ pub struct Cursors {
|
||||
|
||||
pub(crate) fn init(conn: &Connection) -> rusqlite::Result<()> {
|
||||
conn.execute_batch(
|
||||
"CREATE TABLE IF NOT EXISTS sync_state (key TEXT PRIMARY KEY, value TEXT NOT NULL);",
|
||||
"CREATE TABLE IF NOT EXISTS sync_state (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS sync_quarantine (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
server_seq INTEGER NOT NULL,
|
||||
hlc TEXT NOT NULL,
|
||||
payload TEXT NOT NULL,
|
||||
reason TEXT NOT NULL
|
||||
);",
|
||||
)
|
||||
}
|
||||
|
||||
/// Records a pulled op that can never be applied, so it is skipped instead of blocking sync.
|
||||
pub(crate) fn quarantine(
|
||||
g: &Graph,
|
||||
server_seq: i64,
|
||||
hlc: &str,
|
||||
payload: &str,
|
||||
reason: &str,
|
||||
) -> rusqlite::Result<()> {
|
||||
g.conn().execute(
|
||||
"INSERT INTO sync_quarantine(server_seq, hlc, payload, reason) VALUES (?1, ?2, ?3, ?4)",
|
||||
params![server_seq, hlc, payload, reason],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(conn: &Connection, key: &str) -> rusqlite::Result<Option<String>> {
|
||||
conn.query_row("SELECT value FROM sync_state WHERE key=?1", [key], |r| {
|
||||
r.get(0)
|
||||
|
||||
Reference in new issue
Block a user