Skip to content

Commit 7132664

Browse files
Merge branch 'master' into rabbitmq-server-1146-full
Conflicts: Makefile
2 parents d6fa209 + 0bd4b78 commit 7132664

22 files changed

+455
-174
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ define PROJECT_ENV
116116
{background_gc_target_interval, 60000},
117117
%% rabbitmq-server-589
118118
{proxy_protocol, false},
119+
{disk_monitor_failure_retries, 10},
120+
{disk_monitor_failure_retry_interval, 120000},
119121
%% can be stop_rabbit or give_up see rabbitmq-server-1458
120122
{vhost_restart_strategy, stop_rabbit}
121123
]
@@ -224,6 +226,8 @@ clean-escripts:
224226
opt='--stringparam man.indent.verbatims=0' ; \
225227
xsltproc --novalid $(DOCS_DIR)/examples-to-end.xsl $< > $<.tmp && \
226228
xmlto -vv -o $(DOCS_DIR) $$opt man $< 2>&1 | (grep -v '^Note: Writing' || :) && \
229+
awk -F"'u " '/^\.HP / { print $$1; print $$2; next; } { print; }' "$@" > "$@.tmp" && \
230+
mv "$@.tmp" "$@" && \
227231
test -f $@ && \
228232
rm $<.tmp
229233

erlang.mk

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
1818

19-
ERLANG_MK_VERSION = 2.0.0-pre.2-207-g9e9b7d2
19+
ERLANG_MK_VERSION = 2.0.0-pre.2-220-g7a200f5
2020

2121
# Make 3.81 and 3.82 are deprecated.
2222

@@ -4203,17 +4203,16 @@ endif
42034203
# in practice only Makefile is needed so far.
42044204
define dep_autopatch
42054205
if [ -f $(DEPS_DIR)/$(1)/erlang.mk ]; then \
4206+
rm -rf $(DEPS_DIR)/$1/ebin/; \
42064207
$(call erlang,$(call dep_autopatch_appsrc.erl,$(1))); \
42074208
$(call dep_autopatch_erlang_mk,$(1)); \
42084209
elif [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
42094210
if [ 0 != `grep -c "include ../\w*\.mk" $(DEPS_DIR)/$(1)/Makefile` ]; then \
42104211
$(call dep_autopatch2,$(1)); \
4211-
elif [ 0 != `grep -ci rebar $(DEPS_DIR)/$(1)/Makefile` ]; then \
4212+
elif [ 0 != `grep -ci "^[^#].*rebar" $(DEPS_DIR)/$(1)/Makefile` ]; then \
42124213
$(call dep_autopatch2,$(1)); \
4213-
elif [ -n "`find $(DEPS_DIR)/$(1)/ -type f -name \*.mk -not -name erlang.mk -exec grep -i rebar '{}' \;`" ]; then \
4214+
elif [ -n "`find $(DEPS_DIR)/$(1)/ -type f -name \*.mk -not -name erlang.mk -exec grep -i "^[^#].*rebar" '{}' \;`" ]; then \
42144215
$(call dep_autopatch2,$(1)); \
4215-
else \
4216-
$(call erlang,$(call dep_autopatch_app.erl,$(1))); \
42174216
fi \
42184217
else \
42194218
if [ ! -d $(DEPS_DIR)/$(1)/src/ ]; then \
@@ -4225,6 +4224,8 @@ define dep_autopatch
42254224
endef
42264225

42274226
define dep_autopatch2
4227+
mv -n $(DEPS_DIR)/$1/ebin/$1.app $(DEPS_DIR)/$1/src/$1.app.src; \
4228+
rm -f $(DEPS_DIR)/$1/ebin/$1.app; \
42284229
if [ -f $(DEPS_DIR)/$1/src/$1.app.src.script ]; then \
42294230
$(call erlang,$(call dep_autopatch_appsrc_script.erl,$(1))); \
42304231
fi; \
@@ -4536,22 +4537,6 @@ define dep_autopatch_rebar.erl
45364537
halt()
45374538
endef
45384539

4539-
define dep_autopatch_app.erl
4540-
UpdateModules = fun(App) ->
4541-
case filelib:is_regular(App) of
4542-
false -> ok;
4543-
true ->
4544-
{ok, [{application, '$(1)', L0}]} = file:consult(App),
4545-
Mods = filelib:fold_files("$(call core_native_path,$(DEPS_DIR)/$1/src)", "\\\\.erl$$", true,
4546-
fun (F, Acc) -> [list_to_atom(filename:rootname(filename:basename(F)))|Acc] end, []),
4547-
L = lists:keystore(modules, 1, L0, {modules, Mods}),
4548-
ok = file:write_file(App, io_lib:format("~p.~n", [{application, '$(1)', L}]))
4549-
end
4550-
end,
4551-
UpdateModules("$(call core_native_path,$(DEPS_DIR)/$1/ebin/$1.app)"),
4552-
halt()
4553-
endef
4554-
45554540
define dep_autopatch_appsrc_script.erl
45564541
AppSrc = "$(call core_native_path,$(DEPS_DIR)/$1/src/$1.app.src)",
45574542
AppSrcScript = AppSrc ++ ".script",
@@ -4828,6 +4813,8 @@ COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
48284813
ERLC_EXCLUDE ?=
48294814
ERLC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .erl,$(ERLC_EXCLUDE)))
48304815

4816+
ERLC_ASN1_OPTS ?=
4817+
48314818
ERLC_MIB_OPTS ?=
48324819
COMPILE_MIB_FIRST ?=
48334820
COMPILE_MIB_FIRST_PATHS = $(addprefix mibs/,$(addsuffix .mib,$(COMPILE_MIB_FIRST)))
@@ -4877,7 +4864,7 @@ endif
48774864

48784865
ifeq ($(wildcard src/$(PROJECT_MOD).erl),)
48794866
define app_file
4880-
{application, $(PROJECT), [
4867+
{application, '$(PROJECT)', [
48814868
{description, "$(PROJECT_DESCRIPTION)"},
48824869
{vsn, "$(PROJECT_VERSION)"},$(if $(IS_DEP),
48834870
{id$(comma)$(space)"$(1)"}$(comma))
@@ -4889,7 +4876,7 @@ define app_file
48894876
endef
48904877
else
48914878
define app_file
4892-
{application, $(PROJECT), [
4879+
{application, '$(PROJECT)', [
48934880
{description, "$(PROJECT_DESCRIPTION)"},
48944881
{vsn, "$(PROJECT_VERSION)"},$(if $(IS_DEP),
48954882
{id$(comma)$(space)"$(1)"}$(comma))
@@ -4920,7 +4907,7 @@ ERL_FILES += $(addprefix src/,$(patsubst %.asn1,%.erl,$(notdir $(ASN1_FILES))))
49204907

49214908
define compile_asn1
49224909
$(verbose) mkdir -p include/
4923-
$(asn1_verbose) erlc -v -I include/ -o asn1/ +noobj $(1)
4910+
$(asn1_verbose) erlc -v -I include/ -o asn1/ +noobj $(ERLC_ASN1_OPTS) $(1)
49244911
$(verbose) mv asn1/*.erl src/
49254912
$(verbose) mv asn1/*.hrl include/
49264913
$(verbose) mv asn1/*.asn1db include/
@@ -5052,7 +5039,7 @@ $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES):
50525039
ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change
50535040
endif
50545041

5055-
-include $(PROJECT).d
5042+
include $(wildcard $(PROJECT).d)
50565043

50575044
ebin/$(PROJECT).app:: ebin/
50585045

@@ -5277,6 +5264,7 @@ MAN_VERSION ?= $(PROJECT_VERSION)
52775264
define asciidoc2man.erl
52785265
try
52795266
[begin
5267+
io:format(" ADOC ~s~n", [F]),
52805268
ok = asciideck:to_manpage(asciideck:parse_file(F), #{
52815269
compress => gzip,
52825270
outdir => filename:dirname(F),
@@ -5285,7 +5273,8 @@ try
52855273
})
52865274
end || F <- [$(shell echo $(addprefix $(comma)\",$(addsuffix \",$1)) | sed 's/^.//')]],
52875275
halt(0)
5288-
catch _:_ ->
5276+
catch C:E ->
5277+
io:format("Exception ~p:~p~nStacktrace: ~p~n", [C, E, erlang:get_stacktrace()]),
52895278
halt(1)
52905279
end.
52915280
endef
@@ -6123,6 +6112,7 @@ CT_SUITES := $(sort $(subst _SUITE.erl,,$(notdir $(call core_find,$(TEST_DIR)/,*
61236112
endif
61246113
endif
61256114
CT_SUITES ?=
6115+
CT_LOGS_DIR ?= $(CURDIR)/logs
61266116

61276117
# Core targets.
61286118

@@ -6145,13 +6135,13 @@ CT_RUN = ct_run \
61456135
-noinput \
61466136
-pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin $(TEST_DIR) \
61476137
-dir $(TEST_DIR) \
6148-
-logdir $(CURDIR)/logs
6138+
-logdir $(CT_LOGS_DIR)
61496139

61506140
ifeq ($(CT_SUITES),)
61516141
ct: $(if $(IS_APP),,apps-ct)
61526142
else
61536143
ct: test-build $(if $(IS_APP),,apps-ct)
6154-
$(verbose) mkdir -p $(CURDIR)/logs/
6144+
$(verbose) mkdir -p $(CT_LOGS_DIR)
61556145
$(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS)
61566146
endif
61576147

@@ -6179,14 +6169,14 @@ endif
61796169

61806170
define ct_suite_target
61816171
ct-$(1): test-build
6182-
$(verbose) mkdir -p $(CURDIR)/logs/
6172+
$(verbose) mkdir -p $(CT_LOGS_DIR)
61836173
$(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(1)) $(CT_EXTRA) $(CT_OPTS)
61846174
endef
61856175

61866176
$(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
61876177

61886178
distclean-ct:
6189-
$(gen_verbose) rm -rf $(CURDIR)/logs/
6179+
$(gen_verbose) rm -rf $(CT_LOGS_DIR)
61906180

61916181
# Copyright (c) 2013-2016, Loïc Hoguin <[email protected]>
61926182
# This file is part of erlang.mk and subject to the terms of the ISC License.
@@ -6232,8 +6222,10 @@ define filter_opts.erl
62326222
endef
62336223

62346224
$(DIALYZER_PLT): deps app
6235-
$(verbose) dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(OTP_DEPS) $(LOCAL_DEPS) \
6236-
`test -f $(ERLANG_MK_TMP)/deps.log && cat $(ERLANG_MK_TMP)/deps.log`
6225+
$(eval DEPS_LOG := $(shell test -f $(ERLANG_MK_TMP)/deps.log && \
6226+
while read p; do test -d $$p/ebin && echo $$p/ebin; done <$(ERLANG_MK_TMP)/deps.log))
6227+
$(verbose) dialyzer --build_plt --apps erts kernel stdlib \
6228+
$(PLT_APPS) $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS_LOG)
62376229

62386230
plt: $(DIALYZER_PLT)
62396231

@@ -6319,7 +6311,7 @@ escript:: escript-zip
63196311
$(verbose) chmod +x $(ESCRIPT_FILE)
63206312

63216313
distclean-escript:
6322-
$(gen_verbose) rm -f $(ESCRIPT_NAME)
6314+
$(gen_verbose) rm -f $(ESCRIPT_FILE)
63236315

63246316
# Copyright (c) 2015-2016, Loïc Hoguin <[email protected]>
63256317
# Copyright (c) 2014, Enrique Fernandez <[email protected]>
@@ -6495,6 +6487,20 @@ build-shell-deps: $(ALL_SHELL_DEPS_DIRS)
64956487
shell: build-shell-deps
64966488
$(gen_verbose) $(SHELL_ERL) -pa $(SHELL_PATHS) $(SHELL_OPTS)
64976489

6490+
# Copyright (c) 2017, Jean-Sébastien Pédron <[email protected]>
6491+
# This file is contributed to erlang.mk and subject to the terms of the ISC License.
6492+
6493+
.PHONY: show-ERL_LIBS show-ERLC_OPTS show-TEST_ERLC_OPTS
6494+
6495+
show-ERL_LIBS:
6496+
@echo $(ERL_LIBS)
6497+
6498+
show-ERLC_OPTS:
6499+
@$(foreach opt,$(ERLC_OPTS) -pa ebin -I include,echo "$(opt)";)
6500+
6501+
show-TEST_ERLC_OPTS:
6502+
@$(foreach opt,$(TEST_ERLC_OPTS) -pa ebin -I include,echo "$(opt)";)
6503+
64986504
# Copyright (c) 2015-2016, Loïc Hoguin <[email protected]>
64996505
# This file is part of erlang.mk and subject to the terms of the ISC License.
65006506

priv/schema/rabbitmq.schema

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ fun(Conf) ->
999999
[{lager_console_backend, ConsoleLevel}];
10001000
false -> []
10011001
end,
1002-
FileHandler = case cuttlefish:conf_get("log.file", Conf, false) of
1002+
FileHandler = case cuttlefish:conf_get("log.file", Conf, undefined) of
10031003
false -> [];
10041004
File ->
10051005
FileLevel = cuttlefish:conf_get("log.file.level", Conf, info),
@@ -1010,6 +1010,11 @@ fun(Conf) ->
10101010
{level, FileLevel},
10111011
{date, RotationDate},
10121012
{size, RotationSize},
1013+
{formatter_config,
1014+
[date, " ", time, " ", color,
1015+
"[", severity, "] ",
1016+
{pid, ""},
1017+
" ", message, "\n"]},
10131018
{count, RotationCount}]}]
10141019
end,
10151020
SyslogHandler = case cuttlefish:conf_get("log.syslog", Conf, false) of

scripts/rabbitmq-env.bat

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ set paths=
417417
exit /b
418418

419419
:filter_path
420-
set ERL_LIBS=%ERL_LIBS%;%~dps1%~n1%~x1
420+
REM Ensure ERL_LIBS begins with valid path
421+
IF [%ERL_LIBS%] EQU [] (
422+
set ERL_LIBS=%~dps1%~n1%~x1
423+
) else (
424+
set ERL_LIBS=%ERL_LIBS%;%~dps1%~n1%~x1
425+
)
421426
exit /b
422427

423428
:filter_paths_done

scripts/rabbitmq-server

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -e
1+
#!/bin/sh
22
## The contents of this file are subject to the Mozilla Public License
33
## Version 1.1 (the "License"); you may not use this file except in
44
## compliance with the License. You may obtain a copy of the License
@@ -12,9 +12,11 @@
1212
## The Original Code is RabbitMQ.
1313
##
1414
## The Initial Developer of the Original Code is GoPivotal, Inc.
15-
## Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
15+
## Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved.
1616
##
1717

18+
set -e
19+
1820
# Get default settings with user overrides for (RABBITMQ_)<var_name>
1921
# Non-empty defaults should be set in rabbitmq-env
2022
. `dirname $0`/rabbitmq-env
@@ -278,21 +280,38 @@ else
278280
# The Erlang VM should ignore SIGINT.
279281
RABBITMQ_SERVER_START_ARGS="${RABBITMQ_SERVER_START_ARGS} ${RABBITMQ_IGNORE_SIGINT_FLAG}"
280282

281-
# Signal handlers. They all stop RabbitMQ properly (using
282-
# rabbitmqctl stop). Depending on the signal, this script will exit
283-
# with a non-zero error code:
283+
# Signal handlers. They all stop RabbitMQ properly, using
284+
# rabbitmqctl stop. This script will exit with different exit codes:
284285
# SIGHUP SIGTERM SIGTSTP
285-
# They are considered a normal process termination, so the script
286-
# exits with 0.
286+
# Exits 0 since this is considered a normal process termination.
287287
# SIGINT
288-
# They are considered an abnormal process termination, the script
289-
# exits with the job exit code.
288+
# Exits 128 + $signal_number where $signal_number is 2 for SIGINT (see
289+
# http://pubs.opengroup.org/onlinepubs/009695399/utilities/kill.html).
290+
# This is considered an abnormal process termination. Normally, we
291+
# don't need to specify this exit code because the shell propagates it.
292+
# Unfortunately, the signal handler doesn't work as expected in Dash,
293+
# thus we need to explicitely restate the exit code.
290294
trap "stop_rabbitmq_server; exit 0" HUP TERM TSTP
291-
trap "stop_rabbitmq_server" INT
295+
trap "stop_rabbitmq_server; exit 130" INT
292296

293297
start_rabbitmq_server "$@" &
298+
rabbitmq_server_pid=$!
294299

295300
# Block until RabbitMQ exits or a signal is caught.
296301
# Waits for last command (which is start_rabbitmq_server)
297-
wait $!
302+
#
303+
# The "|| true" is here to work around an issue with Dash. Normally
304+
# in a Bourne shell, if `wait` is interrupted by a signal, the
305+
# signal handlers defined above are executed and the script
306+
# terminates with the exit code of `wait` (unless the signal handler
307+
# overrides that).
308+
# In the case of Dash, it looks like `set -e` (set at the beginning
309+
# of this script) gets precedence over signal handling. Therefore,
310+
# when `wait` is interrupted, its exit code is non-zero and because
311+
# of `set -e`, the script terminates immediately without running the
312+
# signal handler. To work around this issue, we use "|| true" to
313+
# force that statement to succeed and the signal handler to properly
314+
# execute. Because the statement below has an exit code of 0, the
315+
# signal handler has to restate the expected exit code.
316+
wait $rabbitmq_server_pid || true
298317
fi

src/rabbit.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
stop_and_halt/0, await_startup/0, status/0, is_running/0, alarms/0,
2323
is_running/1, environment/0, rotate_logs/0, force_event_refresh/1,
2424
start_fhc/0]).
25-
-export([start/2, stop/1]).
25+
-export([start/2, stop/1, prep_stop/1]).
2626
-export([start_apps/1, stop_apps/1]).
2727
-export([log_locations/0, config_files/0, decrypt_config/2]). %% for testing and mgmt-agent
2828

@@ -327,7 +327,11 @@ broker_start() ->
327327
ToBeLoaded = Plugins ++ ?APPS,
328328
start_apps(ToBeLoaded),
329329
maybe_sd_notify(),
330-
ok = log_broker_started(rabbit_plugins:strictly_plugins(rabbit_plugins:active())).
330+
ok = log_broker_started(rabbit_plugins:strictly_plugins(rabbit_plugins:active())),
331+
%% See rabbitmq/rabbitmq-server#1202 for details.
332+
rabbit_peer_discovery:maybe_inject_randomized_delay(),
333+
rabbit_peer_discovery:maybe_register(),
334+
ok.
331335

332336
%% Try to send systemd ready notification if it makes sense in the
333337
%% current environment. standard_error is used intentionally in all
@@ -471,6 +475,8 @@ stop() ->
471475
end,
472476
rabbit_log:info("RabbitMQ is asked to stop...~n", []),
473477
Apps = ?APPS ++ rabbit_plugins:active(),
478+
%% this will also perform unregistration with the peer discovery backend
479+
%% as needed
474480
stop_apps(app_utils:app_dependency_order(Apps, true)),
475481
rabbit_log:info("Successfully stopped RabbitMQ and its dependencies~n", []).
476482

@@ -759,6 +765,10 @@ start(normal, []) ->
759765
Error
760766
end.
761767

768+
prep_stop(State) ->
769+
rabbit_peer_discovery:maybe_unregister(),
770+
State.
771+
762772
stop(_State) ->
763773
ok = rabbit_alarm:stop(),
764774
ok = case rabbit_mnesia:is_clustered() of

src/rabbit_amqqueue_process.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
-spec info_keys() -> rabbit_types:info_keys().
100100
-spec init_with_backing_queue_state
101101
(rabbit_types:amqqueue(), atom(), tuple(), any(),
102-
[rabbit_types:delivery()], pmon:pmon(), dict:dict()) ->
102+
[rabbit_types:delivery()], pmon:pmon(), gb_trees:tree()) ->
103103
#q{}.
104104

105105
%%----------------------------------------------------------------------------

0 commit comments

Comments
 (0)