urvishdesai opened a new pull request, #11218:
URL: https://github.com/apache/gravitino/pull/11218
…ite races
Every entity table already has a current_version column, and every UPDATE
SQL in the mapper layer already checks it in the WHERE clause. The only missing
pieces were a typed exception to distinguish a version mismatch from a generic
I/O error, and a retry loop in the single lock entry point.
- Add OptimisticLockException (GravitinoRuntimeException subclass)
- Replace generic IOException("Failed to update the entity") with
OptimisticLockException in all 11 entity service classes
- Add OCC retry loop (max 3 attempts, 10/20/40 ms backoff) to
TreeLockUtils.doWithTreeLock for WRITE operations; READs are unchanged
- Update TestTreeLockUtils with three new tests covering retry success,
retry exhaustion, and READ non-retry behaviour
- Update TestFilesetMetaService to expect OptimisticLockException
No schema changes, no new dependencies, no configuration required.
Single-node deployments see no behaviour change (TreeLock serialises local
writes so OCC never fires in practice). In HA mode, concurrent cross-node
writes on the same entity are detected and retried automatically via the
database's atomic UPDATE … WHERE current_version = N.
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): Support xxx"
- "[#233] fix: Check null before access result in xxx"
- "[MINOR] refactor: Fix typo in variable name"
- "[MINOR] docs: Fix typo in README"
- "[#255] test: Fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
This PR addresses the HA write-race condition in TreeLock by activating the
optimistic concurrency control (OCC) already built into every entity table's
mapper layer, rather than introducing new lock infrastructure.
Every entity table already carries `current_version INT NOT NULL DEFAULT 1`,
and every `UPDATE` SQL already checks it:
```sql
UPDATE catalog_meta SET ..., current_version = #{new.currentVersion}
WHERE catalog_id = #{old.catalogId}
AND current_version = #{old.currentVersion}
AND deleted_at = 0
```
### Why are the changes needed?
(Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, describe the bug.)
Fix: #(issue)
### Does this PR introduce _any_ user-facing change?
(Please list the user-facing changes introduced by your change, including
1. Change in user-facing APIs.
2. Addition or removal of property keys.)
### How was this patch tested?
(Please test your changes, and provide instructions on how to test it:
1. If you add a feature or fix a bug, add a test to cover your changes.
2. If you fix a flaky test, repeat it for many times to prove it works.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]