Skip to content

Apache Lucene open-source search software

SOLR-3990: Moves getIndexSize() from ReplicationHandler to SolrCore

Dennis Govebd39ae9c9d85
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index cb41602970f..556ab23a0d1 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -386,6 +386,7 @@ Other Changes
* SOLR-9915: PeerSync alreadyInSync check is not backwards compatible and results in full replication during a rolling restart
(Tim Owen via noble)
+* SOLR-3990: Moves getIndexSize() from ReplicationHandler to SolrCore (Shawn Heisey)
================== 6.3.0 ==================
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index a9fec5ad142..08072e158f9 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -146,6 +146,7 @@ import org.apache.solr.update.processor.UpdateRequestProcessorChain;
import org.apache.solr.update.processor.UpdateRequestProcessorChain.ProcessorInfo;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
import org.apache.solr.util.DefaultSolrThreadFactory;
+import org.apache.solr.util.NumberUtils;
import org.apache.solr.util.PropertiesInputStream;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
@@ -391,6 +392,22 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
public IndexReaderFactory getIndexReaderFactory() {
return indexReaderFactory;
}
+
+ public long getIndexSize() {
+ Directory dir;
+ long size = 0;
+ try {
+ 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);
+ }
+ return size;
+ }
@Override
public String getName() {
@@ -2653,6 +2670,9 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
lst.add("refCount", getOpenCount());
lst.add("instanceDir", resourceLoader.getInstancePath());
lst.add("indexDir", getIndexDir());
+ long size = getIndexSize();
+ lst.add("sizeInBytes", size);
+ lst.add("size", NumberUtils.readableSize(size));
CoreDescriptor cd = getCoreDescriptor();
if (cd != null) {
diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
index 08b6f39aa05..edf5e949d24 100644
--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
@@ -813,22 +813,6 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
numTimesReplicated++;
}
- long getIndexSize() {
- Directory dir;
- long size = 0;
- try {
- dir = core.getDirectoryFactory().get(core.getIndexDir(), 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 String getDescription() {
return "ReplicationHandler provides replication of index and configuration files from Master to Slaves";
@@ -855,7 +839,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
public NamedList getStatistics() {
NamedList list = super.getStatistics();
if (core != null) {
- list.add("indexSize", NumberUtils.readableSize(getIndexSize()));
+ list.add("indexSize", NumberUtils.readableSize(core.getIndexSize()));
CommitVersionInfo vInfo = (core != null && !core.isClosed()) ? getIndexVersion(): null;
list.add("indexVersion", null == vInfo ? 0 : vInfo.version);
list.add(GENERATION, null == vInfo ? 0 : vInfo.generation);
@@ -907,7 +891,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
NamedList<Object> master = new SimpleOrderedMap<>();
NamedList<Object> slave = new SimpleOrderedMap<>();
- details.add("indexSize", NumberUtils.readableSize(getIndexSize()));
+ details.add("indexSize", NumberUtils.readableSize(core.getIndexSize()));
details.add("indexPath", core.getIndexDir());
details.add(CMD_SHOW_COMMITS, getCommits());
details.add("isMaster", String.valueOf(isMaster));