Просмотр исходного кода

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

feat(db): check if OTP has mnesia_hook, otherwise fallback to mnesia
Zaiming (Stone) Shi 3 лет назад
Родитель
Сommit
b9f2aa36ea
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      bin/emqx

+ 20 - 0
bin/emqx

@@ -582,6 +582,12 @@ maybe_log_to_console() {
     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)
 case "${COMMAND}" in
     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"
 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"
 
 case "${COMMAND}" in