27
27
import org .apache .lucene .store .IOContext ;
28
28
import org .apache .lucene .util .BytesRef ;
29
29
import org .apache .lucene .util .Constants ;
30
+ import org .apache .lucene .util .FixedBitSet ;
30
31
import org .elasticsearch .ElasticsearchException ;
31
32
import org .elasticsearch .ExceptionsHelper ;
32
33
import org .elasticsearch .action .ActionListener ;
77
78
import org .elasticsearch .index .IndexModule ;
78
79
import org .elasticsearch .index .IndexSettings ;
79
80
import org .elasticsearch .index .IndexVersion ;
81
+ import org .elasticsearch .index .MergePolicyConfig ;
80
82
import org .elasticsearch .index .codec .CodecService ;
81
83
import org .elasticsearch .index .codec .TrackingPostingsInMemoryBytesCodec ;
82
84
import org .elasticsearch .index .engine .CommitStats ;
@@ -1981,7 +1983,10 @@ public void testShardFieldStats() throws IOException {
1981
1983
}
1982
1984
1983
1985
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 ();
1985
1990
IndexShard shard = newShard (true , settings );
1986
1991
assertNull (shard .getShardFieldStats ());
1987
1992
recoverShardFromStore (shard );
@@ -2010,8 +2015,14 @@ public void testShardFieldStatsWithDeletes() throws IOException {
2010
2015
stats = shard .getShardFieldStats ();
2011
2016
// More segments because delete operation is stored in the new segment for replication purposes.
2012
2017
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 ));
2015
2026
2016
2027
// delete another doc:
2017
2028
deleteDoc (shard , "first_1" );
@@ -2022,8 +2033,16 @@ public void testShardFieldStatsWithDeletes() throws IOException {
2022
2033
stats = shard .getShardFieldStats ();
2023
2034
// More segments because delete operation is stored in the new segment for replication purposes.
2024
2035
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 ));
2027
2046
2028
2047
closeShards (shard );
2029
2048
}
0 commit comments