8000 Add validation of lock ordering by andrewaylett · Pull Request #116 · andrewaylett/arc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add validation of lock ordering #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025
Merged

Add validation of lock ordering #116

merged 1 commit into from
Jun 1, 2025

Conversation

andrewaylett
Copy link
Owner

This ensures we only take a single element lock at once, and also that we don't try to take the expiry lock while holding an element lock.

Taking an element lock while holding the expiry lock is expected.

@Copilot Copilot AI review requested due to automatic review settings June 1, 2025 12:47
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds validation of lock ordering to ensure that only a single element lock is held at once and to prevent taking the expiry lock while holding an element lock. Key changes include:

  • Replacing direct lock/unlock calls with methods that return a release token and require passing that token for unlocking.
  • Introducing a new LockOrderGuard class that tracks lock ownership and validates lock ordering.
  • Updating multiple modules (TimeDelayedElement, LRUElementList, InnerArc, ExpiredElementList, Element, and Arc) to integrate the new lock validation mechanism.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/src/main/java/eu/aylett/arc/internal/TimeDelayedElement.java Updated lock usage to capture and use a release token
lib/src/main/java/eu/aylett/arc/internal/LockOrderGuard.java New guard class to enforce lock ordering
lib/src/main/java/eu/aylett/arc/internal/LRUElementList.java Modified locking to use the new release-based mechanism
lib/src/main/java/eu/aylett/arc/internal/InnerArc.java Added assertions to ensure no element lock is held during eviction lock operations
lib/src/main/java/eu/aylett/arc/internal/ExpiredElementList.java Updated lock handling with release tokens
lib/src/main/java/eu/aylett/arc/internal/Element.java Refactored lock and unlock to work with LockOrderGuard
lib/src/main/java/eu/aylett/arc/Arc.java Integrated LockOrderGuard and updated element locking usage

}

@EnsuresLockHeld("this.lock")
public void lock() {
@MayReleaseLocks
public LockOrderGuard.Release lock() {
Copy link
Preview
Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a JavaDoc comment here to clarify that the lock method returns a release token which must be used in the corresponding unlock(LockOrderGuard.Release) method.

Copilot uses AI. Check for mistakes.

return evictionLock.tryLock();
}

@EnsuresLockHeld("this.evictionLock")
@ReleasesNoLocks
public void takeEvictionLock() {
lockOrderGuard.assertNoElementLockHeld();
Copy link
Preview
Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to explain why asserting that no element lock is held before acquiring the eviction lock is crucial for maintaining the lock order invariants.

Copilot uses AI. Check for mistakes.

Copy link
github-actions bot commented Jun 1, 2025
  • Surviving mutants in this change: 11
  • Killed mutants in this change: 20
class surviving killed
🧟eu.aylett.arc.internal.LockOrderGuard 7 6
🧟eu.aylett.arc.internal.InnerArc 3 0
🧟eu.aylett.arc.internal.Element 1 4
💯eu.aylett.arc.internal.ExpiredElementList 0 2
💯eu.aylett.arc.internal.LRUElementList 0 2
💯eu.aylett.arc.Arc 0 4
💯eu.aylett.arc.internal.TimeDelayedElement 0 2

See https://pitest.org

This ensures we only take a single element lock at once, and also that
we don't try to take the expiry lock while holding an element lock.

Taking an element lock while holding the expiry lock is expected.
@andrewaylett andrewaylett enabled auto-merge (rebase) June 1, 2025 12:58
@andrewaylett andrewaylett merged commit d1ebc31 into main Jun 1, 2025
5 checks passed
@andrewaylett andrewaylett deleted the push-yprqkokkkkrk branch June 1, 2025 12:58
Copy link
github-actions bot commented Jun 1, 2025
  • Surviving mutants in this change: 11
  • Killed mutants in this change: 20
class surviving killed
🧟eu.aylett.arc.internal.LockOrderGuard 7 6
🧟eu.aylett.arc.internal.InnerArc 3 0
🧟eu.aylett.arc.internal.Element 1 4
💯eu.aylett.arc.internal.ExpiredElementList 0 2
💯eu.aylett.arc.internal.LRUElementList 0 2
💯eu.aylett.arc.Arc 0 4
💯eu.aylett.arc.internal.TimeDelayedElement 0 2

See https://pitest.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0