diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 3d009d58b0def..a82fb3ccf0333 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -2493,6 +2493,7 @@ public void testConcurrentWritesAndCommits() throws Exception { prevLocalCheckpoint = localCheckpoint; prevMaxSeqNo = maxSeqNo; } + IOUtils.close(commits); } } diff --git a/server/src/test/java/org/elasticsearch/index/seqno/RetentionLeaseIT.java b/server/src/test/java/org/elasticsearch/index/seqno/RetentionLeaseIT.java index a2880c0d330ad..e7561d9f37049 100644 --- a/server/src/test/java/org/elasticsearch/index/seqno/RetentionLeaseIT.java +++ b/server/src/test/java/org/elasticsearch/index/seqno/RetentionLeaseIT.java @@ -105,7 +105,7 @@ public void testRetentionLeasesSyncedOnAdd() throws Exception { // check retention leases have been committed on the primary final RetentionLeases primaryCommittedRetentionLeases = RetentionLeases.decodeRetentionLeases( - primary.acquireLastIndexCommit(false).getIndexCommit().getUserData().get(Engine.RETENTION_LEASES)); + primary.commitStats().getUserData().get(Engine.RETENTION_LEASES)); assertThat(currentRetentionLeases, equalTo(RetentionLeases.toMap(primaryCommittedRetentionLeases))); // check current retention leases have been synced to all replicas @@ -120,7 +120,7 @@ public void testRetentionLeasesSyncedOnAdd() throws Exception { // check retention leases have been committed on the replica final RetentionLeases replicaCommittedRetentionLeases = RetentionLeases.decodeRetentionLeases( - replica.acquireLastIndexCommit(false).getIndexCommit().getUserData().get(Engine.RETENTION_LEASES)); + replica.commitStats().getUserData().get(Engine.RETENTION_LEASES)); assertThat(currentRetentionLeases, equalTo(RetentionLeases.toMap(replicaCommittedRetentionLeases))); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 7d9181909e293..0aee6c45a9129 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -87,6 +87,7 @@ import org.elasticsearch.index.engine.CommitStats; import org.elasticsearch.index.engine.DocIdSeqNoAndTerm; import org.elasticsearch.index.engine.Engine; +import org.elasticsearch.index.engine.EngineTestCase; import org.elasticsearch.index.engine.InternalEngine; import org.elasticsearch.index.seqno.SeqNoStats; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -1254,6 +1255,7 @@ public void beforeIndexDeletion() throws Exception { //check that shards that have same sync id also contain same number of documents assertSameSyncIdSameDocs(); assertOpenTranslogReferences(); + assertNoSnapshottedIndexCommit(); } private void assertSameSyncIdSameDocs() { @@ -1324,6 +1326,28 @@ private void assertOpenTranslogReferences() throws Exception { }); } + private void assertNoSnapshottedIndexCommit() throws Exception { + assertBusy(() -> { + final Collection nodesAndClients = nodes.values(); + for (NodeAndClient nodeAndClient : nodesAndClients) { + IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name); + for (IndexService indexService : indexServices) { + for (IndexShard indexShard : indexService) { + try { + Engine engine = IndexShardTestCase.getEngine(indexShard); + if (engine instanceof InternalEngine) { + assertFalse(indexShard.routingEntry().toString() + " has unreleased snapshotted index commits", + EngineTestCase.hasSnapshottedCommits(engine)); + } + } catch (AlreadyClosedException ignored) { + + } + } + } + } + }); + } + /** * Asserts that the document history in Lucene index is consistent with Translog's on every index shard of the cluster. * This assertion might be expensive, thus we prefer not to execute on every test but only interesting tests.