Skip to content

Commit 96146cb

Browse files
authored
Make CloseIndexClusterStateUpdateRequest a record (#113350)
No need to extend `IndicesClusterStateUpdateRequest`, this thing can be completely immutable.
1 parent 5cec1dd commit 96146cb

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexClusterStateUpdateRequest.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,25 @@
99
package org.elasticsearch.action.admin.indices.close;
1010

1111
import org.elasticsearch.action.support.ActiveShardCount;
12-
import org.elasticsearch.cluster.ack.IndicesClusterStateUpdateRequest;
12+
import org.elasticsearch.core.TimeValue;
13+
import org.elasticsearch.index.Index;
14+
15+
import java.util.Objects;
1316

1417
/**
1518
* Cluster state update request that allows to close one or more indices
1619
*/
17-
public class CloseIndexClusterStateUpdateRequest extends IndicesClusterStateUpdateRequest<CloseIndexClusterStateUpdateRequest> {
18-
19-
private long taskId;
20-
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
21-
22-
public CloseIndexClusterStateUpdateRequest(final long taskId) {
23-
this.taskId = taskId;
24-
}
25-
26-
public long taskId() {
27-
return taskId;
28-
}
29-
30-
public CloseIndexClusterStateUpdateRequest taskId(final long taskId) {
31-
this.taskId = taskId;
32-
return this;
33-
}
34-
35-
public ActiveShardCount waitForActiveShards() {
36-
return waitForActiveShards;
37-
}
38-
39-
public CloseIndexClusterStateUpdateRequest waitForActiveShards(final ActiveShardCount waitForActiveShards) {
40-
this.waitForActiveShards = waitForActiveShards;
41-
return this;
20+
public record CloseIndexClusterStateUpdateRequest(
21+
TimeValue masterNodeTimeout,
22+
TimeValue ackTimeout,
23+
long taskId,
24+
ActiveShardCount waitForActiveShards,
25+
Index[] indices
26+
) {
27+
public CloseIndexClusterStateUpdateRequest {
28+
Objects.requireNonNull(masterNodeTimeout);
29+
Objects.requireNonNull(ackTimeout);
30+
Objects.requireNonNull(waitForActiveShards);
31+
Objects.requireNonNull(indices);
4232
}
4333
}

server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ protected void masterOperation(
120120
return;
121121
}
122122

123-
final CloseIndexClusterStateUpdateRequest closeRequest = new CloseIndexClusterStateUpdateRequest(task.getId()).ackTimeout(
124-
request.ackTimeout()
125-
).masterNodeTimeout(request.masterNodeTimeout()).waitForActiveShards(request.waitForActiveShards()).indices(concreteIndices);
123+
final CloseIndexClusterStateUpdateRequest closeRequest = new CloseIndexClusterStateUpdateRequest(
124+
request.masterNodeTimeout(),
125+
request.ackTimeout(),
126+
task.getId(),
127+
request.waitForActiveShards(),
128+
concreteIndices
129+
);
126130
indexStateService.closeIndices(closeRequest, listener.delegateResponse((delegatedListener, t) -> {
127131
logger.debug(() -> "failed to close indices [" + Arrays.toString(concreteIndices) + "]", t);
128132
delegatedListener.onFailure(t);

x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.action.admin.indices.close.CloseIndexResponse;
1515
import org.elasticsearch.action.admin.indices.open.OpenIndexClusterStateUpdateRequest;
1616
import org.elasticsearch.action.support.ActionFilters;
17+
import org.elasticsearch.action.support.ActiveShardCount;
1718
import org.elasticsearch.action.support.DestructiveOperations;
1819
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
1920
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
@@ -114,9 +115,13 @@ protected void masterOperation(Task task, FreezeRequest request, ClusterState st
114115
return;
115116
}
116117

117-
final CloseIndexClusterStateUpdateRequest closeRequest = new CloseIndexClusterStateUpdateRequest(task.getId()).ackTimeout(
118-
request.ackTimeout()
119-
).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices);
118+
final CloseIndexClusterStateUpdateRequest closeRequest = new CloseIndexClusterStateUpdateRequest(
119+
request.masterNodeTimeout(),
120+
request.ackTimeout(),
121+
task.getId(),
122+
ActiveShardCount.DEFAULT,
123+
concreteIndices
124+
);
120125

121126
indexStateService.closeIndices(closeRequest, new ActionListener<>() {
122127
@Override

0 commit comments

Comments
 (0)