You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by arshadmohammad <gi...@git.apache.org> on 2016/11/21 18:59:31 UTC

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

GitHub user arshadmohammad opened a pull request:

    https://github.com/apache/zookeeper/pull/112

    ZOOKEEPER-2355:Ephemeral node is never deleted if follower fails while reading the proposal packet

    ZOOKEEPER-2355:Ephemeral node is never deleted if follower fails while reading the proposal packet

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/arshadmohammad/zookeeper ZOOKEEPER-2355

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/zookeeper/pull/112.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #112
    
----
commit e8b2b59758c755afedfec8d6ab87d3f7ca0a0ffe
Author: arshadmohammad <ar...@gmail.com>
Date:   2016-11-21T18:29:33Z

    Ephemeral node is never deleted if follower fails while reading the proposal packet

----


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

[GitHub] zookeeper issue #112: ZOOKEEPER-2355:Ephemeral node is never deleted if foll...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/112
  
    @rakeshadr Thanks for double check. Followed your suggestion created ZOOKEEPER-2833 tracking the optimization work. I am merging this now.


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

[GitHub] zookeeper issue #112: ZOOKEEPER-2355:Ephemeral node is never deleted if foll...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/112
  
    If no objection I will commit this one soon given the interests and criticality of the fix.


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

[GitHub] zookeeper issue #112: ZOOKEEPER-2355:Ephemeral node is never deleted if foll...

Posted by rakeshadr <gi...@git.apache.org>.
Github user rakeshadr commented on the issue:

    https://github.com/apache/zookeeper/pull/112
  
    Thanks Michael for pushing this long standing issue.
    
    +1 from me, I'm OK to commit this patch after creating an issue for the code changes suggested previously.


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

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/zookeeper/pull/112


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

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

Posted by rakeshadr <gi...@git.apache.org>.
Github user rakeshadr commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/112#discussion_r125264767
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/Learner.java ---
    @@ -390,6 +391,7 @@ else if (qp.getType() == Leader.SNAP) {
                                 + Long.toHexString(qp.getZxid()));
                         System.exit(13);
                     }
    +                zk.getZKDatabase().setlastProcessedZxid(qp.getZxid());
    --- End diff --
    
    @hanm, Do we have any issue created to handle this case, if not please create one for tracking this change. Thanks!


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

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

Posted by JiangJiafu <gi...@git.apache.org>.
Github user JiangJiafu commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/112#discussion_r121320033
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/EphemeralNodeDeletionTest.java ---
    @@ -0,0 +1,222 @@
    +/**
    + * 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.zookeeper.server.quorum;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertNotNull;
    +import static org.junit.Assert.assertNull;
    +
    +import java.io.IOException;
    +import java.net.SocketTimeoutException;
    +
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.ZooDefs.Ids;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.data.Stat;
    +import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
    +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
    +import org.junit.After;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +public class EphemeralNodeDeletionTest extends QuorumPeerTestBase {
    +    private static int SERVER_COUNT = 3;
    +    private MainThread[] mt = new MainThread[SERVER_COUNT];
    +
    +    /**
    +     * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2355.
    +     * ZooKeeper ephemeral node is never deleted if follower fail while reading
    +     * the proposal packet.
    +     */
    +
    +    @Test(timeout = 120000)
    +    public void testEphemeralNodeDeletion() throws Exception {
    +        final int clientPorts[] = new int[SERVER_COUNT];
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            clientPorts[i] = PortAssignment.unique();
    +            server = "server." + i + "=127.0.0.1:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;127.0.0.1:"
    +                    + clientPorts[i];
    +            sb.append(server + "\n");
    +        }
    +        String currentQuorumCfgSection = sb.toString();
    +        // start all the servers
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection,
    +                    false) {
    +                @Override
    +                public TestQPMain getTestQPMain() {
    +                    return new MockTestQPMain();
    +                }
    +            };
    +            mt[i].start();
    +        }
    +
    +        // ensure all servers started
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        CountdownWatcher watch = new CountdownWatcher();
    +        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[1],
    +                ClientBase.CONNECTION_TIMEOUT, watch);
    +        watch.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    +
    +        /**
    +         * now the problem scenario starts
    +         */
    +
    +        Stat firstEphemeralNode = new Stat();
    +
    +        // 1: create ephemeral node
    +        String nodePath = "/e1";
    +        zk.create(nodePath, "1".getBytes(), Ids.OPEN_ACL_UNSAFE,
    +                CreateMode.EPHEMERAL, firstEphemeralNode);
    +        assertEquals("Current session and ephemeral owner should be same",
    +                zk.getSessionId(), firstEphemeralNode.getEphemeralOwner());
    +
    +        // 2: inject network problem in one of the follower
    +        CustomQuorumPeer follower = (CustomQuorumPeer) getByServerState(mt,
    +                ServerState.FOLLOWING);
    +        follower.setInjectError(true);
    +
    +        // 3: close the session so that ephemeral node is deleted
    +        zk.close();
    +
    --- End diff --
    
    Can this code make sure that the problem scenario happen again? 
    When zk.close() is called, the leader should send closeSession request to all followers, since the error is injected, readPacket of the follower will throw an exception, which cause the follower to exist and begin to look for new leader.
    Is there any chance that the before the follower.setInjectError(false) is called bebofe makeFollower() is called? If the answer is yes, then the problem scenario does not happen. According to the patch, the problem will happen when follower fails to sync with leader while the peerLastZxid is updated to a new one.
    
    I am not sure about this, I hope I'm wrong.


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

[GitHub] zookeeper issue #112: ZOOKEEPER-2355:Ephemeral node is never deleted if foll...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/112
  
    lgtm overall, with one nit on a potential optimization we can do and one potential improvement on test case. 


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

[GitHub] zookeeper issue #112: ZOOKEEPER-2355:Ephemeral node is never deleted if foll...

Posted by rakeshadr <gi...@git.apache.org>.
Github user rakeshadr commented on the issue:

    https://github.com/apache/zookeeper/pull/112
  
    @hanm, Thanks for the heads up. I will give my feedback soon, in a day or two.


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

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/112#discussion_r121793647
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/Learner.java ---
    @@ -390,6 +391,7 @@ else if (qp.getType() == Leader.SNAP) {
                                 + Long.toHexString(qp.getZxid()));
                         System.exit(13);
                     }
    +                zk.getZKDatabase().setlastProcessedZxid(qp.getZxid());
    --- End diff --
    
    The fix looks good to me.
    
    I think we should also set the zxid extracted from the current proposal packet after each proposal is [committed](https://github.com/arshadmohammad/zookeeper/blob/master/src/java/main/org/apache/zookeeper/server/quorum/Learner.java#L460). Otherwise the follower will have a lagged view of the committed transactions, because with the fix in this patch, we will never do setlastProcessedZxid during a DIFF sync. For example imagine a case like this:
    * Follower has its latest zxid with value a before DIFF SYNC happens.
    * Leader send over proposals with zxids value b, c, d. 
    * Follower received and applied proposals b and c. Before follower had a chance to get hands on d, network partition happens.
    * Now partition healed, follower will do a DIFF think again. Because the zk database would not be reloaded from logs (it's already initialized), follower has a skewed view of the world - it thinks it only has tnx a, but in fact it has a, b, and c. So rather asking b, c, and d, the follower could just ask d.
    
    Anyway I think it is an optimization that might worth doing - it is not functional critical because the idempotent nature of applying transactions.


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

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/112#discussion_r125391857
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/Learner.java ---
    @@ -390,6 +391,7 @@ else if (qp.getType() == Leader.SNAP) {
                                 + Long.toHexString(qp.getZxid()));
                         System.exit(13);
                     }
    +                zk.getZKDatabase().setlastProcessedZxid(qp.getZxid());
    --- End diff --
    
    @rakeshadr Created https://issues.apache.org/jira/browse/ZOOKEEPER-2833 to avoid this gets lost.


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

[GitHub] zookeeper pull request #112: ZOOKEEPER-2355:Ephemeral node is never deleted ...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/112#discussion_r121795494
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/EphemeralNodeDeletionTest.java ---
    @@ -0,0 +1,222 @@
    +/**
    + * 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.zookeeper.server.quorum;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertNotNull;
    +import static org.junit.Assert.assertNull;
    +
    +import java.io.IOException;
    +import java.net.SocketTimeoutException;
    +
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.ZooDefs.Ids;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.data.Stat;
    +import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
    +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
    +import org.junit.After;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +public class EphemeralNodeDeletionTest extends QuorumPeerTestBase {
    +    private static int SERVER_COUNT = 3;
    +    private MainThread[] mt = new MainThread[SERVER_COUNT];
    +
    +    /**
    +     * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2355.
    +     * ZooKeeper ephemeral node is never deleted if follower fail while reading
    +     * the proposal packet.
    +     */
    +
    +    @Test(timeout = 120000)
    +    public void testEphemeralNodeDeletion() throws Exception {
    +        final int clientPorts[] = new int[SERVER_COUNT];
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            clientPorts[i] = PortAssignment.unique();
    +            server = "server." + i + "=127.0.0.1:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;127.0.0.1:"
    +                    + clientPorts[i];
    +            sb.append(server + "\n");
    +        }
    +        String currentQuorumCfgSection = sb.toString();
    +        // start all the servers
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection,
    +                    false) {
    +                @Override
    +                public TestQPMain getTestQPMain() {
    +                    return new MockTestQPMain();
    +                }
    +            };
    +            mt[i].start();
    +        }
    +
    +        // ensure all servers started
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        CountdownWatcher watch = new CountdownWatcher();
    +        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[1],
    +                ClientBase.CONNECTION_TIMEOUT, watch);
    +        watch.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    +
    +        /**
    +         * now the problem scenario starts
    +         */
    +
    +        Stat firstEphemeralNode = new Stat();
    +
    +        // 1: create ephemeral node
    +        String nodePath = "/e1";
    +        zk.create(nodePath, "1".getBytes(), Ids.OPEN_ACL_UNSAFE,
    +                CreateMode.EPHEMERAL, firstEphemeralNode);
    +        assertEquals("Current session and ephemeral owner should be same",
    +                zk.getSessionId(), firstEphemeralNode.getEphemeralOwner());
    +
    +        // 2: inject network problem in one of the follower
    +        CustomQuorumPeer follower = (CustomQuorumPeer) getByServerState(mt,
    +                ServerState.FOLLOWING);
    +        follower.setInjectError(true);
    +
    +        // 3: close the session so that ephemeral node is deleted
    +        zk.close();
    +
    --- End diff --
    
    Yes the test case depends on these happened between starting of the partition (injected fault) and ending of the partition. The key invariant I see here is to make sure that during this period, the follower that currently disconnected with the quorum has gone through at least one leader election cycle and also have gone through at least one SYNC cycle. Otherwise the code path that this patch fixes will not be executed - i.e. there will be no errors during syncing the DIFF and everything will just work as expected. We need trigger at least one fault during the first DIFF sync cycle, and currently the test case is not doing this in a fine grained way and potentially due to timing issue we can get flaky behavior.
    
    Though, I am not sure how to precisely control this - I think it will be a nice improvement in test case to explicitly control the behavior as i just said, but this should not block this patch landed.


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