Search in sources :

Example 1 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.

the class ZkController method getLeaderInitiatedRecoveryStateObject.

public Map<String, Object> getLeaderInitiatedRecoveryStateObject(String collection, String shardId, String coreNodeName) {
    if (collection == null || shardId == null || coreNodeName == null)
        // if we don't have complete data about a core in cloud mode, return null
        return null;
    String znodePath = getLeaderInitiatedRecoveryZnodePath(collection, shardId, coreNodeName);
    byte[] stateData = null;
    try {
        stateData = zkClient.getData(znodePath, null, new Stat(), false);
    } catch (NoNodeException ignoreMe) {
    // safe to ignore as this znode will only exist if the leader initiated recovery
    } catch (ConnectionLossException | SessionExpiredException cle) {
        // sort of safe to ignore ??? Usually these are seen when the core is going down
        // or there are bigger issues to deal with than reading this znode
        log.warn("Unable to read " + znodePath + " due to: " + cle);
    } catch (Exception exc) {
        log.error("Failed to read data from znode " + znodePath + " due to: " + exc);
        if (exc instanceof SolrException) {
            throw (SolrException) exc;
        } else {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Failed to read data from znodePath: " + znodePath, exc);
        }
    }
    Map<String, Object> stateObj = null;
    if (stateData != null && stateData.length > 0) {
        // TODO: Remove later ... this is for upgrading from 4.8.x to 4.10.3 (see: SOLR-6732)
        if (stateData[0] == (byte) '{') {
            Object parsedJson = Utils.fromJSON(stateData);
            if (parsedJson instanceof Map) {
                stateObj = (Map<String, Object>) parsedJson;
            } else {
                throw new SolrException(ErrorCode.SERVER_ERROR, "Leader-initiated recovery state data is invalid! " + parsedJson);
            }
        } else {
            // old format still in ZK
            stateObj = Utils.makeMap("state", new String(stateData, StandardCharsets.UTF_8));
        }
    }
    return stateObj;
}
Also used : Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TimeoutException(java.util.concurrent.TimeoutException) SolrException(org.apache.solr.common.SolrException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SolrCoreInitializationException(org.apache.solr.core.SolrCoreInitializationException) SolrException(org.apache.solr.common.SolrException)

Example 2 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.

the class ZkController method getLeaderProps.

/**
   * Get leader props directly from zk nodes.
   *
   * @return leader props
   */
public ZkCoreNodeProps getLeaderProps(final String collection, final String slice, int timeoutms, boolean failImmediatelyOnExpiration) throws InterruptedException {
    int iterCount = timeoutms / 1000;
    Exception exp = null;
    while (iterCount-- > 0) {
        try {
            byte[] data = zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null, true);
            ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data));
            return leaderProps;
        } catch (InterruptedException e) {
            throw e;
        } catch (SessionExpiredException e) {
            if (failImmediatelyOnExpiration) {
                throw new RuntimeException("Session has expired - could not get leader props", exp);
            }
            exp = e;
            Thread.sleep(1000);
        } catch (Exception e) {
            exp = e;
            Thread.sleep(1000);
        }
        if (cc.isShutDown()) {
            throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "CoreContainer is closed");
        }
    }
    throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Could not get leader props", exp);
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) TimeoutException(java.util.concurrent.TimeoutException) SolrException(org.apache.solr.common.SolrException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SolrCoreInitializationException(org.apache.solr.core.SolrCoreInitializationException) SolrException(org.apache.solr.common.SolrException)

Example 3 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project accumulo by apache.

the class ZooReaderWriterTest method testMutateNodeCreationFails.

@Test(expected = SessionExpiredException.class)
public void testMutateNodeCreationFails() throws Exception {
    final String path = "/foo";
    final byte[] value = new byte[] { 0 };
    final List<ACL> acls = Collections.emptyList();
    Mutator mutator = new Mutator() {

        @Override
        public byte[] mutate(byte[] currentValue) throws Exception {
            return new byte[] { 1 };
        }
    };
    zk.create(path, value, acls, CreateMode.PERSISTENT);
    EasyMock.expectLastCall().andThrow(new SessionExpiredException()).once();
    EasyMock.expect(retry.canRetry()).andReturn(false);
    EasyMock.expect(retry.retriesCompleted()).andReturn(1l).once();
    EasyMock.replay(zk, zrw, retryFactory, retry);
    zrw.mutate(path, value, acls, mutator);
}
Also used : Mutator(org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator) ACL(org.apache.zookeeper.data.ACL) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) Test(org.junit.Test)

Example 4 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.

the class TestManagedSchemaThreadSafety method createZkController.

private ZkController createZkController(SolrZkClient client) throws KeeperException, InterruptedException {
    CoreContainer mockAlwaysUpCoreContainer = mock(CoreContainer.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
    // Allow retry on session expiry
    when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(Boolean.FALSE);
    MockZkController zkController = mock(MockZkController.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
    when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);
    when(zkController.getZkClient()).thenReturn(client);
    Mockito.doAnswer(new Answer<Boolean>() {

        volatile boolean sessionExpired = false;

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            String path = (String) invocation.getArguments()[0];
            perhapsExpired();
            Boolean exists = client.exists(path, true);
            perhapsExpired();
            return exists;
        }

        private void perhapsExpired() throws SessionExpiredException {
            if (!sessionExpired && rarely()) {
                sessionExpired = true;
                throw new KeeperException.SessionExpiredException();
            }
        }
    }).when(zkController).pathExists(Mockito.anyString());
    return zkController;
}
Also used : MockZkController(org.apache.solr.cloud.MockZkController) CoreContainer(org.apache.solr.core.CoreContainer) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) KeeperException(org.apache.zookeeper.KeeperException)

Example 5 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.

the class LeaderElectionTest method getLeaderUrl.

private String getLeaderUrl(final String collection, final String slice) throws KeeperException, InterruptedException {
    int iterCount = 60;
    while (iterCount-- > 0) {
        try {
            byte[] data = zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null, true);
            ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data));
            return leaderProps.getCoreUrl();
        } catch (NoNodeException | SessionExpiredException e) {
            Thread.sleep(500);
        }
    }
    zkClient.printLayoutToStdOut();
    throw new RuntimeException("Could not get leader props");
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException)

Aggregations

SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)7 KeeperException (org.apache.zookeeper.KeeperException)3 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 UnknownHostException (java.net.UnknownHostException)2 TimeoutException (java.util.concurrent.TimeoutException)2 SolrException (org.apache.solr.common.SolrException)2 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)2 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)2 SolrCoreInitializationException (org.apache.solr.core.SolrCoreInitializationException)2 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)2 SessionExpirer (org.apache.zookeeper.server.SessionTracker.SessionExpirer)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Mutator (org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator)1 MockZkController (org.apache.solr.cloud.MockZkController)1 CoreContainer (org.apache.solr.core.CoreContainer)1