Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AC141200C27 for ; Sun, 12 Feb 2017 07:15:33 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AA5AF160B5D; Sun, 12 Feb 2017 06:15:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0682B160B5B for ; Sun, 12 Feb 2017 07:15:32 +0100 (CET) Received: (qmail 84487 invoked by uid 500); 12 Feb 2017 06:15:31 -0000 Mailing-List: contact dev-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list dev@zookeeper.apache.org Received: (qmail 84204 invoked by uid 99); 12 Feb 2017 06:15:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Feb 2017 06:15:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 98DBAF217A; Sun, 12 Feb 2017 06:15:30 +0000 (UTC) From: kfirlevari To: dev@zookeeper.apache.org Reply-To: dev@zookeeper.apache.org References: In-Reply-To: Subject: [GitHub] zookeeper pull request #167: commitProcessor does not crash when an unseen c... Content-Type: text/plain Message-Id: <20170212061530.98DBAF217A@git1-us-west.apache.org> Date: Sun, 12 Feb 2017 06:15:30 +0000 (UTC) archived-at: Sun, 12 Feb 2017 06:15:33 -0000 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 localRequests = new HashSet(); + // 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---