Skip to content

Commit

Permalink
rpk: supports triggering on-demand balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
daisukebe committed Aug 21, 2024
1 parent 59e4e6e commit 6203116
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/go/rpk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.55.0
github.com/redpanda-data/common-go/rpadmin v0.1.3
github.com/redpanda-data/common-go/rpadmin v0.1.4
github.com/rs/xid v1.5.0
github.com/safchain/ethtool v0.4.1
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
Expand Down
4 changes: 2 additions & 2 deletions src/go/rpk/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/redpanda-data/common-go/net v0.1.0 h1:JnJioRJuL961r1QXiJQ1tW9+yEaJfu8FpXnUmvQbwNM=
github.com/redpanda-data/common-go/net v0.1.0/go.mod h1:iOdNkjxM7a1T8F3cYHTaKIPFCHzzp/ia6TN+Z+7Tt5w=
github.com/redpanda-data/common-go/rpadmin v0.1.3 h1:JRdr4rHcdr+A0hHr+viJYnPm+dP01bsgVUoQLM7Kz44=
github.com/redpanda-data/common-go/rpadmin v0.1.3/go.mod h1:I7umqhnMhIOSEnIA3fvLtdQU7QO/SbWGCwFfFDs3De4=
github.com/redpanda-data/common-go/rpadmin v0.1.4 h1:NkVvurQRmBT9r58UVezC0DhYjR3vzYkQnkFndJBb5xE=
github.com/redpanda-data/common-go/rpadmin v0.1.4/go.mod h1:I7umqhnMhIOSEnIA3fvLtdQU7QO/SbWGCwFfFDs3De4=
github.com/redpanda-data/go-avro/v2 v2.0.0-20240405204525-77b1144dc525 h1:vskZrV6q8W8flL0Ud23AJUYAd8ZgTadO45+loFnG2G0=
github.com/redpanda-data/go-avro/v2 v2.0.0-20240405204525-77b1144dc525/go.mod h1:3YqAM7pgS5vW/EH7naCjFqnAajSgi0f0CfMe1HGhLxQ=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
Expand Down
67 changes: 67 additions & 0 deletions src/go/rpk/pkg/cli/cluster/partitions/balancer_run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package partitions

import (
"fmt"

"github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)

func newTriggerBalancerCommand(fs afero.Fs, p *config.Params) *cobra.Command {
cmd := &cobra.Command{
Use: "balance",
Short: "Triggers on-demand partition balancing",
Long: `Triggers on-demand partition balancing.
This command allows you to trigger on-demand partition balancing.
With Redpanda Community Edition, the partition count on each broker
can easily become uneven, which leads to data skewing. To distribute
partitions across brokers, you can run this command to trigger
on-demand partition balancing.
With Redpanda Enterprise Edition, Continuous Data Balancing monitors
broker and rack availability, as well as disk usage, to avoid topic
hotspots. However, there are edge cases where users should manually
trigger partition balancing (such as a node becoming unavailable for
a prolonged time and rejoining the cluster thereafter). In such cases,
you should run this command to trigger partition balancing manually.
After you run this command, monitor the balancer progress using:
rpk cluster partitions balancer-status
To see more detailed movement status, monitor the progress using:
rpk cluster partitions move-status
`,

Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
p, err := p.LoadVirtualProfile(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
config.CheckExitCloudAdmin(p)

cl, err := adminapi.NewClient(fs, p)
out.MaybeDie(err, "unable to initialize admin client: %v", err)

err = cl.TriggerBalancer(cmd.Context())
out.MaybeDie(err, "failed to invoke on-demand partition balancing: %v", err)

fmt.Println("Successfully triggered on-demand partition balancing.\n\nPlease find the progress with 'rpk cluster partitions balancer-status'.")
},
}
return cmd
}
1 change: 1 addition & 0 deletions src/go/rpk/pkg/cli/cluster/partitions/partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewPartitionsCommand(fs afero.Fs, p *config.Params) *cobra.Command {
newPartitionEnableCommand(fs, p),
newPartitionMovementsStatusCommand(fs, p),
newTransferLeaderCommand(fs, p),
newTriggerBalancerCommand(fs, p),
newUnsafeRecoveryCommand(fs, p),
)
return cmd
Expand Down

0 comments on commit 6203116

Please sign in to comment.