Skip to content

Commit f0fbfea

Browse files
committed
add doxygen
1 parent dab5307 commit f0fbfea

File tree

11 files changed

+1100
-47
lines changed

11 files changed

+1100
-47
lines changed

include/vix/sync/Operation.hpp

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* @file Operation.hpp
44
* @author Gaspard Kirira
55
*
6-
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* Copyright 2025, Gaspard Kirira.
7+
* All rights reserved.
78
* https://github.com/vixcpp/vix
9+
*
810
* Use of this source code is governed by a MIT license
911
* that can be found in the License file.
1012
*
@@ -21,41 +23,145 @@
2123

2224
namespace vix::sync
2325
{
24-
25-
enum class OperationStatus : uint8_t
26+
/**
27+
* @brief Lifecycle status of a sync operation.
28+
*
29+
* OperationStatus represents the durable state of an operation
30+
* as it flows through the sync pipeline.
31+
*/
32+
enum class OperationStatus : std::uint8_t
2633
{
34+
/**
35+
* @brief Operation is persisted and waiting to be processed.
36+
*/
2737
Pending = 0,
38+
39+
/**
40+
* @brief Operation has been claimed and is currently being processed.
41+
*/
2842
InFlight,
43+
44+
/**
45+
* @brief Operation completed successfully.
46+
*/
2947
Done,
48+
49+
/**
50+
* @brief Operation failed but may be retried.
51+
*/
3052
Failed,
53+
54+
/**
55+
* @brief Operation failed permanently and will not be retried.
56+
*/
3157
PermanentFailed
3258
};
3359

60+
/**
61+
* @brief Durable representation of a single sync operation.
62+
*
63+
* Operation is the core unit stored in the Outbox and WAL. It is designed
64+
* to be:
65+
* - immutable in intent (what to do)
66+
* - mutable in state (status, attempts, timestamps)
67+
*
68+
* The operation lifecycle is fully driven by durable state transitions,
69+
* enabling crash-safe retries and deterministic recovery.
70+
*/
3471
struct Operation
3572
{
73+
/**
74+
* @brief Unique identifier of the operation.
75+
*/
3676
std::string id;
77+
78+
/**
79+
* @brief Logical kind or type of operation.
80+
*
81+
* Examples: "http.request", "p2p.message", "db.mutation".
82+
*/
3783
std::string kind;
84+
85+
/**
86+
* @brief Target of the operation.
87+
*
88+
* Examples: URL, peer id, resource name.
89+
*/
3890
std::string target;
91+
92+
/**
93+
* @brief Opaque payload associated with the operation.
94+
*/
3995
std::string payload;
96+
97+
/**
98+
* @brief Idempotency key used to deduplicate retries.
99+
*/
40100
std::string idempotency_key;
101+
102+
/**
103+
* @brief Creation timestamp in milliseconds.
104+
*/
41105
std::int64_t created_at_ms{0};
106+
107+
/**
108+
* @brief Last update timestamp in milliseconds.
109+
*/
42110
std::int64_t updated_at_ms{0};
111+
112+
/**
113+
* @brief Number of delivery attempts so far.
114+
*/
43115
std::uint32_t attempt{0};
116+
117+
/**
118+
* @brief Next time when the operation becomes eligible for retry.
119+
*/
44120
std::int64_t next_retry_at_ms{0};
121+
122+
/**
123+
* @brief Current lifecycle status.
124+
*/
45125
OperationStatus status{OperationStatus::Pending};
126+
127+
/**
128+
* @brief Last error message, if any.
129+
*/
46130
std::string last_error;
47131

132+
/**
133+
* @brief Check whether the operation is completed.
134+
*/
48135
bool is_done() const noexcept { return status == OperationStatus::Done; }
136+
137+
/**
138+
* @brief Check whether the operation is pending.
139+
*/
49140
bool is_pending() const noexcept { return status == OperationStatus::Pending; }
141+
142+
/**
143+
* @brief Check whether the operation is failed (retryable).
144+
*/
50145
bool is_failed() const noexcept { return status == OperationStatus::Failed; }
51146

147+
/**
148+
* @brief Mark the operation as failed.
149+
*
150+
* @param err Error message.
151+
* @param now_ms Current time in milliseconds.
152+
*/
52153
void fail(std::string err, std::int64_t now_ms)
53154
{
54155
last_error = std::move(err);
55156
status = OperationStatus::Failed;
56157
updated_at_ms = now_ms;
57158
}
58159

160+
/**
161+
* @brief Mark the operation as successfully completed.
162+
*
163+
* @param now_ms Completion time in milliseconds.
164+
*/
59165
void done(std::int64_t now_ms)
60166
{
61167
status = OperationStatus::Done;
@@ -66,4 +172,4 @@ namespace vix::sync
66172

67173
} // namespace vix::sync
68174

69-
#endif
175+
#endif // VIX_SYNC_OPERATION_HPP

include/vix/sync/RetryPolicy.hpp

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* @file RetryPolicy.hpp
44
* @author Gaspard Kirira
55
*
6-
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* Copyright 2025, Gaspard Kirira.
7+
* All rights reserved.
78
* https://github.com/vixcpp/vix
9+
*
810
* Use of this source code is governed by a MIT license
911
* that can be found in the License file.
1012
*
@@ -14,27 +16,84 @@
1416
#ifndef VIX_SYNC_RETRY_POLICY_HPP
1517
#define VIX_SYNC_RETRY_POLICY_HPP
1618

17-
#include <cstdint>
1819
#include <algorithm>
20+
#include <cstdint>
1921

2022
namespace vix::sync
2123
{
22-
24+
/**
25+
* @brief Exponential backoff retry policy.
26+
*
27+
* RetryPolicy defines how failed operations are retried over time.
28+
* It supports:
29+
* - a maximum number of attempts
30+
* - exponential backoff based on a base delay and factor
31+
* - clamping to a maximum delay
32+
* - optional jitter (documented here, applied by caller if needed)
33+
*
34+
* The policy itself is deterministic and side-effect free, making it
35+
* suitable for durable systems where retry timing must be recomputable
36+
* during recovery.
37+
*/
2338
struct RetryPolicy
2439
{
40+
/**
41+
* @brief Maximum number of retry attempts.
42+
*
43+
* Once attempt >= max_attempts, no further retries are allowed.
44+
*/
2545
std::uint32_t max_attempts{8};
26-
std::int64_t base_delay_ms{500}; // 0.5s
46+
47+
/**
48+
* @brief Base delay in milliseconds for the first retry.
49+
*/
50+
std::int64_t base_delay_ms{500}; // 0.5s
51+
52+
/**
53+
* @brief Maximum delay in milliseconds between retries.
54+
*/
2755
std::int64_t max_delay_ms{30'000}; // 30s
28-
// Exponential factor: delay = base * (2^attempt)
56+
57+
/**
58+
* @brief Exponential backoff factor.
59+
*
60+
* Delay grows as: base_delay_ms * (factor ^ attempt).
61+
*/
2962
double factor{2.0};
30-
// 0.0 = none, 0.2 = +/-20%
63+
64+
/**
65+
* @brief Jitter ratio applied by higher-level logic.
66+
*
67+
* Expressed as a fraction:
68+
* - 0.0 = no jitter
69+
* - 0.2 = +/-20% randomization window
70+
*
71+
* @note This policy does not apply jitter directly. It exposes the
72+
* parameter so callers (e.g. Outbox or Engine) can apply randomness
73+
* in a controlled manner.
74+
*/
3175
double jitter_ratio{0.2};
3276

77+
/**
78+
* @brief Check whether another retry is allowed.
79+
*
80+
* @param attempt Current attempt count (0-based).
81+
* @return true if another retry may be scheduled.
82+
*/
3383
bool can_retry(std::uint32_t attempt) const noexcept
3484
{
3585
return attempt < max_attempts;
3686
}
3787

88+
/**
89+
* @brief Compute the retry delay for a given attempt.
90+
*
91+
* The delay grows exponentially and is clamped between
92+
* base_delay_ms and max_delay_ms.
93+
*
94+
* @param attempt Current attempt count (0-based).
95+
* @return Delay in milliseconds before the next retry.
96+
*/
3897
std::int64_t compute_delay_ms(std::uint32_t attempt) const noexcept
3998
{
4099
// attempt: 0,1,2,... (0 => base)
@@ -49,4 +108,4 @@ namespace vix::sync
49108

50109
} // namespace vix::sync
51110

52-
#endif
111+
#endif // VIX_SYNC_RETRY_POLICY_HPP

0 commit comments

Comments
 (0)