Skip to content

Commit c2c0ced

Browse files
authored
Reset desired balance (#94525)
This introduces an endpoint to reset the desired balance. It could be used if computed balance diverged from the actual one a lot to start a new computation from the current state.
1 parent 058bcdb commit c2c0ced

File tree

14 files changed

+571
-70
lines changed

14 files changed

+571
-70
lines changed

docs/reference/cluster.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,5 @@ include::cluster/get-desired-nodes.asciidoc[]
119119
include::cluster/delete-desired-nodes.asciidoc[]
120120

121121
include::cluster/get-desired-balance.asciidoc[]
122+
123+
include::cluster/delete-desired-balance.asciidoc[]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[[delete-desired-balance]]
2+
=== Delete/reset desired balance API
3+
++++
4+
<titleabbrev>Delete/reset desired balance</titleabbrev>
5+
++++
6+
7+
NOTE: {cloud-only}
8+
9+
Exposes the desired balance and basic metrics.
10+
11+
[[delete-desired-balance-request]]
12+
==== {api-request-title}
13+
14+
[source,console]
15+
--------------------------------------------------
16+
DELETE /_internal/desired_balance
17+
--------------------------------------------------
18+
// TEST[skip:Can't reliably test desired balance]

qa/smoke-test-multinode/src/yamlRestTest/resources/rest-api-spec/test/smoke_test_multinode/30_desired_balance.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ setup:
6969

7070
- skip:
7171
version: " - 8.6.99"
72-
reason: "Field added in in 8.7.0"
72+
reason: "cluster_balance_stats added in in 8.7.0"
7373

7474
- do:
7575
cluster.state: {}
@@ -117,7 +117,7 @@ setup:
117117

118118
- skip:
119119
version: " - 8.7.99"
120-
reason: "tier preference added in in 8.8.0"
120+
reason: "tier_preference added in in 8.8.0"
121121

122122
- do:
123123
indices.create:
@@ -142,7 +142,7 @@ setup:
142142

143143
- skip:
144144
version: " - 8.7.99"
145-
reason: "Field added in in 8.8.0"
145+
reason: "cluster_info added in in 8.8.0"
146146

147147
- do:
148148
_internal.get_desired_balance: { }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"_internal.delete_desired_balance":{
3+
"documentation":{
4+
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-desired-balance.html",
5+
"description": "This API is a diagnostics API and the output should not be relied upon for building applications."
6+
},
7+
"stability":"experimental",
8+
"visibility":"private",
9+
"headers":{
10+
"accept": [ "application/json"]
11+
},
12+
"url":{
13+
"paths":[
14+
{
15+
"path":"/_internal/desired_balance",
16+
"methods":[
17+
"DELETE"
18+
]
19+
}
20+
]
21+
}
22+
}
23+
}

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_balance/10_basic.yml

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ setup:
55
reason: "API added in in 8.6.0"
66

77
---
8-
"Test empty desired balance":
8+
"Test get empty desired balance":
99

1010
- do:
1111
_internal.get_desired_balance: { }
@@ -19,12 +19,51 @@ setup:
1919
- gte: { stats.reconciliation_time_in_millis: 0 }
2020
- match: { routing_table: {} }
2121

22+
---
23+
"Test get desired balance for a single shard":
24+
- do:
25+
indices.create:
26+
index: test
27+
body:
28+
settings:
29+
number_of_shards: 1
30+
number_of_replicas: 0
31+
32+
- do:
33+
cluster.health:
34+
index: test
35+
wait_for_status: green
36+
37+
- do:
38+
_internal.get_desired_balance: { }
39+
40+
- gte: { stats.computation_submitted: 0 }
41+
- gte: { stats.computation_executed: 0 }
42+
- gte: { stats.computation_converged: 0 }
43+
- gte: { stats.computation_iterations: 0 }
44+
- gte: { stats.computation_converged_index: 0 }
45+
- gte: { stats.computation_time_in_millis: 0 }
46+
- gte: { stats.reconciliation_time_in_millis: 0 }
47+
48+
- match: { routing_table.test.0.current.0.state: 'STARTED' }
49+
- match: { routing_table.test.0.current.0.shard_id: 0 }
50+
- match: { routing_table.test.0.current.0.index: test }
51+
- is_true: 'routing_table.test.0.current.0.node_is_desired'
52+
- is_false: 'routing_table.test.0.current.0.relocating_node'
53+
- is_false: 'routing_table.test.0.current.0.relocating_node_is_desired'
54+
- is_false: 'routing_table.test.0.current.0.forecast_write_load'
55+
- is_false: 'routing_table.test.0.current.0.forecast_shard_size_in_bytes'
56+
- match: { routing_table.test.0.desired.total: 1 }
57+
- gte: { routing_table.test.0.desired.unassigned: 0 }
58+
- gte: { routing_table.test.0.desired.ignored: 0 }
59+
- is_true: 'routing_table.test.0.desired.node_ids'
60+
2261
---
2362
"Test cluster_balance_stats":
2463

2564
- skip:
2665
version: " - 8.6.99"
27-
reason: "Field added in in 8.7.0"
66+
reason: "cluster_balance_stats added in in 8.7.0"
2867

2968
- do:
3069
cluster.state: {}
@@ -72,7 +111,7 @@ setup:
72111

73112
- skip:
74113
version: " - 8.7.99"
75-
reason: "Field added in in 8.8.0"
114+
reason: "cluster_info added in in 8.8.0"
76115

77116
- do:
78117
_internal.get_desired_balance: { }
@@ -84,7 +123,7 @@ setup:
84123

85124
- skip:
86125
version: " - 8.7.99"
87-
reason: "Node ID added in in 8.8.0"
126+
reason: "node_id and roles added in in 8.8.0"
88127

89128
- do:
90129
cluster.state: {}
@@ -98,51 +137,12 @@ setup:
98137
- is_true: 'cluster_balance_stats.nodes.$node_name.node_id'
99138
- is_true: 'cluster_balance_stats.nodes.$node_name.roles'
100139

101-
---
102-
"Test get desired balance for single shard":
103-
- do:
104-
indices.create:
105-
index: test
106-
body:
107-
settings:
108-
number_of_shards: 1
109-
number_of_replicas: 0
110-
111-
- do:
112-
cluster.health:
113-
index: test
114-
wait_for_status: green
115-
116-
- do:
117-
_internal.get_desired_balance: { }
118-
119-
- gte: { stats.computation_submitted: 0 }
120-
- gte: { stats.computation_executed: 0 }
121-
- gte: { stats.computation_converged: 0 }
122-
- gte: { stats.computation_iterations: 0 }
123-
- gte: { stats.computation_converged_index: 0 }
124-
- gte: { stats.computation_time_in_millis: 0 }
125-
- gte: { stats.reconciliation_time_in_millis: 0 }
126-
127-
- match: { routing_table.test.0.current.0.state: 'STARTED' }
128-
- match: { routing_table.test.0.current.0.shard_id: 0 }
129-
- match: { routing_table.test.0.current.0.index: test }
130-
- is_true: 'routing_table.test.0.current.0.node_is_desired'
131-
- is_false: 'routing_table.test.0.current.0.relocating_node'
132-
- is_false: 'routing_table.test.0.current.0.relocating_node_is_desired'
133-
- is_false: 'routing_table.test.0.current.0.forecast_write_load'
134-
- is_false: 'routing_table.test.0.current.0.forecast_shard_size_in_bytes'
135-
- match: { routing_table.test.0.desired.total: 1 }
136-
- gte: { routing_table.test.0.desired.unassigned: 0 }
137-
- gte: { routing_table.test.0.desired.ignored: 0 }
138-
- is_true: 'routing_table.test.0.desired.node_ids'
139-
140140
---
141141
"Test tier_preference":
142142

143143
- skip:
144144
version: " - 8.7.99"
145-
reason: "tier preference added in in 8.8.0"
145+
reason: "tier_preference added in in 8.8.0"
146146

147147
- do:
148148
indices.create:
@@ -173,3 +173,13 @@ setup:
173173
_internal.get_desired_balance: { }
174174

175175
- gte: { stats.computed_shard_movements: 0 }
176+
177+
---
178+
"Test reset desired balance":
179+
180+
- skip:
181+
version: " - 8.7.99"
182+
reason: "reset API added in in 8.8.0"
183+
184+
- do:
185+
_internal.delete_desired_balance: { }

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import org.apache.logging.log4j.LogManager;
1212
import org.apache.logging.log4j.Logger;
1313
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainAction;
14+
import org.elasticsearch.action.admin.cluster.allocation.DeleteDesiredBalanceAction;
1415
import org.elasticsearch.action.admin.cluster.allocation.GetDesiredBalanceAction;
1516
import org.elasticsearch.action.admin.cluster.allocation.TransportClusterAllocationExplainAction;
17+
import org.elasticsearch.action.admin.cluster.allocation.TransportDeleteDesiredBalanceAction;
1618
import org.elasticsearch.action.admin.cluster.allocation.TransportGetDesiredBalanceAction;
1719
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
1820
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
@@ -310,6 +312,7 @@
310312
import org.elasticsearch.rest.action.admin.cluster.RestClusterStatsAction;
311313
import org.elasticsearch.rest.action.admin.cluster.RestClusterUpdateSettingsAction;
312314
import org.elasticsearch.rest.action.admin.cluster.RestCreateSnapshotAction;
315+
import org.elasticsearch.rest.action.admin.cluster.RestDeleteDesiredBalanceAction;
313316
import org.elasticsearch.rest.action.admin.cluster.RestDeleteDesiredNodesAction;
314317
import org.elasticsearch.rest.action.admin.cluster.RestDeleteRepositoryAction;
315318
import org.elasticsearch.rest.action.admin.cluster.RestDeleteSnapshotAction;
@@ -621,6 +624,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
621624
actions.register(ClearVotingConfigExclusionsAction.INSTANCE, TransportClearVotingConfigExclusionsAction.class);
622625
actions.register(ClusterAllocationExplainAction.INSTANCE, TransportClusterAllocationExplainAction.class);
623626
actions.register(GetDesiredBalanceAction.INSTANCE, TransportGetDesiredBalanceAction.class);
627+
actions.register(DeleteDesiredBalanceAction.INSTANCE, TransportDeleteDesiredBalanceAction.class);
624628
actions.register(ClusterStatsAction.INSTANCE, TransportClusterStatsAction.class);
625629
actions.register(ClusterStateAction.INSTANCE, TransportClusterStateAction.class);
626630
actions.register(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class);
@@ -799,6 +803,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
799803
registerHandler.accept(new RestNodesHotThreadsAction());
800804
registerHandler.accept(new RestClusterAllocationExplainAction());
801805
registerHandler.accept(new RestGetDesiredBalanceAction());
806+
registerHandler.accept(new RestDeleteDesiredBalanceAction());
802807
registerHandler.accept(new RestClusterStatsAction());
803808
registerHandler.accept(new RestClusterStateAction(settingsFilter, threadPool));
804809
registerHandler.accept(new RestClusterHealthAction());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.action.admin.cluster.allocation;
10+
11+
import org.elasticsearch.action.ActionResponse;
12+
import org.elasticsearch.action.ActionType;
13+
14+
public class DeleteDesiredBalanceAction extends ActionType<ActionResponse.Empty> {
15+
16+
public static final DeleteDesiredBalanceAction INSTANCE = new DeleteDesiredBalanceAction();
17+
public static final String NAME = "cluster:admin/desired_balance/reset";
18+
19+
DeleteDesiredBalanceAction() {
20+
super(NAME, in -> ActionResponse.Empty.INSTANCE);
21+
}
22+
}

0 commit comments

Comments
 (0)