Reroute failed shards command is added

This commit is contained in:
Hakan Uyumaz 2022-10-26 16:22:19 +02:00
Родитель 7dd653d2d2
Коммит 86507f5b8a
2 изменённых файлов: 31 добавлений и 0 удалений

15
es.go
Просмотреть файл

@ -1630,6 +1630,21 @@ type AllocateStalePrimary struct {
AcceptDataLoss bool `json:"accept_data_loss,omitempty"`
}
// Reroute allows to change the allocation of individual shards in the cluster.
func (c *Client) Reroute() error {
var urlBuilder strings.Builder
urlBuilder.WriteString("_cluster/reroute?retry_failed=true")
agent := c.buildPostRequest(urlBuilder.String())
_, err := handleErrWithBytes(agent)
if err != nil {
return err
}
return nil
}
// AllocateStalePrimary allows to manually allocate a stale primary shard to a specific node
func (c *Client) AllocateStalePrimaryShard(node, index string, shard int) error {
var urlBuilder strings.Builder

Просмотреть файл

@ -2180,6 +2180,22 @@ func TestClusterAllocationExplain(t *testing.T) {
}
}
func TestReroute(t *testing.T) {
testSetup := &ServerSetup{
Method: "POST",
Path: "/_cluster/reroute",
}
host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})
defer ts.Close()
client := NewClient(host, port)
err := client.Reroute()
if err != nil {
t.Fatalf("Unexpected error expected nil, got %s", err)
}
}
func TestAllocateStalePrimaryShard(t *testing.T) {
testSetup := &ServerSetup{
Method: "POST",