use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class SolrShardReporterTest method test.
@Test
public void test() throws Exception {
waitForRecoveriesToFinish("control_collection", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
waitForRecoveriesToFinish("collection1", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
printLayout();
// wait for at least two reports
Thread.sleep(10000);
ClusterState state = jettys.get(0).getCoreContainer().getZkController().getClusterState();
for (JettySolrRunner jetty : jettys) {
CoreContainer cc = jetty.getCoreContainer();
SolrMetricManager metricManager = cc.getMetricManager();
for (final String coreName : cc.getLoadedCoreNames()) {
CoreDescriptor cd = cc.getCoreDescriptor(coreName);
if (cd.getCloudDescriptor() == null) {
// not a cloud collection
continue;
}
CloudDescriptor cloudDesc = cd.getCloudDescriptor();
DocCollection docCollection = state.getCollection(cloudDesc.getCollectionName());
String replicaName = SolrCoreMetricManager.parseReplicaName(cloudDesc.getCollectionName(), coreName);
if (replicaName == null) {
replicaName = cloudDesc.getCoreNodeName();
}
String registryName = SolrCoreMetricManager.createRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId(), replicaName, null);
String leaderRegistryName = SolrCoreMetricManager.createLeaderRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId());
boolean leader = cloudDesc.isLeader();
Slice slice = docCollection.getSlice(cloudDesc.getShardId());
int numReplicas = slice.getReplicas().size();
if (leader) {
assertTrue(metricManager.registryNames() + " doesn't contain " + leaderRegistryName, metricManager.registryNames().contains(leaderRegistryName));
Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
metrics.forEach((k, v) -> {
assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
AggregateMetric am = (AggregateMetric) v;
if (!k.startsWith("REPLICATION.peerSync")) {
assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), numReplicas, am.size());
}
});
} else {
assertFalse(metricManager.registryNames() + " contains " + leaderRegistryName + " but it's not a leader!", metricManager.registryNames().contains(leaderRegistryName));
Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
metrics.forEach((k, v) -> {
assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
AggregateMetric am = (AggregateMetric) v;
if (!k.startsWith("REPLICATION.peerSync")) {
assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), 1, am.size());
}
});
}
assertTrue(metricManager.registryNames() + " doesn't contain " + registryName, metricManager.registryNames().contains(registryName));
}
}
SolrMetricManager metricManager = controlJetty.getCoreContainer().getMetricManager();
assertTrue(metricManager.registryNames().contains("solr.cluster"));
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class TestIndexSearcher method testUseColdSearcher.
public void testUseColdSearcher() throws Exception {
MockSearchComponent.registerFirstSearcherListener = false;
MockSearchComponent.registerNewSearcherListener = false;
MockSearchComponent.registerSlowSearcherListener = true;
final AtomicBoolean querySucceeded = new AtomicBoolean(false);
SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
SlowSearcherListener.latch = new CountDownLatch(1);
CoreContainer cores = h.getCoreContainer();
CoreDescriptor cd = h.getCore().getCoreDescriptor();
final SolrCore newCore;
boolean coreCreated = false;
try {
System.setProperty("tests.solr.useColdSearcher", "true");
// Create a new core, this should call all the firstSearcherListeners
newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
coreCreated = true;
//validate that the new core was created with the correct solrconfig
assertNotNull(newCore.getSearchComponent("mock"));
assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
assertTrue(newCore.getSolrConfig().useColdSearcher);
Thread t = new Thread() {
public void run() {
try {
doQuery(newCore);
querySucceeded.set(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
;
};
t.start();
// validate that the query runs before the searcher warmer finishes
for (int i = 0; i <= 1000; i++) {
if (querySucceeded.get()) {
break;
}
if (i == 1000) {
fail("Query didn't succeed after 10 secoonds");
}
Thread.sleep(10);
}
assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
} finally {
System.getProperties().remove("tests.solr.useColdSearcher");
if (coreCreated) {
SlowSearcherListener.latch.countDown();
cores.unload("core1");
}
}
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class TestIndexSearcher method testDontUseColdSearcher.
public void testDontUseColdSearcher() throws Exception {
MockSearchComponent.registerFirstSearcherListener = false;
MockSearchComponent.registerNewSearcherListener = false;
MockSearchComponent.registerSlowSearcherListener = true;
final AtomicBoolean querySucceeded = new AtomicBoolean(false);
SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
SlowSearcherListener.latch = new CountDownLatch(1);
CoreContainer cores = h.getCoreContainer();
CoreDescriptor cd = h.getCore().getCoreDescriptor();
final SolrCore newCore;
boolean coreCreated = false;
try {
// Create a new core, this should call all the firstSearcherListeners
newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
coreCreated = true;
//validate that the new core was created with the correct solrconfig
assertNotNull(newCore.getSearchComponent("mock"));
assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
assertFalse(newCore.getSolrConfig().useColdSearcher);
Thread t = new Thread() {
public void run() {
try {
doQuery(newCore);
querySucceeded.set(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
;
};
t.start();
if (System.getProperty(SYSPROP_NIGHTLY) != null) {
// even if we wait here, the SearcherListener should not finish
Thread.sleep(500);
}
// validate that the searcher warmer didn't finish yet.
assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
assertFalse("Query should be waiting for warming to finish", querySucceeded.get());
// Let warmer finish
SlowSearcherListener.latch.countDown();
// Validate that the query eventually succeeds
for (int i = 0; i <= 1000; i++) {
if (querySucceeded.get()) {
break;
}
if (i == 1000) {
fail("Query didn't succeed after 10 secoonds");
}
Thread.sleep(10);
}
} finally {
if (coreCreated) {
cores.unload("core1");
}
}
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class ZkControllerTest method testGetHostName.
public void testGetHostName() throws Exception {
String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
CoreContainer cc = null;
ZkTestServer server = new ZkTestServer(zkDir);
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
cc = getCoreContainer();
ZkController zkController = null;
try {
CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {
@Override
public List<CoreDescriptor> getCurrentDescriptors() {
// do nothing
return null;
}
});
} catch (IllegalArgumentException e) {
fail("ZkController did not normalize host name correctly");
} finally {
if (zkController != null)
zkController.close();
}
} finally {
if (cc != null) {
cc.shutdown();
}
server.shutdown();
}
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class ZkController method registerAllCoresAsDown.
private void registerAllCoresAsDown(final CurrentCoreDescriptorProvider registerOnReconnect, boolean updateLastPublished) {
List<CoreDescriptor> descriptors = registerOnReconnect.getCurrentDescriptors();
if (isClosed)
return;
if (descriptors != null) {
// before registering as live, make sure everyone is in a
// down state
publishNodeAsDown(getNodeName());
for (CoreDescriptor descriptor : descriptors) {
// if it looks like we are going to be the leader, we don't
// want to wait for the following stuff
CloudDescriptor cloudDesc = descriptor.getCloudDescriptor();
String collection = cloudDesc.getCollectionName();
String slice = cloudDesc.getShardId();
try {
int children = zkStateReader.getZkClient().getChildren(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/leader_elect/" + slice + "/election", null, true).size();
if (children == 0) {
log.debug("looks like we are going to be the leader for collection {} shard {}", collection, slice);
continue;
}
} catch (NoNodeException e) {
log.debug("looks like we are going to be the leader for collection {} shard {}", collection, slice);
continue;
} catch (InterruptedException e2) {
Thread.currentThread().interrupt();
} catch (KeeperException e) {
log.warn("", e);
Thread.currentThread().interrupt();
}
final String coreZkNodeName = descriptor.getCloudDescriptor().getCoreNodeName();
try {
log.debug("calling waitForLeaderToSeeDownState for coreZkNodeName={} collection={} shard={}", new Object[] { coreZkNodeName, collection, slice });
waitForLeaderToSeeDownState(descriptor, coreZkNodeName);
} catch (Exception e) {
SolrException.log(log, "", e);
if (isClosed) {
return;
}
}
}
}
}
Aggregations