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);
}
}
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);
}
}
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);
}
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());
}
}
}
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;
}
Aggregations