Skip to content

Commit

Permalink
Reset desired balance (#94525)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
idegtiarenko committed Apr 20, 2023
1 parent 058bcdb commit c2c0ced
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 70 deletions.
2 changes: 2 additions & 0 deletions docs/reference/cluster.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ include::cluster/get-desired-nodes.asciidoc[]
include::cluster/delete-desired-nodes.asciidoc[]

include::cluster/get-desired-balance.asciidoc[]

include::cluster/delete-desired-balance.asciidoc[]
18 changes: 18 additions & 0 deletions docs/reference/cluster/delete-desired-balance.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[delete-desired-balance]]
=== Delete/reset desired balance API
++++
<titleabbrev>Delete/reset desired balance</titleabbrev>
++++

NOTE: {cloud-only}

Exposes the desired balance and basic metrics.

[[delete-desired-balance-request]]
==== {api-request-title}

[source,console]
--------------------------------------------------
DELETE /_internal/desired_balance
--------------------------------------------------
// TEST[skip:Can't reliably test desired balance]
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ setup:

- skip:
version: " - 8.6.99"
reason: "Field added in in 8.7.0"
reason: "cluster_balance_stats added in in 8.7.0"

- do:
cluster.state: {}
Expand Down Expand Up @@ -117,7 +117,7 @@ setup:

- skip:
version: " - 8.7.99"
reason: "tier preference added in in 8.8.0"
reason: "tier_preference added in in 8.8.0"

- do:
indices.create:
Expand All @@ -142,7 +142,7 @@ setup:

- skip:
version: " - 8.7.99"
reason: "Field added in in 8.8.0"
reason: "cluster_info added in in 8.8.0"

- do:
_internal.get_desired_balance: { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"_internal.delete_desired_balance":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-desired-balance.html",
"description": "This API is a diagnostics API and the output should not be relied upon for building applications."
},
"stability":"experimental",
"visibility":"private",
"headers":{
"accept": [ "application/json"]
},
"url":{
"paths":[
{
"path":"/_internal/desired_balance",
"methods":[
"DELETE"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ setup:
reason: "API added in in 8.6.0"

---
"Test empty desired balance":
"Test get empty desired balance":

- do:
_internal.get_desired_balance: { }
Expand All @@ -19,12 +19,51 @@ setup:
- gte: { stats.reconciliation_time_in_millis: 0 }
- match: { routing_table: {} }

---
"Test get desired balance for a single shard":
- do:
indices.create:
index: test
body:
settings:
number_of_shards: 1
number_of_replicas: 0

- do:
cluster.health:
index: test
wait_for_status: green

- do:
_internal.get_desired_balance: { }

- gte: { stats.computation_submitted: 0 }
- gte: { stats.computation_executed: 0 }
- gte: { stats.computation_converged: 0 }
- gte: { stats.computation_iterations: 0 }
- gte: { stats.computation_converged_index: 0 }
- gte: { stats.computation_time_in_millis: 0 }
- gte: { stats.reconciliation_time_in_millis: 0 }

- match: { routing_table.test.0.current.0.state: 'STARTED' }
- match: { routing_table.test.0.current.0.shard_id: 0 }
- match: { routing_table.test.0.current.0.index: test }
- is_true: 'routing_table.test.0.current.0.node_is_desired'
- is_false: 'routing_table.test.0.current.0.relocating_node'
- is_false: 'routing_table.test.0.current.0.relocating_node_is_desired'
- is_false: 'routing_table.test.0.current.0.forecast_write_load'
- is_false: 'routing_table.test.0.current.0.forecast_shard_size_in_bytes'
- match: { routing_table.test.0.desired.total: 1 }
- gte: { routing_table.test.0.desired.unassigned: 0 }
- gte: { routing_table.test.0.desired.ignored: 0 }
- is_true: 'routing_table.test.0.desired.node_ids'

---
"Test cluster_balance_stats":

- skip:
version: " - 8.6.99"
reason: "Field added in in 8.7.0"
reason: "cluster_balance_stats added in in 8.7.0"

- do:
cluster.state: {}
Expand Down Expand Up @@ -72,7 +111,7 @@ setup:

- skip:
version: " - 8.7.99"
reason: "Field added in in 8.8.0"
reason: "cluster_info added in in 8.8.0"

- do:
_internal.get_desired_balance: { }
Expand All @@ -84,7 +123,7 @@ setup:

- skip:
version: " - 8.7.99"
reason: "Node ID added in in 8.8.0"
reason: "node_id and roles added in in 8.8.0"

- do:
cluster.state: {}
Expand All @@ -98,51 +137,12 @@ setup:
- is_true: 'cluster_balance_stats.nodes.$node_name.node_id'
- is_true: 'cluster_balance_stats.nodes.$node_name.roles'

---
"Test get desired balance for single shard":
- do:
indices.create:
index: test
body:
settings:
number_of_shards: 1
number_of_replicas: 0

- do:
cluster.health:
index: test
wait_for_status: green

- do:
_internal.get_desired_balance: { }

- gte: { stats.computation_submitted: 0 }
- gte: { stats.computation_executed: 0 }
- gte: { stats.computation_converged: 0 }
- gte: { stats.computation_iterations: 0 }
- gte: { stats.computation_converged_index: 0 }
- gte: { stats.computation_time_in_millis: 0 }
- gte: { stats.reconciliation_time_in_millis: 0 }

- match: { routing_table.test.0.current.0.state: 'STARTED' }
- match: { routing_table.test.0.current.0.shard_id: 0 }
- match: { routing_table.test.0.current.0.index: test }
- is_true: 'routing_table.test.0.current.0.node_is_desired'
- is_false: 'routing_table.test.0.current.0.relocating_node'
- is_false: 'routing_table.test.0.current.0.relocating_node_is_desired'
- is_false: 'routing_table.test.0.current.0.forecast_write_load'
- is_false: 'routing_table.test.0.current.0.forecast_shard_size_in_bytes'
- match: { routing_table.test.0.desired.total: 1 }
- gte: { routing_table.test.0.desired.unassigned: 0 }
- gte: { routing_table.test.0.desired.ignored: 0 }
- is_true: 'routing_table.test.0.desired.node_ids'

---
"Test tier_preference":

- skip:
version: " - 8.7.99"
reason: "tier preference added in in 8.8.0"
reason: "tier_preference added in in 8.8.0"

- do:
indices.create:
Expand Down Expand Up @@ -173,3 +173,13 @@ setup:
_internal.get_desired_balance: { }

- gte: { stats.computed_shard_movements: 0 }

---
"Test reset desired balance":

- skip:
version: " - 8.7.99"
reason: "reset API added in in 8.8.0"

- do:
_internal.delete_desired_balance: { }
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainAction;
import org.elasticsearch.action.admin.cluster.allocation.DeleteDesiredBalanceAction;
import org.elasticsearch.action.admin.cluster.allocation.GetDesiredBalanceAction;
import org.elasticsearch.action.admin.cluster.allocation.TransportClusterAllocationExplainAction;
import org.elasticsearch.action.admin.cluster.allocation.TransportDeleteDesiredBalanceAction;
import org.elasticsearch.action.admin.cluster.allocation.TransportGetDesiredBalanceAction;
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
Expand Down Expand Up @@ -310,6 +312,7 @@
import org.elasticsearch.rest.action.admin.cluster.RestClusterStatsAction;
import org.elasticsearch.rest.action.admin.cluster.RestClusterUpdateSettingsAction;
import org.elasticsearch.rest.action.admin.cluster.RestCreateSnapshotAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteDesiredBalanceAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteDesiredNodesAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteRepositoryAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteSnapshotAction;
Expand Down Expand Up @@ -621,6 +624,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(ClearVotingConfigExclusionsAction.INSTANCE, TransportClearVotingConfigExclusionsAction.class);
actions.register(ClusterAllocationExplainAction.INSTANCE, TransportClusterAllocationExplainAction.class);
actions.register(GetDesiredBalanceAction.INSTANCE, TransportGetDesiredBalanceAction.class);
actions.register(DeleteDesiredBalanceAction.INSTANCE, TransportDeleteDesiredBalanceAction.class);
actions.register(ClusterStatsAction.INSTANCE, TransportClusterStatsAction.class);
actions.register(ClusterStateAction.INSTANCE, TransportClusterStateAction.class);
actions.register(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class);
Expand Down Expand Up @@ -799,6 +803,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestNodesHotThreadsAction());
registerHandler.accept(new RestClusterAllocationExplainAction());
registerHandler.accept(new RestGetDesiredBalanceAction());
registerHandler.accept(new RestDeleteDesiredBalanceAction());
registerHandler.accept(new RestClusterStatsAction());
registerHandler.accept(new RestClusterStateAction(settingsFilter, threadPool));
registerHandler.accept(new RestClusterHealthAction());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.admin.cluster.allocation;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;

public class DeleteDesiredBalanceAction extends ActionType<ActionResponse.Empty> {

public static final DeleteDesiredBalanceAction INSTANCE = new DeleteDesiredBalanceAction();
public static final String NAME = "cluster:admin/desired_balance/reset";

DeleteDesiredBalanceAction() {
super(NAME, in -> ActionResponse.Empty.INSTANCE);
}
}

0 comments on commit c2c0ced

Please sign in to comment.