Skip to content

Commit e5b4fa1

Browse files
committed
Update testShardFieldStats for new calculation
1 parent 67e7578 commit e5b4fa1

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import org.elasticsearch.index.IndexSettings;
7979
import org.elasticsearch.index.IndexVersion;
8080
import org.elasticsearch.index.codec.CodecService;
81+
import org.elasticsearch.index.codec.TrackingPostingsInMemoryBytesCodec;
8182
import org.elasticsearch.index.engine.CommitStats;
8283
import org.elasticsearch.index.engine.DocIdSeqNoAndSource;
8384
import org.elasticsearch.index.engine.Engine;
@@ -1883,6 +1884,9 @@ public void testShardFieldStats() throws IOException {
18831884
assertThat(stats.totalFields(), equalTo(0));
18841885
assertThat(stats.fieldUsages(), equalTo(0L));
18851886
assertThat(stats.postingsInMemoryBytes(), equalTo(0L));
1887+
1888+
boolean postingsBytesTrackingEnabled = TrackingPostingsInMemoryBytesCodec.TRACK_POSTINGS_IN_MEMORY_BYTES.isEnabled();
1889+
18861890
// index some documents
18871891
int numDocs = between(2, 10);
18881892
for (int i = 0; i < numDocs; i++) {
@@ -1902,9 +1906,9 @@ public void testShardFieldStats() throws IOException {
19021906
// _id(term), _source(0), _version(dv), _primary_term(dv), _seq_no(point,dv), f1(postings,norms),
19031907
// f1.keyword(term,dv), f2(postings,norms), f2.keyword(term,dv),
19041908
assertThat(stats.fieldUsages(), equalTo(13L));
1905-
// _id: 8, f1: 3, f1.keyword: 3, f2: 3, f2.keyword: 3
1906-
// (8 + 3 + 3 + 3 + 3) * 2 = 40
1907-
assertThat(stats.postingsInMemoryBytes(), equalTo(40L));
1909+
// _id: (5,8), f1: 3, f1.keyword: 3, f2: 3, f2.keyword: 3
1910+
// 5 + 8 + 3 + 3 + 3 + 3 = 25
1911+
assertThat(stats.postingsInMemoryBytes(), equalTo(postingsBytesTrackingEnabled ? 25L : 0L));
19081912
// don't re-compute on refresh without change
19091913
if (randomBoolean()) {
19101914
shard.refresh("test");
@@ -1922,12 +1926,19 @@ public void testShardFieldStats() throws IOException {
19221926
}
19231927
assertThat(shard.getShardFieldStats(), sameInstance(stats));
19241928
// index more docs
1925-
numDocs = between(2, 10);
1929+
numDocs = between(1, 10);
1930+
indexDoc(shard, "_doc", "first_0", """
1931+
{
1932+
"f1": "lorem",
1933+
"f2": "bar",
1934+
"f3": "sit amet"
1935+
}
1936+
""");
19261937
for (int i = 0; i < numDocs; i++) {
1927-
indexDoc(shard, "_doc", "first_" + i, """
1938+
indexDoc(shard, "_doc", "first_" + i + 1, """
19281939
{
19291940
"f1": "foo",
1930-
"f2": "bar",
1941+
"f2": "ipsum",
19311942
"f3": "foobar"
19321943
}
19331944
""");
@@ -1952,20 +1963,20 @@ public void testShardFieldStats() throws IOException {
19521963
assertThat(stats.totalFields(), equalTo(21));
19531964
// first segment: 13, second segment: 13 + f3(postings,norms) + f3.keyword(term,dv), and __soft_deletes to previous segment
19541965
assertThat(stats.fieldUsages(), equalTo(31L));
1955-
// segment 1: 40 (see above)
1956-
// segment 2: _id: 8, f1: 3, f1.keyword: 3, f2: 3, f2.keyword: 3, f3: 6, f3.keyword: 6
1957-
// (8 + 3 + 3 + 3 + 3 + 6 + 6) * 2 q= 64
1958-
// 40 + 64 = 104
1959-
assertThat(stats.postingsInMemoryBytes(), equalTo(104L));
1966+
// segment 1: 25 (see above)
1967+
// segment 2: _id: (5,6), f1: (3,5), f1.keyword: (3,5), f2: (3,5), f2.keyword: (3,5), f3: (4,3), f3.keyword: (6,8)
1968+
// (5+6) + (3+5) + (3+5) + (3+5) + (3+5) + (4+3) + (6+8) = 64
1969+
// 25 + 64 = 89
1970+
assertThat(stats.postingsInMemoryBytes(), equalTo(postingsBytesTrackingEnabled ? 89L : 0L));
19601971
shard.forceMerge(new ForceMergeRequest().maxNumSegments(1).flush(true));
19611972
stats = shard.getShardFieldStats();
19621973
assertThat(stats.numSegments(), equalTo(1));
19631974
assertThat(stats.totalFields(), equalTo(12));
19641975
// _id(term), _source(0), _version(dv), _primary_term(dv), _seq_no(point,dv), f1(postings,norms),
19651976
// f1.keyword(term,dv), f2(postings,norms), f2.keyword(term,dv), f3(postings,norms), f3.keyword(term,dv), __soft_deletes
19661977
assertThat(stats.fieldUsages(), equalTo(18L));
1967-
// max(segment1: 40, segment2: 64) = 64
1968-
assertThat(stats.postingsInMemoryBytes(), equalTo(64L));
1978+
// _id: (5,8), f1: (3,5), f1.keyword: (3,5), f2: (3,5), f2.keyword: (3,5), f3: (4,3), f3.keyword: (6,8)
1979+
assertThat(stats.postingsInMemoryBytes(), equalTo(postingsBytesTrackingEnabled ? 66L : 0L));
19691980
closeShards(shard);
19701981
}
19711982

0 commit comments

Comments
 (0)