xinyuiscool commented on a change in pull request #1164: [WIP] Transactional 
State [5/5]: Added implementations for transactional state checkpoints and 
restore
URL: https://github.com/apache/samza/pull/1164#discussion_r331578548
 
 

 ##########
 File path: 
samza-api/src/main/java/org/apache/samza/system/ChangelogSSPIterator.java
 ##########
 @@ -0,0 +1,100 @@
+/*
+ * 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.samza.system;
+
+import java.util.ArrayDeque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+import java.util.Set;
+import org.apache.samza.SamzaException;
+
+public class ChangelogSSPIterator {
+  public enum Mode {
+    RESTORE,
+    TRIM
+  }
+
+  private final SystemConsumer systemConsumer;
+  private final String endOffset;
+  private final SystemAdmin admin;
+  private final Set<SystemStreamPartition> fetchSet;
+  private final boolean trimEnabled;
+  private Queue<IncomingMessageEnvelope> peeks;
+  private Mode mode = Mode.RESTORE;
+
+  // endOffset is inclusive when restoring. endOffset == null means trim from 
staring offset to head.
+  public ChangelogSSPIterator(SystemConsumer systemConsumer,
+      SystemStreamPartition systemStreamPartition, String endOffset, 
SystemAdmin admin, boolean trimEnabled) {
+    this.systemConsumer = systemConsumer;
+    this.endOffset = endOffset;
+    this.trimEnabled = trimEnabled;
+    if (this.trimEnabled && endOffset == null) {
+      mode = Mode.TRIM;
+    }
+    this.admin = admin;
+    this.fetchSet = new HashSet<>();
+    this.fetchSet.add(systemStreamPartition);
+    this.peeks = new ArrayDeque<>();
+  }
+
+  public boolean hasNext() {
+    refresh();
+
+    return peeks.size() > 0;
+  }
+
+  public IncomingMessageEnvelope next() {
+    refresh();
+
+    if (peeks.size() == 0) {
+      throw new NoSuchElementException();
+    }
+
+    IncomingMessageEnvelope envelope = peeks.poll();
+
+    if (this.trimEnabled && (endOffset == null || 
admin.offsetComparator(envelope.getOffset(), endOffset) > 0)) {
 
 Review comment:
   Can you add a comment in this line to explain that the condition is?

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


With regards,
Apache Git Services

Reply via email to