Search in sources :

Example 6 with SolrCore

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

the class StreamHandler method inform.

public void inform(SolrCore core) {
    /* The stream factory will always contain the zkUrl for the given collection
     * Adds default streams with their corresponding function names. These 
     * defaults can be overridden or added to in the solrConfig in the stream 
     * RequestHandler def. Example config override
     *  <lst name="streamFunctions">
     *    <str name="group">org.apache.solr.client.solrj.io.stream.ReducerStream</str>
     *    <str name="count">org.apache.solr.client.solrj.io.stream.RecordCountStream</str>
     *  </lst>
     * */
    String defaultCollection;
    String defaultZkhost;
    CoreContainer coreContainer = core.getCoreContainer();
    this.coreName = core.getName();
    if (coreContainer.isZooKeeperAware()) {
        defaultCollection = core.getCoreDescriptor().getCollectionName();
        defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
        streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
        streamFactory.withDefaultZkHost(defaultZkhost);
        modelCache = new ModelCache(250, defaultZkhost, clientCache);
    }
    streamFactory.withFunctionName("search", CloudSolrStream.class).withFunctionName("facet", FacetStream.class).withFunctionName("update", UpdateStream.class).withFunctionName("jdbc", JDBCStream.class).withFunctionName("topic", TopicStream.class).withFunctionName("commit", CommitStream.class).withFunctionName("random", RandomStream.class).withFunctionName("knn", KnnStream.class).withFunctionName("merge", MergeStream.class).withFunctionName("unique", UniqueStream.class).withFunctionName("top", RankStream.class).withFunctionName("group", GroupOperation.class).withFunctionName("reduce", ReducerStream.class).withFunctionName("parallel", ParallelStream.class).withFunctionName("rollup", RollupStream.class).withFunctionName("stats", StatsStream.class).withFunctionName("innerJoin", InnerJoinStream.class).withFunctionName("leftOuterJoin", LeftOuterJoinStream.class).withFunctionName("hashJoin", HashJoinStream.class).withFunctionName("outerHashJoin", OuterHashJoinStream.class).withFunctionName("intersect", IntersectStream.class).withFunctionName("complement", ComplementStream.class).withFunctionName(SORT, SortStream.class).withFunctionName("train", TextLogitStream.class).withFunctionName("features", FeaturesSelectionStream.class).withFunctionName("daemon", DaemonStream.class).withFunctionName("shortestPath", ShortestPathStream.class).withFunctionName("gatherNodes", GatherNodesStream.class).withFunctionName("nodes", GatherNodesStream.class).withFunctionName("select", SelectStream.class).withFunctionName("shortestPath", ShortestPathStream.class).withFunctionName("gatherNodes", GatherNodesStream.class).withFunctionName("nodes", GatherNodesStream.class).withFunctionName("scoreNodes", ScoreNodesStream.class).withFunctionName("model", ModelStream.class).withFunctionName("classify", ClassifyStream.class).withFunctionName("fetch", FetchStream.class).withFunctionName("executor", ExecutorStream.class).withFunctionName("null", NullStream.class).withFunctionName("priority", PriorityStream.class).withFunctionName("significantTerms", SignificantTermsStream.class).withFunctionName("cartesianProduct", CartesianProductStream.class).withFunctionName("shuffle", ShuffleStream.class).withFunctionName("calc", CalculatorStream.class).withFunctionName("eval", EvalStream.class).withFunctionName("echo", EchoStream.class).withFunctionName("cell", CellStream.class).withFunctionName("list", ListStream.class).withFunctionName("let", LetStream.class).withFunctionName("get", GetStream.class).withFunctionName("timeseries", TimeSeriesStream.class).withFunctionName("tuple", TupStream.class).withFunctionName("sql", SqlStream.class).withFunctionName("col", ColumnEvaluator.class).withFunctionName("predict", PredictEvaluator.class).withFunctionName("regress", RegressionEvaluator.class).withFunctionName("cov", CovarianceEvaluator.class).withFunctionName("conv", ConvolutionEvaluator.class).withFunctionName("normalize", NormalizeEvaluator.class).withFunctionName("rev", ReverseEvaluator.class).withFunctionName("length", LengthEvaluator.class).withFunctionName("rank", RankEvaluator.class).withFunctionName("scale", ScaleEvaluator.class).withFunctionName("distance", DistanceEvaluator.class).withFunctionName("copyOf", CopyOfEvaluator.class).withFunctionName("copyOfRange", CopyOfRangeEvaluator.class).withFunctionName("percentile", PercentileEvaluator.class).withFunctionName("empiricalDistribution", EmpiricalDistributionEvaluator.class).withFunctionName("describe", DescribeEvaluator.class).withFunctionName("finddelay", FindDelayEvaluator.class).withFunctionName("sequence", SequenceEvaluator.class).withFunctionName("array", ArrayEvaluator.class).withFunctionName("hist", HistogramEvaluator.class).withFunctionName("anova", AnovaEvaluator.class).withFunctionName("movingAvg", MovingAverageEvaluator.class).withFunctionName("min", MinMetric.class).withFunctionName("max", MaxMetric.class).withFunctionName("avg", MeanMetric.class).withFunctionName("sum", SumMetric.class).withFunctionName("count", CountMetric.class).withFunctionName("replace", ReplaceOperation.class).withFunctionName("concat", ConcatOperation.class).withFunctionName("group", GroupOperation.class).withFunctionName("distinct", DistinctOperation.class).withFunctionName("having", HavingStream.class).withFunctionName("val", RawValueEvaluator.class).withFunctionName("and", AndEvaluator.class).withFunctionName("eor", ExclusiveOrEvaluator.class).withFunctionName("eq", EqualsEvaluator.class).withFunctionName("gt", GreaterThanEvaluator.class).withFunctionName("gteq", GreaterThanEqualToEvaluator.class).withFunctionName("lt", LessThanEvaluator.class).withFunctionName("lteq", LessThanEqualToEvaluator.class).withFunctionName("not", NotEvaluator.class).withFunctionName("or", OrEvaluator.class).withFunctionName(TemporalEvaluatorYear.FUNCTION_NAME, TemporalEvaluatorYear.class).withFunctionName(TemporalEvaluatorMonth.FUNCTION_NAME, TemporalEvaluatorMonth.class).withFunctionName(TemporalEvaluatorDay.FUNCTION_NAME, TemporalEvaluatorDay.class).withFunctionName(TemporalEvaluatorDayOfYear.FUNCTION_NAME, TemporalEvaluatorDayOfYear.class).withFunctionName(TemporalEvaluatorHour.FUNCTION_NAME, TemporalEvaluatorHour.class).withFunctionName(TemporalEvaluatorMinute.FUNCTION_NAME, TemporalEvaluatorMinute.class).withFunctionName(TemporalEvaluatorSecond.FUNCTION_NAME, TemporalEvaluatorSecond.class).withFunctionName(TemporalEvaluatorEpoch.FUNCTION_NAME, TemporalEvaluatorEpoch.class).withFunctionName(TemporalEvaluatorWeek.FUNCTION_NAME, TemporalEvaluatorWeek.class).withFunctionName(TemporalEvaluatorQuarter.FUNCTION_NAME, TemporalEvaluatorQuarter.class).withFunctionName(TemporalEvaluatorDayOfQuarter.FUNCTION_NAME, TemporalEvaluatorDayOfQuarter.class).withFunctionName("abs", AbsoluteValueEvaluator.class).withFunctionName("add", AddEvaluator.class).withFunctionName("div", DivideEvaluator.class).withFunctionName("mult", MultiplyEvaluator.class).withFunctionName("sub", SubtractEvaluator.class).withFunctionName("log", NaturalLogEvaluator.class).withFunctionName("pow", PowerEvaluator.class).withFunctionName("mod", ModuloEvaluator.class).withFunctionName("ceil", CeilingEvaluator.class).withFunctionName("floor", FloorEvaluator.class).withFunctionName("sin", SineEvaluator.class).withFunctionName("asin", ArcSineEvaluator.class).withFunctionName("sinh", HyperbolicSineEvaluator.class).withFunctionName("cos", CosineEvaluator.class).withFunctionName("acos", ArcCosineEvaluator.class).withFunctionName("cosh", HyperbolicCosineEvaluator.class).withFunctionName("tan", TangentEvaluator.class).withFunctionName("atan", ArcTangentEvaluator.class).withFunctionName("tanh", HyperbolicTangentEvaluator.class).withFunctionName("round", RoundEvaluator.class).withFunctionName("sqrt", SquareRootEvaluator.class).withFunctionName("cbrt", CubedRootEvaluator.class).withFunctionName("coalesce", CoalesceEvaluator.class).withFunctionName("uuid", UuidEvaluator.class).withFunctionName("corr", CorrelationEvaluator.class).withFunctionName("if", IfThenElseEvaluator.class).withFunctionName("analyze", AnalyzeEvaluator.class).withFunctionName("convert", ConversionEvaluator.class);
    // This pulls all the overrides and additions from the config
    List<PluginInfo> pluginInfos = core.getSolrConfig().getPluginInfos(Expressible.class.getName());
    for (PluginInfo pluginInfo : pluginInfos) {
        Class<? extends Expressible> clazz = core.getMemClassLoader().findClass(pluginInfo.className, Expressible.class);
        streamFactory.withFunctionName(pluginInfo.name, clazz);
    }
    core.addCloseHook(new CloseHook() {

        @Override
        public void preClose(SolrCore core) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void postClose(SolrCore core) {
            clientCache.close();
        }
    });
}
Also used : GatherNodesStream(org.apache.solr.client.solrj.io.graph.GatherNodesStream) CoreContainer(org.apache.solr.core.CoreContainer) PluginInfo(org.apache.solr.core.PluginInfo) CloseHook(org.apache.solr.core.CloseHook) ShortestPathStream(org.apache.solr.client.solrj.io.graph.ShortestPathStream) Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) SolrCore(org.apache.solr.core.SolrCore) ModelCache(org.apache.solr.client.solrj.io.ModelCache) ReplaceOperation(org.apache.solr.client.solrj.io.ops.ReplaceOperation) GroupOperation(org.apache.solr.client.solrj.io.ops.GroupOperation) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric)

Example 7 with SolrCore

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

the class ReplicationHandler method registerCloseHook.

/**
   * register a closehook
   */
private void registerCloseHook() {
    core.addCloseHook(new CloseHook() {

        @Override
        public void preClose(SolrCore core) {
            // we don't wait for shutdown - this can deadlock core reload
            if (executorService != null)
                executorService.shutdown();
        }

        @Override
        public void postClose(SolrCore core) {
            if (pollingIndexFetcher != null) {
                pollingIndexFetcher.destroy();
            }
            if (currentIndexFetcher != null && currentIndexFetcher != pollingIndexFetcher) {
                currentIndexFetcher.destroy();
            }
        }
    });
    core.addCloseHook(new CloseHook() {

        @Override
        public void preClose(SolrCore core) {
            ExecutorUtil.shutdownAndAwaitTermination(restoreExecutor);
            if (restoreFuture != null) {
                restoreFuture.cancel(false);
            }
        }

        @Override
        public void postClose(SolrCore core) {
        }
    });
}
Also used : CloseHook(org.apache.solr.core.CloseHook) SolrCore(org.apache.solr.core.SolrCore)

Example 8 with SolrCore

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

the class IndexFetcher method openNewSearcherAndUpdateCommitPoint.

private void openNewSearcherAndUpdateCommitPoint() throws IOException {
    RefCounted<SolrIndexSearcher> searcher = null;
    IndexCommit commitPoint;
    // must get the latest solrCore object because the one we have might be closed because of a reload
    // todo stop keeping solrCore around
    SolrCore core = solrCore.getCoreContainer().getCore(solrCore.getName());
    try {
        Future[] waitSearcher = new Future[1];
        searcher = core.getSearcher(true, true, waitSearcher, true);
        if (waitSearcher[0] != null) {
            try {
                waitSearcher[0].get();
            } catch (InterruptedException | ExecutionException e) {
                SolrException.log(LOG, e);
            }
        }
        commitPoint = searcher.get().getIndexReader().getIndexCommit();
    } finally {
        if (searcher != null) {
            searcher.decref();
        }
        core.close();
    }
    // update the commit point in replication handler
    replicationHandler.indexCommitPoint = commitPoint;
}
Also used : SolrCore(org.apache.solr.core.SolrCore) Future(java.util.concurrent.Future) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) ExecutionException(java.util.concurrent.ExecutionException) IndexCommit(org.apache.lucene.index.IndexCommit)

Example 9 with SolrCore

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

the class CreateSnapshotOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    CoreContainer cc = it.handler.getCoreContainer();
    final SolrParams params = it.req.getParams();
    String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
    String cname = params.required().get(CoreAdminParams.CORE);
    try (SolrCore core = cc.getCore(cname)) {
        if (core == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
        }
        String indexDirPath = core.getIndexDir();
        IndexCommit ic = core.getDeletionPolicy().getLatestCommit();
        if (ic == null) {
            RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
            try {
                ic = searcher.get().getIndexReader().getIndexCommit();
            } finally {
                searcher.decref();
            }
        }
        SolrSnapshotMetaDataManager mgr = core.getSnapshotMetaDataManager();
        mgr.snapshot(commitName, indexDirPath, ic.getGeneration());
        it.rsp.add(CoreAdminParams.CORE, core.getName());
        it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
        it.rsp.add(SolrSnapshotManager.INDEX_DIR_PATH, indexDirPath);
        it.rsp.add(SolrSnapshotManager.GENERATION_NUM, ic.getGeneration());
        it.rsp.add(SolrSnapshotManager.FILE_LIST, ic.getFileNames());
    }
}
Also used : SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SolrException(org.apache.solr.common.SolrException) IndexCommit(org.apache.lucene.index.IndexCommit)

Example 10 with SolrCore

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

the class BackupCoreOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    ZkController zkController = it.handler.coreContainer.getZkController();
    if (zkController == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Internal SolrCloud API");
    }
    final SolrParams params = it.req.getParams();
    String cname = params.get(CoreAdminParams.CORE);
    if (cname == null) {
        throw new IllegalArgumentException(CoreAdminParams.CORE + " is required");
    }
    String name = params.get(NAME);
    if (name == null) {
        throw new IllegalArgumentException(CoreAdminParams.NAME + " is required");
    }
    String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
    BackupRepository repository = it.handler.coreContainer.newBackupRepository(Optional.ofNullable(repoName));
    String location = repository.getBackupLocation(params.get(CoreAdminParams.BACKUP_LOCATION));
    if (location == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'location' is not specified as a query" + " parameter or as a default repository property");
    }
    // An optional parameter to describe the snapshot to be backed-up. If this
    // parameter is not supplied, the latest index commit is backed-up.
    String commitName = params.get(CoreAdminParams.COMMIT_NAME);
    URI locationUri = repository.createURI(location);
    try (SolrCore core = it.handler.coreContainer.getCore(cname)) {
        SnapShooter snapShooter = new SnapShooter(repository, core, locationUri, name, commitName);
        //  file system. Otherwise, perhaps the FS location isn't shared -- we want an error.
        if (!snapShooter.getBackupRepository().exists(snapShooter.getLocation())) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Directory to contain snapshots doesn't exist: " + snapShooter.getLocation());
        }
        snapShooter.validateCreateSnapshot();
        snapShooter.createSnapshot();
    } catch (Exception e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed to backup core=" + cname + " because " + e, e);
    }
}
Also used : SnapShooter(org.apache.solr.handler.SnapShooter) BackupRepository(org.apache.solr.core.backup.repository.BackupRepository) ZkController(org.apache.solr.cloud.ZkController) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) URI(java.net.URI) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

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