Skip to content

Commit

Permalink
ensure Interval advances (#23440)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ldanilek authored and Convex, Inc. committed Mar 14, 2024
1 parent 4b0e312 commit 926422b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/database/src/query/index_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl<T: QueryType> IndexRange<T> {
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();
Expand Down
10 changes: 10 additions & 0 deletions crates/database/src/transaction_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 926422b

Please sign in to comment.