Search in sources :

Example 1 with ZkController

use of org.apache.solr.cloud.ZkController in project lucene-solr by apache.

the class TestManagedSchemaThreadSafety method testThreadSafety.

@Test
@LogLevel("org.apache.solr.common.cloud.SolrZkClient=debug")
public void testThreadSafety() throws Exception {
    //
    final String configsetName = "managed-config";
    try (SolrZkClient client = new SuspendingZkClient(zkServer.getZkHost(), 30000)) {
        // we can pick any to load configs, I suppose, but here we check
        client.upConfig(configset("cloud-managed-upgrade"), configsetName);
    }
    ExecutorService executor = ExecutorUtil.newMDCAwareCachedThreadPool("threadpool");
    try (SolrZkClient raceJudge = new SuspendingZkClient(zkServer.getZkHost(), 30000)) {
        ZkController zkController = createZkController(raceJudge);
        List<Future<?>> futures = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            futures.add(executor.submit(indexSchemaLoader(configsetName, zkController)));
        }
        for (Future<?> future : futures) {
            future.get();
        }
    } finally {
        ExecutorUtil.shutdownAndAwaitTermination(executor);
    }
}
Also used : ZkController(org.apache.solr.cloud.ZkController) MockZkController(org.apache.solr.cloud.MockZkController) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test) LogLevel(org.apache.solr.util.LogLevel)

Example 2 with ZkController

use of org.apache.solr.cloud.ZkController 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)

Example 3 with ZkController

use of org.apache.solr.cloud.ZkController in project lucene-solr by apache.

the class SolrClusterReporter method setCoreContainer.

public void setCoreContainer(CoreContainer cc) {
    if (reporter != null) {
        reporter.close();
        ;
    }
    if (!enabled) {
        log.info("Reporter disabled for registry " + registryName);
        return;
    }
    // start reporter only in cloud mode
    if (!cc.isZooKeeperAware()) {
        log.warn("Not ZK-aware, not starting...");
        return;
    }
    if (period < 1) {
        // don't start it
        log.info("Turning off node reporter, period=" + period);
        return;
    }
    HttpClient httpClient = cc.getUpdateShardHandler().getHttpClient();
    ZkController zk = cc.getZkController();
    String reporterId = zk.getNodeName();
    reporter = SolrReporter.Builder.forReports(metricManager, reports).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).withHandler(handler).withReporterId(reporterId).setCompact(true).cloudClient(// we want to send reports specifically to a selected leader instance
    false).skipAggregateValues(// we don't want to transport details of aggregates
    true).skipHistograms(// we don't want to transport histograms
    true).build(httpClient, new OverseerUrlSupplier(zk));
    reporter.start(period, TimeUnit.SECONDS);
}
Also used : ZkController(org.apache.solr.cloud.ZkController) HttpClient(org.apache.http.client.HttpClient)

Example 4 with ZkController

use of org.apache.solr.cloud.ZkController in project lucene-solr by apache.

the class MDCLoggingContext method setCoreDescriptor.

public static void setCoreDescriptor(CoreContainer coreContainer, CoreDescriptor cd) {
    if (cd != null) {
        int callDepth = CALL_DEPTH.get();
        CALL_DEPTH.set(callDepth + 1);
        if (callDepth > 0) {
            return;
        }
        setCoreName(cd.getName());
        if (coreContainer != null) {
            ZkController zkController = coreContainer.getZkController();
            if (zkController != null) {
                setNodeName(zkController.getNodeName());
            }
        }
        CloudDescriptor ccd = cd.getCloudDescriptor();
        if (ccd != null) {
            setCollection(ccd.getCollectionName());
            setShard(ccd.getShardId());
            setReplica(ccd.getCoreNodeName());
        }
    }
}
Also used : ZkController(org.apache.solr.cloud.ZkController) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor)

Example 5 with ZkController

use of org.apache.solr.cloud.ZkController in project lucene-solr by apache.

the class IndexFetcher method getLeaderReplica.

private Replica getLeaderReplica() throws InterruptedException {
    ZkController zkController = solrCore.getCoreContainer().getZkController();
    CloudDescriptor cd = solrCore.getCoreDescriptor().getCloudDescriptor();
    Replica leaderReplica = zkController.getZkStateReader().getLeaderRetry(cd.getCollectionName(), cd.getShardId());
    return leaderReplica;
}
Also used : ZkController(org.apache.solr.cloud.ZkController) Replica(org.apache.solr.common.cloud.Replica) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor)

Aggregations

ZkController (org.apache.solr.cloud.ZkController)26 SolrException (org.apache.solr.common.SolrException)12 ArrayList (java.util.ArrayList)7 SolrParams (org.apache.solr.common.params.SolrParams)7 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 CloudDescriptor (org.apache.solr.cloud.CloudDescriptor)5 ClusterState (org.apache.solr.common.cloud.ClusterState)5 Replica (org.apache.solr.common.cloud.Replica)4 Slice (org.apache.solr.common.cloud.Slice)4 SolrCore (org.apache.solr.core.SolrCore)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 NamedList (org.apache.solr.common.util.NamedList)3 URI (java.net.URI)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 FilterConfig (javax.servlet.FilterConfig)2 ServletContext (javax.servlet.ServletContext)2