Skip to content

Commit b51c253

Browse files
authored
Merge pull request #1300 from ripienaar/cluster_step_down_placement
Extend meta step down with new placement directives
2 parents 43bca2b + 74f5ad5 commit b51c253

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

cli/server_cluster_command.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type SrvClusterCmd struct {
3131
force bool
3232
peer string
3333
placementCluster string
34+
placementNode string
35+
placementTags []string
3436
balanceServerName string
3537
balanceIdle time.Duration
3638
balanceAccount string
@@ -55,6 +57,8 @@ func configureServerClusterCommand(srv *fisk.CmdClause) {
5557

5658
sd := cluster.Command("step-down", "Force a new leader election by standing down the current meta leader").Alias("stepdown").Alias("sd").Alias("elect").Alias("down").Alias("d").Action(c.metaLeaderStandDownAction)
5759
sd.Flag("cluster", "Request placement of the leader in a specific cluster").StringVar(&c.placementCluster)
60+
sd.Flag("tags", "Request placement of the leader on nodes with specific tag(s)").StringsVar(&c.placementTags)
61+
sd.Flag("host", "Request placement of the leader on a specific node").StringVar(&c.placementNode)
5862
sd.Flag("json", "Produce JSON output").Short('j').UnNegatableBoolVar(&c.json)
5963
sd.Flag("force", "Force leader step down ignoring current leader").Short('f').UnNegatableBoolVar(&c.force)
6064

@@ -253,9 +257,19 @@ func (c *SrvClusterCmd) metaLeaderStandDownAction(_ *fisk.ParseContext) error {
253257
leader = "<unknown>"
254258
}
255259

260+
if c.placementNode != "" || len(c.placementTags) > 0 {
261+
// TODO: check api level instead but requires https://github.com/nats-io/nats-server/issues/6681
262+
fmt.Println("WARNING: Using placement tags or node name required NATS Server 2.11 or newer")
263+
fmt.Println()
264+
}
265+
256266
log.Printf("Requesting leader step down of %q in a %d peer RAFT group", leader, len(resp.Meta.Replicas)+1)
257-
if c.placementCluster != "" {
258-
err = mgr.MetaLeaderStandDown(&api.Placement{Cluster: c.placementCluster})
267+
if c.placementCluster != "" || len(c.placementTags) > 0 || c.placementNode != "" {
268+
err = mgr.MetaLeaderStandDown(&api.Placement{
269+
Cluster: c.placementCluster,
270+
Tags: c.placementTags,
271+
Preferred: c.placementNode,
272+
})
259273
} else {
260274
err = mgr.MetaLeaderStandDown(nil)
261275
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ require (
5656
github.com/nats-io/nsc/v2 v2.10.3-0.20250110165315-eeda721ecff6 // indirect
5757
github.com/nsf/termbox-go v1.1.1 // indirect
5858
github.com/prometheus/client_model v0.6.1 // indirect
59-
github.com/prometheus/common v0.62.0 // indirect
59+
github.com/prometheus/common v0.63.0 // indirect
6060
github.com/prometheus/procfs v0.15.1 // indirect
6161
github.com/rivo/uniseg v0.4.7 // indirect
6262
github.com/shopspring/decimal v1.4.0 // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGC
132132
github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
133133
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
134134
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
135-
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
136-
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
135+
github.com/prometheus/common v0.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k=
136+
github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18=
137137
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
138138
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
139139
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

0 commit comments

Comments
 (0)