Search in sources :

Example 16 with SolrCore

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

the class AnalyzeEvaluator method setStreamContext.

public void setStreamContext(StreamContext context) {
    Object solrCoreObj = context.get("solr-core");
    if (solrCoreObj == null || !(solrCoreObj instanceof SolrCore)) {
        throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "StreamContext must have SolrCore in solr-core key");
    }
    SolrCore solrCore = (SolrCore) solrCoreObj;
    analyzer = solrCore.getLatestSchema().getFieldType(analyzerField).getIndexAnalyzer();
}
Also used : SolrCore(org.apache.solr.core.SolrCore) SolrException(org.apache.solr.common.SolrException)

Example 17 with SolrCore

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

the class TestXLSXResponseWriter method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    System.setProperty("enable.update.log", "false");
    initCore("solrconfig.xml", "schema.xml", getFile("extraction/solr").getAbsolutePath());
    createIndex();
    //find a reference to the default response writer so we can redirect its output later
    SolrCore testCore = h.getCore();
    QueryResponseWriter writer = testCore.getQueryResponseWriter("xlsx");
    if (writer instanceof XLSXResponseWriter) {
        writerXlsx = (XLSXResponseWriter) testCore.getQueryResponseWriter("xlsx");
    } else {
        throw new Exception("XLSXResponseWriter not registered with solr core");
    }
}
Also used : SolrCore(org.apache.solr.core.SolrCore) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 18 with SolrCore

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

the class ReplicateFromLeader method startReplication.

/**
   * Start a replication handler thread that will periodically pull indices from the shard leader
   * @param switchTransactionLog if true, ReplicationHandler will rotate the transaction log once
   * the replication is done
   */
public void startReplication(boolean switchTransactionLog) throws InterruptedException {
    try (SolrCore core = cc.getCore(coreName)) {
        if (core == null) {
            if (cc.isShutDown()) {
                return;
            } else {
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "SolrCore not found:" + coreName + " in " + cc.getLoadedCoreNames());
            }
        }
        SolrConfig.UpdateHandlerInfo uinfo = core.getSolrConfig().getUpdateHandlerInfo();
        String pollIntervalStr = "00:00:03";
        if (uinfo.autoCommmitMaxTime != -1) {
            pollIntervalStr = toPollIntervalStr(uinfo.autoCommmitMaxTime / 2);
        } else if (uinfo.autoSoftCommmitMaxTime != -1) {
            pollIntervalStr = toPollIntervalStr(uinfo.autoSoftCommmitMaxTime / 2);
        }
        LOG.info("Will start replication from leader with poll interval: {}", pollIntervalStr);
        NamedList slaveConfig = new NamedList();
        slaveConfig.add("fetchFromLeader", true);
        slaveConfig.add("pollInterval", pollIntervalStr);
        NamedList replicationConfig = new NamedList();
        replicationConfig.add("slave", slaveConfig);
        String lastCommitVersion = getCommitVersion(core);
        if (lastCommitVersion != null) {
            lastVersion = Long.parseLong(lastCommitVersion);
        }
        replicationProcess = new ReplicationHandler();
        if (switchTransactionLog) {
            replicationProcess.setPollListener((solrCore, pollSuccess) -> {
                if (pollSuccess) {
                    String commitVersion = getCommitVersion(core);
                    if (commitVersion == null)
                        return;
                    if (Long.parseLong(commitVersion) == lastVersion)
                        return;
                    UpdateLog updateLog = solrCore.getUpdateHandler().getUpdateLog();
                    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
                    CommitUpdateCommand cuc = new CommitUpdateCommand(req, false);
                    cuc.setVersion(Long.parseLong(commitVersion));
                    updateLog.copyOverOldUpdates(cuc);
                    lastVersion = Long.parseLong(commitVersion);
                }
            });
        }
        replicationProcess.init(replicationConfig);
        replicationProcess.inform(core);
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrConfig(org.apache.solr.core.SolrConfig) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) UpdateLog(org.apache.solr.update.UpdateLog) ReplicationHandler(org.apache.solr.handler.ReplicationHandler) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) SolrException(org.apache.solr.common.SolrException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 19 with SolrCore

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

the class ZkController method publishAndWaitForDownStates.

public void publishAndWaitForDownStates() throws KeeperException, InterruptedException {
    publishNodeAsDown(getNodeName());
    Set<String> collectionsWithLocalReplica = ConcurrentHashMap.newKeySet();
    for (SolrCore core : cc.getCores()) {
        collectionsWithLocalReplica.add(core.getCoreDescriptor().getCloudDescriptor().getCollectionName());
    }
    CountDownLatch latch = new CountDownLatch(collectionsWithLocalReplica.size());
    for (String collectionWithLocalReplica : collectionsWithLocalReplica) {
        zkStateReader.registerCollectionStateWatcher(collectionWithLocalReplica, (liveNodes, collectionState) -> {
            boolean foundStates = true;
            for (SolrCore core : cc.getCores()) {
                if (core.getCoreDescriptor().getCloudDescriptor().getCollectionName().equals(collectionWithLocalReplica)) {
                    Replica replica = collectionState.getReplica(core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName());
                    if (replica.getState() != Replica.State.DOWN) {
                        foundStates = false;
                    }
                }
            }
            if (foundStates && collectionsWithLocalReplica.remove(collectionWithLocalReplica)) {
                latch.countDown();
            }
            return foundStates;
        });
    }
    boolean allPublishedDown = latch.await(WAIT_DOWN_STATES_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (!allPublishedDown) {
        log.warn("Timed out waiting to see all nodes published as DOWN in our cluster state.");
    }
}
Also used : SolrCore(org.apache.solr.core.SolrCore) CountDownLatch(java.util.concurrent.CountDownLatch) Replica(org.apache.solr.common.cloud.Replica)

Example 20 with SolrCore

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

the class ZkController method registerConfListenerForCore.

/**
   * This will give a callback to the listener whenever a child is modified in the
   * conf directory. It is the responsibility of the listener to check if the individual
   * item of interest has been modified.  When the last core which was interested in
   * this conf directory is gone the listeners will be removed automatically.
   */
public void registerConfListenerForCore(final String confDir, SolrCore core, final Runnable listener) {
    if (listener == null) {
        throw new NullPointerException("listener cannot be null");
    }
    synchronized (confDirectoryListeners) {
        final Set<Runnable> confDirListeners = getConfDirListeners(confDir);
        confDirListeners.add(listener);
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                unregisterConfListener(confDir, listener);
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
}
Also used : CloseHook(org.apache.solr.core.CloseHook) 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