public void terminateSession() { try { zk.closeSession(sessionId); } catch (Exception e) { LOG.warn("Unable to closeSession() for session: 0x" + getSessionId(), e); } }
public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) { closeSession(cnxn.getSessionId()); }
public void terminateSession() { try { zk.closeSession(sessionId); } catch (Exception e) { LOG.warn("Unable to closeSession() for session: 0x" + getSessionId(), e); } }
public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) { closeSession(cnxn.getSessionId()); }
@Test public void testSessionExpire() throws Exception { assertArrayEquals(DATA, RO_ZK.get(PATH).get()); ZooKeeper zk = RO_ZK.zookeeper; long sessionId = zk.getSessionId(); UTIL.getZkCluster().getZooKeeperServers().get(0).closeSession(sessionId); // should not reach keep alive so still the same instance assertSame(zk, RO_ZK.zookeeper); byte[] got = RO_ZK.get(PATH).get(); assertArrayEquals(DATA, got); assertNotNull(RO_ZK.zookeeper); assertNotSame(zk, RO_ZK.zookeeper); assertNotEquals(sessionId, RO_ZK.zookeeper.getSessionId()); }
public static void expireSession(long sessionId){ server.closeSession(sessionId); }
public void terminateSession() { try { zk.closeSession(sessionId); } catch (Exception e) { LOG.warn("Unable to closeSession() for session: 0x" + getSessionId(), e); } }
public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) { closeSession(cnxn.getSessionId()); }
/** * Expires the active session for the given client. The client should be one returned from * {@link #createClient}. * * @param zkClient the client to expire * @throws ZooKeeperClient.ZooKeeperConnectionException if a problem is encountered connecting to * the local zk server while trying to expire the session * @throws InterruptedException if interrupted while requesting expiration */ public final void expireClientSession(ZooKeeperClient zkClient) throws ZooKeeperClient.ZooKeeperConnectionException, InterruptedException { zooKeeperServer.closeSession(zkClient.get().getSessionId()); }
/** * Expire the ZK session of the given service. This requires * (and asserts) that the given service be the current active. * @throws NoNodeException if no service holds the lock */ public void expireActiveLockHolder(int idx) throws NoNodeException { Stat stat = new Stat(); byte[] data = zks.getZKDatabase().getData( DummyZKFC.LOCK_ZNODE, stat, null); assertArrayEquals(Ints.toByteArray(svcs[idx].index), data); long session = stat.getEphemeralOwner(); LOG.info("Expiring svc " + idx + "'s zookeeper session " + session); zks.closeSession(session); }
/** * Expire the ZK session of the given service. This requires * (and asserts) that the given service be the current active. * @throws NoNodeException if no service holds the lock */ public void expireActiveLockHolder(int idx) throws NoNodeException { Stat stat = new Stat(); byte[] data = zks.getZKDatabase().getData( DummyZKFC.LOCK_ZNODE, stat, null); assertArrayEquals(Ints.toByteArray(svcs[idx].index), data); long session = stat.getEphemeralOwner(); LOG.info("Expiring svc " + idx + "'s zookeeper session " + session); zks.closeSession(session); }
/** * Randomly expire the ZK sessions of the two ZKFCs. This differs * from the above test in that it is not a controlled failover - * we just do random expirations and expect neither one to ever * generate fatal exceptions. */ @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000) public void testRandomExpirations() throws Exception { cluster.start(); long st = Time.now(); long runFor = STRESS_RUNTIME_SECS * 1000; Random r = new Random(); while (Time.now() - st < runFor) { cluster.getTestContext().checkException(); int targetIdx = r.nextInt(2); ActiveStandbyElector target = cluster.getElector(targetIdx); long sessId = target.getZKSessionIdForTests(); if (sessId != -1) { LOG.info(String.format("Expiring session %x for svc %d", sessId, targetIdx)); getServer(serverFactory).closeSession(sessId); } Thread.sleep(r.nextInt(300)); } }
/** * Randomly expire the ZK sessions of the two ZKFCs. This differs * from the above test in that it is not a controlled failover - * we just do random expirations and expect neither one to ever * generate fatal exceptions. */ @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000) public void testRandomExpirations() throws Exception { cluster.start(); long st = Time.now(); long runFor = STRESS_RUNTIME_SECS * 1000; Random r = new Random(); while (Time.now() - st < runFor) { cluster.getTestContext().checkException(); int targetIdx = r.nextInt(2); ActiveStandbyElector target = cluster.getElector(targetIdx); long sessId = target.getZKSessionIdForTests(); if (sessId != -1) { LOG.info(String.format("Expiring session %x for svc %d", sessId, targetIdx)); getServer(serverFactory).closeSession(sessId); } Thread.sleep(r.nextInt(300)); } }
@Test public void testSessionExpire() throws Exception { assertArrayEquals(DATA, RO_ZK.get(PATH).get()); ZooKeeper zk = RO_ZK.zookeeper; long sessionId = zk.getSessionId(); UTIL.getZkCluster().getZooKeeperServers().get(0).closeSession(sessionId); // should not reach keep alive so still the same instance assertSame(zk, RO_ZK.zookeeper); byte[] got = RO_ZK.get(PATH).get(); assertArrayEquals(DATA, got); assertNotNull(RO_ZK.zookeeper); assertNotSame(zk, RO_ZK.zookeeper); assertNotEquals(sessionId, RO_ZK.zookeeper.getSessionId()); }
@Test public void testSessionExpire() throws Exception { assertArrayEquals(DATA, RO_ZK.get(PATH).get()); ZooKeeper zk = RO_ZK.zookeeper; long sessionId = zk.getSessionId(); UTIL.getZkCluster().getZooKeeperServers().get(0).closeSession(sessionId); // should not reach keep alive so still the same instance assertSame(zk, RO_ZK.zookeeper); byte[] got = RO_ZK.get(PATH).get(); assertArrayEquals(DATA, got); assertNotNull(RO_ZK.zookeeper); assertNotSame(zk, RO_ZK.zookeeper); assertNotEquals(sessionId, RO_ZK.zookeeper.getSessionId()); }
zks.closeSession(elector.getZKSessionIdForTests());
zks.closeSession(elector.getZKSessionIdForTests());
zks.closeSession(electors[1].getZKSessionIdForTests());
zks.closeSession(electors[1].getZKSessionIdForTests());
zkServer.closeSession(electors[1].getZKSessionIdForTests()); zkServer.closeSession(electors[0].getZKSessionIdForTests());