mirror of https://github.com/apache/lucene.git
SOLR-11235: Some SolrCore metrics should check if core is closed before reporting.
This commit is contained in:
parent
c861c12d15
commit
afe7dffa23
|
@ -459,6 +459,8 @@ Bug Fixes
|
|||
* SOLR-11221: SolrJmxReporter broken on core reload. This resulted in some or most metrics not being reported
|
||||
via JMX after core reloads, depending on timing. (ab)
|
||||
|
||||
* SOLR-11235: Some SolrCore metrics should check if core is closed before reporting. (ab)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -1133,9 +1133,9 @@ public final class SolrCore implements SolrInfoBean, SolrMetricProducer, Closeab
|
|||
manager.registerGauge(this, registry, () -> startTime, true, "startTime", Category.CORE.toString());
|
||||
manager.registerGauge(this, registry, () -> getOpenCount(), true, "refCount", Category.CORE.toString());
|
||||
manager.registerGauge(this, registry, () -> resourceLoader.getInstancePath().toString(), true, "instanceDir", Category.CORE.toString());
|
||||
manager.registerGauge(this, registry, () -> getIndexDir(), true, "indexDir", Category.CORE.toString());
|
||||
manager.registerGauge(this, registry, () -> getIndexSize(), true, "sizeInBytes", Category.INDEX.toString());
|
||||
manager.registerGauge(this, registry, () -> NumberUtils.readableSize(getIndexSize()), true, "size", Category.INDEX.toString());
|
||||
manager.registerGauge(this, registry, () -> isClosed() ? "(closed)" : getIndexDir(), true, "indexDir", Category.CORE.toString());
|
||||
manager.registerGauge(this, registry, () -> isClosed() ? 0 : getIndexSize(), true, "sizeInBytes", Category.INDEX.toString());
|
||||
manager.registerGauge(this, registry, () -> isClosed() ? "(closed)" : NumberUtils.readableSize(getIndexSize()), true, "size", Category.INDEX.toString());
|
||||
if (coreContainer != null) {
|
||||
manager.registerGauge(this, registry, () -> coreContainer.getNamesForCore(this), true, "aliases", Category.CORE.toString());
|
||||
final CloudDescriptor cd = getCoreDescriptor().getCloudDescriptor();
|
||||
|
@ -1488,6 +1488,16 @@ public final class SolrCore implements SolrInfoBean, SolrMetricProducer, Closeab
|
|||
}
|
||||
log.info(logid+" CLOSING SolrCore " + this);
|
||||
|
||||
// stop reporting metrics
|
||||
try {
|
||||
coreMetricManager.close();
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
}
|
||||
|
||||
if( closeHooks != null ) {
|
||||
for( CloseHook hook : closeHooks ) {
|
||||
try {
|
||||
|
@ -1586,15 +1596,6 @@ public final class SolrCore implements SolrInfoBean, SolrMetricProducer, Closeab
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
coreMetricManager.close();
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
}
|
||||
|
||||
// Close the snapshots meta-data directory.
|
||||
Directory snapshotsDir = snapshotMgr.getSnapshotsDir();
|
||||
try {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.solr.metrics.reporters;
|
||||
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
|
@ -174,6 +175,41 @@ public class SolrJmxReporterTest extends SolrTestCaseJ4 {
|
|||
rootName.equals(o.getObjectName().getDomain())).count());
|
||||
}
|
||||
|
||||
private static boolean stopped = false;
|
||||
|
||||
@Test
|
||||
public void testClosedCore() throws Exception {
|
||||
Set<ObjectInstance> objects = mBeanServer.queryMBeans(new ObjectName("*:category=CORE,name=indexDir,*"), null);
|
||||
assertEquals("Unexpected number of indexDir beans: " + objects.toString(), 1, objects.size());
|
||||
final ObjectInstance inst = objects.iterator().next();
|
||||
stopped = false;
|
||||
try {
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
while (!stopped) {
|
||||
try {
|
||||
Object value = mBeanServer.getAttribute(inst.getObjectName(), "Value");
|
||||
assertNotNull(value);
|
||||
} catch (InstanceNotFoundException x) {
|
||||
// no longer present
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
fail("Unexpected error retrieving attribute: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
Thread.sleep(500);
|
||||
h.getCoreContainer().unload(h.getCore().getName());
|
||||
Thread.sleep(2000);
|
||||
objects = mBeanServer.queryMBeans(new ObjectName("*:category=CORE,name=indexDir,*"), null);
|
||||
assertEquals("Unexpected number of beans after core closed: " + objects, 0, objects.size());
|
||||
} finally {
|
||||
stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnabled() throws Exception {
|
||||
String root1 = PREFIX + TestUtil.randomSimpleString(random(), 5, 10);
|
||||
|
|
Loading…
Reference in New Issue