userver: userver/dist_lock/dist_lock_settings.hpp Source File
Loading...
Searching...
No Matches
dist_lock_settings.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dist_lock/dist_lock_settings.hpp
4/// @brief @copybrief dist_lock::DistLockSettings
5
6#include <chrono>
7#include <cstddef>
8#include <optional>
9
10USERVER_NAMESPACE_BEGIN
11
12/// @brief Distributed locking
13namespace dist_lock {
14
15/// Fallback policy shared by all lock participants, including release history.
17 /// Consecutive successful checks that must find no live lock.
18 std::size_t fallback_after_checks{50};
19
20 /// How long a fallback host may acquire locks and continue its work.
21 std::chrono::milliseconds fallback_duration{std::chrono::minutes{10}};
22
23 /// Compare fallback policies.
24 bool operator==(const DistLockFallbackSettings&) const = default;
25};
26
27/// Distributed lock settings
29 /// How often to try to acquire the lock.
30 std::chrono::milliseconds acquire_interval{100};
31
32 /// How often to try to prolong the lock while holding the lock.
33 std::chrono::milliseconds prolong_interval{100};
34
35 /// For how long to acquire/prolong the lock.
36 std::chrono::milliseconds lock_ttl{1000};
37
38 /// How much time we allow for the worker to stop when we're unable to prolong
39 /// the lock.
40 std::chrono::milliseconds forced_stop_margin{50};
41
42 /// Delay before `DoWork` is restarted after exiting with or without an exception.
43 std::chrono::milliseconds worker_func_restart_delay{100};
44
45 /// Defaults to `true` and is updated from dynamic config.
46 /// When switched to `false`, @ref dist_lock::DistLockedWorker will not start any new distributed lock acquisition
47 /// attempts. If a `DoWork` invocation is already running under the lock, it is allowed to finish without forced
48 /// cancellation. In this case @ref dist_lock::DistLockedWorker::IsCancelAdvised returns `true`.
49 bool is_enabled{true};
50
51 /// Shared fallback policy, including on preferred hosts that record release history.
53
54 /// If true, this host waits for fallback checks before acquiring the lock.
55 /// After fallback succeeds, the host can acquire the lock normally until the fallback grant expires.
56 /// If false, this host can acquire the lock immediately when the lock is available.
58
59 /// Compare all timing, enablement and fallback settings.
60 bool operator==(const DistLockSettings&) const = default;
61};
62
63/// Distributed lock waiting mode
65 kWait, ///< waits until distlock becomes free
66 kNoWait, ///< doesn't wait for distlock if it is occupied
67};
68
69/// Distributed lock retry strategy
71 kRetry, ///< Retry on user exception/lock drop
72 kSingleAttempt, ///< Don't retry on user exception/lock drop
73};
74
75} // namespace dist_lock
76
77USERVER_NAMESPACE_END