Skip to content

Commit

Permalink
rpk: add help text for disabled partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
r-vasquez committed Nov 22, 2023
1 parent 3f55f92 commit 432ac93
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/go/rpk/pkg/cli/cluster/partitions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ replicas assignments in the form of: <Node-ID>-<Core>.
If the DISABLED column contains a '-' value, then it means you are running this
command against a cluster that does not support the underlying API.
ENABLED/DISABLED
Disabling a partition in Redpanda involves prohibiting any data consumption or
production to and from it. All internal processes associated with the partition
are stopped, and it remains unloaded during system startup. This measure aims to
maintain cluster health by preventing issues caused by specific corrupted
partitions that may lead to Redpanda crashes. Although the data remains stored
on disk, Redpanda ceases interaction with the disabled partitions to ensure
system stability.
You may disable/enable partition using 'rpk cluster partitions enable/disable'.
EXAMPLES
List all partitions in the cluster.
Expand Down
24 changes: 17 additions & 7 deletions src/go/rpk/pkg/cli/cluster/partitions/toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ Enable partition 1, and 2 of topic 'foo', and partition 5 of topic 'bar' in the
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, topicArg []string) {
if !all && partitions == nil {
fmt.Println("Please select either specific partitions to enable (--partitions) or select all (--all)")
fmt.Println("Please select either specific partitions to enable (--partitions) or select all (--all).")
cmd.Help()
os.Exit(1)
}
if all && len(topicArg) == 0 {
fmt.Println("You must select a topic")
fmt.Println("You must select a topic.")
cmd.Help()
os.Exit(1)
}
Expand All @@ -85,7 +85,7 @@ Enable partition 1, and 2 of topic 'foo', and partition 5 of topic 'bar' in the
},
}
cmd.Flags().StringArrayVarP(&partitions, "partitions", "p", nil, "Comma-separated list of partitions you want to enable. Check help for extended usage")
cmd.Flags().BoolVarP(&all, "all", "a", false, "If true, enable all partitions")
cmd.Flags().BoolVarP(&all, "all", "a", false, "If true, enable all partitions for the specified topic")

cmd.MarkFlagsMutuallyExclusive("partitions", "all")
return cmd
Expand All @@ -109,6 +109,16 @@ where namespace and topic are optional parameters. If the namespace is not
provided, rpk will assume 'kafka'. If the topic is not provided in the flag, rpk
will use the topic provided as an argument to this command.
DISABLED PARTITIONS
Disabling a partition in Redpanda involves prohibiting any data consumption or
production to and from it. All internal processes associated with the partition
are stopped, and it remains unloaded during system startup. This measure aims to
maintain cluster health by preventing issues caused by specific corrupted
partitions that may lead to Redpanda crashes. Although the data remains stored
on disk, Redpanda ceases interaction with the disabled partitions to ensure
system stability.
EXAMPLES
Disable all partitions in topic 'foo'
Expand All @@ -124,12 +134,12 @@ Disable partition 1, and 2 of topic 'foo', and partition 5 of topic 'bar' in the
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, topicArg []string) {
if !all && partitions == nil {
fmt.Println("Please select either specific partitions to disable (--partitions) or select all (--all)")
fmt.Println("Please select either specific partitions to disable (--partitions) or select all (--all).")
cmd.Help()
os.Exit(1)
}
if all && len(topicArg) == 0 {
fmt.Println("You must select a topic")
fmt.Println("You must select a topic.")
cmd.Help()
os.Exit(1)
}
Expand All @@ -150,7 +160,7 @@ Disable partition 1, and 2 of topic 'foo', and partition 5 of topic 'bar' in the
},
}
cmd.Flags().StringArrayVarP(&partitions, "partitions", "p", nil, "Comma-separated list of partitions you want to disable. Use --help for additional information")
cmd.Flags().BoolVarP(&all, "all", "a", false, "If true, disable all partitions")
cmd.Flags().BoolVarP(&all, "all", "a", false, "If true, disable all partitions for the specified topic")

cmd.MarkFlagsMutuallyExclusive("partitions", "all")
return cmd
Expand Down Expand Up @@ -211,7 +221,7 @@ func parsePartition(ntp string) (ns, topic string, partitions []int, rerr error)
// - Index 1: Namespace, if present.
// - Index 2: Topic, if present.
// - Index 3: Comma-separated partitions.
partitionRe = regexp.MustCompile(`^(?:(?:([\w-]+)/)?([\w-]+)/)?(\d+(?:,\d+)*)$`)
partitionRe = regexp.MustCompile(`^(?:(?:([^/]+)/)?([^/]+)/)?(\d+(?:,\d+)*)$`)
})
match := partitionRe.FindStringSubmatch(ntp)
if len(match) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions src/go/rpk/pkg/cli/cluster/partitions/toggle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func Test_parsePartition(t *testing.T) {
expNs: "kafka",
expTopic: "",
expPartitions: []int{13},
}, {
name: "topic with dot",
input: "my.topic.foo/1",
expNs: "kafka",
expTopic: "my.topic.foo",
expPartitions: []int{1},
}, {
name: "wrong format 1",
input: "thirteen",
Expand Down

0 comments on commit 432ac93

Please sign in to comment.