Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::async::saga_builder Class Reference

Builder for Saga pattern transactions. More...

#include <async_operations.h>

Collaboration diagram for database::async::saga_builder:
Collaboration graph

Classes

struct  saga_step
 

Public Member Functions

 saga_builder (transaction_coordinator &coordinator)
 
template<concepts::TransactionAction Action, concepts::CompensationAction Compensation>
saga_builderadd_step (Action &&action, Compensation &&compensation)
 
saga_builderadd_step (std::function< async_result< bool >()> action, std::function< async_result< bool >()> compensation)
 
async_result< bool > execute ()
 

Private Attributes

transaction_coordinatorcoordinator_
 
std::vector< saga_stepsteps_
 

Detailed Description

Builder for Saga pattern transactions.

Definition at line 707 of file async_operations.h.

Constructor & Destructor Documentation

◆ saga_builder()

database::async::saga_builder::saga_builder ( transaction_coordinator & coordinator)
inline
Examples
/home/runner/work/database_system/database_system/database/async/async_operations.h.

Definition at line 1084 of file async_operations.h.

1085 : coordinator_(coordinator)
1086 {
1087 }
transaction_coordinator & coordinator_

Member Function Documentation

◆ add_step() [1/2]

template<concepts::TransactionAction Action, concepts::CompensationAction Compensation>
saga_builder & database::async::saga_builder::add_step ( Action && action,
Compensation && compensation )
Examples
/home/runner/work/database_system/database_system/database/async/async_operations.h.

Definition at line 1099 of file async_operations.h.

1101 {
1102 steps_.push_back({
1103 std::function<async_result<bool>()>(std::forward<Action>(action)),
1104 std::function<async_result<bool>()>(std::forward<Compensation>(compensation))
1105 });
1106 return *this;
1107 }
std::vector< saga_step > steps_

References steps_.

◆ add_step() [2/2]

saga_builder & database::async::saga_builder::add_step ( std::function< async_result< bool >()> action,
std::function< async_result< bool >()> compensation )
inline

Definition at line 1089 of file async_operations.h.

1092 {
1093 steps_.push_back({std::move(action), std::move(compensation)});
1094 return *this;
1095 }

References steps_.

◆ execute()

async_result< bool > database::async::saga_builder::execute ( )
inline
Examples
/home/runner/work/database_system/database_system/database/async/async_operations.h.

Definition at line 1109 of file async_operations.h.

1110 {
1111 std::vector<size_t> completed;
1112
1113 for (size_t i = 0; i < steps_.size(); ++i) {
1114 try {
1115 bool success = steps_[i].action().get();
1116 if (!success) {
1117 for (auto it = completed.rbegin();
1118 it != completed.rend(); ++it) {
1119 try { steps_[*it].compensation().get(); }
1120 catch (...) {}
1121 }
1122 return make_ready_result(false);
1123 }
1124 completed.push_back(i);
1125 } catch (...) {
1126 for (auto it = completed.rbegin();
1127 it != completed.rend(); ++it) {
1128 try { steps_[*it].compensation().get(); }
1129 catch (...) {}
1130 }
1131 return make_ready_result(false);
1132 }
1133 }
1134
1135 return make_ready_result(true);
1136 }
async_result< T > make_ready_result(T value)

References database::async::make_ready_result(), steps_, and database::success.

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ coordinator_

transaction_coordinator& database::async::saga_builder::coordinator_
private

◆ steps_

std::vector<saga_step> database::async::saga_builder::steps_
private

The documentation for this class was generated from the following file: