Search in sources :

Example 6 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class TestBlobHandler method postAndCheck.

public static void postAndCheck(CloudSolrClient cloudClient, String baseUrl, String blobName, ByteBuffer bytes, int count) throws Exception {
    postData(cloudClient, baseUrl, blobName, bytes);
    String url;
    Map map = null;
    List l;
    final RTimer timer = new RTimer();
    int i = 0;
    for (; i < 150; i++) {
        //15 secs
        url = baseUrl + "/.system/blob/" + blobName;
        map = TestSolrConfigHandlerConcurrent.getAsMap(url, cloudClient);
        String numFound = String.valueOf(Utils.getObjectByPath(map, false, Arrays.asList("response", "numFound")));
        if (!("" + count).equals(numFound)) {
            Thread.sleep(100);
            continue;
        }
        l = (List) Utils.getObjectByPath(map, false, Arrays.asList("response", "docs"));
        assertNotNull(l);
        map = (Map) l.get(0);
        assertEquals("" + bytes.limit(), String.valueOf(map.get("size")));
        return;
    }
    fail(StrUtils.formatString("Could not successfully add blob after {0} attempts. Expecting {1} items. time elapsed {2}  output  for url is {3}", i, count, timer.getTime(), getAsString(map)));
}
Also used : List(java.util.List) Map(java.util.Map) RTimer(org.apache.solr.util.RTimer)

Example 7 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method ensureAllReplicasAreActive.

protected List<Replica> ensureAllReplicasAreActive(String testCollectionName, String shardId, int shards, int rf, int maxWaitSecs) throws Exception {
    final RTimer timer = new RTimer();
    Map<String, Replica> notLeaders = new HashMap<>();
    ZkStateReader zkr = cloudClient.getZkStateReader();
    // force the state to be fresh
    zkr.forceUpdateCollection(testCollectionName);
    ClusterState cs = zkr.getClusterState();
    Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
    assertTrue(slices.size() == shards);
    boolean allReplicasUp = false;
    long waitMs = 0L;
    long maxWaitMs = maxWaitSecs * 1000L;
    Replica leader = null;
    while (waitMs < maxWaitMs && !allReplicasUp) {
        cs = cloudClient.getZkStateReader().getClusterState();
        assertNotNull(cs);
        Slice shard = cs.getSlice(testCollectionName, shardId);
        assertNotNull("No Slice for " + shardId, shard);
        // assume true
        allReplicasUp = true;
        Collection<Replica> replicas = shard.getReplicas();
        assertTrue("Did not find correct number of replicas. Expected:" + rf + " Found:" + replicas.size(), replicas.size() == rf);
        leader = shard.getLeader();
        assertNotNull(leader);
        log.info("Found " + replicas.size() + " replicas and leader on " + leader.getNodeName() + " for " + shardId + " in " + testCollectionName);
        // ensure all replicas are "active" and identify the non-leader replica
        for (Replica replica : replicas) {
            if (replica.getState() != Replica.State.ACTIVE) {
                log.info("Replica {} is currently {}", replica.getName(), replica.getState());
                allReplicasUp = false;
            }
            if (!leader.equals(replica))
                notLeaders.put(replica.getName(), replica);
        }
        if (!allReplicasUp) {
            try {
                Thread.sleep(500L);
            } catch (Exception ignoreMe) {
            }
            waitMs += 500L;
        }
    }
    if (!allReplicasUp)
        fail("Didn't see all replicas for shard " + shardId + " in " + testCollectionName + " come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo());
    if (notLeaders.isEmpty())
        fail("Didn't isolate any replicas that are not the leader! ClusterState: " + printClusterStateInfo());
    log.info("Took {} ms to see all replicas become active.", timer.getTime());
    List<Replica> replicas = new ArrayList<>();
    replicas.addAll(notLeaders.values());
    return replicas;
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RTimer(org.apache.solr.util.RTimer) Replica(org.apache.solr.common.cloud.Replica) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Slice(org.apache.solr.common.cloud.Slice)

Example 8 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class FacetProcessor method processSubs.

void processSubs(SimpleOrderedMap<Object> response, Query filter, DocSet domain, boolean skip, Map<String, Object> facetInfo) throws IOException {
    boolean emptyDomain = domain == null || domain.size() == 0;
    for (Map.Entry<String, FacetRequest> sub : freq.getSubFacets().entrySet()) {
        FacetRequest subRequest = sub.getValue();
        // end if it was unproductive.
        if (emptyDomain && !freq.processEmpty && !subRequest.canProduceFromEmpty()) {
            continue;
        }
        Map<String, Object> facetInfoSub = null;
        if (facetInfo != null) {
            facetInfoSub = (Map<String, Object>) facetInfo.get(sub.getKey());
        }
        // If we're skipping this node, then we only need to process sub-facets that have facet info specified.
        if (skip && facetInfoSub == null)
            continue;
        // make a new context for each sub-facet since they can change the domain
        FacetContext subContext = fcontext.sub(filter, domain);
        subContext.facetInfo = facetInfoSub;
        // turn off the skip flag if we're not skipping this bucket
        if (!skip)
            subContext.flags &= ~FacetContext.SKIP_FACET;
        FacetProcessor subProcessor = subRequest.createFacetProcessor(subContext);
        if (fcontext.getDebugInfo() != null) {
            // if fcontext.debugInfo != null, it means rb.debug() == true
            FacetDebugInfo fdebug = new FacetDebugInfo();
            subContext.setDebugInfo(fdebug);
            fcontext.getDebugInfo().addChild(fdebug);
            fdebug.setReqDescription(subRequest.getFacetDescription());
            fdebug.setProcessor(subProcessor.getClass().getSimpleName());
            if (subContext.filter != null)
                fdebug.setFilter(subContext.filter.toString());
            final RTimer timer = new RTimer();
            subProcessor.process();
            long timeElapsed = (long) timer.getTime();
            fdebug.setElapse(timeElapsed);
            fdebug.putInfoItem("domainSize", (long) subContext.base.size());
        } else {
            subProcessor.process();
        }
        response.add(sub.getKey(), subProcessor.getResponse());
    }
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) RTimer(org.apache.solr.util.RTimer)

Example 9 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class LeaderInitiatedRecoveryThread method run.

public void run() {
    RTimer timer = new RTimer();
    String replicaCoreName = nodeProps.getCoreName();
    String replicaCoreNodeName = ((Replica) nodeProps.getNodeProps()).getName();
    String replicaNodeName = nodeProps.getNodeName();
    final String replicaUrl = nodeProps.getCoreUrl();
    if (!zkController.isReplicaInRecoveryHandling(replicaUrl)) {
        throw new SolrException(ErrorCode.INVALID_STATE, "Replica: " + replicaUrl + " should have been marked under leader initiated recovery in ZkController but wasn't.");
    }
    boolean sendRecoveryCommand = publishDownState(replicaCoreName, replicaCoreNodeName, replicaNodeName, replicaUrl, false);
    if (sendRecoveryCommand) {
        try {
            sendRecoveryCommandWithRetry();
        } catch (Exception exc) {
            log.error(getName() + " failed due to: " + exc, exc);
            if (exc instanceof SolrException) {
                throw (SolrException) exc;
            } else {
                throw new SolrException(ErrorCode.SERVER_ERROR, exc);
            }
        } finally {
            zkController.removeReplicaFromLeaderInitiatedRecoveryHandling(replicaUrl);
        }
    } else {
        // replica is no longer in recovery on this node (may be handled on another node)
        zkController.removeReplicaFromLeaderInitiatedRecoveryHandling(replicaUrl);
    }
    log.info("{} completed successfully after running for {}ms", getName(), timer.getTime());
}
Also used : RTimer(org.apache.solr.util.RTimer) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) NoHttpResponseException(org.apache.http.NoHttpResponseException) SolrException(org.apache.solr.common.SolrException) SocketException(java.net.SocketException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) ConnectException(java.net.ConnectException)

Example 10 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method waitForNewShard.

void waitForNewShard(String collectionName, String sliceName) throws KeeperException, InterruptedException {
    log.debug("Waiting for slice {} of collection {} to be available", sliceName, collectionName);
    RTimer timer = new RTimer();
    int retryCount = 320;
    while (retryCount-- > 0) {
        DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
        if (collection == null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to find collection: " + collectionName + " in clusterstate");
        }
        Slice slice = collection.getSlice(sliceName);
        if (slice != null) {
            log.debug("Waited for {}ms for slice {} of collection {} to be available", timer.getTime(), sliceName, collectionName);
            return;
        }
        Thread.sleep(1000);
    }
    throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find new slice " + sliceName + " in collection " + collectionName + " even after waiting for " + timer.getTime() + "ms");
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) RTimer(org.apache.solr.util.RTimer) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Aggregations

RTimer (org.apache.solr.util.RTimer)31 SolrException (org.apache.solr.common.SolrException)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)4 List (java.util.List)3 Random (java.util.Random)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)3 ClusterState (org.apache.solr.common.cloud.ClusterState)3 Replica (org.apache.solr.common.cloud.Replica)3 Slice (org.apache.solr.common.cloud.Slice)3 IdentityHashMap (java.util.IdentityHashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 NoHttpResponseException (org.apache.http.NoHttpResponseException)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2