Search in sources :

Example 26 with RTimer

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

the class HttpPartitionTest method waitToSeeReplicasActive.

protected void waitToSeeReplicasActive(String testCollectionName, String shardId, Set<String> replicasToCheck, int maxWaitSecs) throws Exception {
    final RTimer timer = new RTimer();
    ZkStateReader zkr = cloudClient.getZkStateReader();
    zkr.forceUpdateCollection(testCollectionName);
    ClusterState cs = zkr.getClusterState();
    Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
    boolean allReplicasUp = false;
    long waitMs = 0L;
    long maxWaitMs = maxWaitSecs * 1000L;
    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;
        // wait to see all replicas are "active"
        for (Replica replica : shard.getReplicas()) {
            if (!replicasToCheck.contains(replica.getName()))
                continue;
            final Replica.State state = replica.getState();
            if (state != Replica.State.ACTIVE) {
                log.info("Replica " + replica.getName() + " is currently " + state);
                allReplicasUp = false;
            }
        }
        if (!allReplicasUp) {
            try {
                Thread.sleep(200L);
            } catch (Exception ignoreMe) {
            }
            waitMs += 200L;
        }
    }
    if (!allReplicasUp)
        fail("Didn't see replicas " + replicasToCheck + " come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo(testCollectionName));
    log.info("Took {} ms to see replicas [{}] become active.", timer.getTime(), replicasToCheck);
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) 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) IOException(java.io.IOException)

Example 27 with RTimer

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

the class FacetQueryMerger method process.

@Override
public void process(ResponseBuilder rb) throws IOException {
    // if this is null, faceting is not enabled
    FacetComponentState facetState = getFacetComponentState(rb);
    if (facetState == null)
        return;
    boolean isShard = rb.req.getParams().getBool(ShardParams.IS_SHARD, false);
    FacetContext fcontext = new FacetContext();
    fcontext.base = rb.getResults().docSet;
    fcontext.req = rb.req;
    fcontext.searcher = rb.req.getSearcher();
    fcontext.qcontext = QueryContext.newContext(fcontext.searcher);
    if (isShard) {
        fcontext.flags |= FacetContext.IS_SHARD;
        fcontext.facetInfo = facetState.facetInfo.isEmpty() ? null : (Map<String, Object>) facetState.facetInfo.get(FACET_REFINE);
        if (fcontext.facetInfo != null) {
            fcontext.flags |= FacetContext.IS_REFINEMENT;
            // the root bucket should have been received from all shards previously
            fcontext.flags |= FacetContext.SKIP_FACET;
        }
    }
    FacetProcessor fproc = facetState.facetRequest.createFacetProcessor(fcontext);
    if (rb.isDebug()) {
        FacetDebugInfo fdebug = new FacetDebugInfo();
        fcontext.setDebugInfo(fdebug);
        fdebug.setReqDescription(facetState.facetRequest.getFacetDescription());
        fdebug.setProcessor(fproc.getClass().getSimpleName());
        final RTimer timer = new RTimer();
        fproc.process();
        long timeElapsed = (long) timer.getTime();
        fdebug.setElapse(timeElapsed);
        fdebug.putInfoItem("domainSize", (long) fcontext.base.size());
        rb.req.getContext().put("FacetDebugInfo", fdebug);
    } else {
        fproc.process();
    }
    rb.rsp.add("facets", fproc.getResponse());
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) Map(java.util.Map) RTimer(org.apache.solr.util.RTimer)

Example 28 with RTimer

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

the class SystemInfoHandler method initHostname.

private void initHostname() {
    if (null != System.getProperty(PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP, null)) {
        log.info("Resolving canonical hostname for local host prevented due to '{}' sysprop", PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP);
        hostname = null;
        return;
    }
    RTimer timer = new RTimer();
    try {
        InetAddress addr = InetAddress.getLocalHost();
        hostname = addr.getCanonicalHostName();
    } catch (Exception e) {
        log.warn("Unable to resolve canonical hostname for local host, possible DNS misconfiguration. " + "Set the '" + PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP + "' sysprop to true on startup to " + "prevent future lookups if DNS can not be fixed.", e);
        hostname = null;
        return;
    }
    timer.stop();
    if (15000D < timer.getTime()) {
        String readableTime = String.format(Locale.ROOT, "%.3f", (timer.getTime() / 1000));
        log.warn("Resolving canonical hostname for local host took {} seconds, possible DNS misconfiguration. " + "Set the '{}' sysprop to true on startup to prevent future lookups if DNS can not be fixed.", readableTime, PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP);
    }
}
Also used : RTimer(org.apache.solr.util.RTimer) InetAddress(java.net.InetAddress) IOException(java.io.IOException)

Example 29 with RTimer

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

the class FacetComponent method getFacetCounts.

/**
   * Looks at various Params to determining if any simple Facet Constraint count
   * computations are desired.
   *
   * @see SimpleFacets#getFacetQueryCounts
   * @see SimpleFacets#getFacetFieldCounts
   * @see RangeFacetProcessor#getFacetRangeCounts
   * @see RangeFacetProcessor#getFacetIntervalCounts
   * @see FacetParams#FACET
   * @return a NamedList of Facet Count info or null
   */
public static NamedList<Object> getFacetCounts(SimpleFacets simpleFacets, FacetDebugInfo fdebug) {
    // if someone called this method, benefit of the doubt: assume true
    if (!simpleFacets.getGlobalParams().getBool(FacetParams.FACET, true))
        return null;
    RangeFacetProcessor rangeFacetProcessor = new RangeFacetProcessor(simpleFacets.getRequest(), simpleFacets.getDocsOrig(), simpleFacets.getGlobalParams(), simpleFacets.getResponseBuilder());
    NamedList<Object> counts = new SimpleOrderedMap<>();
    try {
        counts.add(FACET_QUERY_KEY, simpleFacets.getFacetQueryCounts());
        if (fdebug != null) {
            FacetDebugInfo fd = new FacetDebugInfo();
            fd.putInfoItem("action", "field facet");
            fd.setProcessor(simpleFacets.getClass().getSimpleName());
            fdebug.addChild(fd);
            simpleFacets.setFacetDebugInfo(fd);
            final RTimer timer = new RTimer();
            counts.add(FACET_FIELD_KEY, simpleFacets.getFacetFieldCounts());
            long timeElapsed = (long) timer.getTime();
            fd.setElapse(timeElapsed);
        } else {
            counts.add(FACET_FIELD_KEY, simpleFacets.getFacetFieldCounts());
        }
        counts.add(FACET_RANGES_KEY, rangeFacetProcessor.getFacetRangeCounts());
        counts.add(FACET_INTERVALS_KEY, simpleFacets.getFacetIntervalCounts());
        counts.add(SpatialHeatmapFacets.RESPONSE_KEY, simpleFacets.getHeatmapCounts());
    } catch (IOException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, e);
    } catch (SyntaxError e) {
        throw new SolrException(ErrorCode.BAD_REQUEST, e);
    }
    return counts;
}
Also used : FacetDebugInfo(org.apache.solr.search.facet.FacetDebugInfo) SyntaxError(org.apache.solr.search.SyntaxError) IOException(java.io.IOException) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) RTimer(org.apache.solr.util.RTimer) SolrException(org.apache.solr.common.SolrException)

Example 30 with RTimer

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

the class FacetComponent method process.

/**
   * Actually run the query
   */
@Override
public void process(ResponseBuilder rb) throws IOException {
    if (rb.doFacets) {
        SolrParams params = rb.req.getParams();
        SimpleFacets f = newSimpleFacets(rb.req, rb.getResults().docSet, params, rb);
        RTimer timer = null;
        FacetDebugInfo fdebug = null;
        if (rb.isDebug()) {
            fdebug = new FacetDebugInfo();
            rb.req.getContext().put("FacetDebugInfo-nonJson", fdebug);
            timer = new RTimer();
        }
        NamedList<Object> counts = FacetComponent.getFacetCounts(f, fdebug);
        String[] pivots = params.getParams(FacetParams.FACET_PIVOT);
        if (!ArrayUtils.isEmpty(pivots)) {
            PivotFacetProcessor pivotProcessor = new PivotFacetProcessor(rb.req, rb.getResults().docSet, params, rb);
            SimpleOrderedMap<List<NamedList<Object>>> v = pivotProcessor.process(pivots);
            if (v != null) {
                counts.add(PIVOT_KEY, v);
            }
        }
        if (fdebug != null) {
            long timeElapsed = (long) timer.getTime();
            fdebug.setElapse(timeElapsed);
        }
        rb.rsp.add("facet_counts", counts);
    }
}
Also used : FacetDebugInfo(org.apache.solr.search.facet.FacetDebugInfo) SimpleFacets(org.apache.solr.request.SimpleFacets) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) RTimer(org.apache.solr.util.RTimer)

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