Skip to content

Use static constant for "segments_stats" source #129406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public abstract class Engine implements Closeable {
public static final String SEARCH_SOURCE = "search"; // TODO: Make source of search enum?
public static final String CAN_MATCH_SEARCH_SOURCE = "can_match";
protected static final String DOC_STATS_SOURCE = "doc_stats";
protected static final String SEGMENTS_STATS_SOURCE = "segments_stats";
public static final long UNKNOWN_PRIMARY_TERM = -1L;
public static final String ROOT_DOC_FIELD_NAME = "__root_doc_for_nested";

Expand Down Expand Up @@ -1136,15 +1137,15 @@ public SegmentsStats segmentsStats(boolean includeSegmentFileSizes, boolean incl
ensureOpen();
Set<String> segmentName = new HashSet<>();
SegmentsStats stats = new SegmentsStats();
try (Searcher searcher = acquireSearcher("segments_stats", SearcherScope.INTERNAL)) {
try (Searcher searcher = acquireSearcher(SEGMENTS_STATS_SOURCE, SearcherScope.INTERNAL)) {
for (LeafReaderContext ctx : searcher.getIndexReader().getContext().leaves()) {
SegmentReader segmentReader = Lucene.segmentReader(ctx.reader());
fillSegmentStats(segmentReader, includeSegmentFileSizes, stats);
segmentName.add(segmentReader.getSegmentName());
}
}

try (Searcher searcher = acquireSearcher("segments_stats", SearcherScope.EXTERNAL)) {
try (Searcher searcher = acquireSearcher(SEGMENTS_STATS_SOURCE, SearcherScope.EXTERNAL)) {
for (LeafReaderContext ctx : searcher.getIndexReader().getContext().leaves()) {
SegmentReader segmentReader = Lucene.segmentReader(ctx.reader());
if (segmentName.contains(segmentReader.getSegmentName()) == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ final boolean assertSearcherIsWarmedUp(String source, SearcherScope scope) {
switch (source) {
// we can access segment_stats while a shard is still in the recovering state.
case "segments":
case "segments_stats":
case SEGMENTS_STATS_SOURCE:
break;
default:
assert externalReaderManager.isWarmedUp : "searcher was not warmed up yet for source[" + source + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private Engine.Searcher openSearcher(String source, SearcherScope scope) throws
case "refresh_needed":
assert false : "refresh_needed is always false";
case "segments":
case "segments_stats":
case SEGMENTS_STATS_SOURCE:
case "completion_stats":
case FIELD_RANGE_SEARCH_SOURCE: // special case for field_range - we use the cached point values reader
case CAN_MATCH_SEARCH_SOURCE: // special case for can_match phase - we use the cached point values reader
Expand Down