From dev-return-73876-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Fri Sep 28 23:56:31 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id CE340180627 for ; Fri, 28 Sep 2018 23:56:30 +0200 (CEST) Received: (qmail 56131 invoked by uid 500); 28 Sep 2018 21:56:29 -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 56118 invoked by uid 99); 28 Sep 2018 21:56:29 -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; Fri, 28 Sep 2018 21:56:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 08D46E0514; Fri, 28 Sep 2018 21:56:29 +0000 (UTC) From: lvfangmin To: dev@zookeeper.apache.org Reply-To: dev@zookeeper.apache.org References: In-Reply-To: Subject: [GitHub] zookeeper pull request #647: ZOOKEEPER-3125: Fixing pzxid consistent issue w... Content-Type: text/plain Message-Id: <20180928215629.08D46E0514@git1-us-west.apache.org> Date: Fri, 28 Sep 2018 21:56:29 +0000 (UTC) Github user lvfangmin commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/647#discussion_r221390760 --- Diff: src/java/test/org/apache/zookeeper/server/quorum/FuzzySnapshotRelatedTest.java --- @@ -162,6 +167,98 @@ public void process(String path) { new String(zk[followerA].getData(node2, null, null))); } + /** + * It's possibel during SNAP sync, the parent is serialized before the + * child get deleted during sending the snapshot over. + * + * In which case, we need to make sure the pzxid get correctly updated + * when applying the txns received. + */ + @Test + public void testPZxidUpdatedDuringSnapSyncing() throws Exception { + LOG.info("Enable force snapshot sync"); + System.setProperty(LearnerHandler.FORCE_SNAP_SYNC, "true"); + + final String parent = "/testPZxidUpdatedWhenDeletingNonExistNode"; + final String child = parent + "/child"; + createEmptyNode(zk[leaderId], parent); + createEmptyNode(zk[leaderId], child); + + LOG.info("shutdown follower {}", followerA); + mt[followerA].shutdown(); + QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTING); + + LOG.info("Set up ZKDatabase to catch the node serializing in DataTree"); + addSerializeListener(leaderId, parent, child); + + LOG.info("Restart follower A to trigger a SNAP sync with leader"); + mt[followerA].start(); + QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTED); + + LOG.info("Check and make sure the pzxid of the parent is the same " + + "on leader and follower A"); + compareStat(parent, leaderId, followerA); + } + + /** + * It's possible during taking fuzzy snapshot, the parent is serialized + * before the child get deleted in the fuzzy range. + * + * In which case, we need to make sure the pzxid get correctly updated + * when replaying the txns. + */ + @Test + public void testPZxidUpdatedWhenLoadingSnapshot() throws Exception { + + final String parent = "/testPZxidUpdatedDuringTakingSnapshot"; + final String child = parent + "/child"; + createEmptyNode(zk[followerA], parent); + createEmptyNode(zk[followerA], child); + + LOG.info("Set up ZKDatabase to catch the node serializing in DataTree"); + addSerializeListener(followerA, parent, child); + + LOG.info("Take snapshot on follower A"); + ZooKeeperServer zkServer = mt[followerA].main.quorumPeer.getActiveServer(); + zkServer.takeSnapshot(); + + LOG.info("Restarting follower A to load snapshot"); + mt[followerA].shutdown(); + mt[followerA].start(); + QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTED); + + LOG.info("Check and make sure the pzxid of the parent is the same " + + "on leader and follower A"); + compareStat(parent, leaderId, followerA); + } + + private void addSerializeListener(int sid, String parent, String child) { + final ZooKeeper zkClient = zk[followerA]; + CustomDataTree dt = + (CustomDataTree) mt[sid].main.quorumPeer.getZkDb().getDataTree(); + dt.addListener(parent, new NodeSerializeListener() { + @Override + public void nodeSerialized(String path) { + try { + zkClient.delete(child, -1); + LOG.info("Deleted the child node after the parent is serialized"); + } catch (Exception e) { + LOG.error("Error when deleting node {}", e); + } + } + }); + } + + private void compareStat(String path, int sid, int compareWithSid) throws Exception { + Stat stat1 = new Stat(); + zk[sid].getData(path, null, stat1); + + Stat stat2 = new Stat(); + zk[compareWithSid].getData(path, null, stat2); --- End diff -- I made a comment on that before sending this diff out, I was trying to hear the opinion before making the test change here. Seems we agreed on not using RetryRule, I'll improve this test class. ---