|
68 | 68 | notify_decorators/3, |
69 | 69 | spawn_notify_decorators/3]). |
70 | 70 |
|
| 71 | +-export([get_member_with_highest_index/3]). |
| 72 | + |
71 | 73 | -export([is_enabled/0, |
72 | 74 | is_compatible/3, |
73 | 75 | declare/2, |
@@ -1245,7 +1247,7 @@ key_metrics_rpc(ServerId) -> |
1245 | 1247 | Metrics = ra:key_metrics(ServerId), |
1246 | 1248 | Metrics#{machine_version => rabbit_fifo:version()}. |
1247 | 1249 |
|
1248 | | --spec status(rabbit_types:vhost(), Name :: rabbit_misc:resource_name()) -> |
| 1250 | +-spec status(rabbit_types:vhost(), rabbit_misc:resource_name()) -> |
1249 | 1251 | [[{binary(), term()}]] | {error, term()}. |
1250 | 1252 | status(Vhost, QueueName) -> |
1251 | 1253 | %% Handle not found queues |
@@ -1335,6 +1337,38 @@ get_sys_status(Proc) -> |
1335 | 1337 |
|
1336 | 1338 | end. |
1337 | 1339 |
|
| 1340 | +-spec get_member_with_highest_index(rabbit_types:vhost(), rabbit_misc:resource_name(), atom()) -> |
| 1341 | + [[{binary(), term()}]] | {error, term()}. |
| 1342 | +get_member_with_highest_index(Vhost, QueueName, IndexName) -> |
| 1343 | + case ?MODULE:status(Vhost, QueueName) of |
| 1344 | + Status when is_list(Status) -> |
| 1345 | + IndexNameInternal = rabbit_data_coercion:to_atom(IndexName), |
| 1346 | + case index_name_to_status_key(IndexNameInternal) of |
| 1347 | + Key when is_binary(Key) -> |
| 1348 | + {_HighestIndexValue, HighestEntry} = |
| 1349 | + lists:foldl( |
| 1350 | + fun(Entry, {PreviousIndexValue, _PreviousEntry} = Acc) -> |
| 1351 | + case rabbit_misc:pget(Key, Entry) of |
| 1352 | + CurrentIndexValue when is_integer(CurrentIndexValue), |
| 1353 | + CurrentIndexValue > PreviousIndexValue -> |
| 1354 | + {CurrentIndexValue, Entry}; |
| 1355 | + _ -> |
| 1356 | + Acc |
| 1357 | + end |
| 1358 | + end, {-100, []}, Status), |
| 1359 | + [HighestEntry]; |
| 1360 | + undefined -> |
| 1361 | + [] |
| 1362 | + end; |
| 1363 | + {error, _} = Error -> |
| 1364 | + Error |
| 1365 | + end. |
| 1366 | + |
| 1367 | +index_name_to_status_key(I) when I =:= commit; I =:= commit_index -> <<"Commit Index">>; |
| 1368 | +index_name_to_status_key(I) when I =:= log; I =:= log_index -> <<"Last Log Index">>; |
| 1369 | +index_name_to_status_key(I) when I =:= snapshot; I =:= snapshot_index -> <<"Snapshot Index">>; |
| 1370 | +index_name_to_status_key(_I) -> undefined. |
| 1371 | + |
1338 | 1372 | add_member(VHost, Name, Node, Membership, Timeout) |
1339 | 1373 | when is_binary(VHost) andalso |
1340 | 1374 | is_binary(Name) andalso |
|
0 commit comments