1
1
% %--------------------------------------------------------------------
2
- % % Copyright (c) 2021-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
2
+ % % Copyright (c) 2021-2025 EMQ Technologies Co., Ltd. All Rights Reserved.
3
3
% %
4
4
% % Licensed under the Apache License, Version 2.0 (the "License");
5
5
% % you may not use this file except in compliance with the License.
28
28
notify_core_node_up /2 , notify_core_node_down /1 , get_core_node /2 ,
29
29
notify_core_intercept_trans /2 ,
30
30
31
- upstream /1 , upstream_node /1 ,
31
+ upstream /1 , upstream_node /2 ,
32
32
shards_status /0 , shards_up /0 , shards_syncing /0 , shards_down /0 ,
33
33
get_shard_stats /1 , agents /0 , agents /1 , replicants /0 , get_shard_lag /1 ,
34
34
@@ -81,15 +81,12 @@ start_link() ->
81
81
gen_server :start_link ({local , ? SERVER }, ? MODULE , [], []).
82
82
83
83
% % @doc Return name of the core node that is _currently serving_ the
84
- % % downstream shard. Note the difference in behavior as compared with
85
- % % `get_core_node'. Returns `disconnected' if the local replica of the
86
- % % shard is down.
87
- -spec upstream_node (mria_rlog :shard ()) -> {ok , node ()} | disconnected .
88
- upstream_node (Shard ) ->
89
- case upstream (Shard ) of
90
- {ok , Pid } -> {ok , node (Pid )};
91
- disconnected -> disconnected
92
- end .
84
+ % % downstream shard. If shard is currently down, wait until started
85
+ % % for at most `Timeout' millisecond. Note the difference in behavior
86
+ % % as compared with `get_core_node'.
87
+ -spec upstream_node (mria_rlog :shard (), timeout ()) -> {ok , node ()} | timeout .
88
+ upstream_node (Shard , Timeout ) ->
89
+ optvar :read (? optvar ({? core_node , Shard }), Timeout ).
93
90
94
91
% % @doc Return pid of the core node agent that serves us.
95
92
-spec upstream (mria_rlog :shard ()) -> {ok , pid ()} | disconnected .
@@ -99,8 +96,9 @@ upstream(Shard) ->
99
96
undefined -> disconnected
100
97
end .
101
98
102
- % % @doc Return a core node that _might_ be able to serve the specified
103
- % % shard.
99
+ % % @deprecated Return a core node that _might_ be able to serve the
100
+ % % specified shard. WARNING: use of this function leads to unbalanced
101
+ % % load of the core nodes.
104
102
-spec get_core_node (mria_rlog :shard (), timeout ()) -> {ok , node ()} | timeout .
105
103
get_core_node (Shard , Timeout ) ->
106
104
optvar :read (? optvar ({? core_node , Shard }), Timeout ).
@@ -173,10 +171,10 @@ replicants() ->
173
171
174
172
-spec get_shard_lag (mria_rlog :shard ()) -> non_neg_integer () | disconnected .
175
173
get_shard_lag (Shard ) ->
176
- case {mria_config :role (), upstream_node (Shard )} of
174
+ case {mria_config :role (), upstream_node (Shard , 0 )} of
177
175
{core , _ } ->
178
176
0 ;
179
- {replicant , disconnected } ->
177
+ {replicant , timeout } ->
180
178
disconnected ;
181
179
{replicant , {ok , Upstream }} ->
182
180
RemoteSeqNo = erpc :call (Upstream , ? MODULE , get_stat , [Shard , ? core_intercept ], 1000 ),
@@ -244,7 +242,7 @@ get_shard_stats(Shard) ->
244
242
, server_mql => get_mql (Shard )
245
243
};
246
244
replicant ->
247
- case upstream_node (Shard ) of
245
+ case upstream_node (Shard , 0 ) of
248
246
{ok , Upstream } -> ok ;
249
247
_ -> Upstream = undefined
250
248
end ,
0 commit comments