SOLR-12533: getting index size shouldn't create directory (metrics race)

This commit is contained in:
yonik 2018-07-03 22:55:38 -04:00
parent 6d0ad625c8
commit b7b6f242e8
3 changed files with 10 additions and 26 deletions

View File

@ -134,6 +134,8 @@ Bug Fixes
* SOLR-12395: Make 'significantTerms' the SignificantTermsQParserPlugin's name and deprecate its old 'sigificantTerms' name.
(Tobias Kässmann, Christine Poerschke)
* SOLR-12533 Collection collection fails if metrics are called during core creation (Peter Cseh, Mano Kovacs)
Optimizations
----------------------

View File

@ -429,11 +429,13 @@ public final class SolrCore implements SolrInfoBean, SolrMetricProducer, Closeab
Directory dir;
long size = 0;
try {
dir = directoryFactory.get(getIndexDir(), DirContext.DEFAULT, solrConfig.indexConfig.lockType);
try {
size = DirectoryFactory.sizeOfDirectory(dir);
} finally {
directoryFactory.release(dir);
if (directoryFactory.exists(getIndexDir())) {
dir = directoryFactory.get(getIndexDir(), DirContext.DEFAULT, solrConfig.indexConfig.lockType);
try {
size = DirectoryFactory.sizeOfDirectory(dir);
} finally {
directoryFactory.release(dir);
}
}
} catch (IOException e) {
SolrException.log(log, "IO error while trying to get the size of the Directory", e);

View File

@ -24,7 +24,6 @@ import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.store.Directory;
import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrException;
@ -36,7 +35,6 @@ import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.DirectoryFactory;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoBean;
import org.apache.solr.core.snapshots.SolrSnapshotManager;
@ -341,7 +339,7 @@ enum CoreAdminOperation implements CoreAdminOp {
RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
try {
SimpleOrderedMap<Object> indexInfo = LukeRequestHandler.getIndexInfo(searcher.get().getIndexReader());
long size = getIndexSize(core);
long size = core.getIndexSize();
indexInfo.add("sizeInBytes", size);
indexInfo.add("size", NumberUtils.readableSize(size));
info.add("index", indexInfo);
@ -356,24 +354,6 @@ enum CoreAdminOperation implements CoreAdminOp {
return info;
}
static long getIndexSize(SolrCore core) {
Directory dir;
long size = 0;
try {
dir = core.getDirectoryFactory().get(core.getIndexDir(), DirectoryFactory.DirContext.DEFAULT, core.getSolrConfig().indexConfig.lockType);
try {
size = core.getDirectoryFactory().size(dir);
} finally {
core.getDirectoryFactory().release(dir);
}
} catch (IOException e) {
SolrException.log(log, "IO error while trying to get the size of the Directory", e);
}
return size;
}
@Override
public void execute(CallInfo it) throws Exception {
try {