From 95b0ef5606c3e62c89bc6a13eedd6a68f451fde4 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 14 Oct 2024 15:59:38 -0400 Subject: [PATCH] khepri_tree: Accumulate keep-while expirations With this change any tree nodes removed from the tree because their keep-while condition became unsatisfied are accumulated in the return value of the put or delete operation which caused their deletion. These expired tree nodes have props maps in the return map with the `delete_reason` key set to `keep_while`. This enables callers of delete operations to distinguish between deletes which were the target of the delete command (`direct`) and expired nodes (`keep_while`). This also enables callers of put operations to distinguish between creates or updates and deletions. This change only affects functions which return the `khepri_adv:node_props_map()` - functions from the `khepri_adv` and `khepri_adv_tx` modules. Previously the node props map did not include the tree nodes removed because of expired keep-while conditions. --- src/khepri_adv.erl | 66 ++++++++++++++++++++++++---------- src/khepri_tree.erl | 31 ++++++++++++---- test/delete_command.erl | 10 +++++- test/keep_while_conditions.erl | 32 +++++++++++++---- 4 files changed, 107 insertions(+), 32 deletions(-) diff --git a/src/khepri_adv.erl b/src/khepri_adv.erl index d98d9080..71065ef2 100644 --- a/src/khepri_adv.erl +++ b/src/khepri_adv.erl @@ -332,11 +332,18 @@ put(StoreId, PathPattern, Data) -> %% in the path pattern is not met, an error is returned and the tree structure %% is not modified. %% -%% The returned `{ok, NodeProps}' tuple contains a map with the properties and -%% payload (if any) of the targeted tree node: the payload was the one before -%% the update, other properties like the payload version correspond to the -%% updated node. If the targeted tree node didn't exist, `NodeProps' will be -%% an empty map. +%% The returned `{ok, NodePropsMap}' tuple contains a map where keys correspond +%% to the path to a node affected by the put operation. Each key points to a +%% map containing the properties and prior payload (if any) of a tree node +%% created, updated or deleted by the put operation. If the put results in the +%% creation of a tree node this props map will be empty. If the put updates an +%% existing tree node then the props map will contain the payload of the tree +%% node (if any) before the update while the other properties like the payload +%% version correspond to the updated node. The `NodePropsMap' map might also +%% contain deletions if the put operation leads to an existing tree node's +%% keep-while condition becoming unsatisfied. The props map for any nodes +%% deleted because of an expired keep-while condition will contain a +%% `delete_reason' key set to `keep_while'. %% %% The payload must be one of the following form: %%