Github user kfirlevari commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/167#discussion_r100684324
--- Diff:
src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorConcurrencyTest.java
---
@@ -374,4 +372,52 @@ public void noStarvationOfReadRequestsTest() throws
Exception {
!processedRequests.contains(r));
}
}
+
+ /**
+ * In the following test, we verify that we can handle the case that
we got a commit
+ * of a request we never seen since the session that we just
established. This can happen
+ * when a session is just established and there is request waiting to
be commited in the
+ * in the session queue but it sees a commit for a request in the
previous connection
+ */
+ @Test(timeout = 1000)
+ public void noCrashOnCommittedRequestsOfUnSeenRequestTest() throws
Exception {
+ final String path =
"/noCrash/OnCommittedRequests/OfUnSeenRequestTest";
+ final int iteration = 10;
+ final int sessionid = 0x123456;
+ final int firstCXid = 0x100;
+ int readReqId = firstCXid;
+ processor.stoppedMainLoop = true;
+ HashSet<Request> localRequests = new HashSet<Request>();
+ // queue the blocking commit
+ Request firstCommittedReq = newRequest(
+ new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
+ CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
+ OpCode.create, sessionid, readReqId++);
+ processor.queuedRequests.add(firstCommittedReq);
+ localRequests.add(firstCommittedReq);
+ // queue read linkedRequest to queuedRequests
+ for (; readReqId <= iteration+firstCXid; ++readReqId) {
+ Request readReq = newRequest(new GetDataRequest(path, false),
+ OpCode.getData, sessionid, readReqId);
+ processor.queuedRequests.add(readReq);
+ localRequests.add(readReq);
+ }
+ //run once
+
Assert.assertTrue(processor.queuedRequests.containsAll(localRequests));
+ processor.initThreads(iteration* 2);
+ processor.run();
+ Assert.assertTrue(processedRequests.isEmpty());
+ // now we get a commit originated from another host that handles
this same session
+ // just before
+ Request preSessionCommittedReq = newRequest(
+ new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
+ CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
+ OpCode.create, sessionid, firstCXid - 2);
+ processor.committedRequests.add(preSessionCommittedReq);
+ processor.committedRequests.add(firstCommittedReq);
+ processor.run();
+ Assert.assertTrue(processedRequests.peek() ==
preSessionCommittedReq);
--- End diff --
It might be clearer if we change it a bit - only add the
preSessionCommittedReq, and after you that it was handled.
Then we add the following commit (i.e., firstCommittedReq), and verify that
the rest of the messages were processed (+ verify that they weren't processed
before firstCommittedReq was added).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---