diff --git a/libs/utils/src/exp_counter.rs b/libs/utils/src/exp_counter.rs index 89a59a9c45..161ac951cb 100644 --- a/libs/utils/src/exp_counter.rs +++ b/libs/utils/src/exp_counter.rs @@ -32,6 +32,12 @@ pub struct ExpCounter { } impl ExpCounter { + /// Creates an iterator that uses `ExpCounter` for the first half of the + /// range and a linear range counter for the second half. + pub fn with_max_and_linear_search(max: u64) -> impl Iterator { + let linear_start = max / 2; + ExpCounter::with_max(linear_start).chain(linear_start..max) + } /// Creates a new `ExpCounter` instance that counts to the (exclusive) maximum pub fn with_max(max: u64) -> Self { Self { diff --git a/pageserver/src/pgdatadir_mapping.rs b/pageserver/src/pgdatadir_mapping.rs index 3b29f2d2cf..938672a908 100644 --- a/pageserver/src/pgdatadir_mapping.rs +++ b/pageserver/src/pgdatadir_mapping.rs @@ -370,7 +370,7 @@ impl Timeline { // We don't do an explosive search as we want to prove that // every single lsn up to high is giving inconclusive results. // This can only be done by trying all lsns. - for offs in ExpCounter::with_max(high - mid_start) { + for offs in ExpCounter::with_max_and_linear_search(high - mid_start) { mid = offs + mid_start; // Do the query for mid + 1 instead of mid so that we can make definite statements