-
Notifications
You must be signed in to change notification settings - Fork 483
Frontend peek sequencing -- RTR #34238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+120
−72
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2524,67 +2524,73 @@ impl Coordinator { | |
| } | ||
| } | ||
|
|
||
| /// Inner method that performs the actual real-time recency timestamp determination. | ||
| /// This is called by both the old peek sequencing code (via `determine_real_time_recent_timestamp`) | ||
| /// and the new command handler for `Command::DetermineRealTimeRecentTimestamp`. | ||
| pub(crate) async fn determine_real_time_recent_timestamp( | ||
| &self, | ||
| source_ids: impl Iterator<Item = GlobalId>, | ||
| real_time_recency_timeout: Duration, | ||
| ) -> Result<Option<BoxFuture<'static, Result<Timestamp, StorageError<Timestamp>>>>, AdapterError> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This big green block is mostly just code movement from the old |
||
| { | ||
| let item_ids = source_ids.map(|gid| self.catalog.resolve_item_id(&gid)); | ||
|
|
||
| // Find all dependencies transitively because we need to ensure that | ||
| // RTR queries determine the timestamp from the sources' (i.e. | ||
| // storage objects that ingest data from external systems) remap | ||
| // data. We "cheat" a little bit and filter out any IDs that aren't | ||
| // user objects because we know they are not a RTR source. | ||
| let mut to_visit = VecDeque::from_iter(item_ids.filter(CatalogItemId::is_user)); | ||
| // If none of the sources are user objects, we don't need to provide | ||
| // a RTR timestamp. | ||
| if to_visit.is_empty() { | ||
| return Ok(None); | ||
| } | ||
|
|
||
| let mut timestamp_objects = BTreeSet::new(); | ||
|
|
||
| while let Some(id) = to_visit.pop_front() { | ||
| timestamp_objects.insert(id); | ||
| to_visit.extend( | ||
| self.catalog() | ||
| .get_entry(&id) | ||
| .uses() | ||
| .into_iter() | ||
| .filter(|id| !timestamp_objects.contains(id) && id.is_user()), | ||
| ); | ||
| } | ||
| let timestamp_objects = timestamp_objects | ||
| .into_iter() | ||
| .flat_map(|item_id| self.catalog().get_entry(&item_id).global_ids()) | ||
| .collect(); | ||
|
|
||
| let r = self | ||
| .controller | ||
| .determine_real_time_recent_timestamp(timestamp_objects, real_time_recency_timeout) | ||
| .await?; | ||
|
|
||
| Ok(Some(r)) | ||
| } | ||
|
|
||
| /// Checks to see if the session needs a real time recency timestamp and if so returns | ||
| /// a future that will return the timestamp. | ||
| pub(super) async fn determine_real_time_recent_timestamp( | ||
| pub(crate) async fn determine_real_time_recent_timestamp_if_needed( | ||
| &self, | ||
| session: &Session, | ||
| source_ids: impl Iterator<Item = CatalogItemId>, | ||
| source_ids: impl Iterator<Item = GlobalId>, | ||
| ) -> Result<Option<BoxFuture<'static, Result<Timestamp, StorageError<Timestamp>>>>, AdapterError> | ||
| { | ||
| let vars = session.vars(); | ||
|
|
||
| // Ideally this logic belongs inside of | ||
| // `mz-adapter::coord::timestamp_selection::determine_timestamp`. However, including the | ||
| // logic in there would make it extremely difficult and inconvenient to pull the waiting off | ||
| // of the main coord thread. | ||
| let r = if vars.real_time_recency() | ||
| if vars.real_time_recency() | ||
| && vars.transaction_isolation() == &IsolationLevel::StrictSerializable | ||
| && !session.contains_read_timestamp() | ||
| { | ||
| // Find all dependencies transitively because we need to ensure that | ||
| // RTR queries determine the timestamp from the sources' (i.e. | ||
| // storage objects that ingest data from external systems) remap | ||
| // data. We "cheat" a little bit and filter out any IDs that aren't | ||
| // user objects because we know they are not a RTR source. | ||
| let mut to_visit = VecDeque::from_iter(source_ids.filter(CatalogItemId::is_user)); | ||
| // If none of the sources are user objects, we don't need to provide | ||
| // a RTR timestamp. | ||
| if to_visit.is_empty() { | ||
| return Ok(None); | ||
| } | ||
|
|
||
| let mut timestamp_objects = BTreeSet::new(); | ||
|
|
||
| while let Some(id) = to_visit.pop_front() { | ||
| timestamp_objects.insert(id); | ||
| to_visit.extend( | ||
| self.catalog() | ||
| .get_entry(&id) | ||
| .uses() | ||
| .into_iter() | ||
| .filter(|id| !timestamp_objects.contains(id) && id.is_user()), | ||
| ); | ||
| } | ||
| let timestamp_objects = timestamp_objects | ||
| .into_iter() | ||
| .flat_map(|item_id| self.catalog().get_entry(&item_id).global_ids()) | ||
| .collect(); | ||
|
|
||
| let r = self | ||
| .controller | ||
| .determine_real_time_recent_timestamp( | ||
| timestamp_objects, | ||
| *vars.real_time_recency_timeout(), | ||
| ) | ||
| .await?; | ||
|
|
||
| Some(r) | ||
| self.determine_real_time_recent_timestamp(source_ids, *vars.real_time_recency_timeout()) | ||
| .await | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| Ok(r) | ||
| Ok(None) | ||
| } | ||
| } | ||
|
|
||
| #[instrument] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -689,6 +689,10 @@ ALTER SYSTEM SET allow_real_time_recency = true | |
| ---- | ||
| COMPLETE 0 | ||
|
|
||
| # TODO(ggevay): I think this is not actually testing real-time recency, because tables don't participate in the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙈 |
||
| # RTR machinery at all. (We do get the latest contents of a table in STRICT SERIALIZABLE mode even without RTR | ||
| # being turned on.) We do have other tests in Testdrive, though. | ||
|
|
||
| statement ok | ||
| SET REAL_TIME_RECENCY TO TRUE | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This corresponds to the spawning in the old peek sequencing's
peek_real_time_recency.