From 926422b4469b8b0fb37a08365e615d4a31cc74c6 Mon Sep 17 00:00:00 2001 From: Lee Danilek Date: Wed, 13 Mar 2024 21:09:23 -0400 Subject: [PATCH] ensure Interval advances (#23440) return errors if we are fetching a page from an index range and the remaining Interval to query does not shrink. Do this at the lowest levels where we compute the remaining_intervals -- once where we merge it with pending writes, and once where we truncate results based on length and bytes size. and also do this at the highest level where we absolutely require the interval to be advancing -- in the Query loop. GitOrigin-RevId: 8e74577b5a53314c066a3ebaae5f2e9e54a49bdc --- crates/database/src/query/index_range.rs | 1 + crates/database/src/transaction_index.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/crates/database/src/query/index_range.rs b/crates/database/src/query/index_range.rs index 7b714d03..b3a728df 100644 --- a/crates/database/src/query/index_range.rs +++ b/crates/database/src/query/index_range.rs @@ -213,6 +213,7 @@ impl IndexRange { self.version.clone(), ) .await?; + anyhow::ensure!(self.unfetched_interval != new_unfetched_interval); self.unfetched_interval = new_unfetched_interval; self.page_count += 1; self.rows_read += page.len(); diff --git a/crates/database/src/transaction_index.rs b/crates/database/src/transaction_index.rs index bf1a0a0f..ae2cda5d 100644 --- a/crates/database/src/transaction_index.rs +++ b/crates/database/src/transaction_index.rs @@ -237,6 +237,11 @@ impl TransactionIndex { (None, None) => break, } } + if remaining_interval == range_request.interval { + Err(anyhow::anyhow!( + "query for {remaining_interval:?} did not shrink" + ))?; + } (range_results, remaining_interval) }; assert!(results.insert(batch_key, item_result).is_none()); @@ -382,6 +387,11 @@ impl TransactionIndex { indexed_fields.clone(), interval_read, )?; + if interval_unread == interval { + Err(anyhow::anyhow!( + "query for {interval_unread:?} did not shrink" + ))?; + } (out, interval_unread) }; assert!(results.insert(batch_key, result).is_none());