[ 
https://issues.apache.org/jira/browse/BEAM-11996?focusedWorklogId=599395&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-599395
 ]

ASF GitHub Bot logged work on BEAM-11996:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/May/21 18:36
            Start Date: 19/May/21 18:36
    Worklog Time Spent: 10m 
      Work Description: 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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 599395)
    Time Spent: 20m  (was: 10m)

> Implement SpannerIO on top of Splittable DoFn
> ---------------------------------------------
>
>                 Key: BEAM-11996
>                 URL: https://issues.apache.org/jira/browse/BEAM-11996
>             Project: Beam
>          Issue Type: Improvement
>          Components: io-java-gcp
>            Reporter: Boyuan Zhang
>            Assignee: Miguel Anzo
>            Priority: P2
>          Time Spent: 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to