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


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/restriction/PartitionRestrictionTracker.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.gcp.spanner.changestreams.restriction;
+
+import static 
org.apache.beam.sdk.io.gcp.spanner.changestreams.restriction.PartitionMode.DONE;
+import static 
org.apache.beam.sdk.io.gcp.spanner.changestreams.restriction.PartitionMode.STOP;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import com.google.cloud.Timestamp;
+import java.math.BigDecimal;
+import java.util.Optional;
+import java.util.function.Supplier;
+import org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker;
+import 
org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.HasProgress;
+import org.apache.beam.sdk.transforms.splittabledofn.SplitResult;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// TODO: Add java docs
+// TODO: Implement duration waiting for returning false on try claim
+public class PartitionRestrictionTracker
+    extends RestrictionTracker<PartitionRestriction, PartitionPosition> 
implements HasProgress {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(PartitionRestrictionTracker.class);
+  private final PartitionRestrictionSplitter splitter;
+  private final PartitionRestrictionClaimer claimer;
+  private final PartitionRestrictionProgressChecker progressChecker;
+  protected PartitionRestriction restriction;
+  private @Nullable PartitionPosition lastClaimedPosition;
+  protected Supplier<Timestamp> timeSupplier;
+
+  public PartitionRestrictionTracker(PartitionRestriction restriction) {
+    this(
+        restriction,
+        new PartitionRestrictionSplitter(),
+        new PartitionRestrictionClaimer(),
+        new PartitionRestrictionProgressChecker());
+  }
+
+  PartitionRestrictionTracker(
+      PartitionRestriction restriction,
+      PartitionRestrictionSplitter splitter,
+      PartitionRestrictionClaimer claimer,
+      PartitionRestrictionProgressChecker progressChecker) {
+    this.splitter = splitter;
+    this.claimer = claimer;
+    this.restriction = restriction;
+    this.progressChecker = progressChecker;
+    this.timeSupplier = () -> Timestamp.now();
+  }
+
+  @VisibleForTesting
+  public void setTimeSupplier(Supplier<Timestamp> timeSupplier) {
+    this.timeSupplier = timeSupplier;
+  }
+
+  @Override
+  public @Nullable SplitResult<PartitionRestriction> trySplit(double 
fractionOfRemainder) {

Review Comment:
   I did do this in the PartitionRestrictionSplitter class.



-- 
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-unsubscr...@beam.apache.org

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

Reply via email to