hanm commented on a change in pull request #1172: ZOOKEEPER-3594: Ability to 
skip proposing requests with error transactions
URL: https://github.com/apache/zookeeper/pull/1172#discussion_r360630789
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/SkippedRequestQueue.java
 ##########
 @@ -0,0 +1,78 @@
+package org.apache.zookeeper.server.quorum;
+
+import org.apache.zookeeper.server.ExitCode;
+import org.apache.zookeeper.server.Request;
+import org.apache.zookeeper.server.ServerMetrics;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SkippedRequestQueue {
+    private static final Logger LOG = 
LoggerFactory.getLogger(SkippedRequestQueue.class);
+
+    private final AtomicLong lastCommitted = new AtomicLong(-1);
+    private final LinkedBlockingQueue<Request> waitingRequests = new 
LinkedBlockingQueue<>();
+
+    /**
+     * Setter method for lastCommitted zxid
+     */
+    public void setLastCommitted(long zxid) {
+        lastCommitted.set(zxid);
+    }
+
+    public List<Request> setLastCommittedAndGet(long zxid) {
+        synchronized (this) {
+            setLastCommitted(zxid);
+            return getSkippedRequests();
+        }
+    }
+
+    /**
+     * Adds skipped request to the end of the queue that way we ensure the 
order.
+     * Returns all the skipped requests that are ready to be sent back to the 
origin,
+     * meaning if there was a COMMIT that they were waiting for
+     */
+    public List<Request> addAndGet(Request request) {
+        ServerMetrics.getMetrics().QUORUM_PEER_SKIP_QUEUE_SIZE.add(1);
+        synchronized (this) {
+            waitingRequests.add(request);
+            return getSkippedRequests();
+        }
+    }
+
+    /**
+     * This method flushed the error request queue. This method gets called 
from two different
+     * threads thorough skipProposing() and 
updateLastZxidAndGetSkippedRequests().
 
 Review comment:
   where is this `updateLastZxidAndGetSkippedRequests ` method defined? I 
couldn't find it in code base.

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