@Override public int getGlobalOutstandingLimit() { return super.getGlobalOutstandingLimit() / (self.getQuorumSize() - 1); }
@Override protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException { super.revalidateSession(cnxn, sessionId, sessionTimeout); try { // setowner as the leader itself, unless updated // via the follower handlers setOwner(sessionId, ServerCnxn.me); } catch (SessionExpiredException e) { // this is ok, it just means that the session revalidation failed. } } }
@Override public synchronized void shutdown() { if (containerManager != null) { containerManager.stop(); } super.shutdown(); }
/** * Implements the SessionUpgrader interface, * * @param sessionId */ public void upgrade(long sessionId) { Request request = makeUpgradeRequest(sessionId); if (request != null) { LOG.info("Upgrading session 0x" + Long.toHexString(sessionId)); // This must be a global request submitRequest(request); } }
@Override public synchronized void startup() { super.startup(); if (containerManager != null) { containerManager.start(); } }
@Test public void testOnlyUpgradeSessionOnce() throws IOException, InterruptedException, KeeperException { // create a client, and create an ephemeral node to trigger the // upgrading process final String node = "/node-1"; ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0], ClientBase.CONNECTION_TIMEOUT, this); waitForOne(zk, States.CONNECTED); long sessionId = zk.getSessionId(); QuorumZooKeeperServer server = (QuorumZooKeeperServer) mt[0].main.quorumPeer.getActiveServer(); Request create1 = createEphemeralRequest("/data-1", sessionId); Request create2 = createEphemeralRequest("/data-2", sessionId); Assert.assertNotNull("failed to upgrade on a ephemeral create", server.checkUpgradeSession(create1)); Assert.assertNull("tried to upgrade again", server.checkUpgradeSession(create2)); // clean al the setups and close the zk zk.close(); }
return makeUpgradeRequest(request.sessionId);
@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<OpResult> 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())); }
@Override public synchronized void startup() { // check to avoid startup follows shutdown if (shutdown) { LOG.warn("Not starting Read-only server as startup follows shutdown!"); return; } registerJMX(new ReadOnlyBean(this), self.jmxLocalPeerBean); super.startup(); self.cnxnFactory.setZooKeeperServer(this); LOG.info("Read-only server started"); }
@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)); }
@Override protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException { super.revalidateSession(cnxn, sessionId, sessionTimeout); try { // setowner as the leader itself, unless updated // via the follower handlers setOwner(sessionId, ServerCnxn.me); } catch (SessionExpiredException e) { // this is ok, it just means that the session revalidation failed. } } }
@Override public int getGlobalOutstandingLimit() { int divisor = self.getQuorumSize() > 2 ? self.getQuorumSize() - 1 : 1; int globalOutstandingLimit = super.getGlobalOutstandingLimit() / divisor; LOG.info("Override {} to {}", GLOBAL_OUTSTANDING_LIMIT, globalOutstandingLimit); return globalOutstandingLimit; }
@Override public synchronized void shutdown() { if (!canShutdown()) { LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); return; } LOG.info("Shutting down"); try { super.shutdown(); } catch (Exception e) { LOG.warn("Ignoring unexpected exception during shutdown", e); } try { if (syncProcessor != null) { syncProcessor.shutdown(); } } catch (Exception e) { LOG.warn("Ignoring unexpected exception in syncprocessor shutdown", e); } } }
@Override protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException { if (upgradeableSessionTracker.isLocalSession(sessionId)) { super.revalidateSession(cnxn, sessionId, sessionTimeout); } else { getLearner().validateSession(cnxn, sessionId, sessionTimeout); } }
@Override public int getGlobalOutstandingLimit() { return super.getGlobalOutstandingLimit() / (self.getQuorumSize() - 1); }
@Override public synchronized void shutdown() { if (!canShutdown()) { LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); return; } shutdown = true; unregisterJMX(this); // set peer's server to null self.cnxnFactory.setZooKeeperServer(null); // clear all the connections self.cnxnFactory.closeAll(); // shutdown the server itself super.shutdown(); }
@Override protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException, InterruptedException { super.revalidateSession(cnxn, sessionId, sessionTimeout); try { // setowner as the leader itself, unless updated // via the follower handlers setOwner(sessionId, ServerCnxn.me); } catch (SessionExpiredException e) { // this is ok, it just means that the session revalidation failed. } } }