Skip to content

Commit 209de60

Browse files
committed
Allow message id override on merge
When performing a broadcast merge it might be the case that the application wants to return a new message id that results from the merge and have that broadcast instead of the originally received message id. Support this by handling an extra return tuple from the callback.
1 parent c58d8b8 commit 209de60

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/plumtree_broadcast.erl

+2
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ handle_broadcast(false, _MessageId, _Message, Mod, _Round, Root, From, State) ->
354354
State1 = add_lazy(From, Root, State),
355355
_ = send({prune, Root, myself()}, Mod, From),
356356
State1;
357+
handle_broadcast({true, MessageId}, _OldMessageId, Message, Mod, Round, Root, From, State) ->
358+
handle_broadcast(true, MessageId, Message, Mod, Round, Root, From, State);
357359
handle_broadcast(true, MessageId, Message, Mod, Round, Root, From, State) -> %% valid msg
358360
%% remove sender from lazy and set as eager
359361
plumtree_util:log(debug, "moving peer ~p from lazy to eager on tree rooted at ~p",

src/plumtree_broadcast_handler.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
%% Given the message id and payload, merge the message in the local state.
2626
%% If the message has already been received return `false', otherwise return `true'
27-
-callback merge(any(), any()) -> boolean().
27+
%% If a new message id is to be propagated after the merge return `{true, MessageId}`
28+
-callback merge(any(), any()) -> boolean() | {true, any()}.
2829

2930
%% Return true if the message (given the message id) has already been received.
3031
%% `false' otherwise

test/plumtree_test_broadcast_handler.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ merge({Key, _Context} = MsgId, RemoteObj) ->
133133
lager:info("merge object has ben reconciled to ~p",
134134
[Reconciled]),
135135
dbwrite(Key, Reconciled),
136-
true
136+
{true, {Key, plumtree_test_object:context(Reconciled)}}
137137
end.
138138

139139
%% Return true if the message (given the message id) has already been received.

0 commit comments

Comments
 (0)