@@ -18,6 +18,7 @@ class SparseRecovery {
1818 size_t universe_size;
1919 size_t max_recovery_size;
2020 size_t cleanup_sketch_support;
21+ size_t updates_since_recovery_attempt = 0 ;
2122 // 1 - 1/2e. TODO - can do better. closer to 1-1/e. for the power-of-two-rounding,
2223 // I'm gonna propose 0.69 (comfortably below sqrt(2) so we decrease the size every two levels)
2324 // static constexpr double reduction_factor = 0.82;
@@ -88,6 +89,7 @@ class SparseRecovery {
8889 return hash % level_size;
8990 }
9091 void update (const vec_t update) {
92+ updates_since_recovery_attempt++;
9193 vec_hash_t checksum = Bucket_Boruvka::get_index_hash (update, checksum_seed ());
9294 deterministic_bucket ^= {update, checksum};
9395 for (size_t cfr_idx=0 ; cfr_idx < num_levels (); cfr_idx++) {
@@ -99,6 +101,7 @@ class SparseRecovery {
99101 }
100102 void reset () {
101103 // zero contents of the CFRs
104+ updates_since_recovery_attempt = 0 ;
102105 deterministic_bucket = {0 , 0 };
103106 for (size_t i=0 ; i < recovery_buckets.size (); i++) {
104107 recovery_buckets[i] = {0 , 0 };
@@ -108,7 +111,9 @@ class SparseRecovery {
108111
109112
110113 // THIS IS A NON_DESTRUCTIVE OPERATION
114+ // (but cannot be marked const)
111115 RecoveryResult recover () {
116+ updates_since_recovery_attempt = 0 ;
112117 // TODO - DYNAMIc allocation grossness
113118 std::vector<Bucket> recovered_indices;
114119 std::vector<vec_t > recovered_return_vals;
@@ -167,12 +172,20 @@ class SparseRecovery {
167172 return {FAILURE, recovered_return_vals};
168173 };
169174 void merge (const SparseRecovery &other) {
175+ updates_since_recovery_attempt += other.updates_since_recovery_attempt ;
170176 assert (other.recovery_buckets .size () == recovery_buckets.size ());
171177 for (size_t i=0 ; i < recovery_buckets.size (); i++) {
172178 recovery_buckets[i] ^= other.recovery_buckets [i];
173179 }
174180 cleanup_sketch->merge (*other.cleanup_sketch );
175181 };
182+
183+ bool worth_recovery_attempt () const {
184+ // TODO - remove magic number; more complicated logic, etc.
185+ // note that this could be done by looking at the cleanup sketch for a cardinality estimate
186+ return updates_since_recovery_attempt > 1000 ;
187+ };
188+
176189 ~SparseRecovery () {
177190
178191 };
0 commit comments