-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Return cached segments stats if include_unloaded_segments
is true
#39698
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
Changes from all commits
a39ad3a
2f18ca9
31844b6
d734371
1685a65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
|
||
- do: | ||
cluster.health: | ||
wait_for_no_initializing_shards: true | ||
|
||
--- | ||
"Segment Stats": | ||
|
||
- skip: | ||
version: " - 7.99.99" | ||
reason: forbid_closed_indices is not supported in ealier version | ||
|
||
- do: | ||
indices.stats: | ||
metric: [ segments ] | ||
- set: { indices.test.primaries.segments.count: num_segments } | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 1 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
indices.flush: | ||
index: test | ||
|
||
- do: | ||
indices.stats: | ||
metric: [ segments ] | ||
- gt: { indices.test.primaries.segments.count: $num_segments } | ||
- set: { indices.test.primaries.segments.count: num_segments_after_flush } | ||
|
||
- do: | ||
indices.close: | ||
index: test | ||
|
||
- do: | ||
indices.stats: | ||
metric: segments | ||
expand_wildcards: closed | ||
forbid_closed_indices: false | ||
|
||
- match: { indices.test.primaries.segments.count: 0 } | ||
|
||
- do: | ||
indices.stats: | ||
metric: segments | ||
include_unloaded_segments: true | ||
expand_wildcards: closed | ||
forbid_closed_indices: false | ||
|
||
- match: { indices.test.primaries.segments.count: $num_segments_after_flush } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,13 @@ | |
import org.apache.lucene.index.IndexCommit; | ||
import org.apache.lucene.index.IndexWriter; | ||
import org.apache.lucene.index.LeafReader; | ||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.index.SegmentReader; | ||
import org.apache.lucene.store.Directory; | ||
import org.elasticsearch.common.lucene.Lucene; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
|
@@ -36,8 +40,20 @@ | |
*/ | ||
public final class NoOpEngine extends ReadOnlyEngine { | ||
|
||
private final SegmentsStats stats; | ||
|
||
public NoOpEngine(EngineConfig config) { | ||
super(config, null, null, true, Function.identity()); | ||
this.stats = new SegmentsStats(); | ||
Directory directory = store.directory(); | ||
try (DirectoryReader reader = DirectoryReader.open(directory)) { | ||
for (LeafReaderContext ctx : reader.getContext().leaves()) { | ||
SegmentReader segmentReader = Lucene.segmentReader(ctx.reader()); | ||
fillSegmentStats(segmentReader, true, stats); | ||
} | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -47,17 +63,17 @@ protected DirectoryReader open(final IndexCommit commit) throws IOException { | |
final IndexCommit indexCommit = indexCommits.get(indexCommits.size() - 1); | ||
return new DirectoryReader(directory, new LeafReader[0]) { | ||
@Override | ||
protected DirectoryReader doOpenIfChanged() throws IOException { | ||
protected DirectoryReader doOpenIfChanged() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected DirectoryReader doOpenIfChanged(IndexCommit commit) throws IOException { | ||
protected DirectoryReader doOpenIfChanged(IndexCommit commit) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected DirectoryReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes) throws IOException { | ||
protected DirectoryReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes) { | ||
return null; | ||
} | ||
|
||
|
@@ -67,17 +83,17 @@ public long getVersion() { | |
} | ||
|
||
@Override | ||
public boolean isCurrent() throws IOException { | ||
public boolean isCurrent() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public IndexCommit getIndexCommit() throws IOException { | ||
public IndexCommit getIndexCommit() { | ||
return indexCommit; | ||
} | ||
|
||
@Override | ||
protected void doClose() throws IOException { | ||
protected void doClose() { | ||
} | ||
|
||
@Override | ||
|
@@ -86,4 +102,18 @@ public CacheHelper getReaderCacheHelper() { | |
} | ||
}; | ||
} | ||
|
||
@Override | ||
public SegmentsStats segmentsStats(boolean includeSegmentFileSizes, boolean includeUnloadedSegments) { | ||
if (includeUnloadedSegments) { | ||
final SegmentsStats stats = new SegmentsStats(); | ||
stats.add(this.stats); | ||
if (includeSegmentFileSizes == false) { | ||
stats.clearFileSizes(); | ||
} | ||
return stats; | ||
} else { | ||
return super.segmentsStats(includeSegmentFileSizes, includeUnloadedSegments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. calling this will fail on a NoopEngine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm there is a test for this here that shows that it's not failing but returning an empty object. |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we introducing this parameter only for BWC of behavior in 7.x or do you think this could still be useful in 8.0? In 8.0 I would expect this parameter to be false by default, and I'm not sure why I would ever explicitly set it to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ywelsch I must have missed something, the tests failed if I'd not have that in there. Maybe I ran tests before the relevant change was introduced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a misunderstanding. What I meant by "In 8.0 I would expect this parameter to be false by default" is that I think we should make it default to false in 8.0, so that if you include closed indices in your indices stats request, that the request does not fail by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ywelsch I would like to merge as is and then go and change the defaults for stats in a separate pr. ok with you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, let's do it like that