You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "nancyxu123 (via GitHub)" <gi...@apache.org> on 2023/03/04 01:29:00 UTC

[GitHub] [beam] nancyxu123 commented on a diff in pull request #25718: Optimize change stream connector with more efficient batching and blind writes, and add transaction/query tags

nancyxu123 commented on code in PR #25718:
URL: https://github.com/apache/beam/pull/25718#discussion_r1125196909


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerConfig.java:
##########
@@ -43,7 +43,7 @@ public abstract class SpannerConfig implements Serializable {
   // A default host name for batch traffic.
   private static final String DEFAULT_HOST = "https://batch-spanner.googleapis.com/";
   // Deadline for Commit API call.
-  private static final Duration DEFAULT_COMMIT_DEADLINE = Duration.standardSeconds(15);
+  private static final Duration DEFAULT_COMMIT_DEADLINE = Duration.standardSeconds(60);

Review Comment:
   I actually think we can override the commit deadline specifically only for metadata table writes here: https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/MetadataSpannerConfigFactory.java#L87
   
   We probably don't want to override the deadline for all Spanner commits.



##########
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:
   I think you could also call the clear() function?



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org