@@ -26,7 +26,7 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
26
26
log_info ! ( self . logger, "Initiating snapshotting service" ) ;
27
27
28
28
let snapshot_sync_day_factors = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 14 , 21 , u64:: MAX ] ;
29
- let round_day_seconds = config :: SNAPSHOT_CALCULATION_INTERVAL as u64 ;
29
+ const DAY_SECONDS : u64 = 60 * 60 * 24 ;
30
30
31
31
let pending_snapshot_directory = format ! ( "{}/snapshots_pending" , cache_path( ) ) ;
32
32
let pending_symlink_directory = format ! ( "{}/symlinks_pending" , cache_path( ) ) ;
@@ -38,7 +38,7 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
38
38
loop {
39
39
// 1. get the current timestamp
40
40
let snapshot_generation_timestamp = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) ;
41
- let reference_timestamp = Self :: round_down_to_nearest_multiple ( snapshot_generation_timestamp, round_day_seconds ) ;
41
+ let reference_timestamp = Self :: round_down_to_nearest_multiple ( snapshot_generation_timestamp, config :: SNAPSHOT_CALCULATION_INTERVAL as u64 ) ;
42
42
log_info ! ( self . logger, "Capturing snapshots at {} for: {}" , snapshot_generation_timestamp, reference_timestamp) ;
43
43
44
44
// 2. sleep until the next round 24 hours
@@ -70,7 +70,7 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
70
70
let mut snapshot_sync_timestamps: Vec < ( u64 , u64 ) > = Vec :: new ( ) ;
71
71
for factor in & snapshot_sync_day_factors {
72
72
// basically timestamp - day_seconds * factor
73
- let timestamp = reference_timestamp. saturating_sub ( round_day_seconds . saturating_mul ( factor. clone ( ) ) ) ;
73
+ let timestamp = reference_timestamp. saturating_sub ( DAY_SECONDS . saturating_mul ( factor. clone ( ) ) ) ;
74
74
snapshot_sync_timestamps. push ( ( factor. clone ( ) , timestamp) ) ;
75
75
} ;
76
76
@@ -105,7 +105,9 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
105
105
symlink ( & relative_dummy_snapshot_path, & dummy_symlink_path) . unwrap ( ) ;
106
106
}
107
107
108
- for i in 0 ..10_001u64 {
108
+ // Number of intervals since Jan 1, 2022, a few months before RGS server was released.
109
+ let symlink_count = ( reference_timestamp - 1640995200 ) / config:: SNAPSHOT_CALCULATION_INTERVAL as u64 ;
110
+ for i in 0 ..symlink_count {
109
111
// let's create non-dummy-symlinks
110
112
111
113
// first, determine which snapshot range should be referenced
@@ -115,7 +117,7 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
115
117
} else {
116
118
// find min(x) in snapshot_sync_day_factors where x >= i
117
119
snapshot_sync_day_factors. iter ( ) . find ( |x| {
118
- x >= & & i
120
+ * x * DAY_SECONDS >= i * config :: SNAPSHOT_CALCULATION_INTERVAL as u64
119
121
} ) . unwrap ( ) . clone ( )
120
122
} ;
121
123
@@ -126,7 +128,7 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
126
128
// special-case 0 to always refer to a full/initial sync
127
129
0
128
130
} else {
129
- reference_timestamp. saturating_sub ( round_day_seconds . saturating_mul ( i) )
131
+ reference_timestamp. saturating_sub ( ( config :: SNAPSHOT_CALCULATION_INTERVAL as u64 ) . saturating_mul ( i) )
130
132
} ;
131
133
let symlink_path = format ! ( "{}/{}.bin" , pending_symlink_directory, canonical_last_sync_timestamp) ;
132
134
@@ -149,8 +151,8 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
149
151
150
152
// constructing the snapshots may have taken a while
151
153
let current_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) ;
152
- let remainder = current_time % round_day_seconds ;
153
- let time_until_next_day = round_day_seconds - remainder;
154
+ let remainder = current_time % config :: SNAPSHOT_CALCULATION_INTERVAL as u64 ;
155
+ let time_until_next_day = config :: SNAPSHOT_CALCULATION_INTERVAL as u64 - remainder;
154
156
155
157
log_info ! ( self . logger, "Sleeping until next snapshot capture: {}s" , time_until_next_day) ;
156
158
// add in an extra five seconds to assure the rounding down works correctly
0 commit comments