Skip to content

Commit a032f9a

Browse files
committed
move method
1 parent 4879f3f commit a032f9a

2 files changed

Lines changed: 51 additions & 40 deletions

File tree

test/framework/src/main/java/org/elasticsearch/index/seqno/SequenceNumbersTestUtils.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,55 @@ public static void assertShardsHaveSeqNoDocValues(
9696
assertThat("expected to verify " + expectedShards + " shard(s)", nbCheckedShards, equalTo(expectedShards));
9797
}
9898

99+
/**
100+
* Asserts that the total number of {@code _seq_no} doc values across all shards of the given index equals the expected count.
101+
*
102+
* @param cluster the cluster to check
103+
* @param indexName the index to check
104+
* @param expectedCount the expected total number of doc values per shard
105+
* @param expectedShards the exact number of shards expected to be verified
106+
*/
107+
public static void assertShardsSeqNoDocValuesCount(
108+
InternalTestCluster cluster,
109+
String indexName,
110+
long expectedCount,
111+
int expectedShards
112+
) {
113+
int checked = 0;
114+
for (IndicesService indicesService : cluster.getDataNodeInstances(IndicesService.class)) {
115+
for (var indexService : indicesService) {
116+
if (indexService.index().getName().equals(indexName)) {
117+
for (var indexShard : indexService) {
118+
Long count = indexShard.withEngineOrNull(engine -> {
119+
if (engine == null) {
120+
return null;
121+
}
122+
try (var searcher = engine.acquireSearcher("assert_seq_no_count")) {
123+
long total = 0;
124+
for (var leaf : searcher.getLeafContexts()) {
125+
NumericDocValues seqNoDV = leaf.reader().getNumericDocValues(SeqNoFieldMapper.NAME);
126+
if (seqNoDV != null) {
127+
while (seqNoDV.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
128+
total++;
129+
}
130+
}
131+
}
132+
return total;
133+
} catch (IOException e) {
134+
throw new AssertionError(e);
135+
}
136+
});
137+
if (count != null) {
138+
assertThat("retained seq_no doc values count", count, equalTo(expectedCount));
139+
checked++;
140+
}
141+
}
142+
}
143+
}
144+
}
145+
assertThat("expected to verify " + expectedShards + " shard(s)", checked, equalTo(expectedShards));
146+
}
147+
99148
/**
100149
* Waits until all retention leases on all shards of the given index have their retaining sequence number
101150
* equal to the expected value.

x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/CcrSeqNoPruningIT.java

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
package org.elasticsearch.xpack.ccr;
99

10-
import org.apache.lucene.index.NumericDocValues;
11-
import org.apache.lucene.search.DocIdSetIterator;
1210
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
1311
import org.elasticsearch.action.admin.indices.stats.ShardStats;
1412
import org.elasticsearch.action.support.WriteRequest;
@@ -20,21 +18,20 @@
2018
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
2119
import org.elasticsearch.index.seqno.RetentionLease;
2220
import org.elasticsearch.index.seqno.RetentionLeaseUtils;
23-
import org.elasticsearch.indices.IndicesService;
2421
import org.elasticsearch.plugins.Plugin;
2522
import org.elasticsearch.xcontent.XContentType;
2623
import org.elasticsearch.xpack.CcrIntegTestCase;
2724
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
2825
import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction;
2926

30-
import java.io.IOException;
3127
import java.util.Collection;
3228
import java.util.Map;
3329
import java.util.stream.Collectors;
3430
import java.util.stream.Stream;
3531

3632
import static org.elasticsearch.index.seqno.SequenceNumbersTestUtils.assertRetentionLeasesAdvanced;
3733
import static org.elasticsearch.index.seqno.SequenceNumbersTestUtils.assertShardsHaveSeqNoDocValues;
34+
import static org.elasticsearch.index.seqno.SequenceNumbersTestUtils.assertShardsSeqNoDocValuesCount;
3835
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3936
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
4037
import static org.hamcrest.Matchers.equalTo;
@@ -219,7 +216,7 @@ public void testSeqNoPartiallyRetainedByCcrLease() throws Exception {
219216
assertShardsHaveSeqNoDocValues(getLeaderCluster(), leaderIndex, true, numberOfShards);
220217

221218
final long expectedRetainedDocs = newMaxSeqNo + 1 - leaseSeqNoBeforePause;
222-
assertLeaderShardsRetainedSeqNoDocValuesCount(leaderIndex, expectedRetainedDocs, numberOfShards);
219+
assertShardsSeqNoDocValuesCount(getLeaderCluster(), leaderIndex, expectedRetainedDocs, numberOfShards);
223220

224221
followerClient().execute(ResumeFollowAction.INSTANCE, resumeFollow(followerIndex)).actionGet();
225222
assertIndexFullyReplicatedToFollower(leaderIndex, followerIndex);
@@ -261,39 +258,4 @@ private static long getMaxSeqNo(Client client, String index) {
261258
return client.admin().indices().prepareStats(index).get().getShards()[0].getSeqNoStats().getMaxSeqNo();
262259
}
263260

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-
}
299261
}

0 commit comments

Comments
 (0)