From 8c5543b8b22b6da441bcdc643f307c86deb34837 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Sun, 16 Nov 2025 07:10:58 -0800 Subject: [PATCH] fix: include database connection in watermark exchange for resource count retrieval - Updated the watermark exchange methods to accept a database connection, enabling retrieval of peer resource counts during synchronization. - Enhanced logging to provide visibility into the resource counts being exchanged, improving debugging and monitoring capabilities. - Addressed potential issues with resource count availability by ensuring counts are fetched correctly during static exchanges. --- core/src/service/sync/peer.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/service/sync/peer.rs b/core/src/service/sync/peer.rs index e11460a10..df4d7abea 100644 --- a/core/src/service/sync/peer.rs +++ b/core/src/service/sync/peer.rs @@ -1158,7 +1158,7 @@ impl PeerSync { // Exchange watermarks with all peers for peer_id in partners { if let Err(e) = Self::trigger_watermark_exchange( - library_id, device_id, peer_id, &peer_log, &network, + library_id, device_id, peer_id, &peer_log, &network, &db, ) .await { @@ -1434,7 +1434,7 @@ impl PeerSync { // CRITICAL FIX: Actually trigger watermark exchange on reconnection // This fixes the 20-minute idle bug where events die but no recovery happens if let Err(e) = Self::trigger_watermark_exchange( - library_id, device_id, peer_id, &peer_log, &network, + library_id, device_id, peer_id, &peer_log, &network, &db, ) .await { @@ -1560,6 +1560,7 @@ impl PeerSync { peer_id: Uuid, peer_log: &Arc, network: &Arc, + db: &Arc, ) -> Result<()> { info!( peer = %peer_id, @@ -1580,15 +1581,20 @@ impl PeerSync { std::collections::HashMap::new() }); - // Note: Counts unavailable in static context (no db access) - // This is fine - counts only used when called from instance method - let my_peer_resource_counts = std::collections::HashMap::new(); + // Get counts of peer's resources (for gap detection) + let my_peer_resource_counts = Self::get_device_owned_counts(peer_id, db) + .await + .unwrap_or_else(|e| { + warn!(error = %e, peer = %peer_id, "Failed to get peer resource counts in static exchange"); + std::collections::HashMap::new() + }); debug!( peer = %peer_id, my_shared_watermark = ?my_shared_watermark, resource_count = my_resource_watermarks.len(), - "Sending watermark exchange request (static trigger, counts unavailable)" + peer_owned_counts = ?my_peer_resource_counts, + "Sending watermark exchange request with counts" ); // Send request to peer