diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2017-06-24 00:07:55 +0300 |
|---|---|---|
| committer | Michael Klishin <mklishin@pivotal.io> | 2017-06-24 00:07:55 +0300 |
| commit | c599c190bfe936e25ec3e93e6e53fe77ee075893 (patch) | |
| tree | ef1b690de0bc57a2df2fda456393eaf33f8477b5 | |
| parent | 59ce657abcdbbed66799f466792657709baae37d (diff) | |
| parent | 5aa080b9695e341784272268bf90927914f1ce7a (diff) | |
| download | rabbitmq-server-git-c599c190bfe936e25ec3e93e6e53fe77ee075893.tar.gz | |
Merge branch 'master' into rabbitmq-server-1246-master
| -rw-r--r-- | priv/schema/rabbit.schema | 3 | ||||
| -rw-r--r-- | src/rabbit_variable_queue.erl | 6 | ||||
| -rw-r--r-- | src/rabbit_vm.erl | 96 | ||||
| -rw-r--r-- | src/vm_memory_monitor.erl | 110 | ||||
| -rw-r--r-- | test/config_schema_SUITE_data/rabbit.snippets | 40 | ||||
| -rw-r--r-- | test/term_to_binary_compat_prop_SUITE.erl | 22 |
6 files changed, 164 insertions, 113 deletions
diff --git a/priv/schema/rabbit.schema b/priv/schema/rabbit.schema index e3eff6fb59..c503548187 100644 --- a/priv/schema/rabbit.schema +++ b/priv/schema/rabbit.schema @@ -207,6 +207,9 @@ end}. {mapping, "ssl_options.honor_cipher_order", "rabbit.ssl_options.honor_cipher_order", [{datatype, {enum, [true, false]}}]}. +{mapping, "ssl_options.honor_ecc_order", "rabbit.ssl_options.honor_ecc_order", + [{datatype, {enum, [true, false]}}]}. + {mapping, "ssl_options.key.RSAPrivateKey", "rabbit.ssl_options.key", [{datatype, string}]}. diff --git a/src/rabbit_variable_queue.erl b/src/rabbit_variable_queue.erl index 86321003c9..40967e316e 100644 --- a/src/rabbit_variable_queue.erl +++ b/src/rabbit_variable_queue.erl @@ -35,6 +35,10 @@ -export([move_messages_to_vhost_store/0]). +-export([migrate_queue/3, migrate_message/3, get_per_vhost_store_client/2, + get_global_store_client/1, log_upgrade_verbose/1, + log_upgrade_verbose/2]). + -include_lib("stdlib/include/qlc.hrl"). -define(QUEUE_MIGRATION_BATCH_SIZE, 100). @@ -359,8 +363,6 @@ -rabbit_upgrade({multiple_routing_keys, local, []}). -rabbit_upgrade({move_messages_to_vhost_store, message_store, []}). --compile(export_all). - -type seq_id() :: non_neg_integer(). -type rates() :: #rates { in :: float(), diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl index 17dae558b9..c2353ab85f 100644 --- a/src/rabbit_vm.erl +++ b/src/rabbit_vm.erl @@ -16,7 +16,7 @@ -module(rabbit_vm). --export([memory/0, total_memory/0, binary/0, ets_tables_memory/1]). +-export([memory/0, binary/0, ets_tables_memory/1]). -define(MAGIC_PLUGINS, ["cowboy", "ranch", "sockjs"]). @@ -52,7 +52,7 @@ memory() -> 0 end, MgmtDbETS = ets_memory([rabbit_mgmt_storage]), - OsTotal = total_memory(), + OsTotal = vm_memory_monitor:get_process_memory(), [{total, ErlangTotal}, {processes, Processes}, @@ -106,98 +106,6 @@ memory() -> %% claims about negative memory. See %% http://erlang.org/pipermail/erlang-questions/2012-September/069320.html -%% Memory reported by erlang:memory(total) is not supposed to -%% be equal to the total size of all pages mapped to the emulator, -%% according to http://erlang.org/doc/man/erlang.html#memory-0 -%% erlang:memory(total) under-reports memory usage by around 20% --spec total_memory() -> Bytes :: integer(). -total_memory() -> - case get_memory_calculation_strategy() of - rss -> - case get_system_process_resident_memory() of - {ok, MemInBytes} -> - MemInBytes; - {error, Reason} -> - rabbit_log:debug("Unable to get system memory used. Reason: ~p." - " Falling back to erlang memory reporting", - [Reason]), - erlang:memory(total) - end; - erlang -> - erlang:memory(total) - end. - --spec get_memory_calculation_strategy() -> rss | erlang. -get_memory_calculation_strategy() -> - case application:get_env(rabbit, vm_memory_calculation_strategy, rss) of - erlang -> - erlang; - rss -> - rss; - UnsupportedValue -> - rabbit_log:warning( - "Unsupported value '~p' for vm_memory_calculation_strategy. " - "Supported values: (rss|erlang). " - "Defaulting to 'rss'", - [UnsupportedValue] - ), - rss - end. - --spec get_system_process_resident_memory() -> {ok, Bytes :: integer()} | {error, term()}. -get_system_process_resident_memory() -> - try - get_system_process_resident_memory(os:type()) - catch _:Error -> - {error, {"Failed to get process resident memory", Error}} - end. - -get_system_process_resident_memory({unix,darwin}) -> - get_ps_memory(); - -get_system_process_resident_memory({unix, linux}) -> - get_ps_memory(); - -get_system_process_resident_memory({unix,freebsd}) -> - get_ps_memory(); - -get_system_process_resident_memory({unix,openbsd}) -> - get_ps_memory(); - -get_system_process_resident_memory({win32,_OSname}) -> - OsPid = os:getpid(), - Cmd = " tasklist /fi \"pid eq " ++ OsPid ++ "\" /fo LIST 2>&1 ", - CmdOutput = os:cmd(Cmd), - %% Memory usage is displayed in kilobytes - %% with comma-separated thousands - case re:run(CmdOutput, "Mem Usage:\\s+([0-9,]+)\\s+K", [{capture, all_but_first, list}]) of - {match, [Match]} -> - NoCommas = [ N || N <- Match, N =/= $, ], - {ok, list_to_integer(NoCommas) * 1024}; - _ -> - {error, {unexpected_output_from_command, Cmd, CmdOutput}} - end; - -get_system_process_resident_memory({unix, sunos}) -> - get_ps_memory(); - -get_system_process_resident_memory({unix, aix}) -> - get_ps_memory(); - -get_system_process_resident_memory(_OsType) -> - {error, not_implemented_for_os}. - -get_ps_memory() -> - OsPid = os:getpid(), - Cmd = "ps -p " ++ OsPid ++ " -o rss=", - CmdOutput = os:cmd(Cmd), - case re:run(CmdOutput, "[0-9]+", [{capture, first, list}]) of - {match, [Match]} -> - {ok, list_to_integer(Match) * 1024}; - _ -> - {error, {unexpected_output_from_command, Cmd, CmdOutput}} - end. - binary() -> All = interesting_sups(), {Sums, Rest} = diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl index bc45d04d62..f21dc91e0a 100644 --- a/src/vm_memory_monitor.erl +++ b/src/vm_memory_monitor.erl @@ -35,7 +35,8 @@ -export([get_total_memory/0, get_vm_limit/0, get_check_interval/0, set_check_interval/1, get_vm_memory_high_watermark/0, set_vm_memory_high_watermark/1, - get_memory_limit/0, get_memory_use/1]). + get_memory_limit/0, get_memory_use/1, + get_process_memory/0]). %% for tests -export([parse_line_linux/1]). @@ -117,17 +118,109 @@ get_memory_limit() -> get_memory_use(bytes) -> MemoryLimit = get_memory_limit(), - {rabbit_vm:total_memory(), case MemoryLimit > 0.0 of - true -> MemoryLimit; - false -> infinity - end}; + {get_process_memory(), case MemoryLimit > 0.0 of + true -> MemoryLimit; + false -> infinity + end}; get_memory_use(ratio) -> MemoryLimit = get_memory_limit(), case MemoryLimit > 0.0 of - true -> rabbit_vm:total_memory() / MemoryLimit; + true -> get_process_memory() / MemoryLimit; false -> infinity end. +%% Memory reported by erlang:memory(total) is not supposed to +%% be equal to the total size of all pages mapped to the emulator, +%% according to http://erlang.org/doc/man/erlang.html#memory-0 +%% erlang:memory(total) under-reports memory usage by around 20% +-spec get_process_memory() -> Bytes :: integer(). +get_process_memory() -> + case get_memory_calculation_strategy() of + rss -> + case get_system_process_resident_memory() of + {ok, MemInBytes} -> + MemInBytes; + {error, Reason} -> + rabbit_log:debug("Unable to get system memory used. Reason: ~p." + " Falling back to erlang memory reporting", + [Reason]), + erlang:memory(total) + end; + erlang -> + erlang:memory(total) + end. + +-spec get_memory_calculation_strategy() -> rss | erlang. +get_memory_calculation_strategy() -> + case application:get_env(rabbit, vm_memory_calculation_strategy, rss) of + erlang -> + erlang; + rss -> + rss; + UnsupportedValue -> + rabbit_log:warning( + "Unsupported value '~p' for vm_memory_calculation_strategy. " + "Supported values: (rss|erlang). " + "Defaulting to 'rss'", + [UnsupportedValue] + ), + rss + end. + +-spec get_system_process_resident_memory() -> {ok, Bytes :: integer()} | {error, term()}. +get_system_process_resident_memory() -> + try + get_system_process_resident_memory(os:type()) + catch _:Error -> + {error, {"Failed to get process resident memory", Error}} + end. + +get_system_process_resident_memory({unix,darwin}) -> + get_ps_memory(); + +get_system_process_resident_memory({unix, linux}) -> + get_ps_memory(); + +get_system_process_resident_memory({unix,freebsd}) -> + get_ps_memory(); + +get_system_process_resident_memory({unix,openbsd}) -> + get_ps_memory(); + +get_system_process_resident_memory({win32,_OSname}) -> + OsPid = os:getpid(), + Cmd = " tasklist /fi \"pid eq " ++ OsPid ++ "\" /fo LIST 2>&1 ", + CmdOutput = os:cmd(Cmd), + %% Memory usage is displayed in kilobytes + %% with comma-separated thousands + case re:run(CmdOutput, "Mem Usage:\\s+([0-9,]+)\\s+K", [{capture, all_but_first, list}]) of + {match, [Match]} -> + NoCommas = [ N || N <- Match, N =/= $, ], + {ok, list_to_integer(NoCommas) * 1024}; + _ -> + {error, {unexpected_output_from_command, Cmd, CmdOutput}} + end; + +get_system_process_resident_memory({unix, sunos}) -> + get_ps_memory(); + +get_system_process_resident_memory({unix, aix}) -> + get_ps_memory(); + +get_system_process_resident_memory(_OsType) -> + {error, not_implemented_for_os}. + +get_ps_memory() -> + OsPid = os:getpid(), + Cmd = "ps -p " ++ OsPid ++ " -o rss=", + CmdOutput = os:cmd(Cmd), + case re:run(CmdOutput, "[0-9]+", [{capture, first, list}]) of + {match, [Match]} -> + {ok, list_to_integer(Match) * 1024}; + _ -> + {error, {unexpected_output_from_command, Cmd, CmdOutput}} + end. + %%---------------------------------------------------------------------------- %% gen_server callbacks %%---------------------------------------------------------------------------- @@ -149,7 +242,7 @@ init([MemFraction, AlarmFuns]) -> {ok, set_mem_limits(State, MemFraction)}. handle_call(get_vm_memory_high_watermark, _From, - #state{memory_config_limit = MemLimit} = State) -> + #state{memory_config_limit = MemLimit} = State) -> {reply, MemLimit, State}; handle_call({set_vm_memory_high_watermark, MemLimit}, _From, State) -> @@ -268,7 +361,7 @@ parse_mem_limit(_) -> internal_update(State = #state { memory_limit = MemLimit, alarmed = Alarmed, alarm_funs = {AlarmSet, AlarmClear} }) -> - MemUsed = rabbit_vm:total_memory(), + MemUsed = get_process_memory(), NewAlarmed = MemUsed > MemLimit, case {Alarmed, NewAlarmed} of {false, true} -> emit_update_info(set, MemUsed, MemLimit), @@ -365,7 +458,6 @@ get_total_memory({unix, aix}) -> get_total_memory(_OsType) -> unknown. - %% A line looks like "Foo bar: 123456." parse_line_mach(Line) -> [Name, RHS | _Rest] = string:tokens(Line, ":"), diff --git a/test/config_schema_SUITE_data/rabbit.snippets b/test/config_schema_SUITE_data/rabbit.snippets index 03a687db66..5d03ba1b13 100644 --- a/test/config_schema_SUITE_data/rabbit.snippets +++ b/test/config_schema_SUITE_data/rabbit.snippets @@ -310,6 +310,46 @@ tcp_listen_options.exit_on_close = false", {verify,verify_peer}, {fail_if_no_peer_cert,false}]}]}], []}, + {ssl_options_honor_cipher_order, + "listeners.ssl.1 = 5671 + ssl_options.cacertfile = test/config_schema_SUITE_data/certs/cacert.pem + ssl_options.certfile = test/config_schema_SUITE_data/certs/cert.pem + ssl_options.keyfile = test/config_schema_SUITE_data/certs/key.pem + ssl_options.depth = 2 + ssl_options.verify = verify_peer + ssl_options.fail_if_no_peer_cert = false + ssl_options.honor_cipher_order = true", + [{rabbit, + [{ssl_listeners,[5671]}, + {ssl_options, + [{cacertfile,"test/config_schema_SUITE_data/certs/cacert.pem"}, + {certfile,"test/config_schema_SUITE_data/certs/cert.pem"}, + {keyfile,"test/config_schema_SUITE_data/certs/key.pem"}, + {depth,2}, + {verify,verify_peer}, + {fail_if_no_peer_cert, false}, + {honor_cipher_order, true}]}]}], + []}, + {ssl_options_honor_ecc_order, + "listeners.ssl.1 = 5671 + ssl_options.cacertfile = test/config_schema_SUITE_data/certs/cacert.pem + ssl_options.certfile = test/config_schema_SUITE_data/certs/cert.pem + ssl_options.keyfile = test/config_schema_SUITE_data/certs/key.pem + ssl_options.depth = 2 + ssl_options.verify = verify_peer + ssl_options.fail_if_no_peer_cert = false + ssl_options.honor_ecc_order = true", + [{rabbit, + [{ssl_listeners,[5671]}, + {ssl_options, + [{cacertfile,"test/config_schema_SUITE_data/certs/cacert.pem"}, + {certfile,"test/config_schema_SUITE_data/certs/cert.pem"}, + {keyfile,"test/config_schema_SUITE_data/certs/key.pem"}, + {depth,2}, + {verify,verify_peer}, + {fail_if_no_peer_cert, false}, + {honor_ecc_order, true}]}]}], + []}, {ssl_cert_login_from, "ssl_cert_login_from = common_name", [{rabbit,[{ssl_cert_login_from,common_name}]}], diff --git a/test/term_to_binary_compat_prop_SUITE.erl b/test/term_to_binary_compat_prop_SUITE.erl index 6c8a92a29f..69aa63433d 100644 --- a/test/term_to_binary_compat_prop_SUITE.erl +++ b/test/term_to_binary_compat_prop_SUITE.erl @@ -23,6 +23,8 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("proper/include/proper.hrl"). +-define(ITERATIONS_TO_RUN_UNTIL_CONFIDENT, 10000). + all() -> [ pre_3_6_11_works, @@ -48,20 +50,22 @@ init_per_testcase(Testcase, Config) -> %% If this test fails - the erlang version is not supported in %% RabbitMQ-3.6.10 and earlier. pre_3_6_11_works(Config) -> - Fun = fun () -> prop_pre_3_6_11_works(Config) end, - rabbit_ct_proper_helpers:run_proper(Fun, [], 50000). + Property = fun () -> prop_pre_3_6_11_works(Config) end, + rabbit_ct_proper_helpers:run_proper(Property, [], + ?ITERATIONS_TO_RUN_UNTIL_CONFIDENT). prop_pre_3_6_11_works(_Config) -> ?FORALL(Term, any(), begin Current = term_to_binary(Term), Compat = term_to_binary_compat:term_to_binary_1(Term), - Current =:= Compat + binary_to_term(Current) =:= binary_to_term(Compat) end). term_to_binary_latin_atom(Config) -> - Fun = fun () -> prop_term_to_binary_latin_atom(Config) end, - rabbit_ct_proper_helpers:run_proper(Fun, [], 10000). + Property = fun () -> prop_term_to_binary_latin_atom(Config) end, + rabbit_ct_proper_helpers:run_proper(Property, [], + ?ITERATIONS_TO_RUN_UNTIL_CONFIDENT). prop_term_to_binary_latin_atom(_Config) -> ?FORALL(LatinString, list(integer(0, 255)), @@ -69,12 +73,14 @@ prop_term_to_binary_latin_atom(_Config) -> Length = length(LatinString), Atom = list_to_atom(LatinString), Binary = list_to_binary(LatinString), - <<131,100, Length:16, Binary/binary>> =:= term_to_binary_compat:term_to_binary_1(Atom) + <<131,100, Length:16, Binary/binary>> =:= + term_to_binary_compat:term_to_binary_1(Atom) end). queue_name_to_binary(Config) -> - Fun = fun () -> prop_queue_name_to_binary(Config) end, - rabbit_ct_proper_helpers:run_proper(Fun, [], 10000). + Property = fun () -> prop_queue_name_to_binary(Config) end, + rabbit_ct_proper_helpers:run_proper(Property, [], + ?ITERATIONS_TO_RUN_UNTIL_CONFIDENT). prop_queue_name_to_binary(_Config) -> |
