|
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). |
@@ -2077,31 +2080,52 @@ delivery_effect(ConsumerKey, [{MsgId, ?MSG(Idx, Header)}], |
2077 | 2080 | {send_msg, CPid, {delivery, CTag, [{MsgId, {Header, RawMsg}}]}, |
2078 | 2081 | ?DELIVERY_SEND_MSG_OPTS}; |
2079 | 2082 | delivery_effect(ConsumerKey, Msgs, |
2080 | | - #?STATE{cfg = #cfg{resource = QR}} = State) -> |
| 2083 | + #?STATE{cfg = #cfg{resource = _QR}} = State) -> |
2081 | 2084 | {CTag, CPid} = consumer_id(ConsumerKey, State), |
2082 | | - {RaftIdxs, Num} = lists:foldr(fun ({_, ?MSG(I, _)}, {Acc, N}) -> |
2083 | | - {[I | Acc], N+1} |
2084 | | - end, {[], 0}, Msgs), |
2085 | | - {log, RaftIdxs, |
2086 | | - fun (Commands) |
2087 | | - when length(Commands) < Num -> |
2088 | | - %% the mandatory length/1 guard is a bit :( |
2089 | | - rabbit_log:info("~ts: requested read consumer tag '~ts' of ~b " |
2090 | | - "indexes ~w but only ~b were returned. " |
2091 | | - "This is most likely a stale read request " |
2092 | | - "and can be ignored", |
2093 | | - [rabbit_misc:rs(QR), CTag, Num, RaftIdxs, |
2094 | | - length(Commands)]), |
2095 | | - []; |
2096 | | - (Commands) -> |
2097 | | - DelMsgs = lists:zipwith( |
2098 | | - fun (Cmd, {MsgId, ?MSG(_Idx, Header)}) -> |
2099 | | - {MsgId, {Header, get_msg(Cmd)}} |
2100 | | - end, Commands, Msgs), |
2101 | | - [{send_msg, CPid, {delivery, CTag, DelMsgs}, |
| 2085 | + {RaftIdxs, _Num} = lists:foldr(fun ({_, ?MSG(I, _)}, {Acc, N}) -> |
| 2086 | + {[I | Acc], N+1} |
| 2087 | + end, {[], 0}, Msgs), |
| 2088 | + rabbit_log:debug("DELIVERY EFFECT created for ~s ~p!", [CTag, RaftIdxs]), |
| 2089 | + {log_ext, RaftIdxs, |
| 2090 | + fun |
| 2091 | + % (Commands) |
| 2092 | + % when length(Commands) < Num -> |
| 2093 | + % %% the mandatory length/1 guard is a bit :( |
| 2094 | + % rabbit_log:info("~ts: requested read consumer tag '~ts' of ~b " |
| 2095 | + % "indexes ~w but only ~b were returned. " |
| 2096 | + % "This is most likely a stale read request " |
| 2097 | + % "and can be ignored", |
| 2098 | + % [rabbit_misc:rs(QR), CTag, Num, RaftIdxs, |
| 2099 | + % length(Commands)]), |
| 2100 | + % []; |
| 2101 | + (ReadPlan) -> |
| 2102 | + rabbit_log:debug("READPLAN created for ~s ~p!", [CTag, RaftIdxs]), |
| 2103 | + %% TODO: check if CPid is local or not |
| 2104 | + %% TODO: could consider introducing a leader local proxy process |
| 2105 | + [{send_msg, CPid, {delivery, CTag, ReadPlan, Msgs}, |
2102 | 2106 | ?DELIVERY_SEND_MSG_OPTS}] |
2103 | 2107 | end, |
2104 | 2108 | {local, node(CPid)}}. |
| 2109 | + % {log, RaftIdxs, |
| 2110 | + % fun (Commands) |
| 2111 | + % when length(Commands) < Num -> |
| 2112 | + % %% the mandatory length/1 guard is a bit :( |
| 2113 | + % rabbit_log:info("~ts: requested read consumer tag '~ts' of ~b " |
| 2114 | + % "indexes ~w but only ~b were returned. " |
| 2115 | + % "This is most likely a stale read request " |
| 2116 | + % "and can be ignored", |
| 2117 | + % [rabbit_misc:rs(QR), CTag, Num, RaftIdxs, |
| 2118 | + % length(Commands)]), |
| 2119 | + % []; |
| 2120 | + % (Commands) -> |
| 2121 | + % DelMsgs = lists:zipwith( |
| 2122 | + % fun (Cmd, {MsgId, ?MSG(_Idx, Header)}) -> |
| 2123 | + % {MsgId, {Header, get_msg(Cmd)}} |
| 2124 | + % end, Commands, Msgs), |
| 2125 | + % [{send_msg, CPid, {delivery, CTag, DelMsgs}, |
| 2126 | + % ?DELIVERY_SEND_MSG_OPTS}] |
| 2127 | + % end, |
| 2128 | + % {local, node(CPid)}}. |
2105 | 2129 |
|
2106 | 2130 | reply_log_effect(RaftIdx, MsgId, Header, Ready, From) -> |
2107 | 2131 | {log, [RaftIdx], |
@@ -3014,3 +3038,11 @@ incr_msg(Msg0, DelFailed, Anns) -> |
3014 | 3038 | false -> |
3015 | 3039 | Msg2 |
3016 | 3040 | end. |
| 3041 | + |
| 3042 | +exec_read(Flru0, ReadPlan, Msgs) -> |
| 3043 | + {Entries, Flru} = ra_log_read_plan:execute(ReadPlan, Flru0), |
| 3044 | + %% return a list in original order |
| 3045 | + {lists:map(fun ({MsgId, ?MSG(Idx, Header)}) -> |
| 3046 | + Cmd = maps:get(Idx, Entries), |
| 3047 | + {MsgId, {Header, get_msg(Cmd)}} |
| 3048 | + end, Msgs), Flru}. |
0 commit comments