This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix limit logic for EventsStream #7358
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc3e7e1
Factor out functions for injecting events into database
richvdh 13c40f8
Rework TestReplicationDataHandler
richvdh 1a69b43
Fix AssertionErrors being thrown by EventsStream
richvdh 295970a
changelog
richvdh e40939a
Move logic into `get_all_updated_current_state_deltas`
richvdh e2180da
reduce diff
richvdh 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 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 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 |
---|---|---|
|
@@ -176,16 +176,30 @@ async def _update_function( | |
from_token, upper_limit, target_row_count | ||
) # type: List[Tuple] | ||
|
||
# again, if we've hit the limit there, we'll need to limit the other sources | ||
assert len(state_rows) < target_row_count | ||
assert len(state_rows) <= target_row_count | ||
|
||
# there can be more than one row per stream_id in that table, so if we hit | ||
# the limit there, we'll need to truncate the results so that we have a complete | ||
# set of changes for all the stream IDs we include. | ||
if len(state_rows) == target_row_count: | ||
assert state_rows[-1][0] <= upper_limit | ||
upper_limit = state_rows[-1][0] | ||
limited = True | ||
upper_limit = state_rows[-1][0] - 1 | ||
|
||
# search for the point to truncate the list | ||
for idx in range(len(state_rows) - 1, 0, -1): | ||
if state_rows[idx - 1][0] <= upper_limit: | ||
state_rows = state_rows[:idx] | ||
break | ||
else: | ||
# bother. We didn't get a full set of changes for even a single | ||
# stream id. let's run the query again, without a row limit, but for | ||
# just one stream id. | ||
upper_limit += 1 | ||
state_rows = await self._store.get_all_updated_current_state_deltas( | ||
from_token, upper_limit, limit=None | ||
) | ||
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. I think we should probably move this logic into |
||
|
||
# FIXME: is it a given that there is only one row per stream_id in the | ||
# state_deltas table (so that we can be sure that we have got all of the | ||
# rows for upper_limit)? | ||
limited = True | ||
|
||
# finally, fetch the ex-outliers rows. We assume there are few enough of these | ||
# not to bother with the limit. | ||
|
This file contains 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 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 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
Oops, something went wrong.
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.
I'd probably write this as
for idx, row in reversed(enumerate(state_rows)):
or somethingThere 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.
you can't do
reversed(enumerate(...))
, because enumerate returns a generator.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.
Well that's tedious isn't it. Might be worth saying that we're walking backwards to find the last row of the set of rows with the second to last stream ID. Or something. But with better words. Mebs. 🤷♂️