2929import java .util .Optional ;
3030
3131import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertNoFailures ;
32+ import static org .hamcrest .Matchers .greaterThan ;
3233import static org .hamcrest .Matchers .lessThanOrEqualTo ;
3334
3435public class IndexingMemoryControllerIT extends ESSingleNodeTestCase {
@@ -37,7 +38,9 @@ public class IndexingMemoryControllerIT extends ESSingleNodeTestCase {
3738 protected Settings nodeSettings () {
3839 return Settings .builder ()
3940 .put (super .nodeSettings ())
40- // small indexing buffer so that we can trigger refresh after buffering 100 deletes
41+ // small indexing buffer so that
42+ // 1. We can trigger refresh after buffering 100 deletes
43+ // 2. Indexing memory Controller writes indexing buffers in sync with indexing on the indexing thread
4144 .put ("indices.memory.index_buffer_size" , "1kb" )
4245 .build ();
4346 }
@@ -111,4 +114,21 @@ public void testDeletesAloneCanTriggerRefresh() throws Exception {
111114 }
112115 assertThat (shard .getEngineOrNull ().getIndexBufferRAMBytesUsed (), lessThanOrEqualTo (ByteSizeUnit .KB .toBytes (1 )));
113116 }
117+
118+ /* When there is memory pressure, we write indexing buffers to disk on the same thread as the indexing thread,
119+ * @see org.elasticsearch.indices.IndexingMemoryController.
120+ * This test verifies that we update the stats that capture the combined time for indexing + writing the
121+ * indexing buffers.
122+ */
123+ public void testIndexingUpdatesRelevantStats () throws Exception {
124+ IndexService indexService = createIndex ("index" , indexSettings (1 , 0 ).put ("index.refresh_interval" , -1 ).build ());
125+ IndexShard shard = indexService .getShard (0 );
126+ for (int i = 0 ; i < 100 ; i ++) {
127+ prepareIndex ("index" ).setId (Integer .toString (i )).setSource ("field" , "value" ).get ();
128+ }
129+ assertThat (
130+ shard .indexingStats ().getTotal ().getTotalIndexExecutionTimeInMillis (),
131+ greaterThan (shard .indexingStats ().getTotal ().getIndexTime ().getMillis ())
132+ );
133+ }
114134}
0 commit comments