From 86507f5b8af2461f5f4de2d36e6f0b8b66f76121 Mon Sep 17 00:00:00 2001 From: Hakan Uyumaz Date: Wed, 26 Oct 2022 16:22:19 +0200 Subject: [PATCH 1/2] Reroute failed shards command is added --- es.go | 15 +++++++++++++++ es_test.go | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/es.go b/es.go index e4b48e7..5e004f2 100644 --- a/es.go +++ b/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 diff --git a/es_test.go b/es_test.go index 6e77dda..9b9db51 100644 --- a/es_test.go +++ b/es_test.go @@ -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", From 9ca417d204b6e6769bad11137fb68774586c9016 Mon Sep 17 00:00:00 2001 From: Hakan Uyumaz Date: Wed, 26 Oct 2022 18:29:31 +0200 Subject: [PATCH 2/2] Renaming after review --- es.go | 4 ++-- es_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/es.go b/es.go index 5e004f2..eb7a51c 100644 --- a/es.go +++ b/es.go @@ -1630,8 +1630,8 @@ 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 { +// RerouteWithRetryFailed retries allocation of shards that are blocked due to too many subsequent allocation failures. +func (c *Client) RerouteWithRetryFailed() error { var urlBuilder strings.Builder urlBuilder.WriteString("_cluster/reroute?retry_failed=true") diff --git a/es_test.go b/es_test.go index 9b9db51..4d7bbde 100644 --- a/es_test.go +++ b/es_test.go @@ -2190,7 +2190,7 @@ func TestReroute(t *testing.T) { defer ts.Close() client := NewClient(host, port) - err := client.Reroute() + err := client.RerouteWithRetryFailed() if err != nil { t.Fatalf("Unexpected error expected nil, got %s", err) }