Skip to content

Commit 38ee71c

Browse files
author
elasticsearchmachine
committed
[CI] Auto commit changes from spotless
1 parent afbbe16 commit 38ee71c

File tree

7 files changed

+56
-99
lines changed

7 files changed

+56
-99
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/BulkMetadataService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ class BulkMetadataOperationContext<T> {
4141
public static <T> BulkMetadataOperationContext<T> stateModified(T context) {
4242
return new BulkMetadataOperationContext<>(true, context);
4343
}
44+
4445
public static BulkMetadataOperationContext<Void> stateModified() {
4546
return new BulkMetadataOperationContext<>(true, null);
4647
}
48+
4749
public static <T> BulkMetadataOperationContext<T> stateUnmodified(T context) {
4850
return new BulkMetadataOperationContext<>(false, context);
4951
}
52+
5053
public static BulkMetadataOperationContext<Void> stateUnmodified() {
5154
return new BulkMetadataOperationContext<>(false, null);
5255
}

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataContentService.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ public void taskSucceeded(ContentPackClusterStateUpdateTask task, Void unused) {
7979
private abstract static class ContentPackClusterStateUpdateTask implements ClusterStateTaskListener {
8080
final ActionListener<AcknowledgedResponse> listener;
8181

82-
ContentPackClusterStateUpdateTask(
83-
ActionListener<AcknowledgedResponse> listener
84-
) {
82+
ContentPackClusterStateUpdateTask(ActionListener<AcknowledgedResponse> listener) {
8583
this.listener = listener;
8684
}
8785

@@ -127,10 +125,7 @@ public static final class ContentPack {
127125
private final Map<String, BulkMetadataOperation> packageContents;
128126
private final TimeValue masterTimeout;
129127

130-
private ContentPack(
131-
Map<String, BulkMetadataOperation> packageContents,
132-
TimeValue masterTimeout
133-
) {
128+
private ContentPack(Map<String, BulkMetadataOperation> packageContents, TimeValue masterTimeout) {
134129
this.packageContents = packageContents;
135130
this.masterTimeout = masterTimeout;
136131
}
@@ -183,8 +178,7 @@ public boolean equals(Object obj) {
183178
if (obj == this) return true;
184179
if (obj == null || obj.getClass() != this.getClass()) return false;
185180
var that = (ContentPack) obj;
186-
return Objects.equals(this.packageContents, that.packageContents) &&
187-
Objects.equals(this.masterTimeout, that.masterTimeout);
181+
return Objects.equals(this.packageContents, that.packageContents) && Objects.equals(this.masterTimeout, that.masterTimeout);
188182
}
189183

190184
@Override
@@ -194,9 +188,7 @@ public int hashCode() {
194188

195189
@Override
196190
public String toString() {
197-
return "ContentPack[" +
198-
"packageContents=" + packageContents + ", " +
199-
"masterTimeout=" + masterTimeout + ']';
191+
return "ContentPack[" + "packageContents=" + packageContents + ", " + "masterTimeout=" + masterTimeout + ']';
200192
}
201193
}
202194

@@ -303,7 +295,7 @@ public void installContentPack(
303295

304296
SubscribableListener.newForked((ActionListener<Collection<Void>> l) -> {
305297
// PRTODO: Is this cluster state by-definition less fresh than the one we maintain in the IngestService?
306-
// Is this safe to check against?
298+
// Is this safe to check against?
307299
ClusterState clusterState = clusterService.state();
308300
forEachService(services, (service) -> service.validateBatch(clusterState));
309301
forEachService(services, (service) -> service.filterBatch(clusterState));
@@ -314,27 +306,23 @@ public void installContentPack(
314306
}).andThen((ActionListener<AcknowledgedResponse> l, Collection<Void> depResults) -> {
315307
ClusterState clusterState = clusterService.state();
316308
forEachService(services, (service) -> service.dependencyValidation(clusterState));
317-
taskQueue.submitTask(
318-
"create-content-pack, cause [" + cause + "]",
319-
new ContentPackClusterStateUpdateTask(l) {
320-
@Override
321-
public ClusterState execute(ClusterState currentState) throws Exception {
322-
Metadata.Builder metadataBuilder = Metadata.builder(currentState.metadata());
323-
OrCollector stateModified = new OrCollector();
324-
// PRTODO: The problem here is that each service takes its current view of the state from the currentState
325-
// but there's no way to guarantee that the "currentView" of the content hasn't already been invalidated
326-
forEachServiceAccumulate(services, (service) -> service.applyBatch(currentState, metadataBuilder), stateModified);
327-
if (stateModified.result()) {
328-
ClusterState candidateState = ClusterState.builder(currentState).metadata(metadataBuilder).build();
329-
forEachService(services, (service) -> service.validateFinalClusterState(currentState, candidateState));
330-
return candidateState;
331-
} else {
332-
return currentState;
333-
}
309+
taskQueue.submitTask("create-content-pack, cause [" + cause + "]", new ContentPackClusterStateUpdateTask(l) {
310+
@Override
311+
public ClusterState execute(ClusterState currentState) throws Exception {
312+
Metadata.Builder metadataBuilder = Metadata.builder(currentState.metadata());
313+
OrCollector stateModified = new OrCollector();
314+
// PRTODO: The problem here is that each service takes its current view of the state from the currentState
315+
// but there's no way to guarantee that the "currentView" of the content hasn't already been invalidated
316+
forEachServiceAccumulate(services, (service) -> service.applyBatch(currentState, metadataBuilder), stateModified);
317+
if (stateModified.result()) {
318+
ClusterState candidateState = ClusterState.builder(currentState).metadata(metadataBuilder).build();
319+
forEachService(services, (service) -> service.validateFinalClusterState(currentState, candidateState));
320+
return candidateState;
321+
} else {
322+
return currentState;
334323
}
335-
},
336-
contentPack.masterTimeout
337-
);
324+
}
325+
}, contentPack.masterTimeout);
338326
}).addListener(listener);
339327
}
340328

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ public BulkMetadataOperationContext<InterimTemplateValidationInfo> applyBatch(
468468
);
469469
}
470470

471-
472471
@Override
473472
public void validateFinalClusterState(ClusterState previousState, ClusterState newState, InterimTemplateValidationInfo context)
474473
throws Exception {
@@ -479,11 +478,7 @@ public void validateFinalClusterState(ClusterState previousState, ClusterState n
479478
final String composableTemplateName = entry.getKey();
480479
final ComposableIndexTemplate composableTemplate = entry.getValue();
481480
try {
482-
validateIndexTemplateV2(
483-
composableTemplateName,
484-
composableTemplate,
485-
newState
486-
);
481+
validateIndexTemplateV2(composableTemplateName, composableTemplate, newState);
487482
} catch (Exception e) {
488483
// For the sake of error message backwards compatibility, do not wrap the
489484
// exception if this is a single composable index template updated
@@ -531,9 +526,7 @@ private static StringBuilder generateTemplateNamesForException(
531526
if (failingComponents.isEmpty() == false) {
532527
builder.append(failingComponents);
533528
}
534-
var failingTemplate = updatedComposableIndexTemplates.containsKey(composableTemplateName)
535-
? composableTemplateName
536-
: null;
529+
var failingTemplate = updatedComposableIndexTemplates.containsKey(composableTemplateName) ? composableTemplateName : null;
537530
if (failingTemplate != null) {
538531
if (failingComponents.isEmpty() == false) {
539532
builder.append(", ");
@@ -988,11 +981,7 @@ public static Map<String, List<String>> v2TemplateOverlaps(
988981
}
989982

990983
// Visibility for testing
991-
void validateIndexTemplateV2(
992-
String name,
993-
ComposableIndexTemplate indexTemplate,
994-
ClusterState candidateState
995-
) {
984+
void validateIndexTemplateV2(String name, ComposableIndexTemplate indexTemplate, ClusterState candidateState) {
996985
// Workaround for the fact that start_time and end_time are injected by the MetadataCreateDataStreamService upon creation,
997986
// but when validating templates that create data streams the MetadataCreateDataStreamService isn't used.
998987
var finalTemplate = indexTemplate.template();
@@ -1179,10 +1168,7 @@ public static void validateDataStreamsStillReferenced(
11791168
// previous template was removed or its patterns changed to not match anymore. Either way,
11801169
// the previous template was changed and thus is the offender here
11811170
if (updatedIndexTemplateNames.contains(originalTemplate)) {
1182-
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(
1183-
originalTemplate,
1184-
(k) -> new HashSet<>()
1185-
).add(dataStream);
1171+
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(originalTemplate, (k) -> new HashSet<>()).add(dataStream);
11861172
} else {
11871173
// Not sure how this could happen. Somehow we had a template in the last version that matched, but now we don't,
11881174
// and it wasn't one that changed. Assert on it and collect for graceful degradation.
@@ -1208,28 +1194,18 @@ public static void validateDataStreamsStillReferenced(
12081194
// Ok both templates changed, but we don't know if both changes are responsible for why the data stream broke.
12091195
// What causes a template to be the reason for breaking? Patterns, priority, and template changes.
12101196
// Does it matter? We're going to reject both operations. Just label both of them as the cause of the problem.
1211-
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(
1212-
newTemplate,
1213-
(k) -> new HashSet<>()
1214-
).add(dataStream);
1215-
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(
1216-
originalTemplate,
1217-
(k) -> new HashSet<>()
1218-
).add(dataStream);
1197+
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(newTemplate, (k) -> new HashSet<>()).add(dataStream);
1198+
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(originalTemplate, (k) -> new HashSet<>())
1199+
.add(dataStream);
12191200
} else if (newTemplateWasUpdated) {
12201201
// A new template was inserted ahead of the old one, and it is not a data stream template
12211202
// Just the new one is the problem
1222-
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(
1223-
newTemplate,
1224-
(k) -> new HashSet<>()
1225-
).add(dataStream);
1203+
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(newTemplate, (k) -> new HashSet<>()).add(dataStream);
12261204
} else {
12271205
// Old template was changed and the new template (unchanged) is now incorrectly applied
12281206
// The old one changing is the problem
1229-
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(
1230-
originalTemplate,
1231-
(k) -> new HashSet<>()
1232-
).add(dataStream);
1207+
offendingTemplateToUnreferencedDataStreams.computeIfAbsent(originalTemplate, (k) -> new HashSet<>())
1208+
.add(dataStream);
12331209
}
12341210
}
12351211
}

server/src/main/java/org/elasticsearch/ingest/IngestService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ public class IngestService
121121
public static final String INGEST_ORIGIN = "ingest";
122122

123123
public static final String BULK_METADATA_SERVICE_NAME = "elasticsearch.ingest";
124+
124125
public static final class BulkPipelineCreateOperation extends BulkMetadataOperation {
125126
final List<PutPipelineRequest> requests;
127+
126128
public BulkPipelineCreateOperation(List<PutPipelineRequest> requests) {
127129
super(BULK_METADATA_SERVICE_NAME);
128130
this.requests = requests;
@@ -716,10 +718,7 @@ static Map<String, PipelineConfiguration> getPipelines(IngestMetadata currentIng
716718
* @param request put pipeline request to validate
717719
* @return source data from the give request, potentially updated with version info if needed
718720
*/
719-
static BytesReference validatePipelineVersionAndGetSource(
720-
IngestMetadata currentIngestMetadata,
721-
PutPipelineRequest request
722-
) {
721+
static BytesReference validatePipelineVersionAndGetSource(IngestMetadata currentIngestMetadata, PutPipelineRequest request) {
723722
if (request.getVersion() != null) {
724723
var currentPipeline = currentIngestMetadata != null ? currentIngestMetadata.getPipelines().get(request.getId()) : null;
725724
if (currentPipeline == null) {

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,9 @@ public void testRemoveMultipleIndexTemplateV2Wildcards() throws Exception {
622622
ComposableIndexTemplate bazTemplate = ComposableIndexTemplateTests.randomInstance();
623623
MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
624624

625-
final ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder()
626-
.put("foo", fooTemplate)
627-
.put("bar", barTemplate)
628-
.put("baz", bazTemplate)
629-
).build();
625+
final ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
626+
.metadata(Metadata.builder().put("foo", fooTemplate).put("bar", barTemplate).put("baz", bazTemplate))
627+
.build();
630628

631629
Exception e = expectThrows(
632630
IndexTemplateMissingException.class,
@@ -2074,9 +2072,7 @@ public void testUpdateComponentTemplateFailsIfResolvedIndexTemplatesWouldBeInval
20742072

20752073
assertThat(
20762074
e.getMessage(),
2077-
containsString(
2078-
"updating templates [c2] results in invalid " + "composable template [my-template] after templates are merged"
2079-
)
2075+
containsString("updating templates [c2] results in invalid " + "composable template [my-template] after templates are merged")
20802076
);
20812077

20822078
assertNotNull(e.getCause());

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public static void refreshPhaseDefinition(
7171
/**
7272
* Rereads the phase JSON for the given index, and updates the provided metadata.
7373
*/
74-
public static IndexMetadata.Builder refreshPhaseDefinition(
75-
final IndexMetadata idxMeta,
76-
final LifecyclePolicyMetadata updatedPolicy
77-
) {
74+
public static IndexMetadata.Builder refreshPhaseDefinition(final IndexMetadata idxMeta, final LifecyclePolicyMetadata updatedPolicy) {
7875
String index = idxMeta.getIndex().getName();
7976
assert eligibleToCheckForRefresh(idxMeta) : "index " + index + " is missing crucial information needed to refresh phase definition";
8077

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/PutLifecycleMetadataService.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ private static BulkMetadataOperationContext<Void> doApplyBatch(
201201
);
202202
} catch (Exception e) {
203203
// PRTODO: This is a mess - we try and apply all index metadata refreshes for this policy change at the very end of
204-
// this function, but I don't know for sure if it can't throw an exception and end up here. The old logic just returns
205-
// the new state with the policy and without any refreshes. We don't really have that luxury unless we build the
206-
// cluster state after every application. Maybe that's fine and I'm over complicating things.
204+
// this function, but I don't know for sure if it can't throw an exception and end up here. The old logic just returns
205+
// the new state with the policy and without any refreshes. We don't really have that luxury unless we build the
206+
// cluster state after every application. Maybe that's fine and I'm over complicating things.
207207
logger.warn(() -> "unable to refresh indices phase JSON for updated policy [" + oldPolicy.getName() + "]", e);
208208
}
209209
}
@@ -224,21 +224,18 @@ public void addLifecycle(PutLifecycleRequest request, ClusterState state, Action
224224
if (finalBulkOp.isEmpty()) {
225225
return;
226226
}
227-
submitUnbatchedTask(
228-
"put-lifecycle-" + request.getPolicy().getName(),
229-
new BulkUpdateLifecyclePolicyTask(request, listener) {
230-
@Override
231-
public ClusterState execute(ClusterState currentState) throws Exception {
232-
var mb = Metadata.builder(currentState.metadata());
233-
BulkMetadataOperationContext<Void> ctx = applyBatch(finalBulkOp, currentState, mb);
234-
if (ctx != null && ctx.isMetadataModified()) {
235-
return ClusterState.builder(currentState).metadata(mb).build();
236-
} else {
237-
return currentState;
238-
}
227+
submitUnbatchedTask("put-lifecycle-" + request.getPolicy().getName(), new BulkUpdateLifecyclePolicyTask(request, listener) {
228+
@Override
229+
public ClusterState execute(ClusterState currentState) throws Exception {
230+
var mb = Metadata.builder(currentState.metadata());
231+
BulkMetadataOperationContext<Void> ctx = applyBatch(finalBulkOp, currentState, mb);
232+
if (ctx != null && ctx.isMetadataModified()) {
233+
return ClusterState.builder(currentState).metadata(mb).build();
234+
} else {
235+
return currentState;
239236
}
240237
}
241-
);
238+
});
242239
}
243240

244241
/**
@@ -331,6 +328,7 @@ private abstract static class BulkUpdateLifecyclePolicyTask extends AckedCluster
331328
protected BulkUpdateLifecyclePolicyTask(PutLifecycleRequest request, ActionListener<AcknowledgedResponse> listener) {
332329
super(request, listener);
333330
}
331+
334332
@Override
335333
public abstract ClusterState execute(ClusterState currentState) throws Exception;
336334
}

0 commit comments

Comments
 (0)