Skip to content

Commit

Permalink
Merge pull request #101 from github/uyumazhakan/reroute
Browse files Browse the repository at this point in the history
  • Loading branch information
UyumazHakan authored Oct 26, 2022
2 parents 7dd653d + 9ca417d commit 2b93a65
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"`
}

// 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")

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.RerouteWithRetryFailed()
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 2b93a65

Please sign in to comment.