Skip to content

Commit

Permalink
Reroute failed shards command is added
Browse files Browse the repository at this point in the history
  • Loading branch information
UyumazHakan committed Oct 26, 2022
1 parent 7dd653d commit 86507f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions es.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 86507f5

Please sign in to comment.