Merge pull request #7583 from thalesmg/check-mria-otp-compat

feat(db): check if OTP has mnesia_hook, otherwise fallback to mnesia
This commit is contained in:
Zaiming (Stone) Shi 2022-04-12 07:16:47 +01:00 committed by GitHub
commit b9f2aa36ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -582,6 +582,12 @@ maybe_log_to_console() {
fi fi
} }
# check if using an OTP version that has the mnesia_hook patch for use
# in mria.
is_otp_compatible() {
"$ERTS_DIR"/bin/erl -noshell -eval 'try mnesia_hook:module_info() of _ -> init:stop() catch _:_ -> init:stop(1) end.' 1>/dev/null 2>/dev/null
}
## IS_BOOT_COMMAND is set for later to inspect node name and cookie from hocon config (or env variable) ## IS_BOOT_COMMAND is set for later to inspect node name and cookie from hocon config (or env variable)
case "${COMMAND}" in case "${COMMAND}" in
start|console|console_clean|foreground) start|console|console_clean|foreground)
@ -652,6 +658,20 @@ if [ -z "$COOKIE" ]; then
die "Please set node.cookie in $EMQX_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE__COOKIE" die "Please set node.cookie in $EMQX_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE__COOKIE"
fi fi
## check if OTP version has mnesia_hook patch; if not, fallback to
## using Mnesia DB backend.
if [[ "${EMQX_DB__BACKEND:-}" != "mnesia"
|| "${EMQX_DB__ROLE:-}" != "core" ]]; then
if [[ "$IS_BOOT_COMMAND" == 'yes'
&& "$(get_config_value 'db.backend')" == "rlog" ]]; then
if ! is_otp_compatible; then
echoerr "DB Backend is RLOG, but an incompatible OTP version has been detected. Falling back to using Mnesia DB backend."
export EMQX_DB__BACKEND=mnesia
export EMQX_DB__ROLE=core
fi
fi
fi
cd "$ROOTDIR" cd "$ROOTDIR"
case "${COMMAND}" in case "${COMMAND}" in