|
25 | 25 | import org.apache.lucene.search.ReferenceManager;
|
26 | 26 | import org.apache.lucene.search.similarities.Similarity;
|
27 | 27 | import org.apache.lucene.store.AlreadyClosedException;
|
28 |
| -import org.apache.lucene.store.Directory; |
29 |
| -import org.apache.lucene.store.IOContext; |
30 | 28 | import org.apache.lucene.util.Accountable;
|
31 | 29 | import org.apache.lucene.util.Accountables;
|
32 | 30 | import org.apache.lucene.util.SetOnce;
|
|
69 | 67 | import org.elasticsearch.search.suggest.completion.CompletionStats;
|
70 | 68 |
|
71 | 69 | import java.io.Closeable;
|
72 |
| -import java.io.FileNotFoundException; |
73 | 70 | import java.io.IOException;
|
74 | 71 | import java.io.UncheckedIOException;
|
75 |
| -import java.nio.file.NoSuchFileException; |
76 | 72 | import java.util.Arrays;
|
77 | 73 | import java.util.Base64;
|
78 | 74 | import java.util.Comparator;
|
@@ -139,7 +135,7 @@ protected Engine(EngineConfig engineConfig) {
|
139 | 135 | this.store = engineConfig.getStore();
|
140 | 136 | // we use the engine class directly here to make sure all subclasses have the same logger name
|
141 | 137 | this.logger = Loggers.getLogger(Engine.class,
|
142 |
| - engineConfig.getShardId()); |
| 138 | + engineConfig.getShardId()); |
143 | 139 | this.eventListener = engineConfig.getEventListener();
|
144 | 140 | }
|
145 | 141 |
|
@@ -182,7 +178,7 @@ public DocsStats docStats() {
|
182 | 178 | // when indexing but not refreshing in general. Yet, if a refresh happens the internal searcher is refresh as well so we are
|
183 | 179 | // safe here.
|
184 | 180 | try (Searcher searcher = acquireSearcher("docStats", SearcherScope.INTERNAL)) {
|
185 |
| - return docsStats(searcher.getIndexReader()); |
| 181 | + return docsStats(searcher.getIndexReader()); |
186 | 182 | }
|
187 | 183 | }
|
188 | 184 |
|
@@ -289,12 +285,14 @@ boolean throttleLockIsHeldByCurrentThread() { // to be used in assertions and te
|
289 | 285 |
|
290 | 286 | /**
|
291 | 287 | * Returns the <code>true</code> iff this engine is currently under index throttling.
|
| 288 | + * |
292 | 289 | * @see #getIndexThrottleTimeInMillis()
|
293 | 290 | */
|
294 | 291 | public abstract boolean isThrottled();
|
295 | 292 |
|
296 | 293 | /**
|
297 | 294 | * Trims translog for terms below <code>belowTerm</code> and seq# above <code>aboveSeqNo</code>
|
| 295 | + * |
298 | 296 | * @see Translog#trimOperations(long, long)
|
299 | 297 | */
|
300 | 298 | public abstract void trimOperationsFromTranslog(long belowTerm, long aboveSeqNo) throws EngineException;
|
@@ -819,86 +817,38 @@ protected void fillSegmentStats(SegmentReader segmentReader, boolean includeSegm
|
819 | 817 | stats.addNormsMemoryInBytes(guardedRamBytesUsed(segmentReader.getNormsReader()));
|
820 | 818 | stats.addPointsMemoryInBytes(guardedRamBytesUsed(segmentReader.getPointsReader()));
|
821 | 819 | stats.addDocValuesMemoryInBytes(guardedRamBytesUsed(segmentReader.getDocValuesReader()));
|
822 |
| - |
823 | 820 | if (includeSegmentFileSizes) {
|
824 |
| - // TODO: consider moving this to StoreStats |
825 |
| - stats.addFileSizes(getSegmentFileSizes(segmentReader)); |
| 821 | + stats.addFiles(getSegmentFileSizes(segmentReader)); |
826 | 822 | }
|
827 | 823 | }
|
828 | 824 |
|
829 |
| - private ImmutableOpenMap<String, Long> getSegmentFileSizes(SegmentReader segmentReader) { |
830 |
| - Directory directory = null; |
831 |
| - SegmentCommitInfo segmentCommitInfo = segmentReader.getSegmentInfo(); |
832 |
| - boolean useCompoundFile = segmentCommitInfo.info.getUseCompoundFile(); |
833 |
| - if (useCompoundFile) { |
834 |
| - try { |
835 |
| - directory = engineConfig.getCodec().compoundFormat().getCompoundReader(segmentReader.directory(), |
836 |
| - segmentCommitInfo.info, IOContext.READ); |
837 |
| - } catch (IOException e) { |
838 |
| - logger.warn(() -> new ParameterizedMessage("Error when opening compound reader for Directory [{}] and " + |
839 |
| - "SegmentCommitInfo [{}]", segmentReader.directory(), segmentCommitInfo), e); |
840 |
| - |
841 |
| - return ImmutableOpenMap.of(); |
842 |
| - } |
843 |
| - } else { |
844 |
| - directory = segmentReader.directory(); |
845 |
| - } |
846 |
| - |
847 |
| - assert directory != null; |
848 |
| - |
849 |
| - String[] files; |
850 |
| - if (useCompoundFile) { |
851 |
| - try { |
852 |
| - files = directory.listAll(); |
853 |
| - } catch (IOException e) { |
854 |
| - final Directory finalDirectory = directory; |
855 |
| - logger.warn(() -> |
856 |
| - new ParameterizedMessage("Couldn't list Compound Reader Directory [{}]", finalDirectory), e); |
857 |
| - return ImmutableOpenMap.of(); |
858 |
| - } |
859 |
| - } else { |
860 |
| - try { |
861 |
| - files = segmentReader.getSegmentInfo().files().toArray(new String[]{}); |
862 |
| - } catch (IOException e) { |
863 |
| - logger.warn(() -> |
864 |
| - new ParameterizedMessage("Couldn't list Directory from SegmentReader [{}] and SegmentInfo [{}]", |
865 |
| - segmentReader, segmentReader.getSegmentInfo()), e); |
866 |
| - return ImmutableOpenMap.of(); |
867 |
| - } |
868 |
| - } |
869 |
| - |
870 |
| - ImmutableOpenMap.Builder<String, Long> map = ImmutableOpenMap.builder(); |
871 |
| - for (String file : files) { |
872 |
| - String extension = IndexFileNames.getExtension(file); |
873 |
| - long length = 0L; |
874 |
| - try { |
875 |
| - length = directory.fileLength(file); |
876 |
| - } catch (NoSuchFileException | FileNotFoundException e) { |
877 |
| - final Directory finalDirectory = directory; |
878 |
| - logger.warn(() -> new ParameterizedMessage("Tried to query fileLength but file is gone [{}] [{}]", |
879 |
| - finalDirectory, file), e); |
880 |
| - } catch (IOException e) { |
881 |
| - final Directory finalDirectory = directory; |
882 |
| - logger.warn(() -> new ParameterizedMessage("Error when trying to query fileLength [{}] [{}]", |
883 |
| - finalDirectory, file), e); |
884 |
| - } |
885 |
| - if (length == 0L) { |
886 |
| - continue; |
887 |
| - } |
888 |
| - map.put(extension, length); |
889 |
| - } |
890 |
| - |
891 |
| - if (useCompoundFile) { |
892 |
| - try { |
893 |
| - directory.close(); |
894 |
| - } catch (IOException e) { |
895 |
| - final Directory finalDirectory = directory; |
896 |
| - logger.warn(() -> new ParameterizedMessage("Error when closing compound reader on Directory [{}]", |
897 |
| - finalDirectory), e); |
| 825 | + private ImmutableOpenMap<String, SegmentsStats.FileStats> getSegmentFileSizes(SegmentReader segmentReader) { |
| 826 | + try { |
| 827 | + final ImmutableOpenMap.Builder<String, SegmentsStats.FileStats> files = ImmutableOpenMap.builder(); |
| 828 | + final SegmentCommitInfo segmentCommitInfo = segmentReader.getSegmentInfo(); |
| 829 | + for (String fileName : segmentCommitInfo.files()) { |
| 830 | + String fileExtension = IndexFileNames.getExtension(fileName); |
| 831 | + if (fileExtension != null) { |
| 832 | + try { |
| 833 | + long fileLength = segmentReader.directory().fileLength(fileName); |
| 834 | + files.put(fileExtension, new SegmentsStats.FileStats(fileExtension, fileLength, 1L, fileLength, fileLength)); |
| 835 | + } catch (IOException ioe) { |
| 836 | + logger.warn(() -> |
| 837 | + new ParameterizedMessage("Error when retrieving file length for [{}]", fileName), ioe); |
| 838 | + } catch (AlreadyClosedException ace) { |
| 839 | + logger.warn(() -> |
| 840 | + new ParameterizedMessage("Error when retrieving file length for [{}], directory is closed", fileName), ace); |
| 841 | + return ImmutableOpenMap.of(); |
| 842 | + } |
| 843 | + } |
898 | 844 | }
|
| 845 | + return files.build(); |
| 846 | + } catch (IOException e) { |
| 847 | + logger.warn(() -> |
| 848 | + new ParameterizedMessage("Error when listing files for segment reader [{}] and segment info [{}]", |
| 849 | + segmentReader, segmentReader.getSegmentInfo()), e); |
| 850 | + return ImmutableOpenMap.of(); |
899 | 851 | }
|
900 |
| - |
901 |
| - return map.build(); |
902 | 852 | }
|
903 | 853 |
|
904 | 854 | protected void writerSegmentStats(SegmentsStats stats) {
|
|
0 commit comments