Ensure flush happen before closing an index (#40184)

If there's an ongoing flush triggered by the translog flush threshold,
we may fail to execute a flush because waitIfOngoing is false by
default.

Relates to #36342
This commit is contained in:
Nhat Nguyen 2019-03-19 21:27:08 -04:00
parent e716b9ceee
commit c4960ad736
2 changed files with 12 additions and 1 deletions

View File

@ -108,7 +108,7 @@ public class TransportVerifyShardBeforeCloseAction extends TransportReplicationA
throw new IllegalStateException("Index shard " + shardId + " must be blocked by " + request.clusterBlock() + " before closing");
}
indexShard.verifyShardBeforeIndexClosing();
indexShard.flush(new FlushRequest().force(true));
indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true));
logger.trace("{} shard is ready for closing", shardId);
}

View File

@ -29,7 +29,10 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.indices.IndexClosedException;
import org.elasticsearch.test.BackgroundIndexer;
import org.elasticsearch.test.ESIntegTestCase;
@ -56,6 +59,14 @@ public class CloseIndexIT extends ESIntegTestCase {
private static final int MAX_DOCS = 25_000;
@Override
public Settings indexSettings() {
Settings.builder().put(super.indexSettings())
.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
new ByteSizeValue(randomIntBetween(1, 4096), ByteSizeUnit.KB));
return super.indexSettings();
}
public void testCloseMissingIndex() {
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test").get());
assertThat(e.getMessage(), is("no such index [test]"));