Make it clear that the limit for an update_function is a target

This commit is contained in:
Richard van der Hoff 2020-04-23 15:45:12 +01:00
parent 23b28266ac
commit 9cbdfb3a2f
1 changed files with 9 additions and 5 deletions

View File

@ -24,8 +24,8 @@ from synapse.replication.http.streams import ReplicationGetStreamUpdates
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# the number of rows to request from an update_function.
MAX_EVENTS_BEHIND = 500000 _STREAM_UPDATE_TARGET_ROW_COUNT = 100
# Some type aliases to make things a bit easier. # Some type aliases to make things a bit easier.
@ -56,7 +56,11 @@ StreamUpdateResult = Tuple[List[Tuple[Token, StreamRow]], Token, bool]
# * from_token: the previous stream token: the starting point for fetching the # * from_token: the previous stream token: the starting point for fetching the
# updates # updates
# * to_token: the new stream token: the point to get updates up to # * to_token: the new stream token: the point to get updates up to
# * limit: the maximum number of rows to return # * target_row_count: a target for the number of rows to be returned.
#
# The update_function is expected to return up to _approximately_ target_row_count rows.
# If there are more updates available, it should set `limited` in the result, and
# it will be called again to get the next batch.
# #
UpdateFunction = Callable[[Token, Token, int], Awaitable[StreamUpdateResult]] UpdateFunction = Callable[[Token, Token, int], Awaitable[StreamUpdateResult]]
@ -138,7 +142,7 @@ class Stream(object):
return updates, current_token, limited return updates, current_token, limited
async def get_updates_since( async def get_updates_since(
self, from_token: Token, upto_token: Token, limit: int = 100 self, from_token: Token, upto_token: Token
) -> StreamUpdateResult: ) -> StreamUpdateResult:
"""Like get_updates except allows specifying from when we should """Like get_updates except allows specifying from when we should
stream updates stream updates
@ -156,7 +160,7 @@ class Stream(object):
return [], upto_token, False return [], upto_token, False
updates, upto_token, limited = await self.update_function( updates, upto_token, limited = await self.update_function(
from_token, upto_token, limit, from_token, upto_token, _STREAM_UPDATE_TARGET_ROW_COUNT,
) )
return updates, upto_token, limited return updates, upto_token, limited