Skip to content

OTP-20 compatibility workaround for queue directory names. 3.6 only! #1246

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 4 commits into from
Jun 8, 2017
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/rabbit_queue_index.erl
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ recover_message(false, _, no_del, RelSeq, {Segment, DirtyCount}) ->
DirtyCount + 2}.

queue_name_to_dir_name(Name = #resource { kind = queue }) ->
<<Num:128>> = erlang:md5(term_to_binary(Name)),
<<Num:128>> = erlang:md5(term_to_binary_compat:queue_name_to_binary(Name)),
rabbit_misc:format("~.36B", [Num]).

queues_dir() ->
Expand Down
32 changes: 32 additions & 0 deletions src/term_to_binary_compat.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is GoPivotal, Inc.
%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved.
%%

-module(term_to_binary_compat).

-include("rabbit.hrl").

-export([queue_name_to_binary/1]).

queue_name_to_binary(#resource{kind = queue} = {resource, VHost, queue, Name}) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use #resource here to make things a bit more forward-compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot and should not be forward-compatible.
The function is a workaround and in 3.7 we should get rid of it. The code assumes that the record will be a tuple of this specific format. The match asserts that we haven't changed the record and the function still makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

VHostBSize = byte_size(VHost),
NameBSize = byte_size(Name),
<<131, %% Binary format "version"
104, 4, %% 4-element tuple
100, 0, 8, "resource", %% `resource` atom
109, VHostBSize:32, VHost/binary, %% Vhost binary
100, 0, 5, "queue", %% `queue` atom
109, NameBSize:32, Name/binary>>. %% Name binary

2 changes: 1 addition & 1 deletion test/backing_queue_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ make_publish_delivered(IsPersistent, PayloadFun, PropFun, N) ->
PropFun(N, #message_properties{size = 10})}.

queue_name(Config, Name) ->
Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name),
Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)),
queue_name(Name1).

queue_name(Name) ->
Expand Down
2 changes: 1 addition & 1 deletion test/cluster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ test_spawn_remote() ->
end.

queue_name(Config, Name) ->
Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name),
Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)),
queue_name(Name1).

queue_name(Name) ->
Expand Down
62 changes: 62 additions & 0 deletions test/term_to_binary_compat_prop_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is GoPivotal, Inc.
%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved.
%%


-module(term_to_binary_compat_prop_SUITE).

-compile(export_all).

-include("rabbit.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("proper/include/proper.hrl").

all() ->
%% The test should run on OTP < 20 (erts < 9)
case erts_gt_8() of
true ->
[];
false ->
[queue_name_to_binary]
end.

erts_gt_8() ->
Vsn = erlang:system_info(version),
[Maj|_] = string:tokens(Vsn, "."),
list_to_integer(Maj) > 8.

init_per_suite(Config) ->
rabbit_ct_helpers:log_environment(),
rabbit_ct_helpers:run_setup_steps(Config).

end_per_suite(Config) ->
rabbit_ct_helpers:run_teardown_steps(Config).

init_per_testcase(Testcase, Config) ->
rabbit_ct_helpers:testcase_started(Config, Testcase).

queue_name_to_binary(Config) ->
Fun = fun () -> prop_queue_name_to_binary(Config) end,
rabbit_ct_proper_helpers:run_proper(Fun, [], 10000).


prop_queue_name_to_binary(_Config) ->
?FORALL({Vhost, QName}, {binary(), binary()},
begin
Resource = rabbit_misc:r(Vhost, queue, QName),
Legacy = term_to_binary_compat:queue_name_to_binary(Resource),
Current = term_to_binary(Resource),
Current =:= Legacy
end).
2 changes: 1 addition & 1 deletion test/unit_inbroker_parallel_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ on_disk_stop(Pid) ->
end.

queue_name(Config, Name) ->
Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name),
Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)),
queue_name(Name1).

queue_name(Name) ->
Expand Down