Add 0.bin symlink for clients requiring an initial rapid sync.
authorArik Sosman <git@arik.io>
Mon, 22 Aug 2022 21:39:02 +0000 (14:39 -0700)
committerArik Sosman <git@arik.io>
Mon, 22 Aug 2022 21:43:51 +0000 (14:43 -0700)
src/snapshot.rs

index 93be8402dd5253abd62200ac55c30e4715a7b1a7..3e39fd25df66aa6f282c94ffa9dc27a9a033c80c 100644 (file)
@@ -89,19 +89,30 @@ impl Snapshotter {
                                }
                        }
 
-                       for i in 1..10_001u64 {
+                       for i in 0..10_001u64 {
                                // let's create symlinks
 
                                // first, determine which snapshot range should be referenced
-                               // find min(x) in snapshot_sync_day_factors where x >= i
-                               let referenced_day_range = snapshot_sync_day_factors.iter().find(|x| {
-                                       x >= &&i
-                               }).unwrap().clone();
+                               let referenced_day_range = if i == 0 {
+                                       // special-case 0 to always refer to a full/initial sync
+                                       u64::MAX
+                               } else {
+                                       // find min(x) in snapshot_sync_day_factors where x >= i
+                                       snapshot_sync_day_factors.iter().find(|x| {
+                                               x >= &&i
+                                       }).unwrap().clone()
+                               };
 
                                let snapshot_filename = snapshot_filenames_by_day_range.get(&referenced_day_range).unwrap();
-                               let simulated_last_sync_timestamp = timestamp_seen.saturating_sub(round_day_seconds.saturating_mul(i));
                                let relative_snapshot_path = format!("{}/{}", relative_symlink_to_snapshot_path, snapshot_filename);
-                               let canonical_last_sync_timestamp = Self::round_down_to_nearest_multiple(simulated_last_sync_timestamp, round_day_seconds);
+
+                               let canonical_last_sync_timestamp = if i == 0 {
+                                       // special-case 0 to always refer to a full/initial sync
+                                       0
+                               } else {
+                                       let simulated_last_sync_timestamp = timestamp_seen.saturating_sub(round_day_seconds.saturating_mul(i));
+                                       Self::round_down_to_nearest_multiple(simulated_last_sync_timestamp, round_day_seconds)
+                               };
                                let symlink_path = format!("{}/{}.bin", pending_symlink_directory, canonical_last_sync_timestamp);
 
                                println!("Symlinking: {} -> {} ({} -> {}", i, referenced_day_range, symlink_path, relative_snapshot_path);