Add embedded driver retries and reopen-on-contention for multi-process use #43
+1,543
−146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the embedded Dolt database/sql driver resilient to multi-process contention by adding configurable retries with backoff and ensuring retries reopen
the underlying Dolt SQL engine so connections don’t get stuck in a read-only/fallback state.
Key changes
• Retry policy via DSN params: retry, retrytimeout, retrymaxattempts, retryinitialdelay, retrymaxdelay.
• Embedded-mode tuning DSN params:
• nocache=true to disable Dolt’s in-process singleton DB cache during embedded opens
• failonlocktimeout=true to fail fast on journal lock timeout (avoids silent read-only fallback)
• Retry logic:
• Retries now apply to engine open (so Ping() / first connect can succeed after contention clears)
• Retries apply to statement execution (reopen engine + backoff + retry on retryable errors)
• Engine reopen support:
• DoltConn stores datasource + retry policy, uses a mutex, can rebuild se + gmsCtx
• Statements/transactions reference the connection and always fetch the current engine/context
• Error classification:
• Adds conservative retryable detection (including Dolt’s new nbs.ErrDatabaseLocked).
• Tests:
• New multi-process contention tests (concurrency_lock_test.go) covering:
• no-retry fast failure under contention
• retry-enabled eventual success after lock release