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
8USERVER_NAMESPACE_BEGIN
9
10/// @brief Distributed locking
11namespace dist_lock {
12
13/// Distributed lock settings
15 /// How often to try to acquire the lock.
16 std::chrono::milliseconds acquire_interval{100};
17
18 /// How often to try to prolong the lock while holding the lock.
19 std::chrono::milliseconds prolong_interval{100};
20
21 /// For how long to acquire/prolong the lock.
22 std::chrono::milliseconds lock_ttl{1000};
23
24 /// How much time we allow for the worker to stop when we're unable to prolong
25 /// the lock.
26 std::chrono::milliseconds forced_stop_margin{50};
27
28 /// Delay before failed worker_func restart
29 std::chrono::milliseconds worker_func_restart_delay{100};
30
31 /// Defaults to `true` and is updated from dynamic config.
32 /// When switched to `false`, @ref dist_lock::DistLockedWorker will not start any new distributed lock acquisition
33 /// attempts. If a `DoWork` invocation is already running under the lock, it is allowed to finish without forced
34 /// cancellation. In this case @ref dist_lock::DistLockedWorker::IsCancelAdvised returns `true`.
35 bool is_enabled{true};
36};
37
38/// Distributed lock waiting mode
40 kWait, ///< waits until distlock becomes free
41 kNoWait, ///< doesn't wait for distlock if it is occupied
42};
43
44/// Distributed lock retry strategy
46 kRetry, ///< Retry on user exception/lock drop
47 kSingleAttempt, ///< Don't retry on user exception/lock drop
48};
49
50} // namespace dist_lock
51
52USERVER_NAMESPACE_END