Skip to content

Commit a23338a

Browse files
Merge pull request #1246 from rabbitmq/rabbitmq-server-1243
OTP-20 compatibility workaround for queue directory names. 3.6 only!
2 parents d6d9e98 + a674f9b commit a23338a

6 files changed

+98
-4
lines changed

src/rabbit_queue_index.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ recover_message(false, _, no_del, RelSeq, {Segment, DirtyCount}) ->
653653
DirtyCount + 2}.
654654

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

659659
queues_dir() ->

src/term_to_binary_compat.erl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(term_to_binary_compat).
18+
19+
-include("rabbit.hrl").
20+
21+
-export([queue_name_to_binary/1]).
22+
23+
queue_name_to_binary(#resource{kind = queue} = {resource, VHost, queue, Name}) ->
24+
VHostBSize = byte_size(VHost),
25+
NameBSize = byte_size(Name),
26+
<<131, %% Binary format "version"
27+
104, 4, %% 4-element tuple
28+
100, 0, 8, "resource", %% `resource` atom
29+
109, VHostBSize:32, VHost/binary, %% Vhost binary
30+
100, 0, 5, "queue", %% `queue` atom
31+
109, NameBSize:32, Name/binary>>. %% Name binary
32+

test/backing_queue_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ make_publish_delivered(IsPersistent, PayloadFun, PropFun, N) ->
12531253
PropFun(N, #message_properties{size = 10})}.
12541254

12551255
queue_name(Config, Name) ->
1256-
Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name),
1256+
Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)),
12571257
queue_name(Name1).
12581258

12591259
queue_name(Name) ->

test/cluster_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ test_spawn_remote() ->
354354
end.
355355

356356
queue_name(Config, Name) ->
357-
Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name),
357+
Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)),
358358
queue_name(Name1).
359359

360360
queue_name(Name) ->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
18+
-module(term_to_binary_compat_prop_SUITE).
19+
20+
-compile(export_all).
21+
22+
-include("rabbit.hrl").
23+
-include_lib("common_test/include/ct.hrl").
24+
-include_lib("proper/include/proper.hrl").
25+
26+
all() ->
27+
%% The test should run on OTP < 20 (erts < 9)
28+
case erts_gt_8() of
29+
true ->
30+
[];
31+
false ->
32+
[queue_name_to_binary]
33+
end.
34+
35+
erts_gt_8() ->
36+
Vsn = erlang:system_info(version),
37+
[Maj|_] = string:tokens(Vsn, "."),
38+
list_to_integer(Maj) > 8.
39+
40+
init_per_suite(Config) ->
41+
rabbit_ct_helpers:log_environment(),
42+
rabbit_ct_helpers:run_setup_steps(Config).
43+
44+
end_per_suite(Config) ->
45+
rabbit_ct_helpers:run_teardown_steps(Config).
46+
47+
init_per_testcase(Testcase, Config) ->
48+
rabbit_ct_helpers:testcase_started(Config, Testcase).
49+
50+
queue_name_to_binary(Config) ->
51+
Fun = fun () -> prop_queue_name_to_binary(Config) end,
52+
rabbit_ct_proper_helpers:run_proper(Fun, [], 10000).
53+
54+
55+
prop_queue_name_to_binary(_Config) ->
56+
?FORALL({Vhost, QName}, {binary(), binary()},
57+
begin
58+
Resource = rabbit_misc:r(Vhost, queue, QName),
59+
Legacy = term_to_binary_compat:queue_name_to_binary(Resource),
60+
Current = term_to_binary(Resource),
61+
Current =:= Legacy
62+
end).

test/unit_inbroker_parallel_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ on_disk_stop(Pid) ->
158158
end.
159159

160160
queue_name(Config, Name) ->
161-
Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name),
161+
Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)),
162162
queue_name(Name1).
163163

164164
queue_name(Name) ->

0 commit comments

Comments
 (0)