From 404e9194949e9ea6617577faac7672b0d249d1a0 Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Tue, 19 Mar 2024 15:11:35 +0100 Subject: [PATCH] refactor(dsrepl): make shard allocator more robust and consistent Co-Authored-By: Thales Macedo Garitezi --- .../src/emqx_ds_replication_shard_allocator.erl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/emqx_durable_storage/src/emqx_ds_replication_shard_allocator.erl b/apps/emqx_durable_storage/src/emqx_ds_replication_shard_allocator.erl index 80181f032..6da33f09f 100644 --- a/apps/emqx_durable_storage/src/emqx_ds_replication_shard_allocator.erl +++ b/apps/emqx_durable_storage/src/emqx_ds_replication_shard_allocator.erl @@ -54,7 +54,7 @@ init({DB, Opts}) -> _ = logger:set_process_metadata(#{db => DB, domain => [ds, db, shard_allocator]}), State = #{db => DB, opts => Opts, status => allocating}, case allocate_shards(State) of - NState = #{} -> + {ok, NState} -> {ok, NState}; {error, Data} -> _ = logger:notice( @@ -74,7 +74,7 @@ handle_cast(_Cast, State) -> handle_info(timeout, State) -> case allocate_shards(State) of - NState = #{} -> + {ok, NState} -> {noreply, NState}; {error, Data} -> _ = logger:notice( @@ -84,7 +84,9 @@ handle_info(timeout, State) -> } ), {noreply, State, ?ALLOCATE_RETRY_TIMEOUT} - end. + end; +handle_info(_Info, State) -> + {noreply, State}. terminate(_Reason, #{db := DB, shards := Shards}) -> erase_db_meta(DB), @@ -102,7 +104,7 @@ allocate_shards(State = #{db := DB, opts := Opts}) -> ok = start_egresses(DB, Shards), ok = save_db_meta(DB, Shards), ok = save_shards_meta(DB, Shards), - State#{shards => Shards, status := ready}; + {ok, State#{shards => Shards, status := ready}}; {error, Reason} -> {error, Reason} end.