Renew the lease by CAS-writing the same payload to bump `updated_at_ms` and `resource_version`.
(&self, guard: &mut LeaseGuard)
| 168 | /// Renew the lease by CAS-writing the same payload to bump |
| 169 | /// `updated_at_ms` and `resource_version`. |
| 170 | pub async fn renew(&self, guard: &mut LeaseGuard) -> Result<(), LeaseError> { |
| 171 | let payload = LeasePayload { |
| 172 | holder: self.replica_id.clone(), |
| 173 | acquired_at_ms: guard.acquired_at_ms, |
| 174 | }; |
| 175 | let payload_bytes = |
| 176 | serde_json::to_vec(&payload).map_err(|e| PersistenceError::Encode(e.to_string()))?; |
| 177 | |
| 178 | match self |
| 179 | .store |
| 180 | .put_if( |
| 181 | LEASE_OBJECT_TYPE, |
| 182 | LEASE_SINGLETON_ID, |
| 183 | LEASE_SINGLETON_NAME, |
| 184 | &payload_bytes, |
| 185 | None, |
| 186 | WriteCondition::MatchResourceVersion(guard.resource_version), |
| 187 | ) |
| 188 | .await |
| 189 | { |
| 190 | Ok(result) => { |
| 191 | guard.resource_version = result.resource_version; |
| 192 | Ok(()) |
| 193 | } |
| 194 | Err(PersistenceError::Conflict { .. }) => Err(LeaseError::Conflict), |
| 195 | Err(e) => Err(LeaseError::Store(e)), |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /// Release the lease so a standby replica can acquire immediately |
| 200 | /// without waiting for TTL expiry. |
no test coverage detected