ChangyuLi28 commented on code in PR #25718:
URL: https://github.com/apache/beam/pull/25718#discussion_r1126893247
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/action/DetectNewPartitionsAction.java:
##########
@@ -146,15 +146,22 @@ private ProcessContinuation schedulePartitions(
OutputReceiver<PartitionMetadata> receiver,
Timestamp minWatermark,
TreeMap<Timestamp, List<PartitionMetadata>> batches) {
+ List<PartitionMetadata> batchPartitionsDifferentCreatedAt = new
ArrayList<>();
+ int numTimestampsHandledSofar = 0;
for (Map.Entry<Timestamp, List<PartitionMetadata>> batch :
batches.entrySet()) {
+ numTimestampsHandledSofar++;
final Timestamp batchCreatedAt = batch.getKey();
- final List<PartitionMetadata> batchPartitions = batch.getValue();
-
- final Timestamp scheduledAt = updateBatchToScheduled(batchPartitions);
- if (!tracker.tryClaim(batchCreatedAt)) {
- return ProcessContinuation.stop();
+ final List<PartitionMetadata> batchPartitionsSameCreatedAt =
batch.getValue();
+ batchPartitionsDifferentCreatedAt.addAll(batchPartitionsSameCreatedAt);
+ if (batchPartitionsDifferentCreatedAt.size() >= 200
+ || numTimestampsHandledSofar == batches.size()) {
+ final Timestamp scheduledAt =
updateBatchToScheduled(batchPartitionsDifferentCreatedAt);
+ if (!tracker.tryClaim(batchCreatedAt)) {
+ return ProcessContinuation.stop();
+ }
+ outputBatch(receiver, minWatermark, batchPartitionsDifferentCreatedAt,
scheduledAt);
+ batchPartitionsDifferentCreatedAt = new ArrayList<>();
Review Comment:
Do you mean call batchPartitionsDifferentCreatedAt.clear() instead of
initializing a new ArrayList at line 163? I thought clear() has time complexity
O(n) while initialize new ArrayList has O(1) but clear() may be better from
other considerations. Let me know if you still prefer clear().
--
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]