Search in sources :

Example 36 with Stat

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

the class RequestParams method getFreshRequestParams.

public static RequestParams getFreshRequestParams(SolrResourceLoader loader, RequestParams requestParams) {
    if (loader instanceof ZkSolrResourceLoader) {
        ZkSolrResourceLoader resourceLoader = (ZkSolrResourceLoader) loader;
        try {
            Stat stat = resourceLoader.getZkController().getZkClient().exists(resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, null, true);
            log.debug("latest version of {} in ZK  is : {}", resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, stat == null ? "" : stat.getVersion());
            if (stat == null) {
                requestParams = new RequestParams(Collections.EMPTY_MAP, -1);
            } else if (requestParams == null || stat.getVersion() > requestParams.getZnodeVersion()) {
                Object[] o = getMapAndVersion(loader, RequestParams.RESOURCE);
                requestParams = new RequestParams((Map) o[0], (Integer) o[1]);
                log.info("request params refreshed to version {}", requestParams.getZnodeVersion());
            }
        } catch (KeeperException | InterruptedException e) {
            SolrZkClient.checkInterrupted(e);
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
        }
    } else {
        Object[] o = getMapAndVersion(loader, RequestParams.RESOURCE);
        requestParams = new RequestParams((Map) o[0], (Integer) o[1]);
    }
    return requestParams;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) KeeperException(org.apache.zookeeper.KeeperException) SolrException(org.apache.solr.common.SolrException)

Example 37 with Stat

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

the class ZkIndexSchemaReader method updateSchema.

private void updateSchema(Watcher watcher, int expectedZkVersion) throws KeeperException, InterruptedException {
    Stat stat = new Stat();
    synchronized (getSchemaUpdateLock()) {
        final ManagedIndexSchema oldSchema = managedIndexSchemaFactory.getSchema();
        if (expectedZkVersion == -1 || oldSchema.schemaZkVersion < expectedZkVersion) {
            byte[] data = zkClient.getData(managedSchemaPath, watcher, stat, true);
            if (stat.getVersion() != oldSchema.schemaZkVersion) {
                log.info("Retrieved schema version " + stat.getVersion() + " from ZooKeeper");
                long start = System.nanoTime();
                InputSource inputSource = new InputSource(new ByteArrayInputStream(data));
                String resourceName = managedIndexSchemaFactory.getManagedSchemaResourceName();
                ManagedIndexSchema newSchema = new ManagedIndexSchema(managedIndexSchemaFactory.getConfig(), resourceName, inputSource, managedIndexSchemaFactory.isMutable(), resourceName, stat.getVersion(), oldSchema.getSchemaUpdateLock());
                managedIndexSchemaFactory.setSchema(newSchema);
                long stop = System.nanoTime();
                log.info("Finished refreshing schema in " + TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS) + " ms");
            } else {
                log.info("Current schema version " + oldSchema.schemaZkVersion + " is already the latest");
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) Stat(org.apache.zookeeper.data.Stat) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 38 with Stat

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

the class DistributedMap method size.

public int size() throws KeeperException, InterruptedException {
    Stat stat = new Stat();
    zookeeper.getData(dir, null, stat, true);
    return stat.getNumChildren();
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Example 39 with Stat

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

the class SizeLimitedDistributedMap method put.

@Override
public void put(String trackingId, byte[] data) throws KeeperException, InterruptedException {
    if (this.size() >= maxSize) {
        // Bring down the size
        List<String> children = zookeeper.getChildren(dir, null, true);
        int cleanupSize = maxSize / 10;
        final PriorityQueue priorityQueue = new PriorityQueue<Long>(cleanupSize) {

            @Override
            protected boolean lessThan(Long a, Long b) {
                return (a > b);
            }
        };
        for (String child : children) {
            Stat stat = zookeeper.exists(dir + "/" + child, null, true);
            priorityQueue.insertWithOverflow(stat.getMzxid());
        }
        long topElementMzxId = (Long) priorityQueue.top();
        for (String child : children) {
            Stat stat = zookeeper.exists(dir + "/" + child, null, true);
            if (stat.getMzxid() <= topElementMzxId)
                zookeeper.delete(dir + "/" + child, -1, true);
        }
    }
    super.put(trackingId, data);
}
Also used : Stat(org.apache.zookeeper.data.Stat) PriorityQueue(org.apache.lucene.util.PriorityQueue)

Example 40 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat 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)

Aggregations

Stat (org.apache.zookeeper.data.Stat)799 KeeperException (org.apache.zookeeper.KeeperException)266 Test (org.junit.Test)124 IOException (java.io.IOException)120 ZooKeeper (org.apache.zookeeper.ZooKeeper)88 ArrayList (java.util.ArrayList)67 Test (org.testng.annotations.Test)58 Test (org.junit.jupiter.api.Test)53 Watcher (org.apache.zookeeper.Watcher)49 AsyncCallback (org.apache.zookeeper.AsyncCallback)48 ACL (org.apache.zookeeper.data.ACL)47 List (java.util.List)43 CountDownLatch (java.util.concurrent.CountDownLatch)43 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 CuratorFramework (org.apache.curator.framework.CuratorFramework)37 Map (java.util.Map)34 HashMap (java.util.HashMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)29 ExecutionException (java.util.concurrent.ExecutionException)27