|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.ccr; |
9 | 9 |
|
10 | | -import org.apache.lucene.index.NumericDocValues; |
11 | | -import org.apache.lucene.search.DocIdSetIterator; |
12 | 10 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; |
13 | 11 | import org.elasticsearch.action.admin.indices.stats.ShardStats; |
14 | 12 | import org.elasticsearch.action.support.WriteRequest; |
|
20 | 18 | import org.elasticsearch.index.mapper.SeqNoFieldMapper; |
21 | 19 | import org.elasticsearch.index.seqno.RetentionLease; |
22 | 20 | import org.elasticsearch.index.seqno.RetentionLeaseUtils; |
23 | | -import org.elasticsearch.indices.IndicesService; |
24 | 21 | import org.elasticsearch.plugins.Plugin; |
25 | 22 | import org.elasticsearch.xcontent.XContentType; |
26 | 23 | import org.elasticsearch.xpack.CcrIntegTestCase; |
27 | 24 | import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; |
28 | 25 | import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; |
29 | 26 |
|
30 | | -import java.io.IOException; |
31 | 27 | import java.util.Collection; |
32 | 28 | import java.util.Map; |
33 | 29 | import java.util.stream.Collectors; |
34 | 30 | import java.util.stream.Stream; |
35 | 31 |
|
36 | 32 | import static org.elasticsearch.index.seqno.SequenceNumbersTestUtils.assertRetentionLeasesAdvanced; |
37 | 33 | import static org.elasticsearch.index.seqno.SequenceNumbersTestUtils.assertShardsHaveSeqNoDocValues; |
| 34 | +import static org.elasticsearch.index.seqno.SequenceNumbersTestUtils.assertShardsSeqNoDocValuesCount; |
38 | 35 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
39 | 36 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; |
40 | 37 | import static org.hamcrest.Matchers.equalTo; |
@@ -219,7 +216,7 @@ public void testSeqNoPartiallyRetainedByCcrLease() throws Exception { |
219 | 216 | assertShardsHaveSeqNoDocValues(getLeaderCluster(), leaderIndex, true, numberOfShards); |
220 | 217 |
|
221 | 218 | final long expectedRetainedDocs = newMaxSeqNo + 1 - leaseSeqNoBeforePause; |
222 | | - assertLeaderShardsRetainedSeqNoDocValuesCount(leaderIndex, expectedRetainedDocs, numberOfShards); |
| 219 | + assertShardsSeqNoDocValuesCount(getLeaderCluster(), leaderIndex, expectedRetainedDocs, numberOfShards); |
223 | 220 |
|
224 | 221 | followerClient().execute(ResumeFollowAction.INSTANCE, resumeFollow(followerIndex)).actionGet(); |
225 | 222 | assertIndexFullyReplicatedToFollower(leaderIndex, followerIndex); |
@@ -261,39 +258,4 @@ private static long getMaxSeqNo(Client client, String index) { |
261 | 258 | return client.admin().indices().prepareStats(index).get().getShards()[0].getSeqNoStats().getMaxSeqNo(); |
262 | 259 | } |
263 | 260 |
|
264 | | - private void assertLeaderShardsRetainedSeqNoDocValuesCount(String indexName, long expectedCount, int expectedShards) { |
265 | | - int checked = 0; |
266 | | - for (IndicesService indicesService : getLeaderCluster().getDataNodeInstances(IndicesService.class)) { |
267 | | - for (var indexService : indicesService) { |
268 | | - if (indexService.index().getName().equals(indexName)) { |
269 | | - for (var indexShard : indexService) { |
270 | | - Long count = indexShard.withEngineOrNull(engine -> { |
271 | | - if (engine == null) { |
272 | | - return null; |
273 | | - } |
274 | | - try (var searcher = engine.acquireSearcher("assert_seq_no_count")) { |
275 | | - long total = 0; |
276 | | - for (var leaf : searcher.getLeafContexts()) { |
277 | | - NumericDocValues seqNoDV = leaf.reader().getNumericDocValues(SeqNoFieldMapper.NAME); |
278 | | - if (seqNoDV != null) { |
279 | | - while (seqNoDV.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { |
280 | | - total++; |
281 | | - } |
282 | | - } |
283 | | - } |
284 | | - return total; |
285 | | - } catch (IOException e) { |
286 | | - throw new AssertionError(e); |
287 | | - } |
288 | | - }); |
289 | | - if (count != null) { |
290 | | - assertThat("retained seq_no doc values count", count, equalTo(expectedCount)); |
291 | | - checked++; |
292 | | - } |
293 | | - } |
294 | | - } |
295 | | - } |
296 | | - } |
297 | | - assertThat("expected to verify " + expectedShards + " shard(s)", checked, equalTo(expectedShards)); |
298 | | - } |
299 | 261 | } |
0 commit comments