Remove unnecessary region locking from LockFile

The lock file protocol relies on the atomic creation of a standardized
name in the parent directory of the file being updated.  Since the
creation is atomic, at most one thread in any process can succeed on
this creation, and all others will fail.  While the lock file exists,
that file is private to the thread that is writing it, and no others
will attempt to read or modify the file.

Consequently the use of the region level locks around the file are
unnecessary, and may actually reduce performance when using NFS, SMB,
or some other sort of remote filesystem that supports locking.

Change-Id: Ice312b6fb4fdf9d36c734c3624c6d0537903913b
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-11-10 17:28:14 -08:00
parent e0e7fe531d
commit ed5fe8af9a
1 changed files with 0 additions and 31 deletions

View File

@ -54,8 +54,6 @@
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.text.MessageFormat;
import org.eclipse.jgit.JGitText;
@ -87,8 +85,6 @@ public boolean accept(File dir, String name) {
private final File lck;
private FileLock fLck;
private boolean haveLck;
private FileOutputStream os;
@ -131,23 +127,6 @@ public boolean lock() throws IOException {
haveLck = true;
try {
os = new FileOutputStream(lck);
try {
fLck = os.getChannel().tryLock();
if (fLck == null)
throw new OverlappingFileLockException();
} catch (OverlappingFileLockException ofle) {
// We cannot use unlock() here as this file is not
// held by us, but we thought we created it. We must
// not delete it, as it belongs to some other process.
//
haveLck = false;
try {
os.close();
} catch (IOException ioe) {
// Fail by returning haveLck = false.
}
os = null;
}
} catch (IOException ioe) {
unlock();
throw ioe;
@ -276,7 +255,6 @@ public void write(final byte[] content) throws IOException {
} else {
os.write(content);
}
fLck.release();
os.close();
os = null;
} catch (IOException ioe) {
@ -337,7 +315,6 @@ public void close() throws IOException {
out.flush();
if (fsync)
os.getChannel().force(true);
fLck.release();
out.close();
os = null;
} catch (IOException ioe) {
@ -472,14 +449,6 @@ public long getCommitLastModified() {
*/
public void unlock() {
if (os != null) {
if (fLck != null) {
try {
fLck.release();
} catch (IOException ioe) {
// Huh?
}
fLck = null;
}
try {
os.close();
} catch (IOException ioe) {