Skip to content

Commit

Permalink
Merge pull request #4 from rabbitmq/handle-stopped-store-in-is_migrat…
Browse files Browse the repository at this point in the history
…ion_finished

mnesia_to_khepri: Support stopped Khepri store in `is_migration_finished/2`
  • Loading branch information
dumbbell authored Oct 26, 2023
2 parents a8e8b8d + 7a59c6b commit 046439f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/m2k_table_copy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ proceed(SupPid) ->
IsFinished :: boolean() | {in_flight, pid()} | undefined.

is_migration_finished(StoreId, MigrationId) when is_binary(MigrationId) ->
%% If the Khepri store is not running, we can assume that the migration
%% didn't take place yet.
case is_khepri_store_running(StoreId) of
true -> is_migration_finished1(StoreId, MigrationId);
false -> false
end.

is_migration_finished1(StoreId, MigrationId) ->
ProjectionName = ?PROJECTION_NAME,
try
case ets:lookup(ProjectionName, MigrationId) of
Expand All @@ -84,7 +92,7 @@ is_migration_finished(StoreId, MigrationId) when is_binary(MigrationId) ->
error:badarg ->
case setup_projection(StoreId, ProjectionName) of
ok ->
is_migration_finished(StoreId, MigrationId);
is_migration_finished1(StoreId, MigrationId);
Error ->
?LOG_WARNING(
"Mnesia->Khepri data copy: failed to setup Khepri "
Expand All @@ -97,6 +105,10 @@ is_migration_finished(StoreId, MigrationId) when is_binary(MigrationId) ->
end
end.

is_khepri_store_running(StoreId) ->
RunningStoreIds = khepri:get_store_ids(),
lists:member(StoreId, RunningStoreIds).

setup_projection(StoreId, ProjectionName) ->
?LOG_DEBUG(
"Mnesia->Khepri data copy: setup Khepri projection (name: \"~s\")",
Expand Down
7 changes: 7 additions & 0 deletions test/mnesia_to_khepri_table_copy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,13 @@ is_migration_finished_works(Config) ->
StoreId = RaSystem,
MigrationId = store_id_to_mig_id(StoreId),

%% `is_migration_finished/2' works even if the given store is unavailable.
?assertEqual(
false,
erpc:call(
Node1,
mnesia_to_khepri, is_migration_finished, [StoreId, MigrationId])),

?assertEqual(
{ok, StoreId},
rpc:call(Node1, khepri, start, [RaSystem, StoreId])),
Expand Down

0 comments on commit 046439f

Please sign in to comment.