diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2010-11-24 13:38:02 +0000 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-11-24 13:38:02 +0000 |
commit | ab223e2881c2ce24ab1ede21439b1a0c03b46333 (patch) | |
tree | eba4627dfd1afc31c22902388cc465126372fcce | |
parent | 864455892ac2e007ecb989515710c45a539fc761 (diff) | |
parent | 2e61008fe9ea9166d45b4c44ebc427a79e8e9397 (diff) | |
download | rabbitmq-server-ab223e2881c2ce24ab1ede21439b1a0c03b46333.tar.gz |
Merging bug23519 into default (again)
-rw-r--r-- | src/rabbit_mnesia.erl | 18 | ||||
-rw-r--r-- | src/rabbit_upgrade.erl | 37 |
2 files changed, 31 insertions, 24 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 6c74d4dd..a62e7a6f 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -34,7 +34,7 @@ -export([ensure_mnesia_dir/0, dir/0, status/0, init/0, is_db_empty/0, cluster/1, force_cluster/1, reset/0, force_reset/0, - is_clustered/0, empty_ram_only_tables/0, wait_for_tables/0]). + is_clustered/0, empty_ram_only_tables/0, copy_db/1]). -export([table_names/0]). @@ -65,7 +65,7 @@ -spec(is_clustered/0 :: () -> boolean()). -spec(empty_ram_only_tables/0 :: () -> 'ok'). -spec(create_tables/0 :: () -> 'ok'). --spec(wait_for_tables/0 :: () -> 'ok'). +-spec(copy_db/1 :: (file:filename()) -> rabbit_types:ok_or_error(any())). -endif. @@ -376,7 +376,7 @@ init_db(ClusterNodes, Force) -> mnesia:system_info(db_nodes)} of {[], true, [_]} -> %% True single disc node, attempt upgrade - wait_for_tables(), + ok = wait_for_tables(), case rabbit_upgrade:maybe_upgrade() of ok -> ensure_schema_ok(); version_not_available -> schema_ok_or_move() @@ -384,7 +384,7 @@ init_db(ClusterNodes, Force) -> {[], true, _} -> %% "Master" (i.e. without config) disc node in cluster, %% verify schema - wait_for_tables(), + ok = wait_for_tables(), ensure_version_ok(rabbit_upgrade:read_version()), ensure_schema_ok(); {[], false, _} -> @@ -475,6 +475,16 @@ move_db() -> rabbit_misc:ensure_ok(mnesia:start(), cannot_start_mnesia), ok. +copy_db(Destination) -> + mnesia:stop(), + case rabbit_misc:recursive_copy(dir(), Destination) of + ok -> + rabbit_misc:ensure_ok(mnesia:start(), cannot_start_mnesia), + ok = wait_for_tables(); + {error, E} -> + {error, E} + end. + create_tables() -> lists:foreach(fun ({Tab, TabDef}) -> TabDef1 = proplists:delete(match, TabDef), diff --git a/src/rabbit_upgrade.erl b/src/rabbit_upgrade.erl index a6b599d1..40af654a 100644 --- a/src/rabbit_upgrade.erl +++ b/src/rabbit_upgrade.erl @@ -132,31 +132,28 @@ apply_upgrades(Upgrades) -> ok = file:close(Lock), BackupDir = dir() ++ "-upgrade-backup", info("Upgrades: ~w to apply~n", [length(Upgrades)]), - mnesia:stop(), - case rabbit_misc:recursive_copy(dir(), BackupDir) of + case rabbit_mnesia:copy_db(BackupDir) of ok -> - %% We need to make the backup after creating the lock file - %% so that it protects us from trying to overwrite the - %% backup. Unfortunately this means the lock file exists in - %% the backup too, which is not intuitive. Remove it. + %% We need to make the backup after creating the + %% lock file so that it protects us from trying to + %% overwrite the backup. Unfortunately this means + %% the lock file exists in the backup too, which + %% is not intuitive. Remove it. ok = file:delete(lock_filename(BackupDir)), - ok; + info("Upgrades: Mnesia dir backed up to ~p~n", [BackupDir]), + [apply_upgrade(Upgrade) || Upgrade <- Upgrades], + info("Upgrades: All upgrades applied successfully~n", []), + ok = write_version(), + ok = rabbit_misc:recursive_delete([BackupDir]), + info("Upgrades: Mnesia backup removed~n", []), + ok = file:delete(LockFile); {error, E} -> - %% If we can't backup, the upgrade hasn't started hence we - %% don't need the lockfile since the real mnesia dir is the - %% good one. + %% If we can't backup, the upgrade hasn't started + %% hence we don't need the lockfile since the real + %% mnesia dir is the good one. ok = file:delete(LockFile), exit({could_not_back_up_mnesia_dir, E}) - end, - rabbit_misc:ensure_ok(mnesia:start(), cannot_start_mnesia), - rabbit_mnesia:wait_for_tables(), - info("Upgrades: Mnesia dir backed up to ~p~n", [BackupDir]), - [apply_upgrade(Upgrade) || Upgrade <- Upgrades], - info("Upgrades: All upgrades applied successfully~n", []), - ok = write_version(), - ok = rabbit_misc:recursive_delete([BackupDir]), - info("Upgrades: Mnesia backup removed~n", []), - ok = file:delete(LockFile); + end; {error, eexist} -> throw({error, previous_upgrade_failed}); {error, _} = Error -> |