Skip to content

Commit f9024eb

Browse files
committed
Allow single-index analysis
1 parent 63fc87a commit f9024eb

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

server/src/internalClusterTest/java/org/elasticsearch/repositories/blobstore/BlobStoreMetadataIntegrityIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.action.admin.cluster.repositories.integrity.VerifyRepositoryIntegrityAction;
1212
import org.elasticsearch.action.index.IndexRequestBuilder;
1313
import org.elasticsearch.action.support.PlainActionFuture;
14+
import org.elasticsearch.common.Strings;
1415
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.core.Releasable;
1617
import org.elasticsearch.core.Releasables;
@@ -93,7 +94,7 @@ public void testIntegrityCheck() throws Exception {
9394
createFullSnapshot(REPOSITORY_NAME, "test-snapshot-" + snapshotIndex);
9495
}
9596

96-
final var request = new VerifyRepositoryIntegrityAction.Request(REPOSITORY_NAME, 5, 5, 5, 5, 10000, false);
97+
final var request = new VerifyRepositoryIntegrityAction.Request(REPOSITORY_NAME, Strings.EMPTY_ARRAY, 5, 5, 5, 5, 10000, false);
9798

9899
final var response = PlainActionFuture.<VerifyRepositoryIntegrityAction.Response, RuntimeException>get(
99100
listener -> client().execute(VerifyRepositoryIntegrityAction.INSTANCE, request, listener),

server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/integrity/VerifyRepositoryIntegrityAction.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Iterator;
4343
import java.util.List;
4444
import java.util.Map;
45+
import java.util.Objects;
4546

4647
public class VerifyRepositoryIntegrityAction extends ActionType<VerifyRepositoryIntegrityAction.Response> {
4748

@@ -55,6 +56,7 @@ private VerifyRepositoryIntegrityAction() {
5556
public static class Request extends MasterNodeReadRequest<Request> {
5657

5758
private final String repository;
59+
private final String[] indices;
5860
private final int threadpoolConcurrency;
5961
private final int snapshotVerificationConcurrency;
6062
private final int indexVerificationConcurrency;
@@ -64,6 +66,7 @@ public static class Request extends MasterNodeReadRequest<Request> {
6466

6567
public Request(
6668
String repository,
69+
String[] indices,
6770
int threadpoolConcurrency,
6871
int snapshotVerificationConcurrency,
6972
int indexVerificationConcurrency,
@@ -72,6 +75,7 @@ public Request(
7275
boolean permitMissingSnapshotDetails
7376
) {
7477
this.repository = repository;
78+
this.indices = Objects.requireNonNull(indices, "indices");
7579
this.threadpoolConcurrency = requireMin("threadpoolConcurrency", 0, threadpoolConcurrency);
7680
this.snapshotVerificationConcurrency = requireMin("snapshotVerificationConcurrency", 1, snapshotVerificationConcurrency);
7781
this.indexVerificationConcurrency = requireMin("indexVerificationConcurrency", 1, indexVerificationConcurrency);
@@ -94,6 +98,7 @@ private static int requireMin(String name, int min, int value) {
9498
public Request(StreamInput in) throws IOException {
9599
super(in);
96100
this.repository = in.readString();
101+
this.indices = in.readStringArray();
97102
this.threadpoolConcurrency = in.readVInt();
98103
this.snapshotVerificationConcurrency = in.readVInt();
99104
this.indexVerificationConcurrency = in.readVInt();
@@ -106,6 +111,7 @@ public Request(StreamInput in) throws IOException {
106111
public void writeTo(StreamOutput out) throws IOException {
107112
super.writeTo(out);
108113
out.writeString(repository);
114+
out.writeStringArray(indices);
109115
out.writeVInt(threadpoolConcurrency);
110116
out.writeVInt(snapshotVerificationConcurrency);
111117
out.writeVInt(indexVerificationConcurrency);
@@ -124,6 +130,14 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
124130
return new CancellableTask(id, type, action, getDescription(), parentTaskId, headers);
125131
}
126132

133+
public String getRepository() {
134+
return repository;
135+
}
136+
137+
public String[] getIndices() {
138+
return indices;
139+
}
140+
127141
public int getThreadpoolConcurrency() {
128142
return threadpoolConcurrency;
129143
}
@@ -152,6 +166,7 @@ public Request withDefaultThreadpoolConcurrency(Settings settings) {
152166
if (threadpoolConcurrency == 0) {
153167
final var request = new Request(
154168
repository,
169+
indices,
155170
Math.max(1, EsExecutors.allocatedProcessors(settings) / 2),
156171
snapshotVerificationConcurrency,
157172
indexVerificationConcurrency,
@@ -249,7 +264,7 @@ protected ClusterBlockException checkBlock(Request request, ClusterState state)
249264
protected void masterOperation(Task task, Request request, ClusterState state, ActionListener<Response> listener) throws Exception {
250265
// TODO add mechanism to block blob deletions while this is running
251266
final var cancellableTask = (CancellableTask) task;
252-
repositoriesService.repository(request.repository)
267+
repositoriesService.repository(request.getRepository())
253268
.verifyMetadataIntegrity(
254269
request.withDefaultThreadpoolConcurrency(clusterService.getSettings()),
255270
listener.map(Response::new),

server/src/main/java/org/elasticsearch/repositories/blobstore/MetadataVerifier.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class MetadataVerifier implements Releasable {
6969
private final ProgressLogger snapshotProgressLogger;
7070
private final ProgressLogger indexProgressLogger;
7171
private final ProgressLogger indexSnapshotProgressLogger;
72+
private final Set<String> requestedIndices;
7273

7374
MetadataVerifier(
7475
BlobStoreRepository blobStoreRepository,
@@ -92,6 +93,8 @@ class MetadataVerifier implements Releasable {
9293
this.snapshotProgressLogger = new ProgressLogger("snapshots", repositoryData.getSnapshotIds().size(), 100);
9394
this.indexProgressLogger = new ProgressLogger("indices", repositoryData.getIndices().size(), 20);
9495
this.indexSnapshotProgressLogger = new ProgressLogger("index snapshots", repositoryData.getIndexSnapshotCount(), 1000);
96+
97+
this.requestedIndices = Set.of(verifyRequest.getIndices());
9598
}
9699

97100
@Override
@@ -136,7 +139,11 @@ public void run() {
136139
indexSnapshotProgressLogger.getExpectedMax()
137140
);
138141

139-
verifySnapshots();
142+
if (requestedIndices.isEmpty()) {
143+
verifySnapshots();
144+
} else {
145+
verifyIndices();
146+
}
140147
}
141148

142149
private void verifySnapshots() {
@@ -231,6 +238,10 @@ private class IndexVerifier {
231238
}
232239

233240
void run() {
241+
if (requestedIndices.isEmpty() == false && requestedIndices.contains(indexId.getName()) == false) {
242+
return;
243+
}
244+
234245
runThrottled(
235246
makeVoidListener(indexRefs, () -> {}),
236247
repositoryData.getSnapshots(indexId).iterator(),

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryIntegrityAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.elasticsearch.action.admin.cluster.repositories.integrity.VerifyRepositoryIntegrityAction;
1212
import org.elasticsearch.client.internal.node.NodeClient;
13+
import org.elasticsearch.common.Strings;
1314
import org.elasticsearch.rest.BaseRestHandler;
1415
import org.elasticsearch.rest.RestRequest;
1516
import org.elasticsearch.rest.action.RestCancellableNodeClient;
@@ -35,6 +36,7 @@ public String getName() {
3536
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
3637
final var verifyRequest = new VerifyRepositoryIntegrityAction.Request(
3738
request.param("repository"),
39+
request.paramAsStringArray("indices", Strings.EMPTY_ARRAY),
3840
request.paramAsInt("threadpool_concurrency", 0),
3941
request.paramAsInt("snapshot_verification_concurrency", 5),
4042
request.paramAsInt("index_verification_concurrency", 5),

0 commit comments

Comments
 (0)