2727import org .apache .lucene .store .IOContext ;
2828import org .apache .lucene .util .BytesRef ;
2929import org .apache .lucene .util .Constants ;
30+ import org .apache .lucene .util .FixedBitSet ;
3031import org .elasticsearch .ElasticsearchException ;
3132import org .elasticsearch .ExceptionsHelper ;
3233import org .elasticsearch .action .ActionListener ;
7778import org .elasticsearch .index .IndexModule ;
7879import org .elasticsearch .index .IndexSettings ;
7980import org .elasticsearch .index .IndexVersion ;
81+ import org .elasticsearch .index .MergePolicyConfig ;
8082import org .elasticsearch .index .codec .CodecService ;
8183import org .elasticsearch .index .codec .TrackingPostingsInMemoryBytesCodec ;
8284import org .elasticsearch .index .engine .CommitStats ;
@@ -1981,7 +1983,10 @@ public void testShardFieldStats() throws IOException {
19811983 }
19821984
19831985 public void testShardFieldStatsWithDeletes () throws IOException {
1984- Settings settings = Settings .builder ().put (IndexSettings .INDEX_REFRESH_INTERVAL_SETTING .getKey (), TimeValue .MINUS_ONE ).build ();
1986+ Settings settings = Settings .builder ()
1987+ .put (MergePolicyConfig .INDEX_MERGE_ENABLED , false )
1988+ .put (IndexSettings .INDEX_REFRESH_INTERVAL_SETTING .getKey (), TimeValue .MINUS_ONE )
1989+ .build ();
19851990 IndexShard shard = newShard (true , settings );
19861991 assertNull (shard .getShardFieldStats ());
19871992 recoverShardFromStore (shard );
@@ -2010,8 +2015,14 @@ public void testShardFieldStatsWithDeletes() throws IOException {
20102015 stats = shard .getShardFieldStats ();
20112016 // More segments because delete operation is stored in the new segment for replication purposes.
20122017 assertThat (stats .numSegments (), equalTo (2 ));
2013- // Delete op is stored in new segment, but marked as deleted. All segements have live docs:
2014- assertThat (stats .liveDocsBytes (), equalTo (liveDocsTrackingEnabled ? 40L : 0L ));
2018+ long expectedLiveDocsSize = 0 ;
2019+ if (liveDocsTrackingEnabled ) {
2020+ // Delete op is stored in new segment, but marked as deleted. All segements have live docs:
2021+ expectedLiveDocsSize += new FixedBitSet (numDocs ).ramBytesUsed ();
2022+ // Second segment the delete operation that is marked as deleted:
2023+ expectedLiveDocsSize += new FixedBitSet (1 ).ramBytesUsed ();
2024+ }
2025+ assertThat (stats .liveDocsBytes (), equalTo (expectedLiveDocsSize ));
20152026
20162027 // delete another doc:
20172028 deleteDoc (shard , "first_1" );
@@ -2022,8 +2033,16 @@ public void testShardFieldStatsWithDeletes() throws IOException {
20222033 stats = shard .getShardFieldStats ();
20232034 // More segments because delete operation is stored in the new segment for replication purposes.
20242035 assertThat (stats .numSegments (), equalTo (3 ));
2025- // Delete op is stored in new segment, but marked as deleted. All segements have live docs:
2026- assertThat (stats .liveDocsBytes (), equalTo (liveDocsTrackingEnabled ? 56L : 0L ));
2036+ expectedLiveDocsSize = 0 ;
2037+ if (liveDocsTrackingEnabled ) {
2038+ // Delete op is stored in new segment, but marked as deleted. All segements have live docs:
2039+ // First segment with deletes
2040+ expectedLiveDocsSize += new FixedBitSet (numDocs ).ramBytesUsed ();
2041+ // Second and third segments the delete operation that is marked as deleted:
2042+ expectedLiveDocsSize += new FixedBitSet (1 ).ramBytesUsed ();
2043+ expectedLiveDocsSize += new FixedBitSet (1 ).ramBytesUsed ();
2044+ }
2045+ assertThat (stats .liveDocsBytes (), equalTo (expectedLiveDocsSize ));
20272046
20282047 closeShards (shard );
20292048 }
0 commit comments