From 1b60751cb27f9d559a06b3a92127320c95ffa129 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Mon, 30 Oct 2023 10:40:05 +0100 Subject: [PATCH 1/5] Add diagram about hedging's context and callbacks --- docs/strategies/hedging.md | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index e07b8e9edd6..886d3ddd1bf 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -454,6 +454,7 @@ Here's the flow: - After the strategy has an accepted result from a hedged action, the resilience context from the action is merged back into the primary context. - All ongoing hedged actions are cancelled and discarded. The hedging strategy awaits the propagation of cancellation. + ### Merging action context into the primary context After merging, the primary context contains: @@ -471,6 +472,45 @@ Some insights about the hedging callback behavior in relation to hedging context > [!NOTE] > The hedging strategy ensures that both `ActionGenerator` and `OnHedging` are never executed concurrently. Any modifications to the contexts are thread-safe in these callbacks. +### Sequence diagram about contexts and callbacks + +For the sake of conciseness the `Caller` is not depicted on the diagram. + +```mermaid +sequenceDiagram + autonumber + participant P as Pipeline + participant H as Hedging + participant AG as ActionGenerator + participant UC as UserCallback + participant HUC as HedgedUserCallback + participant OH as OnHedging + + P->>H: Calls ExecuteCore
with Primary Context + H-->>H: Deep clones
Primary Context + + H->>+UC: Invokes
with Primary Context + UC-->>UC: Processes
+ Modifies Context + UC->>-H: Fails + + H-->>H: Deep clones
Primary Context + H->>+AG: Invokes
with both Contexts + AG-->>AG: Modifies Primary Context + AG->>-H: Returns factory + + H->>+OH: Invokes
with both Contexts + OH-->>OH: Executes callback
+ Modifies Action Context + OH->>-H: Finishes + + H-->>H: Invokes factory + H->>+HUC: Invokes
with Action Context + HUC-->>HUC: Processes
+ Modifies Context + HUC->>-H: Fails + + H-->>H: Merges Action Context
onto Primary Context + H->>P: Propagates failure
with Primary Context +``` + ## Action generator The hedging options include an `ActionGenerator` property, allowing you to customize the actions executed during hedging. By default, the `ActionGenerator` returns the original callback passed to the strategy. The original callback also includes any logic introduced by subsequent resilience strategies. For more advanced scenarios, the `ActionGenerator` can be used to return entirely new hedged actions, as demonstrated in the example below: From 706434f5ee39693c336372772d7650ebda0dedd4 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Mon, 30 Oct 2023 10:43:50 +0100 Subject: [PATCH 2/5] Remove extra whitespace --- docs/strategies/hedging.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index 886d3ddd1bf..ca0bbddae83 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -454,7 +454,6 @@ Here's the flow: - After the strategy has an accepted result from a hedged action, the resilience context from the action is merged back into the primary context. - All ongoing hedged actions are cancelled and discarded. The hedging strategy awaits the propagation of cancellation. - ### Merging action context into the primary context After merging, the primary context contains: From 4401e2e1580235d17086334e6a40d88943162d4e Mon Sep 17 00:00:00 2001 From: peter-csala Date: Mon, 30 Oct 2023 11:01:01 +0100 Subject: [PATCH 3/5] Update diagram based on feedback --- docs/strategies/hedging.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index ca0bbddae83..697bc7e739a 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -494,11 +494,11 @@ sequenceDiagram H-->>H: Deep clones
Primary Context H->>+AG: Invokes
with both Contexts - AG-->>AG: Modifies Primary Context + AG-->>AG: Executes callback
+ Modifies Primary
or Action Context AG->>-H: Returns factory H->>+OH: Invokes
with both Contexts - OH-->>OH: Executes callback
+ Modifies Action Context + OH-->>OH: Executes callback
+ Modifies Primary
or Action Context OH->>-H: Finishes H-->>H: Invokes factory From 2fc503f11a03769eb55db22eff225939ff81487a Mon Sep 17 00:00:00 2001 From: peter-csala Date: Mon, 30 Oct 2023 12:53:41 +0100 Subject: [PATCH 4/5] Update diagram due to recent changes --- docs/strategies/hedging.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index 697bc7e739a..e36d617849e 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -488,17 +488,17 @@ sequenceDiagram P->>H: Calls ExecuteCore
with Primary Context H-->>H: Deep clones
Primary Context - H->>+UC: Invokes
with Primary Context + H->>+UC: Invokes
with Action Context UC-->>UC: Processes
+ Modifies Context UC->>-H: Fails H-->>H: Deep clones
Primary Context H->>+AG: Invokes
with both Contexts - AG-->>AG: Executes callback
+ Modifies Primary
or Action Context + AG-->>AG: Executes callback
+ Modifies Primary
and / or Action Context AG->>-H: Returns factory H->>+OH: Invokes
with both Contexts - OH-->>OH: Executes callback
+ Modifies Primary
or Action Context + OH-->>OH: Executes callback
+ Modifies Primary
and / or Action Context OH->>-H: Finishes H-->>H: Invokes factory From fb30254947bbdd13a64397667fd49ed615942735 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Mon, 30 Oct 2023 13:06:44 +0100 Subject: [PATCH 5/5] Move OnHedging participant next to ActionGenerator --- docs/strategies/hedging.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index e36d617849e..6527073ee5d 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -481,9 +481,9 @@ sequenceDiagram participant P as Pipeline participant H as Hedging participant AG as ActionGenerator + participant OH as OnHedging participant UC as UserCallback participant HUC as HedgedUserCallback - participant OH as OnHedging P->>H: Calls ExecuteCore
with Primary Context H-->>H: Deep clones
Primary Context