Try to acquire certificate renew lock Returns true if lock acquired, false if already locked by another node
(&self, domain: &str, lock_timeout_secs: u64)
| 948 | /// Try to acquire certificate renew lock |
| 949 | /// Returns true if lock acquired, false if already locked by another node |
| 950 | pub fn try_acquire_cert_lock(&self, domain: &str, lock_timeout_secs: u64) -> bool { |
| 951 | let now = std::time::SystemTime::now() |
| 952 | .duration_since(std::time::UNIX_EPOCH) |
| 953 | .unwrap_or_default() |
| 954 | .as_secs(); |
| 955 | |
| 956 | if let Some(existing) = self.get_cert_lock(domain) { |
| 957 | // Check if lock is still valid (not expired) |
| 958 | if now < existing.started_at + lock_timeout_secs { |
| 959 | return false; |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | // Acquire the lock |
| 964 | let lock = CertRenewLock { |
| 965 | started_at: now, |
| 966 | started_by: self.my_node_id, |
| 967 | }; |
| 968 | self.persistent |
| 969 | .write() |
| 970 | .put_encoded(keys::cert_lock(domain), &lock) |
| 971 | .is_ok() |
| 972 | } |
| 973 | |
| 974 | /// Release certificate renew lock |
| 975 | pub fn release_cert_lock(&self, domain: &str) -> Result<()> { |
no test coverage detected