fix(dsrepl): verify if shards already allocated first
This commit is contained in:
parent
0119728d45
commit
5157e61418
|
@ -497,13 +497,6 @@ open_db_trans(DB, CreateOpts) ->
|
||||||
-spec allocate_shards_trans(emqx_ds:db()) -> [emqx_ds_replication_layer:shard_id()].
|
-spec allocate_shards_trans(emqx_ds:db()) -> [emqx_ds_replication_layer:shard_id()].
|
||||||
allocate_shards_trans(DB) ->
|
allocate_shards_trans(DB) ->
|
||||||
Opts = #{n_shards := NShards, n_sites := NSites} = db_config_trans(DB),
|
Opts = #{n_shards := NShards, n_sites := NSites} = db_config_trans(DB),
|
||||||
Nodes = mnesia:match_object(?NODE_TAB, ?NODE_PAT(), read),
|
|
||||||
case length(Nodes) of
|
|
||||||
N when N >= NSites ->
|
|
||||||
ok;
|
|
||||||
_ ->
|
|
||||||
mnesia:abort({insufficient_sites_online, NSites, Nodes})
|
|
||||||
end,
|
|
||||||
case mnesia:match_object(?SHARD_TAB, ?SHARD_PAT({DB, '_'}), write) of
|
case mnesia:match_object(?SHARD_TAB, ?SHARD_PAT({DB, '_'}), write) of
|
||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
|
@ -511,6 +504,13 @@ allocate_shards_trans(DB) ->
|
||||||
ShardsAllocated = [Shard || #?SHARD_TAB{shard = {_DB, Shard}} <- Records],
|
ShardsAllocated = [Shard || #?SHARD_TAB{shard = {_DB, Shard}} <- Records],
|
||||||
mnesia:abort({shards_already_allocated, ShardsAllocated})
|
mnesia:abort({shards_already_allocated, ShardsAllocated})
|
||||||
end,
|
end,
|
||||||
|
Nodes = mnesia:match_object(?NODE_TAB, ?NODE_PAT(), read),
|
||||||
|
case length(Nodes) of
|
||||||
|
N when N >= NSites ->
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
mnesia:abort({insufficient_sites_online, NSites, Nodes})
|
||||||
|
end,
|
||||||
Shards = gen_shards(NShards),
|
Shards = gen_shards(NShards),
|
||||||
Sites = [S || #?NODE_TAB{site = S} <- Nodes],
|
Sites = [S || #?NODE_TAB{site = S} <- Nodes],
|
||||||
Allocation = compute_allocation(Shards, Sites, Opts),
|
Allocation = compute_allocation(Shards, Sites, Opts),
|
||||||
|
|
Loading…
Reference in New Issue