boyuanzz commented on a change in pull request #14811:
URL: https://github.com/apache/beam/pull/14811#discussion_r635492915



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/BatchSpannerRead.java
##########
@@ -104,15 +98,31 @@ public void teardown() throws Exception {
     }
 
     @ProcessElement
-    public void processElement(ProcessContext c) throws Exception {
+    public void processElement(ProcessContext c, 
RestrictionTracker<OffsetRange, Long> tracker)
+        throws Exception {
       Transaction tx = c.sideInput(txView);
       BatchReadOnlyTransaction context =
           
spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId());
-      for (Partition p : execute(c.element(), context)) {
-        c.output(p);
+      List<Partition> partitions = execute(c.element(), context);
+      BatchReadOnlyTransaction batchTx =
+          
spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId());
+      for (int i = (int) tracker.currentRestriction().getFrom(); i < 
partitions.size(); i++) {
+        if (tracker.tryClaim(Long.valueOf(i))) {
+          try (ResultSet resultSet = batchTx.execute(partitions.get(i))) {
+            while (resultSet.next()) {
+              Struct s = resultSet.getCurrentRowAsStruct();
+              c.output(s);
+            }
+          }
+        }
       }
     }
 
+    @GetInitialRestriction
+    public OffsetRange getInitialRange() {
+      return new OffsetRange(0L, Long.MAX_VALUE);

Review comment:
       The `Last attempted offset was 0 in range [0, 9223372036854775807), 
claiming work in [1, 9223372036854775807) was not attempted.` failure from your 
email is a `checkDone` failure from 
https://github.com/apache/beam/blob/a16bbf78bb5b3d3a14d13fb39ed442c612d0b493/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/splittabledofn/OffsetRangeTracker.java#L109-L124
 
   
   By default, your code will use 
[OffsetRangeTracker](https://github.com/apache/beam/blob/a16bbf78bb5b3d3a14d13fb39ed442c612d0b493/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/splittabledofn/OffsetRangeTracker.java),
 which treats `Long.MAX_VALUE` as the real amount of work. You may want to look 
into 
[GrowableOffsetRangeTracker](https://github.com/apache/beam/blob/a16bbf78bb5b3d3a14d13fb39ed442c612d0b493/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/splittabledofn/GrowableOffsetRangeTracker.java)
 which treats `Long.MAX_VALUE` as a notion of unknown amount of work.




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to