[TEST] Add test only API that allows to pass the inactive time in NS directly
if we set the inactive time for the shard via API the entire test if fully time dependent and might fail if we concurrently check if the shard is inactive while the document we are indexing is in-flight.
This commit is contained in:
parent
54d2b5f3b6
commit
1bff08b2b3
|
@ -1034,8 +1034,12 @@ public class IndexShard extends AbstractIndexShardComponent {
|
|||
* indexing operation, and become inactive (reducing indexing and translog buffers to tiny values) if so. This returns true
|
||||
* if the shard is inactive. */
|
||||
public boolean checkIdle() {
|
||||
return checkIdle(inactiveTime.nanos());
|
||||
}
|
||||
|
||||
final boolean checkIdle(long inactiveTimeNS) { // pkg private for testing
|
||||
Engine engineOrNull = getEngineOrNull();
|
||||
if (engineOrNull != null && System.nanoTime() - engineOrNull.getLastWriteNanos() >= inactiveTime.nanos()) {
|
||||
if (engineOrNull != null && System.nanoTime() - engineOrNull.getLastWriteNanos() >= inactiveTimeNS) {
|
||||
boolean wasActive = active.getAndSet(false);
|
||||
if (wasActive) {
|
||||
updateBufferSize(IndexingMemoryController.INACTIVE_SHARD_INDEXING_BUFFER, IndexingMemoryController.INACTIVE_SHARD_TRANSLOG_BUFFER);
|
||||
|
|
|
@ -81,7 +81,6 @@ import org.elasticsearch.indices.recovery.RecoveryState;
|
|||
import org.elasticsearch.test.DummyShardLock;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -330,15 +329,13 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
assertEquals(0, indexShard.getOperationsCount());
|
||||
}
|
||||
|
||||
@TestLogging("indices.flush:TRACE,index.shard:TRACE,index.engine:TRACE")
|
||||
@AwaitsFix(bugUrl = "simonw is working on this")
|
||||
public void testMarkAsInactiveTriggersSyncedFlush() throws Exception {
|
||||
assertAcked(client().admin().indices().prepareCreate("test")
|
||||
.setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0, IndexShard.INDEX_SHARD_INACTIVE_TIME_SETTING, "0s"));
|
||||
.setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
|
||||
client().prepareIndex("test", "test").setSource("{}").get();
|
||||
ensureGreen("test");
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
client().prepareIndex("test", "test").setSource("{}").get();// make the shard active...
|
||||
Boolean result = indicesService.indexService("test").getShardOrNull(0).checkIdle();
|
||||
Boolean result = indicesService.indexService("test").getShardOrNull(0).checkIdle(0);
|
||||
assertEquals(Boolean.TRUE, result);
|
||||
assertBusy(() -> {
|
||||
IndexStats indexStats = client().admin().indices().prepareStats("test").clear().get().getIndex("test");
|
||||
|
|
Loading…
Reference in New Issue