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:
parent
e716b9ceee
commit
c4960ad736
|
@ -108,7 +108,7 @@ public class TransportVerifyShardBeforeCloseAction extends TransportReplicationA
|
||||||
throw new IllegalStateException("Index shard " + shardId + " must be blocked by " + request.clusterBlock() + " before closing");
|
throw new IllegalStateException("Index shard " + shardId + " must be blocked by " + request.clusterBlock() + " before closing");
|
||||||
}
|
}
|
||||||
indexShard.verifyShardBeforeIndexClosing();
|
indexShard.verifyShardBeforeIndexClosing();
|
||||||
indexShard.flush(new FlushRequest().force(true));
|
indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true));
|
||||||
logger.trace("{} shard is ready for closing", shardId);
|
logger.trace("{} shard is ready for closing", shardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,10 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.IndexNotFoundException;
|
||||||
|
import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.indices.IndexClosedException;
|
import org.elasticsearch.indices.IndexClosedException;
|
||||||
import org.elasticsearch.test.BackgroundIndexer;
|
import org.elasticsearch.test.BackgroundIndexer;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
|
@ -56,6 +59,14 @@ public class CloseIndexIT extends ESIntegTestCase {
|
||||||
|
|
||||||
private static final int MAX_DOCS = 25_000;
|
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() {
|
public void testCloseMissingIndex() {
|
||||||
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test").get());
|
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test").get());
|
||||||
assertThat(e.getMessage(), is("no such index [test]"));
|
assertThat(e.getMessage(), is("no such index [test]"));
|
||||||
|
|
Loading…
Reference in New Issue