Skip to content

Commit 31ea368

Browse files
Fix misc. issues
1 parent 31ddb67 commit 31ea368

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ public static class Builder {
320320
private List<FieldCapabilitiesIndexResponse> indexResponses = Collections.emptyList();
321321
private List<FieldCapabilitiesFailure> failures = Collections.emptyList();
322322
private TransportVersion minTransportVersion = null;
323+
private ResolvedIndexExpressions resolvedIndexExpressions = null;
323324

324325
private Builder() {}
325326

@@ -366,6 +367,11 @@ public Builder withMinTransportVersion(TransportVersion minTransportVersion) {
366367
return this;
367368
}
368369

370+
public Builder withResolvedIndexExpressions(ResolvedIndexExpressions resolvedIndexExpressions) {
371+
this.resolvedIndexExpressions = resolvedIndexExpressions;
372+
return this;
373+
}
374+
369375
public FieldCapabilitiesResponse build() {
370376
return new FieldCapabilitiesResponse(
371377
indices,
@@ -375,7 +381,7 @@ public FieldCapabilitiesResponse build() {
375381
indexResponses,
376382
failures,
377383
minTransportVersion,
378-
null
384+
resolvedIndexExpressions
379385
);
380386
}
381387
}

server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -379,38 +379,43 @@ private <R extends ActionResponse> void doExecuteForked(
379379
* this, we use `CountDown` and track each response, irrespective of whether it's valid or not, and then perform the
380380
* reconciliation when it has counted down and the request is a resolvable CPS request.
381381
*/
382-
CountDown countDownResponses = new CountDown(remoteClusterIndices.size());
382+
Runnable crossProjectReconciler;
383383
Map<String, ResolvedIndexExpressions> linkedProjectsResponses = ConcurrentCollections.newConcurrentMap();
384-
Runnable crossProjectReconciler = () -> {
385-
if (countDownResponses.countDown() && crossProjectEnabled) {
386-
/*
387-
* This happens when one or more linked projects respond with an error instead of a valid response -- say, networking
388-
* error.
389-
*/
390-
if (linkedProjectsResponses.size() != remoteClusterIndices.size()) {
391-
listener.onFailure(
392-
new IllegalArgumentException(
393-
"Invalid number of responses received: "
394-
+ linkedProjectsResponses.size()
395-
+ " vs expected "
396-
+ remoteClusterIndices.size()
397-
)
398-
);
399-
return;
400-
}
384+
if (remoteClusterIndices.size() > 0) {
385+
CountDown countDownResponses = new CountDown(remoteClusterIndices.size());
386+
crossProjectReconciler = () -> {
387+
if (countDownResponses.countDown() && crossProjectEnabled) {
388+
/*
389+
* This happens when one or more linked projects respond with an error instead of a valid response -- say
390+
* networking error.
391+
*/
392+
if (linkedProjectsResponses.size() != remoteClusterIndices.size()) {
393+
listener.onFailure(
394+
new IllegalArgumentException(
395+
"Invalid number of responses received: "
396+
+ linkedProjectsResponses.size()
397+
+ " vs expected "
398+
+ remoteClusterIndices.size()
399+
)
400+
);
401+
return;
402+
}
401403

402-
Exception validationEx = CrossProjectIndexResolutionValidator.validate(
403-
request.indicesOptions(),
404-
null,
405-
request.getResolvedIndexExpressions(),
406-
linkedProjectsResponses
407-
);
404+
Exception validationEx = CrossProjectIndexResolutionValidator.validate(
405+
request.indicesOptions(),
406+
null,
407+
request.getResolvedIndexExpressions(),
408+
linkedProjectsResponses
409+
);
408410

409-
if (validationEx != null) {
410-
listener.onFailure(validationEx);
411+
if (validationEx != null) {
412+
listener.onFailure(validationEx);
413+
}
411414
}
412-
}
413-
};
415+
};
416+
} else {
417+
crossProjectReconciler = () -> {};
418+
}
414419

415420
// this is the cross cluster part of this API - we force the other cluster to not merge the results but instead
416421
// send us back all individual index results.
@@ -631,6 +636,7 @@ private static void mergeIndexResponses(
631636
.withResolvedRemotelyBuilder(resolvedRemotely)
632637
.withMinTransportVersion(minTransportVersion.get())
633638
.withFailures(failures)
639+
.withResolvedIndexExpressions(request.getResolvedIndexExpressions())
634640
.build()
635641
);
636642
}

0 commit comments

Comments
 (0)