Search in sources :

Example 26 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class RequestSyncShardOp method execute.

@Override
public void execute(CallInfo it) throws Exception {
    final SolrParams params = it.req.getParams();
    log.info("I have been requested to sync up my shard");
    ZkController zkController = it.handler.coreContainer.getZkController();
    if (zkController == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Only valid for SolrCloud");
    }
    String cname = params.get(CoreAdminParams.CORE);
    if (cname == null) {
        throw new IllegalArgumentException(CoreAdminParams.CORE + " is required");
    }
    SyncStrategy syncStrategy = null;
    try (SolrCore core = it.handler.coreContainer.getCore(cname)) {
        if (core != null) {
            syncStrategy = new SyncStrategy(core.getCoreContainer());
            Map<String, Object> props = new HashMap<>();
            props.put(ZkStateReader.BASE_URL_PROP, zkController.getBaseUrl());
            props.put(ZkStateReader.CORE_NAME_PROP, cname);
            props.put(ZkStateReader.NODE_NAME_PROP, zkController.getNodeName());
            boolean success = syncStrategy.sync(zkController, core, new ZkNodeProps(props), true).isSuccess();
            // solrcloud_debug
            if (log.isDebugEnabled()) {
                try {
                    RefCounted<SolrIndexSearcher> searchHolder = core.getNewestSearcher(false);
                    SolrIndexSearcher searcher = searchHolder.get();
                    try {
                        log.debug(core.getCoreContainer().getZkController().getNodeName() + " synched " + searcher.search(new MatchAllDocsQuery(), 1).totalHits);
                    } finally {
                        searchHolder.decref();
                    }
                } catch (Exception e) {
                    log.debug("Error in solrcloud_debug block", e);
                }
            }
            if (!success) {
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Sync Failed");
            }
        } else {
            SolrException.log(log, "Could not find core to call sync:" + cname);
        }
    } finally {
        // no recoveryStrat close for now
        if (syncStrategy != null) {
            syncStrategy.close();
        }
    }
}
Also used : HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) SyncStrategy(org.apache.solr.cloud.SyncStrategy) SolrException(org.apache.solr.common.SolrException) ZkController(org.apache.solr.cloud.ZkController) SolrParams(org.apache.solr.common.params.SolrParams) SolrException(org.apache.solr.common.SolrException)

Example 27 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class HttpCacheHeaderUtil method calcLastModified.

/**
   * Calculate the appropriate last-modified time for Solr relative the current request.
   * 
   * @return the timestamp to use as a last modified time.
   */
public static long calcLastModified(final SolrQueryRequest solrReq) {
    final SolrCore core = solrReq.getCore();
    final SolrIndexSearcher searcher = solrReq.getSearcher();
    final LastModFrom lastModFrom = core.getSolrConfig().getHttpCachingConfig().getLastModFrom();
    long lastMod;
    try {
        // assume default, change if needed (getOpenTime() should be fast)
        lastMod = LastModFrom.DIRLASTMOD == lastModFrom ? IndexDeletionPolicyWrapper.getCommitTimestamp(searcher.getIndexReader().getIndexCommit()) : searcher.getOpenTimeStamp().getTime();
    } catch (IOException e) {
        // we're pretty freaking screwed if this happens
        throw new SolrException(ErrorCode.SERVER_ERROR, e);
    }
    // second granularity
    return lastMod - (lastMod % 1000L);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IOException(java.io.IOException) LastModFrom(org.apache.solr.core.SolrConfig.HttpCachingConfig.LastModFrom) SolrException(org.apache.solr.common.SolrException)

Example 28 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class HttpCacheHeaderUtil method calcEtag.

/**
   * Calculates a tag for the ETag header.
   *
   * @return a tag
   */
public static String calcEtag(final SolrQueryRequest solrReq) {
    final SolrCore core = solrReq.getCore();
    final long currentIndexVersion = solrReq.getSearcher().getIndexReader().getVersion();
    EtagCacheVal etagCache = etagCoreCache.get(core);
    if (null == etagCache) {
        final String etagSeed = core.getSolrConfig().getHttpCachingConfig().getEtagSeed();
        etagCache = new EtagCacheVal(etagSeed);
        etagCoreCache.put(core, etagCache);
    }
    return etagCache.calcEtag(currentIndexVersion);
}
Also used : SolrCore(org.apache.solr.core.SolrCore)

Example 29 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class HttpSolrCall method getCoreByCollection.

protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
    ZkStateReader zkStateReader = cores.getZkController().getZkStateReader();
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection collection = clusterState.getCollectionOrNull(collectionName);
    if (collection == null) {
        return null;
    }
    Set<String> liveNodes = clusterState.getLiveNodes();
    if (isPreferLeader) {
        List<Replica> leaderReplicas = collection.getLeaderReplicas(cores.getZkController().getNodeName());
        SolrCore core = randomlyGetSolrCore(liveNodes, leaderReplicas);
        if (core != null)
            return core;
    }
    List<Replica> replicas = collection.getReplicas(cores.getZkController().getNodeName());
    return randomlyGetSolrCore(liveNodes, replicas);
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) SolrCore(org.apache.solr.core.SolrCore) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 30 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class HttpSolrCall method checkProps.

private SolrCore checkProps(ZkNodeProps zkProps) {
    String corename;
    SolrCore core = null;
    if (cores.getZkController().getNodeName().equals(zkProps.getStr(NODE_NAME_PROP))) {
        corename = zkProps.getStr(CORE_NAME_PROP);
        core = cores.getCore(corename);
    }
    return core;
}
Also used : SolrCore(org.apache.solr.core.SolrCore)

Aggregations

SolrCore (org.apache.solr.core.SolrCore)254 Test (org.junit.Test)88 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)57 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)55 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)52 SolrException (org.apache.solr.common.SolrException)41 CoreContainer (org.apache.solr.core.CoreContainer)40 NamedList (org.apache.solr.common.util.NamedList)38 HashMap (java.util.HashMap)33 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)33 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)32 File (java.io.File)28 MapSolrParams (org.apache.solr.common.params.MapSolrParams)26 ArrayList (java.util.ArrayList)25 IOException (java.io.IOException)23 SolrParams (org.apache.solr.common.params.SolrParams)19 Map (java.util.Map)17 Replica (org.apache.solr.common.cloud.Replica)17 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)15 SolrInputDocument (org.apache.solr.common.SolrInputDocument)13