Skip to content

Deprecate set_stream_retention_policy command #13358

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 1 commit into from
Feb 19, 2025
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
16 changes: 2 additions & 14 deletions deps/rabbit/docs/rabbitmq-streams.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
.\" ------------------------------------------------------------------
Expand Down
19 changes: 0 additions & 19 deletions deps/rabbit/src/rabbit_stream_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()} |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <vhost>] <name> <policy>"

def usage_additional() do
[
["<name>", "stream queue name"],
["<policy>", "retention policy"]
]
end

def usage_doc_guides() do
[
DocGuide.streams()
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading