Skip to content

Commit

Permalink
khepri_tree: Ignore unknown props to return
Browse files Browse the repository at this point in the history
[Why]
A future version of Khepri might introduce new props to return. If a
Khepri cluster is being upgraded and several versions of the Khepri
machine are running at the same time, an old node could be called with
props to return it doesn’t know.

[How]
We simply ignore unknown props.

In the process, we ignore `delete_reason` because it is set by another
part of the code anyway.
  • Loading branch information
dumbbell committed Dec 11, 2024
1 parent 6f88694 commit 5c73387
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/khepri_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ gather_node_props(#node{props = #{payload_version := PVersion,
end;
(raw_payload, Acc) ->
Acc#{raw_payload => Payload};
(delete_reason, Acc) ->
(_Unknown, Acc) ->
%% We ignore props we don't know about. It might be a new one in
%% a future version of the machine.
Acc
end, #{}, WantedProps);
gather_node_props(#node{}, _Options) ->
Expand Down
14 changes: 14 additions & 0 deletions test/queries.erl
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,17 @@ include_child_names_in_query_response_test() ->
child_list_version => 2,
child_names => [bar, quux]}}},
Ret).

use_an_unknown_prop_to_return_test() ->
Commands = [#put{path = [foo],
payload = khepri_payload:data(value)}],
S0 = khepri_machine:init(?MACH_PARAMS(Commands)),
Tree = khepri_machine:get_tree(S0),
Ret = khepri_tree:find_matching_nodes(
Tree, [foo],
#{props_to_return => [payload,
future_prop_name]}),

?assertEqual(
{ok, #{[foo] => #{data => value}}},
Ret).

0 comments on commit 5c73387

Please sign in to comment.