|
89 | 89 | make_purge/0, |
90 | 90 | make_purge_nodes/1, |
91 | 91 | make_update_config/1, |
92 | | - make_garbage_collection/0 |
| 92 | + make_garbage_collection/0, |
| 93 | + |
| 94 | + exec_read/3 |
| 95 | + |
93 | 96 | ]). |
94 | 97 |
|
95 | 98 | -ifdef(TEST). |
@@ -2058,31 +2061,57 @@ delivery_effect(ConsumerKey, [{MsgId, ?MSG(Idx, Header)}], |
2058 | 2061 | {send_msg, CPid, {delivery, CTag, [{MsgId, {Header, RawMsg}}]}, |
2059 | 2062 | ?DELIVERY_SEND_MSG_OPTS}; |
2060 | 2063 | delivery_effect(ConsumerKey, Msgs, |
2061 | | - #?STATE{cfg = #cfg{resource = QR}} = State) -> |
| 2064 | + #?STATE{cfg = #cfg{resource = _QR}} = State) -> |
2062 | 2065 | {CTag, CPid} = consumer_id(ConsumerKey, State), |
2063 | | - {RaftIdxs, Num} = lists:foldr(fun ({_, ?MSG(I, _)}, {Acc, N}) -> |
| 2066 | + {RaftIdxs, _Num} = lists:foldr(fun ({_, ?MSG(I, _)}, {Acc, N}) -> |
2064 | 2067 | {[I | Acc], N+1} |
2065 | 2068 | end, {[], 0}, Msgs), |
2066 | | - {log, RaftIdxs, |
2067 | | - fun (Commands) |
2068 | | - when length(Commands) < Num -> |
2069 | | - %% the mandatory length/1 guard is a bit :( |
2070 | | - rabbit_log:info("~ts: requested read consumer tag '~ts' of ~b " |
2071 | | - "indexes ~w but only ~b were returned. " |
2072 | | - "This is most likely a stale read request " |
2073 | | - "and can be ignored", |
2074 | | - [rabbit_misc:rs(QR), CTag, Num, RaftIdxs, |
2075 | | - length(Commands)]), |
2076 | | - []; |
2077 | | - (Commands) -> |
2078 | | - DelMsgs = lists:zipwith( |
2079 | | - fun (Cmd, {MsgId, ?MSG(_Idx, Header)}) -> |
2080 | | - {MsgId, {Header, get_msg(Cmd)}} |
2081 | | - end, Commands, Msgs), |
2082 | | - [{send_msg, CPid, {delivery, CTag, DelMsgs}, |
| 2069 | + {log_ext, RaftIdxs, |
| 2070 | + fun |
| 2071 | + % (Commands) |
| 2072 | + % when length(Commands) < Num -> |
| 2073 | + % %% the mandatory length/1 guard is a bit :( |
| 2074 | + % rabbit_log:info("~ts: requested read consumer tag '~ts' of ~b " |
| 2075 | + % "indexes ~w but only ~b were returned. " |
| 2076 | + % "This is most likely a stale read request " |
| 2077 | + % "and can be ignored", |
| 2078 | + % [rabbit_misc:rs(QR), CTag, Num, RaftIdxs, |
| 2079 | + % length(Commands)]), |
| 2080 | + % []; |
| 2081 | + (ReadPlan) -> |
| 2082 | + % Fun = fun (Flru0) -> |
| 2083 | + % {Entries, Flru} = ra_log:execute_read(ReadPlan, Flru0), |
| 2084 | + % %% pretend entries is a map |
| 2085 | + % {lists:map(fun ({MsgId, ?MSG(Idx, Header)}) -> |
| 2086 | + % {_, _, Cmd} = maps:get(Idx, Entries), |
| 2087 | + % %% hacky |
| 2088 | + % {MsgId, {Header, get_msg(element(3, Cmd))}} |
| 2089 | + % end, Msgs), Flru} |
| 2090 | + % end, |
| 2091 | + [{send_msg, CPid, {delivery, CTag, ReadPlan, Msgs}, |
2083 | 2092 | ?DELIVERY_SEND_MSG_OPTS}] |
2084 | 2093 | end, |
2085 | 2094 | {local, node(CPid)}}. |
| 2095 | + % {log, RaftIdxs, |
| 2096 | + % fun (Commands) |
| 2097 | + % when length(Commands) < Num -> |
| 2098 | + % %% the mandatory length/1 guard is a bit :( |
| 2099 | + % rabbit_log:info("~ts: requested read consumer tag '~ts' of ~b " |
| 2100 | + % "indexes ~w but only ~b were returned. " |
| 2101 | + % "This is most likely a stale read request " |
| 2102 | + % "and can be ignored", |
| 2103 | + % [rabbit_misc:rs(QR), CTag, Num, RaftIdxs, |
| 2104 | + % length(Commands)]), |
| 2105 | + % []; |
| 2106 | + % (Commands) -> |
| 2107 | + % DelMsgs = lists:zipwith( |
| 2108 | + % fun (Cmd, {MsgId, ?MSG(_Idx, Header)}) -> |
| 2109 | + % {MsgId, {Header, get_msg(Cmd)}} |
| 2110 | + % end, Commands, Msgs), |
| 2111 | + % [{send_msg, CPid, {delivery, CTag, DelMsgs}, |
| 2112 | + % ?DELIVERY_SEND_MSG_OPTS}] |
| 2113 | + % end, |
| 2114 | + % {local, node(CPid)}}. |
2086 | 2115 |
|
2087 | 2116 | reply_log_effect(RaftIdx, MsgId, Header, Ready, From) -> |
2088 | 2117 | {log, [RaftIdx], |
@@ -2995,3 +3024,12 @@ incr_msg(Msg0, DelFailed, Anns) -> |
2995 | 3024 | false -> |
2996 | 3025 | Msg2 |
2997 | 3026 | end. |
| 3027 | + |
| 3028 | +exec_read(Flru0, ReadPlan, Msgs) -> |
| 3029 | + {Entries, Flru} = ra_log:execute_read(ReadPlan, Flru0), |
| 3030 | + %% pretend entries is a map |
| 3031 | + {lists:map(fun ({MsgId, ?MSG(Idx, Header)}) -> |
| 3032 | + {_, _, Cmd} = maps:get(Idx, Entries), |
| 3033 | + %% hacky |
| 3034 | + {MsgId, {Header, get_msg(element(3, Cmd))}} |
| 3035 | + end, Msgs), Flru}. |
0 commit comments