From 8465fc5b4c509d91e298b9cb8a09c1bb54800a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= Date: Tue, 18 Feb 2025 09:55:57 +0100 Subject: [PATCH] Deprecate set_stream_retention_policy CLI command It is not working as expected. Policies are the way to change data retention for stream. --- deps/rabbit/docs/rabbitmq-streams.8 | 16 +----- deps/rabbit/src/rabbit_stream_queue.erl | 19 ------- .../set_stream_retention_policy_command.ex | 23 +++------ ...t_stream_retention_policy_command_test.exs | 49 ++++--------------- 4 files changed, 18 insertions(+), 89 deletions(-) diff --git a/deps/rabbit/docs/rabbitmq-streams.8 b/deps/rabbit/docs/rabbitmq-streams.8 index b3ba4ea9a299..408ab6c53d8f 100644 --- a/deps/rabbit/docs/rabbitmq-streams.8 +++ b/deps/rabbit/docs/rabbitmq-streams.8 @@ -3,9 +3,9 @@ .\" 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-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. +.\" Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. .\" -.Dd June 22, 2023 +.Dd February 18, 2025 .Dt RABBITMQ-STREAMS 8 .Os "RabbitMQ Server" .Sh NAME @@ -129,18 +129,6 @@ Example: .Dl rabbitmq-streams restart_stream --vhost Qo a-vhost Qc Qo a-stream Qc --preferred-leader-node Qo node .\" ------------------------------------ .El -.Ss Policies -.Bl -tag -width Ds -.\" ------------------------------------ -.It Cm set_stream_retention_policy Ar stream Ar policy Fl -vhost Ar virtual-host -.Pp -Set the retention policy of a stream. -.Pp -Example: -.Sp -.Dl rabbitmq-streams set_stream_retention_policy --vhost Qo a-vhost Qc Qo a-stream Qc Qo a-policy Qc -.\" ------------------------------------ -.El .Ss Stream plugin .Bl -tag -width Ds .\" ------------------------------------------------------------------ diff --git a/deps/rabbit/src/rabbit_stream_queue.erl b/deps/rabbit/src/rabbit_stream_queue.erl index 7b6eb0510a1f..ccb345a55def 100644 --- a/deps/rabbit/src/rabbit_stream_queue.erl +++ b/deps/rabbit/src/rabbit_stream_queue.erl @@ -42,7 +42,6 @@ -export([list_with_minimum_quorum/0]). --export([set_retention_policy/3]). -export([restart_stream/3, add_replica/3, delete_replica/3, @@ -999,24 +998,6 @@ update_leader_pid(Pid, #stream_client{} = State) -> state_info(_) -> #{}. -set_retention_policy(Name, VHost, Policy) -> - case rabbit_amqqueue:check_max_age(Policy) of - {error, _} = E -> - E; - MaxAge -> - QName = queue_resource(VHost, Name), - Fun = fun(Q) -> - Conf = amqqueue:get_type_state(Q), - amqqueue:set_type_state(Q, Conf#{max_age => MaxAge}) - end, - case rabbit_amqqueue:update(QName, Fun) of - not_found -> - {error, not_found}; - _ -> - ok - end - end. - -spec restart_stream(VHost :: binary(), Queue :: binary(), #{preferred_leader_node => node()}) -> {ok, node()} | diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/streams/commands/set_stream_retention_policy_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/streams/commands/set_stream_retention_policy_command.ex index efd97a9f79f7..1fd83343cc82 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/streams/commands/set_stream_retention_policy_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/streams/commands/set_stream_retention_policy_command.ex @@ -2,7 +2,7 @@ ## 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-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. +## 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.Streams.Commands.SetStreamRetentionPolicyCommand do alias RabbitMQ.CLI.Core.DocGuide @@ -14,29 +14,18 @@ defmodule RabbitMQ.CLI.Streams.Commands.SetStreamRetentionPolicyCommand do use RabbitMQ.CLI.Core.AcceptsTwoPositionalArguments use RabbitMQ.CLI.Core.RequiresRabbitAppRunning - def run([name, retention_policy], %{node: node_name, vhost: vhost}) do - :rabbit_misc.rpc_call(node_name, :rabbit_stream_queue, :set_retention_policy, [ - name, - vhost, - retention_policy - ]) + def run(_, _) do + :ok end use RabbitMQ.CLI.DefaultOutput - def banner([name, retention_policy], _) do - "Setting retention policy of stream queue #{name} to #{retention_policy} ..." + def banner(_, _) do + "DEPRECATED. This command is a no-op. Use a policy to set data retention." end def usage, do: "set_stream_retention_policy [--vhost ] " - def usage_additional() do - [ - ["", "stream queue name"], - ["", "retention policy"] - ] - end - def usage_doc_guides() do [ DocGuide.streams() @@ -45,5 +34,5 @@ defmodule RabbitMQ.CLI.Streams.Commands.SetStreamRetentionPolicyCommand do def help_section(), do: :policies - def description(), do: "Sets the retention policy of a stream queue" + def description(), do: "DEPRECATED. This command is a no-op. Use a policy to set data retention." end diff --git a/deps/rabbitmq_cli/test/streams/set_stream_retention_policy_command_test.exs b/deps/rabbitmq_cli/test/streams/set_stream_retention_policy_command_test.exs index 4d492a5984a6..428529b00d4a 100644 --- a/deps/rabbitmq_cli/test/streams/set_stream_retention_policy_command_test.exs +++ b/deps/rabbitmq_cli/test/streams/set_stream_retention_policy_command_test.exs @@ -2,7 +2,7 @@ ## 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-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. +## 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.Streams.Commands.SetStreamRetentionPolicyCommandTest do @@ -17,52 +17,23 @@ defmodule RabbitMQ.CLI.Streams.Commands.SetStreamRetentionPolicyCommandTest do :ok end - setup context do + setup do {:ok, opts: %{ - node: get_rabbit_hostname(), - timeout: context[:test_timeout] || 30000 + node: get_rabbit_hostname() }} end - test "validate: when no arguments are provided, returns a failure" do - assert @command.validate([], %{}) == {:validation_failure, :not_enough_args} - end - - test "validate: when one argument is provided, returns a failure" do - assert @command.validate(["stream-queue-a"], %{}) == {:validation_failure, :not_enough_args} - end - - test "validate: when three or more arguments are provided, returns a failure" do - assert @command.validate(["stream-queue-a", "1D", "one-extra-arg"], %{}) == - {:validation_failure, :too_many_args} - - assert @command.validate(["stream-queue-a", "1D", "extra-arg", "another-extra-arg"], %{}) == - {:validation_failure, :too_many_args} - end - - test "validate: treats two positional arguments and default switches as a success" do - assert @command.validate(["stream-queue-a", "2Y"], %{}) == :ok - end - - @tag test_timeout: 3000 - test "run: targeting an unreachable node throws a badrpc" do + test "run: no op", context do assert match?( - {:badrpc, _}, - @command.run( - ["stream-queue-a", "1Y"], - %{node: :jake@thedog, vhost: "/", timeout: 200} - ) + :ok, + @command.run([context[:opts][:node]], context[:opts]) ) end - test "run: targeting an unknown queue returns an error", context do - assert match?( - {:error, _}, - @command.run( - ["stream-queue-a", "1Y"], - Map.merge(context[:opts], %{vhost: "/"}) - ) - ) + test "banner", context do + assert @command.banner(["a"], context[:opts]) =~ + ~r/DEPRECATED. This command is a no-op./ end + end