SOLR-10721: Provide a way to know when Core Discovery is finished and when all async cores are done loading

This commit is contained in:
Erick 2017-05-23 12:20:58 -07:00
parent 6a82b42b93
commit 28b8696d77
3 changed files with 35 additions and 5 deletions

View File

@ -222,6 +222,9 @@ New Features
* SOLR-10307: Allow Passing SSL passwords through environment variables. (Mano Kovacs via Mark Miller)
* SOLR-10721: Provide a way to know when Core Discovery is finished and when all async cores are done loading
(Erick Erickson)
Bug Fixes
----------------------
* SOLR-10723 JSON Facet API: resize() implemented incorrectly for CountSlotAcc, HllAgg.NumericAcc

View File

@ -186,6 +186,13 @@ public class CoreContainer {
protected MetricsCollectorHandler metricsCollectorHandler;
// Bits for the state variable.
public final static long LOAD_COMPLETE = 0x1L;
public final static long CORE_DISCOVERY_COMPLETE = 0x2L;
public final static long INITIAL_CORE_LOAD_COMPLETE = 0x4L;
private volatile long status = 0L;
private enum CoreInitFailedAction { fromleader, none }
/**
@ -579,7 +586,8 @@ public class CoreContainer {
Collections.sort(cds, coreComparator::compare);
}
checkForDuplicateCoreNames(cds);
status |= CORE_DISCOVERY_COMPLETE;
for (final CoreDescriptor cd : cds) {
if (cd.isTransient() || !cd.isLoadOnStartup()) {
getTransientCacheHandler().addTransientDescriptor(cd.getName(), cd);
@ -641,8 +649,11 @@ public class CoreContainer {
if (isZooKeeperAware()) {
zkSys.getZkController().checkOverseerDesignate();
}
// This is a bit redundant but these are two distinct concepts for all they're accomplished at the same time.
status |= LOAD_COMPLETE | INITIAL_CORE_LOAD_COMPLETE;
}
public TransientSolrCoreCache getTransientCacheHandler() {
if (transientCoreCache == null) {
@ -1533,6 +1544,10 @@ public class CoreContainer {
return cfg;
}
public long getStatus() {
return status;
}
}
class CloserThread extends Thread {

View File

@ -33,6 +33,9 @@ import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.apache.solr.core.CoreContainer.CORE_DISCOVERY_COMPLETE;
import static org.apache.solr.core.CoreContainer.INITIAL_CORE_LOAD_COMPLETE;
import static org.apache.solr.core.CoreContainer.LOAD_COMPLETE;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.internal.matchers.StringContains.containsString;
@ -107,14 +110,23 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
}
private CoreContainer init() throws Exception {
final CoreContainer cores = new CoreContainer();
final CoreContainer container = new CoreContainer();
try {
cores.load();
container.load();
} catch (Exception e) {
cores.shutdown();
container.shutdown();
throw e;
}
return cores;
long status = container.getStatus();
assertTrue("Load complete flag should be set",
(status & LOAD_COMPLETE) == LOAD_COMPLETE);
assertTrue("Core discovery should be complete",
(status & CORE_DISCOVERY_COMPLETE) == CORE_DISCOVERY_COMPLETE);
assertTrue("Initial core loading should be complete",
(status & INITIAL_CORE_LOAD_COMPLETE) == INITIAL_CORE_LOAD_COMPLETE);
return container;
}
@After