public synchronized void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException, KeeperException.UnknownSessionException { LOG.debug("Checking session 0x" + Long.toHexString(sessionId)); SessionImpl session = sessionsById.get(sessionId); if (session == null) { throw new KeeperException.UnknownSessionException(); } if (session.isClosing()) { throw new KeeperException.SessionExpiredException(); } if (session.owner == null) { session.owner = owner; } else if (session.owner != owner) { throw new KeeperException.SessionMovedException(); } }
public void checkSession(long sessionId, Object owner) throws SessionExpiredException, SessionMovedException { if (localSessionTracker != null) { try { localSessionTracker.checkSession(sessionId, owner); return; } catch (UnknownSessionException e) { // Check whether it's a global session. We can ignore those // because they are handled at the leader, but if not, rethrow. // We check local session status first to avoid race condition // with session upgrading. if (!isGlobalSession(sessionId)) { throw new SessionExpiredException(); } } } }
public void setOwner(long sessionId, Object owner) throws SessionExpiredException { if (localSessionTracker != null) { try { localSessionTracker.setOwner(sessionId, owner); return; } catch (SessionExpiredException e) { // Check whether it's a global session. We can ignore those // because they are handled at the leader, but if not, rethrow. // We check local session status first to avoid race condition // with session upgrading. if (!isGlobalSession(sessionId)) { throw e; } } } }
@Test public void testGetPartitionsMetadata() throws Exception { DestinationName topic1 = DestinationName.get("persistent://test/local/ns/my-topic-1"); PartitionedTopicMetadata m = service.getDiscoveryProvider().getPartitionedTopicMetadata(service, topic1, "role") .get(); assertEquals(m.partitions, 0); // Simulate ZK error mockZookKeeper.failNow(Code.SESSIONEXPIRED); DestinationName topic2 = DestinationName.get("persistent://test/local/ns/my-topic-2"); CompletableFuture<PartitionedTopicMetadata> future = service.getDiscoveryProvider() .getPartitionedTopicMetadata(service, topic2, "role"); try { future.get(); fail("Partition metadata lookup should have failed"); } catch (ExecutionException e) { assertEquals(e.getCause().getClass(), SessionExpiredException.class); } }
synchronized public void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException { SessionImpl session = sessionsById.get(sessionId); if (session == null || session.isClosing()) { throw new KeeperException.SessionExpiredException(); } if (session.owner == null) { session.owner = owner; } else if (session.owner != owner) { throw new KeeperException.SessionMovedException(); } }
synchronized public void setOwner(long id, Object owner) throws SessionExpiredException { SessionImpl session = sessionsById.get(id); if (session == null || session.isClosing()) { throw new KeeperException.SessionExpiredException(); } session.owner = owner; }
@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. } }
public void checkGlobalSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException { try { checkSession(sessionId, owner); } catch (KeeperException.UnknownSessionException e) { throw new KeeperException.SessionExpiredException(); } }
public void checkGlobalSession(long sessionId, Object owner) throws SessionExpiredException, SessionMovedException { try { globalSessionTracker.checkSession(sessionId, owner); } catch (UnknownSessionException e) { // For global session, if we don't know it, it is already expired throw new SessionExpiredException(); } }
public void setOwner(long sessionId, Object owner) throws SessionExpiredException { if (localSessionTracker != null) { try { localSessionTracker.setOwner(sessionId, owner); return; } catch(SessionExpiredException e) { // Ignore. We'll check instead whether it's a global session } } globalSessionTracker.setOwner(sessionId, owner); }
/** * A private method used to re-establish a zookeeper session with a peer cluster. * @param ke */ protected void reconnect(KeeperException ke) { if (ke instanceof ConnectionLossException || ke instanceof SessionExpiredException || ke instanceof AuthFailedException) { String clusterKey = ctx.getPeerConfig().getClusterKey(); LOG.warn("Lost the ZooKeeper connection for peer " + clusterKey, ke); try { reloadZkWatcher(); } catch (IOException io) { LOG.warn("Creation of ZookeeperWatcher failed for peer " + clusterKey, io); } } }
synchronized public void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException { SessionImpl session = sessionsById.get(sessionId); if (session == null) { throw new KeeperException.SessionExpiredException(); } if (session.owner == null) { session.owner = owner; } else if (session.owner != owner) { throw new KeeperException.SessionMovedException(); } }
synchronized public void setOwner(long id, Object owner) throws SessionExpiredException { SessionImpl session = sessionsById.get(id); if (session == null) { throw new KeeperException.SessionExpiredException(); } session.owner = owner; }