From 1bff08b2b39cec42536d853779d7e3cbe3fa517b Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 6 Nov 2015 09:16:30 +0100 Subject: [PATCH] [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. --- .../java/org/elasticsearch/index/shard/IndexShard.java | 6 +++++- .../org/elasticsearch/index/shard/IndexShardTests.java | 9 +++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 73bcffe4917..6e7893df983 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -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); diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index af0f93b57b2..1c6b80cac79 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -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");