-
Notifications
You must be signed in to change notification settings - Fork 4k
For 4.1.x, by @aaron-seo: introduce a command that would force QQs to take a checkpoint and truncate its segments #13548
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d3dfd9
Add force checkpoint functions for quorum queues and command line tool
aaron-seo fa31086
Fix force_checkpoint tests and CLI command
aaron-seo 6a78e9f
Add timeout to rpc call for force_checkpoint
aaron-seo d54fee2
Update a #13175 test to not use private Ra machine state
michaelklishin d17b085
Quorum queue machine: do not publish certain state records
michaelklishin 7d3292c
quorum_queue_SUITE: keep Raft state logging in force_checkpoint_on_queue
michaelklishin 0c2b6a1
Force checkpoint in all members
dcorbacho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
deps/rabbitmq_cli/lib/rabbitmq/cli/queues/commands/force_checkpoint_command.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| ## This Source Code Form is subject to the terms of the Mozilla Public | ||
| ## License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| ## file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| ## | ||
| ## Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
|
|
||
| defmodule RabbitMQ.CLI.Queues.Commands.ForceCheckpointCommand do | ||
| alias RabbitMQ.CLI.Core.{DocGuide} | ||
|
|
||
| @behaviour RabbitMQ.CLI.CommandBehaviour | ||
|
|
||
| defp default_opts, | ||
| do: %{vhost_pattern: ".*", queue_pattern: ".*", errors_only: false} | ||
|
|
||
| def switches(), | ||
| do: [ | ||
| vhost_pattern: :string, | ||
| queue_pattern: :string, | ||
| errors_only: :boolean | ||
| ] | ||
|
|
||
| def merge_defaults(args, opts) do | ||
| {args, Map.merge(default_opts(), opts)} | ||
| end | ||
|
|
||
| use RabbitMQ.CLI.Core.RequiresRabbitAppRunning | ||
| use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments | ||
|
|
||
| def run([], %{ | ||
| node: node_name, | ||
| vhost_pattern: vhost_pat, | ||
| queue_pattern: queue_pat, | ||
| errors_only: errors_only | ||
| }) do | ||
| args = [vhost_pat, queue_pat] | ||
|
|
||
| case :rabbit_misc.rpc_call(node_name, :rabbit_quorum_queue, :force_checkpoint, args) do | ||
| {:badrpc, _} = error -> | ||
| error | ||
|
|
||
| results when errors_only -> | ||
| for {{:resource, vhost, _kind, name}, {:error, _, _} = res} <- results, | ||
| do: [ | ||
| {:vhost, vhost}, | ||
| {:name, name}, | ||
| {:result, res} | ||
| ] | ||
|
|
||
| results -> | ||
| for {{:resource, vhost, _kind, name}, res} <- results, | ||
| do: [ | ||
| {:vhost, vhost}, | ||
| {:name, name}, | ||
| {:result, res} | ||
| ] | ||
| end | ||
| end | ||
|
|
||
| use RabbitMQ.CLI.DefaultOutput | ||
|
|
||
| def formatter(), do: RabbitMQ.CLI.Formatters.Table | ||
|
|
||
| def usage, | ||
| do: "force_checkpoint [--vhost-pattern <pattern>] [--queue-pattern <pattern>]" | ||
|
|
||
| def usage_additional do | ||
| [ | ||
| ["--queue-pattern <pattern>", "regular expression to match queue names"], | ||
| ["--vhost-pattern <pattern>", "regular expression to match virtual host names"], | ||
| ["--errors-only", "only list queues which reported an error"] | ||
| ] | ||
| end | ||
|
|
||
| def usage_doc_guides() do | ||
| [ | ||
| DocGuide.quorum_queues() | ||
| ] | ||
| end | ||
|
|
||
| def help_section, do: :replication | ||
|
|
||
| def description, | ||
| do: "Forces checkpoints for all matching quorum queues" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it will only force a checkpoint on the local member of the matching queues, if there is a local member. |
||
|
|
||
| def banner([], _) do | ||
| "Forcing checkpoint for all matching quorum queues..." | ||
| end | ||
| end | ||
64 changes: 64 additions & 0 deletions
64
deps/rabbitmq_cli/test/queues/force_checkpoint_command_test.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| ## This Source Code Form is subject to the terms of the Mozilla Public | ||
| ## License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| ## file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| ## | ||
| ## Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
|
|
||
| defmodule RabbitMQ.CLI.Queues.Commands.ForceCheckpointCommandTest do | ||
| use ExUnit.Case, async: false | ||
| import TestHelper | ||
|
|
||
| @command RabbitMQ.CLI.Queues.Commands.ForceCheckpointCommand | ||
|
|
||
| setup_all do | ||
| RabbitMQ.CLI.Core.Distribution.start() | ||
|
|
||
| :ok | ||
| end | ||
|
|
||
| setup context do | ||
| {:ok, | ||
| opts: %{ | ||
| node: get_rabbit_hostname(), | ||
| timeout: context[:test_timeout] || 30000, | ||
| vhost_pattern: ".*", | ||
| queue_pattern: ".*", | ||
| errors_only: false | ||
| }} | ||
| end | ||
|
|
||
| test "merge_defaults: defaults to reporting complete results" do | ||
| assert @command.merge_defaults([], %{}) == | ||
| {[], | ||
| %{ | ||
| vhost_pattern: ".*", | ||
| queue_pattern: ".*", | ||
| errors_only: false | ||
| }} | ||
| end | ||
|
|
||
| test "validate: accepts no positional arguments" do | ||
| assert @command.validate([], %{}) == :ok | ||
| end | ||
|
|
||
| test "validate: any positional arguments fail validation" do | ||
| assert @command.validate(["quorum-queue-a"], %{}) == {:validation_failure, :too_many_args} | ||
|
|
||
| assert @command.validate(["quorum-queue-a", "two"], %{}) == | ||
| {:validation_failure, :too_many_args} | ||
|
|
||
| assert @command.validate(["quorum-queue-a", "two", "three"], %{}) == | ||
| {:validation_failure, :too_many_args} | ||
| end | ||
|
|
||
| @tag test_timeout: 3000 | ||
| test "run: targeting an unreachable node throws a badrpc", context do | ||
| assert match?( | ||
| {:badrpc, _}, | ||
| @command.run( | ||
| [], | ||
| Map.merge(context[:opts], %{node: :jake@thedog}) | ||
| ) | ||
| ) | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will include queues that do not have any members on the current node but the
force_checkpoint_on_queuewill only ask any local member to force a checkpoint.