Skip to content

Commit 089796b

Browse files
authored
[MRESOLVER-521] Improve congested file locks behaviour (#455)
Instead to immediately give up and sleep, they will sit a while to enter critical region. This is important for "hot" locks. Explanation: currently a "loser" will _immediately give up_ and will go to sleep 100ms if cannot enter critical region, even if winner exits critical region within next 5ms. The retry is needed to ensure that it is retried as much as given time/unit takes, that was before consumed by constant retries+sleeps. The logic still works, as if tryLock spends time/unit waiting on criticalRegion (which is possible only on VERY HIGHLY congested locks), there will be no retry happening. --- https://issues.apache.org/jira/browse/MRESOLVER-521
1 parent 9c1e29d commit 089796b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/FileLockNamedLock.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ public FileLockNamedLock(
8787

8888
@Override
8989
protected boolean doLockShared(final long time, final TimeUnit unit) throws InterruptedException {
90-
return retry(time, unit, RETRY_SLEEP_MILLIS, this::doLockShared, null, false);
90+
return retry(time, unit, RETRY_SLEEP_MILLIS, () -> doLockSharedPerform(time, unit), null, false);
9191
}
9292

9393
@Override
9494
protected boolean doLockExclusively(final long time, final TimeUnit unit) throws InterruptedException {
95-
return retry(time, unit, RETRY_SLEEP_MILLIS, this::doLockExclusively, null, false);
95+
return retry(time, unit, RETRY_SLEEP_MILLIS, () -> doLockExclusivelyPerform(time, unit), null, false);
9696
}
9797

98-
private Boolean doLockShared() {
99-
if (criticalRegion.tryLock()) {
98+
private Boolean doLockSharedPerform(final long time, final TimeUnit unit) throws InterruptedException {
99+
if (criticalRegion.tryLock(time, unit)) {
100100
try {
101101
Deque<Boolean> steps = threadSteps.computeIfAbsent(Thread.currentThread(), k -> new ArrayDeque<>());
102102
FileLock obtainedLock = fileLockRef.get();
@@ -130,8 +130,8 @@ private Boolean doLockShared() {
130130
return null;
131131
}
132132

133-
private Boolean doLockExclusively() {
134-
if (criticalRegion.tryLock()) {
133+
private Boolean doLockExclusivelyPerform(final long time, final TimeUnit unit) throws InterruptedException {
134+
if (criticalRegion.tryLock(time, unit)) {
135135
try {
136136
Deque<Boolean> steps = threadSteps.computeIfAbsent(Thread.currentThread(), k -> new ArrayDeque<>());
137137
FileLock obtainedLock = fileLockRef.get();

0 commit comments

Comments
 (0)