Merge branch 'stable-5.13' into stable-6.0
* stable-5.13: If tryLock fails to get the lock another gc has it Fix GcConcurrentTest#testInterruptGc Don't swallow IOException in GC.PidLock#lock Check if FileLock is valid before using or releasing it Change-Id: I708d0936fa86b028e4da4e7e21f332f8b48ad293
This commit is contained in:
commit
238f1693f7
|
@ -14,10 +14,10 @@
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.ClosedByInterruptException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.BrokenBarrierException;
|
import java.util.concurrent.BrokenBarrierException;
|
||||||
|
@ -226,10 +226,8 @@ public void testInterruptGc() throws Exception {
|
||||||
if (cause instanceof CancelledException) {
|
if (cause instanceof CancelledException) {
|
||||||
assertEquals(JGitText.get().operationCanceled,
|
assertEquals(JGitText.get().operationCanceled,
|
||||||
cause.getMessage());
|
cause.getMessage());
|
||||||
} else if (cause instanceof IOException) {
|
} else if (cause instanceof ClosedByInterruptException) {
|
||||||
Throwable cause2 = cause.getCause();
|
// thread was interrupted
|
||||||
assertTrue(cause2 instanceof InterruptedException
|
|
||||||
|| cause2 instanceof ExecutionException);
|
|
||||||
} else {
|
} else {
|
||||||
fail("unexpected exception " + e);
|
fail("unexpected exception " + e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1631,7 +1631,7 @@ private class PidLock implements AutoCloseable {
|
||||||
pidFile = repo.getDirectory().toPath().resolve(GC_PID);
|
pidFile = repo.getDirectory().toPath().resolve(GC_PID);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean lock() {
|
boolean lock() throws IOException {
|
||||||
if (Files.exists(pidFile)) {
|
if (Files.exists(pidFile)) {
|
||||||
Instant mtime = FS.DETECTED
|
Instant mtime = FS.DETECTED
|
||||||
.lastModifiedInstant(pidFile.toFile());
|
.lastModifiedInstant(pidFile.toFile());
|
||||||
|
@ -1649,8 +1649,8 @@ boolean lock() {
|
||||||
f = new RandomAccessFile(pidFile.toFile(), "rw"); //$NON-NLS-1$
|
f = new RandomAccessFile(pidFile.toFile(), "rw"); //$NON-NLS-1$
|
||||||
channel = f.getChannel();
|
channel = f.getChannel();
|
||||||
lock = channel.tryLock();
|
lock = channel.tryLock();
|
||||||
if (lock == null) {
|
if (lock == null || !lock.isValid()) {
|
||||||
failedToLock();
|
gcAlreadyRunning();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
channel.write(ByteBuffer
|
channel.write(ByteBuffer
|
||||||
|
@ -1670,7 +1670,7 @@ boolean lock() {
|
||||||
JGitText.get().closePidLockFailed, pidFile),
|
JGitText.get().closePidLockFailed, pidFile),
|
||||||
e1);
|
e1);
|
||||||
}
|
}
|
||||||
return false;
|
throw e;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1728,7 +1728,7 @@ private String getHostName() {
|
||||||
public void close() {
|
public void close() {
|
||||||
boolean wasLocked = false;
|
boolean wasLocked = false;
|
||||||
try {
|
try {
|
||||||
if (lock != null) {
|
if (lock != null && lock.isValid()) {
|
||||||
lock.release();
|
lock.release();
|
||||||
wasLocked = true;
|
wasLocked = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue