Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpk: supports triggering on-demand balancer #22855

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading