MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / with_lock_retry

Function with_lock_retry

atomic-repository/src/content_search.rs:650–664  ·  view source on GitHub ↗

Run `op`, retrying with exponential backoff when it fails with a lock conflict. syntext documents lock downgrades in `build`/`compact` as brief windows where a concurrent `open` can surface `LockConflict`, with the caller expected to retry. Locks also live as long as the `Index` handle, so an immediately preceding call in this process (e.g. `build` right before an `update`) may still be holding o

(
    op: impl Fn() -> Result<T, ContentSearchError>,
)

Source from the content-addressed store, hash-verified

648/// `update`) may still be holding one while its handle drops or a parallel
649/// test's handles overlap. A transient conflict must not fail the operation.
650fn with_lock_retry<T>(
651 op: impl Fn() -> Result<T, ContentSearchError>,
652) -> Result<T, ContentSearchError> {
653 let mut delay_ms = LOCK_RETRY_BASE_DELAY_MS;
654 for attempt in 0..=LOCK_RETRY_ATTEMPTS {
655 match op() {
656 Err(ContentSearchError::LockConflict) if attempt < LOCK_RETRY_ATTEMPTS => {
657 std::thread::sleep(std::time::Duration::from_millis(delay_ms));
658 delay_ms *= 2;
659 }
660 other => return other,
661 }
662 }
663 unreachable!("loop returns on the final attempt")
664}
665
666// ---------------------------------------------------------------------------
667// Error type

Callers 2

build_content_indexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected