Skip to content

Commit

Permalink
Better error message for large elements. (#30639)
Browse files Browse the repository at this point in the history
This will cause an exception when the too-large element is emitted,
rather than later when the proto is serialized (which happens on
another thread and may also cause spurious errors in the data channel
consumption).

---------

Co-authored-by: tvalentyn <[email protected]>
  • Loading branch information
robertwb and tvalentyn authored Mar 15, 2024
1 parent c298da5 commit 3aa78d2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdks/python/apache_beam/runners/worker/data_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

_DEFAULT_SIZE_FLUSH_THRESHOLD = 10 << 20 # 10MB
_DEFAULT_TIME_FLUSH_THRESHOLD_MS = 0 # disable time-based flush by default
_FLUSH_MAX_SIZE = (2 << 30) - 100 # 2GB less some overhead, protobuf/grpc limit

# Keep a set of completed instructions to discard late received data. The set
# can have up to _MAX_CLEANED_INSTRUCTIONS items. See _GrpcDataChannel.
Expand Down Expand Up @@ -147,6 +148,14 @@ def maybe_flush(self):
def flush(self):
# type: () -> None
if self._flush_callback:
if self.size() > _FLUSH_MAX_SIZE:
raise ValueError(
f'Buffer size {self.size()} exceeds GRPC limit {_FLUSH_MAX_SIZE}. '
'This is likely due to a single element that is too large. '
'To resolve, prefer multiple small elements over single large '
'elements in PCollections. If needed, store large blobs in '
'external storage systems, and use PCollections to pass their '
'metadata, or use a custom coder that reduces the element\'s size.')
self._flush_callback(self.get())
self._clear()

Expand Down

0 comments on commit 3aa78d2

Please sign in to comment.