emqx_mqueue_SUITE.erl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2017-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_mqueue_SUITE).
  17. -compile(export_all).
  18. -compile(nowarn_export_all).
  19. -include_lib("emqx/include/emqx.hrl").
  20. -include_lib("emqx/include/emqx_mqtt.hrl").
  21. -include_lib("proper/include/proper.hrl").
  22. -include_lib("eunit/include/eunit.hrl").
  23. -define(Q, emqx_mqueue).
  24. all() -> emqx_common_test_helpers:all(?MODULE).
  25. t_info(_) ->
  26. Q = ?Q:init(#{max_len => 5, store_qos0 => true}),
  27. true = ?Q:info(store_qos0, Q),
  28. 5 = ?Q:info(max_len, Q),
  29. 0 = ?Q:info(len, Q),
  30. 0 = ?Q:info(dropped, Q),
  31. #{
  32. store_qos0 := true,
  33. max_len := 5,
  34. len := 0,
  35. dropped := 0
  36. } = ?Q:info(Q).
  37. t_in(_) ->
  38. Opts = #{max_len => 5, store_qos0 => true},
  39. Q = ?Q:init(Opts),
  40. ?assert(?Q:is_empty(Q)),
  41. {_, Q1} = ?Q:in(#message{}, Q),
  42. ?assertEqual(1, ?Q:len(Q1)),
  43. {_, Q2} = ?Q:in(#message{qos = 1}, Q1),
  44. ?assertEqual(2, ?Q:len(Q2)),
  45. {_, Q3} = ?Q:in(#message{qos = 2}, Q2),
  46. {_, Q4} = ?Q:in(#message{}, Q3),
  47. {_, Q5} = ?Q:in(#message{}, Q4),
  48. ?assertEqual(5, ?Q:len(Q5)).
  49. t_in_qos0(_) ->
  50. Opts = #{max_len => 5, store_qos0 => false},
  51. Q = ?Q:init(Opts),
  52. {_, Q1} = ?Q:in(#message{qos = 0}, Q),
  53. ?assert(?Q:is_empty(Q1)),
  54. {_, Q2} = ?Q:in(#message{qos = 0}, Q1),
  55. ?assert(?Q:is_empty(Q2)).
  56. t_out(_) ->
  57. Opts = #{max_len => 5, store_qos0 => true},
  58. Q = ?Q:init(Opts),
  59. {empty, Q} = ?Q:out(Q),
  60. {_, Q1} = ?Q:in(#message{}, Q),
  61. {Value, Q2} = ?Q:out(Q1),
  62. ?assertEqual(0, ?Q:len(Q2)),
  63. ?assertEqual({value, #message{}}, Value).
  64. t_simple_mqueue(_) ->
  65. Opts = #{max_len => 3, store_qos0 => false},
  66. Q = ?Q:init(Opts),
  67. ?assertEqual(3, ?Q:max_len(Q)),
  68. ?assert(?Q:is_empty(Q)),
  69. {_, Q1} = ?Q:in(#message{qos = 1, payload = <<"1">>}, Q),
  70. {_, Q2} = ?Q:in(#message{qos = 1, payload = <<"2">>}, Q1),
  71. {_, Q3} = ?Q:in(#message{qos = 1, payload = <<"3">>}, Q2),
  72. {_, Q4} = ?Q:in(#message{qos = 1, payload = <<"4">>}, Q3),
  73. ?assertEqual(3, ?Q:len(Q4)),
  74. {{value, Msg}, Q5} = ?Q:out(Q4),
  75. ?assertEqual(<<"2">>, Msg#message.payload),
  76. ?assertEqual([{len, 2}, {max_len, 3}, {dropped, 1}], ?Q:stats(Q5)).
  77. t_infinity_simple_mqueue(_) ->
  78. Opts = #{max_len => 0, store_qos0 => false},
  79. Q = ?Q:init(Opts),
  80. ?assert(?Q:is_empty(Q)),
  81. ?assertEqual(0, ?Q:max_len(Q)),
  82. Qx = lists:foldl(
  83. fun(I, AccQ) ->
  84. {_, NewQ} = ?Q:in(#message{qos = 1, payload = iolist_to_binary([I])}, AccQ),
  85. NewQ
  86. end,
  87. Q,
  88. lists:seq(1, 255)
  89. ),
  90. ?assertEqual(255, ?Q:len(Qx)),
  91. ?assertEqual([{len, 255}, {max_len, 0}, {dropped, 0}], ?Q:stats(Qx)),
  92. {{value, V}, _Qy} = ?Q:out(Qx),
  93. ?assertEqual(<<1>>, V#message.payload).
  94. t_priority_mqueue(_) ->
  95. Opts = #{
  96. max_len => 3,
  97. priorities =>
  98. #{
  99. <<"t1">> => 1,
  100. <<"t2">> => 2,
  101. <<"t3">> => 3
  102. },
  103. store_qos0 => false
  104. },
  105. Q = ?Q:init(Opts),
  106. ?assertEqual(3, ?Q:max_len(Q)),
  107. ?assert(?Q:is_empty(Q)),
  108. {_, Q1} = ?Q:in(#message{qos = 1, topic = <<"t2">>}, Q),
  109. {_, Q2} = ?Q:in(#message{qos = 1, topic = <<"t1">>}, Q1),
  110. {_, Q3} = ?Q:in(#message{qos = 1, topic = <<"t3">>}, Q2),
  111. ?assertEqual(3, ?Q:len(Q3)),
  112. {_, Q4} = ?Q:in(#message{qos = 1, topic = <<"t2">>}, Q3),
  113. ?assertEqual(4, ?Q:len(Q4)),
  114. {_, Q5} = ?Q:in(#message{qos = 1, topic = <<"t2">>}, Q4),
  115. ?assertEqual(5, ?Q:len(Q5)),
  116. {_, Q6} = ?Q:in(#message{qos = 1, topic = <<"t2">>}, Q5),
  117. ?assertEqual(5, ?Q:len(Q6)),
  118. {{value, _Msg}, Q7} = ?Q:out(Q6),
  119. ?assertEqual(4, ?Q:len(Q7)).
  120. t_priority_mqueue_conservation(_) ->
  121. true = proper:quickcheck(conservation_prop()).
  122. t_priority_order(_) ->
  123. Opts = #{
  124. max_len => 5,
  125. shift_multiplier => 1,
  126. priorities =>
  127. #{
  128. <<"t1">> => 0,
  129. <<"t2">> => 1,
  130. <<"t3">> => 2
  131. },
  132. store_qos0 => false
  133. },
  134. Messages = [
  135. {Topic, Message}
  136. || Topic <- [<<"t1">>, <<"t2">>, <<"t3">>],
  137. Message <- lists:seq(1, 10)
  138. ],
  139. Q = lists:foldl(
  140. fun({Topic, Message}, Q) ->
  141. element(2, ?Q:in(#message{topic = Topic, qos = 1, payload = Message}, Q))
  142. end,
  143. ?Q:init(Opts),
  144. Messages
  145. ),
  146. ?assertMatch(
  147. [
  148. {<<"t3">>, 6},
  149. {<<"t3">>, 7},
  150. {<<"t3">>, 8},
  151. {<<"t2">>, 6},
  152. {<<"t2">>, 7},
  153. {<<"t1">>, 6},
  154. {<<"t3">>, 9},
  155. {<<"t3">>, 10},
  156. {<<"t2">>, 8},
  157. %% Note: for performance reasons we don't reset the
  158. %% counter when we run out of messages with the
  159. %% current prio, so next is t1:
  160. {<<"t1">>, 7},
  161. {<<"t2">>, 9},
  162. {<<"t2">>, 10},
  163. {<<"t1">>, 8},
  164. {<<"t1">>, 9},
  165. {<<"t1">>, 10}
  166. ],
  167. drain(Q)
  168. ).
  169. t_priority_order2(_) ->
  170. Opts = #{
  171. max_len => 5,
  172. shift_multiplier => 2,
  173. priorities =>
  174. #{
  175. <<"t1">> => 0,
  176. <<"t2">> => 1
  177. },
  178. store_qos0 => false
  179. },
  180. Messages = [
  181. {Topic, Message}
  182. || Topic <- [<<"t1">>, <<"t2">>],
  183. Message <- lists:seq(1, 10)
  184. ],
  185. Q = lists:foldl(
  186. fun({Topic, Message}, Q) ->
  187. element(2, ?Q:in(#message{topic = Topic, qos = 1, payload = Message}, Q))
  188. end,
  189. ?Q:init(Opts),
  190. Messages
  191. ),
  192. ?assertMatch(
  193. [
  194. {<<"t2">>, 6},
  195. {<<"t2">>, 7},
  196. {<<"t2">>, 8},
  197. {<<"t2">>, 9},
  198. {<<"t1">>, 6},
  199. {<<"t1">>, 7},
  200. {<<"t2">>, 10},
  201. {<<"t1">>, 8},
  202. {<<"t1">>, 9},
  203. {<<"t1">>, 10}
  204. ],
  205. drain(Q)
  206. ).
  207. t_infinity_priority_mqueue(_) ->
  208. Opts = #{
  209. max_len => 0,
  210. priorities =>
  211. #{
  212. <<"t">> => 1,
  213. <<"t1">> => 2
  214. },
  215. store_qos0 => false
  216. },
  217. Q = ?Q:init(Opts),
  218. ?assertEqual(0, ?Q:max_len(Q)),
  219. Qx = lists:foldl(
  220. fun(I, AccQ) ->
  221. {undefined, AccQ1} = ?Q:in(
  222. #message{topic = <<"t1">>, qos = 1, payload = iolist_to_binary([I])}, AccQ
  223. ),
  224. {undefined, AccQ2} = ?Q:in(
  225. #message{topic = <<"t">>, qos = 1, payload = iolist_to_binary([I])}, AccQ1
  226. ),
  227. AccQ2
  228. end,
  229. Q,
  230. lists:seq(1, 255)
  231. ),
  232. ?assertEqual(510, ?Q:len(Qx)),
  233. ?assertEqual([{len, 510}, {max_len, 0}, {dropped, 0}], ?Q:stats(Qx)).
  234. %%TODO: fixme later
  235. t_length_priority_mqueue(_) ->
  236. Opts = #{
  237. max_len => 2,
  238. store_qos0 => false
  239. },
  240. Q = ?Q:init(Opts),
  241. 2 = ?Q:max_len(Q),
  242. {_, Q1} = ?Q:in(#message{topic = <<"x">>, qos = 1, payload = <<1>>}, Q),
  243. {_, Q2} = ?Q:in(#message{topic = <<"x">>, qos = 1, payload = <<2>>}, Q1),
  244. {_, Q3} = ?Q:in(#message{topic = <<"y">>, qos = 1, payload = <<3>>}, Q2),
  245. {_, Q4} = ?Q:in(#message{topic = <<"y">>, qos = 1, payload = <<4>>}, Q3),
  246. ?assertEqual(2, ?Q:len(Q4)),
  247. {{value, _Val}, Q5} = ?Q:out(Q4),
  248. ?assertEqual(1, ?Q:len(Q5)).
  249. t_dropped(_) ->
  250. Q = ?Q:init(#{max_len => 1, store_qos0 => true}),
  251. Msg = emqx_message:make(<<"t">>, <<"payload">>),
  252. {undefined, Q1} = ?Q:in(Msg, Q),
  253. {Msg, Q2} = ?Q:in(Msg, Q1),
  254. ?assertEqual(1, ?Q:dropped(Q2)).
  255. t_query(_) ->
  256. EmptyQ = ?Q:init(#{max_len => 500, store_qos0 => true}),
  257. ?assertEqual({[], #{position => none, start => none}}, ?Q:query(EmptyQ, #{limit => 50})),
  258. RandPos = {erlang:system_time(nanosecond), 0},
  259. ?assertEqual(
  260. {[], #{position => RandPos, start => none}},
  261. ?Q:query(EmptyQ, #{position => RandPos, limit => 50})
  262. ),
  263. ?assertEqual(
  264. {[], #{position => none, start => none}},
  265. ?Q:query(EmptyQ, #{continuation => none, limit => 50})
  266. ),
  267. Q = lists:foldl(
  268. fun(Seq, QAcc) ->
  269. Msg = emqx_message:make(<<"t">>, integer_to_binary(Seq)),
  270. {_, QAcc1} = ?Q:in(Msg, QAcc),
  271. QAcc1
  272. end,
  273. EmptyQ,
  274. lists:seq(1, 114)
  275. ),
  276. {LastPos, LastStart} = lists:foldl(
  277. fun(PageSeq, {Pos, PrevStart}) ->
  278. Limit = 10,
  279. PagerParams = #{position => Pos, limit => Limit},
  280. {Page, #{position := NextPos, start := Start}} = ?Q:query(Q, PagerParams),
  281. ?assertEqual(10, length(Page)),
  282. ExpFirstPayload = integer_to_binary(PageSeq * Limit - Limit + 1),
  283. ExpLastPayload = integer_to_binary(PageSeq * Limit),
  284. FirstMsg = lists:nth(1, Page),
  285. LastMsg = lists:nth(10, Page),
  286. ?assertEqual(ExpFirstPayload, emqx_message:payload(FirstMsg)),
  287. ?assertEqual(ExpLastPayload, emqx_message:payload(LastMsg)),
  288. %% start value must not change as Mqueue is not modified during traversal
  289. NextStart =
  290. case PageSeq of
  291. 1 ->
  292. ?assertEqual({mqueue_ts(FirstMsg), 0}, Start),
  293. Start;
  294. _ ->
  295. ?assertEqual(PrevStart, Start),
  296. PrevStart
  297. end,
  298. {NextPos, NextStart}
  299. end,
  300. {none, none},
  301. lists:seq(1, 11)
  302. ),
  303. {LastPartialPage, #{position := FinalPos} = LastMeta} = ?Q:query(Q, #{
  304. position => LastPos, limit => 10
  305. }),
  306. LastMsg = lists:nth(4, LastPartialPage),
  307. ?assertEqual(4, length(LastPartialPage)),
  308. ?assertEqual(<<"111">>, emqx_message:payload(lists:nth(1, LastPartialPage))),
  309. ?assertEqual(<<"114">>, emqx_message:payload(LastMsg)),
  310. ?assertEqual(#{position => {mqueue_ts(LastMsg), 0}, start => LastStart}, LastMeta),
  311. ?assertEqual(
  312. {[], #{start => LastStart, position => FinalPos}},
  313. ?Q:query(Q, #{position => FinalPos, limit => 10})
  314. ),
  315. {LargePage, LargeMeta} = ?Q:query(Q, #{position => none, limit => 1000}),
  316. ?assertEqual(114, length(LargePage)),
  317. ?assertEqual(<<"1">>, emqx_message:payload(hd(LargePage))),
  318. ?assertEqual(<<"114">>, emqx_message:payload(lists:last(LargePage))),
  319. ?assertEqual(#{start => LastStart, position => FinalPos}, LargeMeta),
  320. {FullPage, FullMeta} = ?Q:query(Q, #{position => none, limit => 114}),
  321. ?assertEqual(LargePage, FullPage),
  322. ?assertEqual(LargeMeta, FullMeta),
  323. {_, Q1} = emqx_mqueue:out(Q),
  324. {PageAfterRemove, #{start := StartAfterRemove}} = ?Q:query(Q1, #{position => none, limit => 10}),
  325. ?assertEqual(<<"2">>, emqx_message:payload(hd(PageAfterRemove))),
  326. ?assertEqual(StartAfterRemove, {mqueue_ts(hd(PageAfterRemove)), 0}).
  327. t_query_with_priorities(_) ->
  328. Priorities = #{<<"t/infinity">> => infinity, <<"t/10">> => 10, <<"t/5">> => 5},
  329. EmptyQ = ?Q:init(#{max_len => 500, store_qos0 => true, priorities => Priorities}),
  330. ?assertEqual({[], #{position => none, start => none}}, ?Q:query(EmptyQ, #{limit => 50})),
  331. RandPos = {erlang:system_time(nanosecond), 0},
  332. ?assertEqual(
  333. {[], #{position => RandPos, start => none}},
  334. ?Q:query(EmptyQ, #{position => RandPos, limit => 50})
  335. ),
  336. ?assertEqual(
  337. {[], #{position => none, start => none}},
  338. ?Q:query(EmptyQ, #{continuation => none, limit => 50})
  339. ),
  340. {Q, ExpMsgsAcc} = lists:foldl(
  341. fun(Topic, {QAcc, MsgsAcc}) ->
  342. {TopicQ, TopicMsgs} =
  343. lists:foldl(
  344. fun(Seq, {TopicQAcc, TopicMsgsAcc}) ->
  345. Payload = <<Topic/binary, "_", (integer_to_binary(Seq))/binary>>,
  346. Msg = emqx_message:make(Topic, Payload),
  347. {_, TopicQAcc1} = ?Q:in(Msg, TopicQAcc),
  348. {TopicQAcc1, [Msg | TopicMsgsAcc]}
  349. end,
  350. {QAcc, []},
  351. lists:seq(1, 10)
  352. ),
  353. {TopicQ, [lists:reverse(TopicMsgs) | MsgsAcc]}
  354. end,
  355. {EmptyQ, []},
  356. [<<"t/test">>, <<"t/5">>, <<"t/infinity">>, <<"t/10">>]
  357. ),
  358. %% Manual resorting from the highest to the lowest priority
  359. [ExpMsgsPrio0, ExpMsgsPrio5, ExpMsgsPrioInf, ExpMsgsPrio10] = lists:reverse(ExpMsgsAcc),
  360. ExpMsgs = ExpMsgsPrioInf ++ ExpMsgsPrio10 ++ ExpMsgsPrio5 ++ ExpMsgsPrio0,
  361. {AllMsgs, #{start := StartPos, position := Pos}} = ?Q:query(Q, #{position => none, limit => 40}),
  362. ?assertEqual(40, length(AllMsgs)),
  363. ?assertEqual(ExpMsgs, with_empty_extra(AllMsgs)),
  364. FirstMsg = hd(AllMsgs),
  365. LastMsg = lists:last(AllMsgs),
  366. ?assertEqual(<<"t/infinity_1">>, emqx_message:payload(FirstMsg)),
  367. ?assertEqual(StartPos, {mqueue_ts(FirstMsg), infinity}),
  368. ?assertEqual(<<"t/test_10">>, emqx_message:payload(LastMsg)),
  369. ?assertMatch({_, 0}, Pos),
  370. ?assertEqual(Pos, {mqueue_ts(LastMsg), mqueue_prio(LastMsg)}),
  371. Pos5 = {mqueue_ts(lists:nth(5, AllMsgs)), mqueue_prio(lists:nth(5, AllMsgs))},
  372. LastInfPos = {mqueue_ts(lists:nth(10, AllMsgs)), mqueue_prio(lists:nth(5, AllMsgs))},
  373. {MsgsPrioInfTo10, #{start := StartPos, position := PosPrio10Msg5}} = ?Q:query(Q, #{
  374. position => Pos5, limit => 10
  375. }),
  376. ?assertEqual(10, length(MsgsPrioInfTo10)),
  377. ?assertEqual(<<"t/infinity_6">>, emqx_message:payload(hd(MsgsPrioInfTo10))),
  378. ?assertEqual(<<"t/10_5">>, emqx_message:payload(lists:last(MsgsPrioInfTo10))),
  379. ?assertEqual(PosPrio10Msg5, {
  380. mqueue_ts(lists:last(MsgsPrioInfTo10)), mqueue_prio(lists:last(MsgsPrioInfTo10))
  381. }),
  382. {MsgsPrioInfTo5, #{start := StartPos, position := PosPrio5Msg5}} = ?Q:query(Q, #{
  383. position => Pos5, limit => 20
  384. }),
  385. ?assertEqual(20, length(MsgsPrioInfTo5)),
  386. ?assertEqual(<<"t/infinity_6">>, emqx_message:payload(hd(MsgsPrioInfTo5))),
  387. ?assertEqual(<<"t/5_5">>, emqx_message:payload(lists:last(MsgsPrioInfTo5))),
  388. ?assertEqual(PosPrio5Msg5, {
  389. mqueue_ts(lists:last(MsgsPrioInfTo5)), mqueue_prio(lists:last(MsgsPrioInfTo5))
  390. }),
  391. {MsgsPrio10, #{start := StartPos, position := PosPrio10}} = ?Q:query(Q, #{
  392. position => LastInfPos, limit => 10
  393. }),
  394. ?assertEqual(ExpMsgsPrio10, with_empty_extra(MsgsPrio10)),
  395. ?assertEqual(10, length(MsgsPrio10)),
  396. ?assertEqual(<<"t/10_1">>, emqx_message:payload(hd(MsgsPrio10))),
  397. ?assertEqual(<<"t/10_10">>, emqx_message:payload(lists:last(MsgsPrio10))),
  398. ?assertEqual(PosPrio10, {mqueue_ts(lists:last(MsgsPrio10)), mqueue_prio(lists:last(MsgsPrio10))}),
  399. {MsgsPrio10To5, #{start := StartPos, position := _}} = ?Q:query(Q, #{
  400. position => LastInfPos, limit => 20
  401. }),
  402. ?assertEqual(ExpMsgsPrio10 ++ ExpMsgsPrio5, with_empty_extra(MsgsPrio10To5)).
  403. conservation_prop() ->
  404. ?FORALL(
  405. {Priorities, Messages},
  406. ?LET(
  407. Priorities,
  408. topic_priorities(),
  409. {Priorities, messages(Priorities)}
  410. ),
  411. try
  412. Opts = #{
  413. max_len => 0,
  414. priorities => maps:from_list(Priorities),
  415. store_qos0 => false
  416. },
  417. %% Put messages in
  418. Q1 = lists:foldl(
  419. fun({Topic, Message}, Q) ->
  420. element(2, ?Q:in(#message{topic = Topic, qos = 1, payload = Message}, Q))
  421. end,
  422. ?Q:init(Opts),
  423. Messages
  424. ),
  425. %% Collect messages
  426. Got = lists:sort(drain(Q1)),
  427. Expected = lists:sort(Messages),
  428. case Expected =:= Got of
  429. true ->
  430. true;
  431. false ->
  432. ct:pal("Mismatch: expected ~p~nGot ~p~n", [Expected, Got]),
  433. false
  434. end
  435. catch
  436. EC:Err:Stack ->
  437. ct:pal("Error: ~p", [{EC, Err, Stack}]),
  438. false
  439. end
  440. ).
  441. %% Proper generators:
  442. topic(Priorities) ->
  443. {Topics, _} = lists:unzip(Priorities),
  444. oneof(Topics).
  445. topic_priorities() ->
  446. non_empty(list({binary(), priority()})).
  447. priority() ->
  448. oneof([integer(), infinity]).
  449. messages(Topics) ->
  450. list({topic(Topics), binary()}).
  451. %% Internal functions:
  452. drain(Q) ->
  453. case ?Q:out(Q) of
  454. {empty, _} ->
  455. [];
  456. {{value, #message{topic = T, payload = P}}, Q1} ->
  457. [{T, P} | drain(Q1)]
  458. end.
  459. mqueue_ts(#message{extra = #{mqueue_insert_ts := Ts}}) -> Ts.
  460. mqueue_prio(#message{extra = #{mqueue_priority := Prio}}) -> Prio.
  461. with_empty_extra(Msgs) ->
  462. [M#message{extra = #{}} || M <- Msgs].