SOLR-8793: Fix stale commit files' size computation in LukeRequestHandler

This commit is contained in:
Shai Erera 2016-03-08 22:11:18 +02:00
parent e490b329b3
commit 4384627f08
2 changed files with 16 additions and 1 deletions

View File

@ -423,6 +423,11 @@ Bug Fixes
* SOLR-8712: Variable solr.core.instanceDir was not being resolved (Kristine
Jetzke, Shawn Heisey, Alan Woodward)
* SOLR-8793: Fix Core admin status API to not fail when computing the size of the segments_N
file if the file no longer exists (for example, if a commit happened and the IndexReader
hasn't refreshed yet). In this case the reported size of the file is -1.
(Shai Erera, Alexey Serba, Richard Coggins)
======================= 5.5.0 =======================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -582,7 +582,7 @@ public class LukeRequestHandler extends RequestHandlerBase
IndexCommit indexCommit = reader.getIndexCommit();
String segmentsFileName = indexCommit.getSegmentsFileName();
indexInfo.add("segmentsFile", segmentsFileName);
indexInfo.add("segmentsFileSizeInBytes", indexCommit.getDirectory().fileLength(segmentsFileName));
indexInfo.add("segmentsFileSizeInBytes", getFileLength(indexCommit.getDirectory(), segmentsFileName));
Map<String,String> userData = indexCommit.getUserData();
indexInfo.add("userData", userData);
String s = userData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
@ -592,6 +592,16 @@ public class LukeRequestHandler extends RequestHandlerBase
return indexInfo;
}
private static long getFileLength(Directory dir, String filename) {
try {
return dir.fileLength(filename);
} catch (IOException e) {
// Whatever the error is, only log it and return -1.
log.warn("Error getting file length for [{}]", filename, e);
return -1;
}
}
/** Returns the sum of RAM bytes used by each segment */
private static long getIndexHeapUsed(DirectoryReader reader) {
long indexHeapRamBytesUsed = 0;