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 B7275200C3E for ; Tue, 21 Mar 2017 16:45:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B5C37160B74; Tue, 21 Mar 2017 15:45:49 +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 E00BC160B68 for ; Tue, 21 Mar 2017 16:45:48 +0100 (CET) Received: (qmail 59524 invoked by uid 500); 21 Mar 2017 15:45:48 -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 59513 invoked by uid 99); 21 Mar 2017 15:45:48 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Mar 2017 15:45:48 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 9C05BC0370 for ; Tue, 21 Mar 2017 15:45:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -98.548 X-Spam-Level: X-Spam-Status: No, score=-98.548 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652, URIBL_BLOCKED=0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id wx31p1gHmlMY for ; Tue, 21 Mar 2017 15:45:45 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 682925FB40 for ; Tue, 21 Mar 2017 15:45:45 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4E362E05CE for ; Tue, 21 Mar 2017 15:45:43 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 38202254D3 for ; Tue, 21 Mar 2017 15:45:42 +0000 (UTC) Date: Tue, 21 Mar 2017 15:45:42 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@zookeeper.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (ZOOKEEPER-2725) Upgrading to a global session fails with a multiop MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 21 Mar 2017 15:45:49 -0000 [ https://issues.apache.org/jira/browse/ZOOKEEPER-2725?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15934781#comment-15934781 ] ASF GitHub Bot commented on ZOOKEEPER-2725: ------------------------------------------- Github user enixon commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/195#discussion_r107191973 --- Diff: src/java/test/org/apache/zookeeper/server/MultiOpSessionUpgradeTest.java --- @@ -0,0 +1,135 @@ +/** + * 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; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.OpResult; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.GetDataRequest; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumZooKeeperServer; +import org.apache.zookeeper.server.quorum.UpgradeableSessionTracker; +import org.apache.zookeeper.test.QuorumBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MultiOpSessionUpgradeTest extends QuorumBase { + protected static final Logger LOG = LoggerFactory.getLogger(MultiOpSessionUpgradeTest.class); + + @Override + public void setUp() throws Exception { + localSessionsEnabled = true; + localSessionsUpgradingEnabled = true; + super.setUp(); + } + + @Test + public void ephemeralCreateMultiOpTest() throws KeeperException, InterruptedException, IOException { + final ZooKeeper zk = createClient(); + + String data = "test"; + String path = "/ephemeralcreatemultiop"; + zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId()); + Assert.assertNotNull("unable to find server interlocutor", server); + UpgradeableSessionTracker sessionTracker = (UpgradeableSessionTracker)server.getSessionTracker(); + Assert.assertFalse("session already global", sessionTracker.isGlobalSession(zk.getSessionId())); + + List multi = null; + try { + multi = zk.multi(Arrays.asList( + Op.setData(path, data.getBytes(), 0), + Op.create(path + "/e", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL), + Op.create(path + "/p", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create(path + "/q", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL) + )); + } catch (KeeperException.SessionExpiredException e) { + // the scenario that inspired this unit test + Assert.fail("received session expired for a session promotion in a multi-op"); + } + + Assert.assertNotNull(multi); + Assert.assertEquals(4, multi.size()); + Assert.assertEquals(data, new String(zk.getData(path + "/e", false, null))); + Assert.assertEquals(data, new String(zk.getData(path + "/p", false, null))); + Assert.assertEquals(data, new String(zk.getData(path + "/q", false, null))); + Assert.assertTrue("session not promoted", sessionTracker.isGlobalSession(zk.getSessionId())); + } + + @Test + public void directCheckUpgradeSessionTest() throws IOException, InterruptedException, KeeperException { + final ZooKeeper zk = createClient(); + + String path = "/directcheckupgradesession"; + zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId()); + Assert.assertNotNull("unable to find server interlocutor", server); + + Request readRequest = makeGetDataRequest(path, zk.getSessionId()); + Request createRequest = makeCreateRequest(path + "/e", zk.getSessionId()); + Assert.assertNull("tried to upgrade on a read", server.checkUpgradeSession(readRequest)); + Assert.assertNotNull("failed to upgrade on a create", server.checkUpgradeSession(createRequest)); + Assert.assertNull("tried to upgrade after successful promotion", + server.checkUpgradeSession(createRequest)); + } + + private Request makeGetDataRequest(String path, long sessionId) throws IOException { + ByteArrayOutputStream boas = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas); + GetDataRequest getDataRequest = new GetDataRequest(path, false); + getDataRequest.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray()); + return new Request(null, sessionId, 1, ZooDefs.OpCode.getData, bb, new ArrayList<>()); --- End diff -- Can't believe I missed those - something about them was bothering me about those lines when I was preparing the commit too. Will fix. > Upgrading to a global session fails with a multiop > -------------------------------------------------- > > Key: ZOOKEEPER-2725 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2725 > Project: ZooKeeper > Issue Type: Bug > Components: server > Affects Versions: 3.5.2 > Reporter: Brian Nixon > > On an ensemble with local sessions enabled, when a client with a local session requests the creation of an ephemeral node within a multi-op, the client gets a session expired message. The same multi-op works if the session is already global. This breaks the client's expectation of seamless promotion from local session to global session server-side. -- This message was sent by Atlassian JIRA (v6.3.15#6346)