diff options
author | Matthias Radestock <matthias@lshift.net> | 2008-12-17 12:48:50 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2008-12-17 12:48:50 +0000 |
commit | 8e75389ce0a65e5173b57f2d41896bf792eb5d74 (patch) | |
tree | bb8f134a33df62d545411830f7968c65da78691e | |
parent | 3da3de882bbdf55e340aa60f29d98d1435914204 (diff) | |
parent | 355f006458e19e18643960f3a09e274f754984cd (diff) | |
download | rabbitmq-server-8e75389ce0a65e5173b57f2d41896bf792eb5d74.tar.gz |
merge bug20030 into default
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | packaging/RPMS/Fedora/Makefile | 1 | ||||
-rw-r--r-- | packaging/RPMS/Fedora/rabbitmq-server-preserve-db.sh | 28 | ||||
-rw-r--r-- | packaging/RPMS/Fedora/rabbitmq-server.spec | 6 | ||||
-rw-r--r-- | packaging/debs/Debian/Makefile | 2 | ||||
-rw-r--r-- | packaging/debs/Debian/debian/config | 25 | ||||
-rw-r--r-- | packaging/debs/Debian/debian/control | 2 | ||||
-rw-r--r-- | packaging/debs/Debian/debian/po/POTFILES.in | 1 | ||||
-rw-r--r-- | packaging/debs/Debian/debian/postinst | 1 | ||||
-rw-r--r-- | packaging/debs/Debian/debian/templates | 20 | ||||
-rwxr-xr-x | scripts/rabbitmq-mnesia-current | 57 | ||||
-rw-r--r-- | src/rabbit_mnesia.erl | 86 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 2 |
13 files changed, 53 insertions, 183 deletions
@@ -78,10 +78,6 @@ run: all RABBITMQ_SERVER_START_ARGS="$(RABBITMQ_SERVER_START_ARGS) -s rabbit" \ ./scripts/rabbitmq-server -check-mnesia-schema: all - $(BASIC_SCRIPT_ENVIRONMENT_SETTINGS) \ - ./scripts/rabbitmq-mnesia-current - run-node: all $(BASIC_SCRIPT_ENVIRONMENT_SETTINGS) \ RABBITMQ_NODE_ONLY=true \ @@ -169,7 +165,6 @@ install: all docs_all cp scripts/rabbitmq-server $(SBIN_DIR) cp scripts/rabbitmqctl $(SBIN_DIR) cp scripts/rabbitmq-multi $(SBIN_DIR) - cp scripts/rabbitmq-mnesia-current $(SBIN_DIR) for section in 1 5; do \ mkdir -p $(MAN_DIR)/man$$section; \ for manpage in docs/*.$$section.pod; do \ diff --git a/packaging/RPMS/Fedora/Makefile b/packaging/RPMS/Fedora/Makefile index 5610de51..c05f14a7 100644 --- a/packaging/RPMS/Fedora/Makefile +++ b/packaging/RPMS/Fedora/Makefile @@ -17,7 +17,6 @@ prepare: cp init.d SOURCES/rabbitmq-server.init cp rabbitmqctl_wrapper SOURCES/rabbitmq-server.wrapper cp rabbitmq-server.logrotate SOURCES/rabbitmq-server.logrotate - cp rabbitmq-server-preserve-db.sh SOURCES server: prepare rpmbuild -ba SPECS/rabbitmq-server.spec $(DEFINES) --target i386 diff --git a/packaging/RPMS/Fedora/rabbitmq-server-preserve-db.sh b/packaging/RPMS/Fedora/rabbitmq-server-preserve-db.sh deleted file mode 100644 index e885b6b8..00000000 --- a/packaging/RPMS/Fedora/rabbitmq-server-preserve-db.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -if [ "$1x" = "x" ]; then - echo "You haven't specified the initial location of the RabbitMQ database" - exit 1 -fi - -if [ ! -d "$1" ]; then - echo "The directory containing the RabbitMQ database doesn't exist" - exit 1 -fi - -echo -echo "The RabbitMQ database schema has changed." -echo "If your RabbitMQ database contains important data," -echo "such as user accounts, durable exchanges and queues," -echo "or persistent messages, then we recommend you contact" -echo "support@rabbitmq.com for assistance with the upgrade." -echo "The current RabbitMQ database will be moved to the" -echo "directory: " - -CURRENT_MNESIA_DIR=$1 -DATE=`date +'%d_%m_%Y'` -TMP_OLD_MNESIA_DIR=$CURRENT_MNESIA_DIR.$$.${DATE} -mv "$CURRENT_MNESIA_DIR" "$TMP_OLD_MNESIA_DIR" - -echo "$TMP_OLD_MNESIA_DIR" -echo
\ No newline at end of file diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 736e2329..0f4a98c9 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -7,7 +7,6 @@ Source: http://www.rabbitmq.com/releases/rabbitmq-server/v%{version}/%{name}-%{v Source1: rabbitmq-server.init Source2: rabbitmq-server.wrapper Source3: rabbitmq-server.logrotate -Source4: rabbitmq-server-preserve-db.sh URL: http://www.rabbitmq.com/ Vendor: LShift Ltd., Cohesive Financial Technologies LLC., Rabbit Technlogies Ltd. %if 0%{?debian} @@ -100,11 +99,6 @@ fi chown -R rabbitmq:rabbitmq /var/lib/rabbitmq chown -R rabbitmq:rabbitmq /var/log/rabbitmq -su rabbitmq -s /bin/sh -c %{_rabbitbindir}/rabbitmq-mnesia-current -if [ $? = 1 ]; then - /bin/sh %SOURCE4 /var/lib/rabbitmq/mnesia -fi - /sbin/chkconfig --add %{name} /sbin/service rabbitmq-server start diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index 0bf3a2d8..9479feb0 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -21,7 +21,7 @@ package: clean cp -r debian $(UNPACKED_DIR) chmod a+x $(UNPACKED_DIR)/debian/rules UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) - cd $(UNPACKED_DIR); debconf-updatepo; GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) + cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) rm -rf $(UNPACKED_DIR) clean: diff --git a/packaging/debs/Debian/debian/config b/packaging/debs/Debian/debian/config deleted file mode 100644 index 9020888a..00000000 --- a/packaging/debs/Debian/debian/config +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -e - -# Source debconf library. -. /usr/share/debconf/confmodule - -if ! su rabbitmq -s /bin/sh -c /usr/lib/rabbitmq/bin/rabbitmq-mnesia-current ; then - db_beginblock - db_input high rabbitmq-server/mnesia-dir-note || true - db_input high rabbitmq-server/do-what-with-mnesia-dir || true - db_endblock - db_go - - db_get rabbitmq-server/do-what-with-mnesia-dir - if [ "$RET" = "Deleted" ]; then - rm -r /var/lib/rabbitmq/mnesia/ - elif [ "$RET" = "Moved" ]; then - db_input high rabbitmq-server/move-mnesia-dir-where || true - db_go - - db_get rabbitmq-server/move-mnesia-dir-where - - mkdir -p "`dirname $RET`" - mv /var/lib/rabbitmq/mnesia "$RET" - fi -fi diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control index d5d49f3f..b2b3ab02 100644 --- a/packaging/debs/Debian/debian/control +++ b/packaging/debs/Debian/debian/control @@ -7,7 +7,7 @@ Standards-Version: 3.8.0 Package: rabbitmq-server Architecture: all -Depends: erlang-nox, adduser, ${misc:Depends} +Depends: erlang-nox, adduser, logrotate, ${misc:Depends} Description: An AMQP server written in Erlang RabbitMQ is an implementation of AMQP, the emerging standard for high performance enterprise messaging. The RabbitMQ server is a robust and diff --git a/packaging/debs/Debian/debian/po/POTFILES.in b/packaging/debs/Debian/debian/po/POTFILES.in deleted file mode 100644 index cef83a34..00000000 --- a/packaging/debs/Debian/debian/po/POTFILES.in +++ /dev/null @@ -1 +0,0 @@ -[type: gettext/rfc822deb] templates diff --git a/packaging/debs/Debian/debian/postinst b/packaging/debs/Debian/debian/postinst index d0575628..f92131d0 100644 --- a/packaging/debs/Debian/debian/postinst +++ b/packaging/debs/Debian/debian/postinst @@ -34,7 +34,6 @@ chown -R rabbitmq:rabbitmq /var/log/rabbitmq case "$1" in configure) - . /usr/share/debconf/confmodule ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/packaging/debs/Debian/debian/templates b/packaging/debs/Debian/debian/templates deleted file mode 100644 index 2d5acc15..00000000 --- a/packaging/debs/Debian/debian/templates +++ /dev/null @@ -1,20 +0,0 @@ -Template: rabbitmq-server/mnesia-dir-note -Type: note -_Description: Schema changed - The RabbitMQ database schema has changed. If your RabbitMQ database - contains important data, such as user accounts, durable exchanges and - queues, or persistent messages, then it is recommended to contact - support@rabbitmq.com for assistance with the upgrade. If you want to - experiment with the new version in the meantime, simply move the database - directory to a safe place. In all other cases just remove the directory. - -Template: rabbitmq-server/do-what-with-mnesia-dir -Type: select -_Choices: Moved, Deleted, Kept (WILL BREAK) -Default: Moved -_Description: The old RabbitMQ database directory should be: - -Template: rabbitmq-server/move-mnesia-dir-where -Type: string -Default: /var/lib/rabbitmq/mnesia-old/ -_Description: Directory where the old RabbitMQ database should be moved: diff --git a/scripts/rabbitmq-mnesia-current b/scripts/rabbitmq-mnesia-current deleted file mode 100755 index 081066da..00000000 --- a/scripts/rabbitmq-mnesia-current +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh -## The contents of this file are subject to the Mozilla Public License -## Version 1.1 (the "License"); you may not use this file except in -## compliance with the License. You may obtain a copy of the License at -## http://www.mozilla.org/MPL/ -## -## Software distributed under the License is distributed on an "AS IS" -## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -## License for the specific language governing rights and limitations -## under the License. -## -## The Original Code is RabbitMQ. -## -## The Initial Developers of the Original Code are LShift Ltd, -## Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd. -## -## Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, -## Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd -## are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial -## Technologies LLC, and Rabbit Technologies Ltd. -## -## Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift -## Ltd. Portions created by Cohesive Financial Technologies LLC are -## Copyright (C) 2007-2009 Cohesive Financial Technologies -## LLC. Portions created by Rabbit Technologies Ltd are Copyright -## (C) 2007-2009 Rabbit Technologies Ltd. -## -## All Rights Reserved. -## -## Contributor(s): ______________________________________. -## - -[ -f /etc/default/rabbitmq ] && . /etc/default/rabbitmq - -[ "x" = "x$RABBITMQ_CLUSTER_CONFIG_FILE" ] && RABBITMQ_CLUSTER_CONFIG_FILE=${CLUSTER_CONFIG_FILE} -[ "x" = "x$RABBITMQ_CLUSTER_CONFIG_FILE" ] && RABBITMQ_CLUSTER_CONFIG_FILE=/etc/default/rabbitmq_cluster.config -[ "x" = "x$RABBITMQ_NODENAME" ] && RABBITMQ_NODENAME=${NODENAME} -[ "x" = "x$RABBITMQ_NODENAME" ] && RABBITMQ_NODENAME=rabbit -[ "x" = "x$RABBITMQ_MNESIA_BASE" ] && RABBITMQ_MNESIA_BASE=${MNESIA_BASE} -[ "x" = "x$RABBITMQ_MNESIA_BASE" ] && RABBITMQ_MNESIA_BASE=/var/lib/rabbitmq/mnesia -[ "x" = "x$RABBITMQ_MNESIA_DIR" ] && RABBITMQ_MNESIA_DIR=${MNESIA_DIR} -[ "x" = "x$RABBITMQ_MNESIA_DIR" ] && RABBITMQ_MNESIA_DIR=${RABBITMQ_MNESIA_BASE}/${RABBITMQ_NODENAME} - -if [ -f "$RABBITMQ_CLUSTER_CONFIG_FILE" ]; then - RABBITMQ_CLUSTER_CONFIG_OPTION="-rabbit cluster_config \"$RABBITMQ_CLUSTER_CONFIG_FILE\"" -else - RABBITMQ_CLUSTER_CONFIG_OPTION="" -fi - -exec erl \ - -pa "`dirname $0`/../ebin" \ - -noshell \ - -sname ${RABBITMQ_NODENAME} \ - -eval 'halt(case rabbit_mnesia:schema_current() of true -> 0; false -> 1 end).' \ - -mnesia dir "\"${RABBITMQ_MNESIA_DIR}\"" \ - -kernel error_logger '{file,"'/dev/null'"}' \ - ${RABBITMQ_CLUSTER_CONFIG_OPTION} diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 57dd9256..d19c37cb 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -36,9 +36,6 @@ -export([table_names/0]). -%% Called by rabbitmq-mnesia-current script --export([schema_current/0]). - %% create_tables/0 exported for helping embed RabbitMQ in or alongside %% other mnesia-using Erlang applications, such as ejabberd -export([create_tables/0]). @@ -57,7 +54,6 @@ -spec(reset/0 :: () -> 'ok'). -spec(force_reset/0 :: () -> 'ok'). -spec(create_tables/0 :: () -> 'ok'). --spec(schema_current/0 :: () -> bool()). -endif. @@ -101,20 +97,6 @@ cluster(ClusterNodes) -> reset() -> reset(false). force_reset() -> reset(true). -%% This is invoked by rabbitmq-mnesia-current. -schema_current() -> - application:start(mnesia), - ok = ensure_mnesia_running(), - ok = ensure_mnesia_dir(), - ok = init_db(read_cluster_nodes_config()), - try - ensure_schema_integrity(), - true - catch - {error, {schema_integrity_check_failed, _Reason}} -> - false - end. - %%-------------------------------------------------------------------- table_definitions() -> @@ -169,17 +151,12 @@ ensure_mnesia_not_running() -> yes -> throw({error, mnesia_unexpectedly_running}) end. -ensure_schema_integrity() -> - case catch lists:foreach(fun (Tab) -> - mnesia:table_info(Tab, version) - end, - table_names()) of - {'EXIT', Reason} -> throw({error, {schema_integrity_check_failed, - Reason}}); - _ -> ok - end, +check_schema_integrity() -> %%TODO: more thorough checks - ok. + case catch [mnesia:table_info(Tab, version) || Tab <- table_names()] of + {'EXIT', Reason} -> {error, Reason}; + _ -> ok + end. %% The cluster node config file contains some or all of the disk nodes %% that are members of the cluster this node is / should be a part of. @@ -259,7 +236,20 @@ init_db(ClusterNodes) -> case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of {ok, []} -> if WasDiskNode and IsDiskNode -> - ok; + case check_schema_integrity() of + ok -> + ok; + {error, Reason} -> + %% NB: we cannot use rabbit_log here since + %% it may not have been started yet + error_logger:warning_msg( + "schema integrity check failed: ~p~n" ++ + "moving database to backup location " ++ + "and recreating schema from scratch~n", + [Reason]), + ok = move_db(), + ok = create_schema() + end; WasDiskNode -> throw({error, {cannot_convert_disk_node_to_ram_node, ClusterNodes}}); @@ -292,6 +282,28 @@ create_schema() -> cannot_start_mnesia), create_tables(). +move_db() -> + mnesia:stop(), + MnesiaDir = filename:dirname(mnesia:system_info(directory) ++ "/"), + {{Year, Month, Day}, {Hour, Minute, Second}} = erlang:universaltime(), + BackupDir = lists:flatten( + io_lib:format("~s_~w~2..0w~2..0w~2..0w~2..0w~2..0w", + [MnesiaDir, + Year, Month, Day, Hour, Minute, Second])), + case file:rename(MnesiaDir, BackupDir) of + ok -> + %% NB: we cannot use rabbit_log here since it may not have + %% been started yet + error_logger:warning_msg("moved database from ~s to ~s~n", + [MnesiaDir, BackupDir]), + ok; + {error, Reason} -> throw({error, {cannot_backup_mnesia, + MnesiaDir, BackupDir, Reason}}) + end, + ok = ensure_mnesia_dir(), + rabbit_misc:ensure_ok(mnesia:start(), cannot_start_mnesia), + ok. + create_tables() -> lists:foreach(fun ({Tab, TabArgs}) -> case mnesia:create_table(Tab, TabArgs) of @@ -353,13 +365,17 @@ create_local_table_copy(Tab, Type) -> ok. wait_for_tables() -> - ok = ensure_schema_integrity(), - case mnesia:wait_for_tables(table_names(), 30000) of - ok -> ok; - {timeout, BadTabs} -> - throw({error, {timeout_waiting_for_tables, BadTabs}}); + case check_schema_integrity() of + ok -> + case mnesia:wait_for_tables(table_names(), 30000) of + ok -> ok; + {timeout, BadTabs} -> + throw({error, {timeout_waiting_for_tables, BadTabs}}); + {error, Reason} -> + throw({error, {failed_waiting_for_tables, Reason}}) + end; {error, Reason} -> - throw({error, {failed_waiting_for_tables, Reason}}) + throw({error, {schema_integrity_check_failed, Reason}}) end. reset(Force) -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 1853a855..df2e71d9 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -139,8 +139,6 @@ test_topic_matching() -> passed. test_app_management() -> - true = rabbit_mnesia:schema_current(), - %% starting, stopping, status ok = control_action(stop_app, []), ok = control_action(stop_app, []), |