Search in sources :

Example 56 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project lucene-solr by apache.

the class ManagedIndexSchemaFactory method warnIfNonManagedSchemaExists.

/**
   * Return whether a non-managed schema exists, either in local storage or on ZooKeeper. 
   */
private void warnIfNonManagedSchemaExists() {
    if (!resourceName.equals(managedSchemaResourceName)) {
        boolean exists = false;
        SolrResourceLoader loader = config.getResourceLoader();
        if (loader instanceof ZkSolrResourceLoader) {
            ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
            String nonManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + resourceName;
            try {
                exists = zkLoader.getZkController().pathExists(nonManagedSchemaPath);
            } catch (InterruptedException e) {
                // Restore the interrupted status
                Thread.currentThread().interrupt();
                // Log as warning and suppress the exception 
                log.warn("", e);
            } catch (KeeperException e) {
                // log as warning and suppress the exception
                log.warn("Error checking for the existence of the non-managed schema " + resourceName, e);
            }
        } else {
            // Config is not in ZooKeeper
            InputStream nonManagedSchemaInputStream = null;
            try {
                nonManagedSchemaInputStream = loader.openSchema(resourceName);
                if (null != nonManagedSchemaInputStream) {
                    exists = true;
                }
            } catch (IOException e) {
            // This is expected when the non-managed schema does not exist
            } finally {
                IOUtils.closeQuietly(nonManagedSchemaInputStream);
            }
        }
        if (exists) {
            log.warn("The schema has been upgraded to managed, but the non-managed schema " + resourceName + " is still loadable.  PLEASE REMOVE THIS FILE.");
        }
    }
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 57 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project lucene-solr by apache.

the class ZkClientClusterStateProvider method connect.

@Override
public void connect() {
    if (zkStateReader == null) {
        synchronized (this) {
            if (zkStateReader == null) {
                ZkStateReader zk = null;
                try {
                    zk = new ZkStateReader(zkHost, zkClientTimeout, zkConnectTimeout);
                    zk.createClusterStateWatchersAndUpdate();
                    zkStateReader = zk;
                    log.info("Cluster at {} ready", zkHost);
                } catch (InterruptedException e) {
                    zk.close();
                    Thread.currentThread().interrupt();
                    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
                } catch (KeeperException e) {
                    zk.close();
                    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
                } catch (Exception e) {
                    if (zk != null)
                        zk.close();
                    // do not wrap because clients may be relying on the underlying exception being thrown
                    throw e;
                }
            }
        }
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Example 58 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project lucene-solr by apache.

the class ZkSolrClientTest method testZkCmdExectutor.

public void testZkCmdExectutor() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = null;
    try {
        server = new ZkTestServer(zkDir);
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        final int timeout = random().nextInt(10000) + 5000;
        ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(timeout);
        final long start = System.nanoTime();
        try {
            zkCmdExecutor.retryOperation(new ZkOperation() {

                @Override
                public String execute() throws KeeperException, InterruptedException {
                    if (System.nanoTime() - start > TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS)) {
                        throw new KeeperException.SessionExpiredException();
                    }
                    throw new KeeperException.ConnectionLossException();
                }
            });
        } catch (KeeperException.SessionExpiredException e) {
        } catch (Exception e) {
            fail("Expected " + KeeperException.SessionExpiredException.class.getSimpleName() + " but got " + e.getClass().getSimpleName());
        }
    } finally {
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : KeeperException(org.apache.zookeeper.KeeperException) ZkCmdExecutor(org.apache.solr.common.cloud.ZkCmdExecutor) ZkOperation(org.apache.solr.common.cloud.ZkOperation) KeeperException(org.apache.zookeeper.KeeperException)

Example 59 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project lucene-solr by apache.

the class SolrTestCaseJ4 method deleteCore.

/**
   * Shuts down the test harness, and makes the best attempt possible
   * to delete dataDir, unless the system property "solr.test.leavedatadir"
   * is set.
   */
public static void deleteCore() {
    if (h != null) {
        log.info("###deleteCore");
        // If the test case set up Zk, it should still have it as available,
        // otherwise the core close will just be unnecessarily delayed.
        CoreContainer cc = h.getCoreContainer();
        if (!cc.getCores().isEmpty() && cc.isZooKeeperAware()) {
            try {
                cc.getZkController().getZkClient().exists("/", false);
            } catch (KeeperException e) {
                log.error("Testing connectivity to ZK by checking for root path failed", e);
                fail("Trying to tear down a ZK aware core container with ZK not reachable");
            } catch (InterruptedException ignored) {
            }
        }
        h.close();
    }
    if (factoryProp == null) {
        System.clearProperty("solr.directoryFactory");
    }
    solrConfig = null;
    h = null;
    lrf = null;
    configString = schemaString = null;
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) KeeperException(org.apache.zookeeper.KeeperException)

Example 60 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project lucene-solr by apache.

the class ZkStateReader method createClusterStateWatchersAndUpdate.

public synchronized void createClusterStateWatchersAndUpdate() throws KeeperException, InterruptedException {
    // We need to fetch the current cluster state and the set of live nodes
    LOG.debug("Updating cluster state from ZooKeeper... ");
    // Sanity check ZK structure.
    if (!zkClient.exists(CLUSTER_STATE, true)) {
        throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Cannot connect to cluster at " + zkClient.getZkServerAddress() + ": cluster not found/not ready");
    }
    // on reconnect of SolrZkClient force refresh and re-add watches.
    loadClusterProperties();
    refreshLiveNodes(new LiveNodeWatcher());
    refreshLegacyClusterState(new LegacyClusterStateWatcher());
    refreshStateFormat2Collections();
    refreshCollectionList(new CollectionsChildWatcher());
    synchronized (ZkStateReader.this.getUpdateLock()) {
        constructState(Collections.emptySet());
        zkClient.exists(ALIASES, new Watcher() {

            @Override
            public void process(WatchedEvent event) {
                // session events are not change events, and do not remove the watcher
                if (EventType.None.equals(event.getType())) {
                    return;
                }
                try {
                    synchronized (ZkStateReader.this.getUpdateLock()) {
                        LOG.debug("Updating aliases... ");
                        // remake watch
                        final Watcher thisWatch = this;
                        final Stat stat = new Stat();
                        final byte[] data = zkClient.getData(ALIASES, thisWatch, stat, true);
                        ZkStateReader.this.aliases = ClusterState.load(data);
                        LOG.debug("New alias definition is: " + ZkStateReader.this.aliases.toString());
                    }
                } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) {
                    LOG.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: [{}]", e.getMessage());
                } catch (KeeperException e) {
                    LOG.error("A ZK error has occurred", e);
                    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "A ZK error has occurred", e);
                } catch (InterruptedException e) {
                    // Restore the interrupted status
                    Thread.currentThread().interrupt();
                    LOG.warn("Interrupted", e);
                }
            }
        }, true);
    }
    updateAliases();
    if (securityNodeListener != null) {
        addSecuritynodeWatcher(pair -> {
            ConfigData cd = new ConfigData();
            cd.data = pair.first() == null || pair.first().length == 0 ? EMPTY_MAP : Utils.getDeepCopy((Map) fromJSON(pair.first()), 4, false);
            cd.version = pair.second() == null ? -1 : pair.second().getVersion();
            securityData = cd;
            securityNodeListener.run();
        });
        securityData = getSecurityProps(true);
    }
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) Stat(org.apache.zookeeper.data.Stat) Watcher(org.apache.zookeeper.Watcher) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)566 IOException (java.io.IOException)188 Stat (org.apache.zookeeper.data.Stat)127 ZooKeeper (org.apache.zookeeper.ZooKeeper)87 ArrayList (java.util.ArrayList)51 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)45 Watcher (org.apache.zookeeper.Watcher)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 Test (org.junit.jupiter.api.Test)38 CountDownLatch (java.util.concurrent.CountDownLatch)30 SolrException (org.apache.solr.common.SolrException)30 HashMap (java.util.HashMap)29 List (java.util.List)28 ACL (org.apache.zookeeper.data.ACL)27 Test (org.junit.Test)27 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)25 ServerName (org.apache.hadoop.hbase.ServerName)24 Map (java.util.Map)23 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)23 InterruptedIOException (java.io.InterruptedIOException)20