palantir / atlasdb

Transactional Distributed Database Layer
https://palantir.github.io/atlasdb/
Apache License 2.0
44 stars 7 forks source link

Don't retry lock request in lock condition #7158

Open pkoenig10 opened 2 weeks ago

pkoenig10 commented 2 weeks ago

Before this PR

Consider the following code:

transactionManager.runWithLocksWithRetry(
        () -> LockRequest.builder(lockDescriptors)
                .blockForAtMost(SimpleTimeDuration.of(10, TimeUnit.SECONDS))
                .build(),
        (txn, heldLocks) -> { ... });

As a caller, I would expect that I could use the blockForAtMost value to control how long I'm willing to wait for the lock before giving up. So I would expect that this code would wait for 10 seconds to acquire the lock and then fail by throwing a LockAcquisitionException if it cannot acquire the lock.

However, the AdvisoryLocksCondition that is used here will end up retrying the lock request 10 times. So this code will actually wait for up to 100 seconds to acquire the lock. This is surprising behavior and can result in much higher latency than callers intended.

With these retries, it is difficult for callers to reliably control how long they wait to acquire locks, since the actual time depends on implementation details of AtlasDB - namely, how many retries are performed here.

It seems much better to avoid retries here so callers are in complete control over how long to wait for locks.

Some of the blocking modes don't really makes sense to retry anyways. The only blocking mode that would be reasonable to retry is BLOCK_UNTIL_TIMEOUT and that has the problems mentioned above.

After this PR

When running transactions with locks, AtlasDB does not retry the lock request if it was unable to acquire the locks on the first attempt.

changelog-app[bot] commented 2 weeks ago

Generate changelog in changelog-dir>`changelog/@unreleased`</changelog-dir

What do the change types mean? - `feature`: A new feature of the service. - `improvement`: An incremental improvement in the functionality or operation of the service. - `fix`: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way. - `break`: Has the potential to break consumers of this service's API, inclusive of both Palantir services and external consumers of the service's API (e.g. customer-written software or integrations). - `deprecation`: Advertises the intention to remove service functionality without any change to the operation of the service itself. - `manualTask`: Requires the possibility of manual intervention (running a script, eyeballing configuration, performing database surgery, ...) at the time of upgrade for it to succeed. - `migration`: A fully automatic upgrade migration task with no engineer input required. _Note: only one type should be chosen._
How are new versions calculated? - ❗The `break` and `manual task` changelog types will result in a major release! - 🐛 The `fix` changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease. - ✨ All others will result in a minor version release.

Type

- [ ] Feature - [x] Improvement - [ ] Fix - [ ] Break - [ ] Deprecation - [ ] Manual task - [ ] Migration

Description

Advisory lock acquisition is no longer retried. Lock acquisition will behave exactly as specified in the provided `LockRequest`. **Check the box to generate changelog(s)** - [x] Generate changelog entry