Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
/vulcanizerPublic archive

Commitd2dba4b

Browse files
committed
Allocate stale primary shard functionality is added
1 parente471a00 commitd2dba4b

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

‎es.go‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ type ClusterSettings struct {
227227
// A setting name and value with the setting name to be a "collapsed" version of
228228
// the setting. A setting of:
229229
//
230-
//{ "indices": { "recovery" : { "max_bytes_per_sec": "10mb" } } }
230+
//{ "indices": { "recovery" : { "max_bytes_per_sec": "10mb" } } }
231231
//
232232
// would be represented by:
233233
//
234-
//ClusterSetting{ Setting: "indices.recovery.max_bytes_per_sec", Value: "10mb" }
234+
//ClusterSetting{ Setting: "indices.recovery.max_bytes_per_sec", Value: "10mb" }
235235
typeSettingstruct {
236236
Settingstring
237237
Valuestring
@@ -1606,3 +1606,55 @@ func (c *Client) ClusterAllocationExplain(req *ClusterAllocationExplainRequest,
16061606

16071607
returnstring(body),nil
16081608
}
1609+
1610+
typeRerouteRequeststruct {
1611+
// The commands to perform (move, cancel, allocate, etc)
1612+
Commands []RerouteCommand`json:"commands,omitempty"`
1613+
}
1614+
1615+
typeRerouteCommandstruct {
1616+
AllocateStalePrimaryAllocateStalePrimary`json:"allocate_stale_primary,omitempty"`
1617+
}
1618+
1619+
typeAllocateStalePrimarystruct {
1620+
// The node ID or node name of the node to assign the shard to.
1621+
Nodestring`json:"node,omitempty"`
1622+
1623+
// The name of the index containing the shard to be assigned.
1624+
Indexstring`json:"index,omitempty"`
1625+
1626+
// The shard ID of the shard to be assigned.
1627+
Shard*int`json:"shard,omitempty"`
1628+
1629+
// If a node which has the good copy of the data rejoins the cluster later on, that data will be deleted or overwritten with the data of the stale copy that was forcefully allocated with this command.
1630+
AcceptDataLossbool`json:"accept_data_loss,omitempty"`
1631+
}
1632+
1633+
// AllocateStalePrimary allows to manually allocate a stale primary shard to a specific node
1634+
func (c*Client)AllocateStalePrimaryShard(node,indexstring,shardint)error {
1635+
varurlBuilder strings.Builder
1636+
urlBuilder.WriteString("_cluster/reroute")
1637+
1638+
agent:=c.buildPostRequest(urlBuilder.String())
1639+
1640+
req:=RerouteRequest{
1641+
Commands: []RerouteCommand{
1642+
{
1643+
AllocateStalePrimary:AllocateStalePrimary{
1644+
Node:node,
1645+
Index:index,
1646+
Shard:&shard,
1647+
AcceptDataLoss:true,
1648+
},
1649+
},
1650+
},
1651+
}
1652+
agent.Set("Content-Type","application/json").Send(req)
1653+
1654+
_,err:=handleErrWithBytes(agent)
1655+
iferr!=nil {
1656+
returnerr
1657+
}
1658+
1659+
returnnil
1660+
}

‎es_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,3 +2179,20 @@ func TestClusterAllocationExplain(t *testing.T) {
21792179
})
21802180
}
21812181
}
2182+
2183+
funcTestAllocateStalePrimaryShard(t*testing.T) {
2184+
testSetup:=&ServerSetup{
2185+
Method:"POST",
2186+
Path:"/_cluster/reroute",
2187+
Body:`{"commands":[{"allocate_stale_primary":{"accept_data_loss":true,"index":"test-index","node":"test-node","shard":0}}]}`,
2188+
}
2189+
2190+
host,port,ts:=setupTestServers(t, []*ServerSetup{testSetup})
2191+
deferts.Close()
2192+
client:=NewClient(host,port)
2193+
2194+
err:=client.AllocateStalePrimaryShard("test-node","test-index",0)
2195+
iferr!=nil {
2196+
t.Fatalf("Unexpected error. expected nil, got %s",err)
2197+
}
2198+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp