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. * SOLR-12395: Make 'significantTerms' the SignificantTermsQParserPlugin's name and deprecate its old 'sigificantTerms' name.
(Tobias Kässmann, Christine Poerschke) (Tobias Kässmann, Christine Poerschke)
* SOLR-12533 Collection collection fails if metrics are called during core creation (Peter Cseh, Mano Kovacs)
Optimizations Optimizations
---------------------- ----------------------

View File

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