github-actions[bot] commented on code in PR #41176:
URL: https://github.com/apache/beam/pull/41176#discussion_r4529245855
##########
sdks/python/apache_beam/runners/worker/operations.py:
##########
@@ -1222,16 +1223,23 @@ def finish(self):
def flush(self, target):
# type: (int) -> None
limit = self.size - target
- for ix, (kw, vs) in enumerate(list(self.table.items())):
+ if limit <= 0:
+ return
+ keys_to_delete = []
+ for ix, (kw, vs) in enumerate(self.table.items()):
if ix >= limit:
break
- del self.table[kw]
+ keys_to_delete.append(kw)
key, windows = kw
output_value = [v.value[1] for v in vs]
- windowed_value = WindowedValue((key, output_value),
- vs[0].timestamp,
- windows)
+ windowed_value = windowed_value_create((key, output_value),
+ vs[0].timestamp_micros,
+ windows,
+ vs[0].pane_info)
self.output(windowed_value)
+ for kw in keys_to_delete:
+ del self.table[kw]
+ self.size -= len(keys_to_delete)
Review Comment:
**🟠High**: `PGBKOperation.process` increments `self.size += 1` for every
incoming element, so `self.size` tracks the total number of buffered values
across all keys rather than the number of unique keys in `self.table`.
Decrementing `self.size` by `len(keys_to_delete)` (the number of evicted keys)
instead of the number of evicted elements (`sum(len(vs) ...)`), and comparing
the key index `ix` against `limit = self.size - target`, causes `self.size` to
under-decrement by `len(vs) - 1` whenever a flushed key has multiple values.
Over a bundle with duplicate keys, this leaked count accumulates in
`self.size` until `self.size > self.max_size` even when `self.table` is empty,
causing every subsequent `process()` call to invoke `flush()` and emit
ungrouped single-element lists. Similarly, if `self.size` is meants to track
element count, decrementing `self.size -= len(vs)` inside the loop (and
breaking once `self.size <= target`, or clearing `self.table.clear()` and
setting `self.size = 0` when `target <= 0`) keeps `self.size` accurate and
implements the in-place clear for full flushes mentioned in the PR description.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]