[
https://issues.apache.org/jira/browse/OAK-1530?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13941540#comment-13941540
]
Thomas Mueller commented on OAK-1530:
-------------------------------------
(I forgot to write, locking a file doesn't work well for NFS, but I assume we
don't target NFS). Patch (untested):
{noformat}
Index: MappedAccess.java
===================================================================
--- MappedAccess.java (revision 1579559)
+++ MappedAccess.java (working copy)
@@ -22,22 +22,42 @@
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
class MappedAccess implements FileAccess {
private final MappedByteBuffer buffer;
+
+ private final FileLock fileLock;
private boolean updated = false;
MappedAccess(RandomAccessFile file, int length) throws IOException {
+ FileLock lock = null;
+ boolean success = false;
try {
long l = file.length();
if (l == 0) { // it's a new file
l = length;
updated = true;
}
- buffer = file.getChannel().map(READ_WRITE, 0, l);
+ FileChannel c = file.getChannel();
+ lock = c.lock();
+ buffer = c.map(READ_WRITE, 0, l);
+ fileLock = lock;
+ success = true;
} finally {
+ if (!success && lock != null) {
+ try {
+ lock.release();
+ } catch (ClosedChannelException e) {
+ // ignore
+ } catch (IOException e) {
+ // ignore
+ }
+ }
file.close();
}
}
@@ -76,6 +96,7 @@
@Override
public void close() throws IOException {
flush();
+ fileLock.release();
}
}
{noformat}
> TarMK thread logs warning
> -------------------------
>
> Key: OAK-1530
> URL: https://issues.apache.org/jira/browse/OAK-1530
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: core, segmentmk
> Affects Versions: 0.18
> Environment: Windows 7, JDK 1.7.0_51 64 Bit
> Reporter: Marcel Reutegger
> Assignee: Jukka Zitting
> Priority: Minor
> Fix For: 0.19
>
>
> From time to time I see warnings from the TarMK flush thread. I'm not sure if
> this is caused by my environment. In any case it would be good to at least
> know why it happens and then fix or document it.
> {noformat}
> 12.03.2014 10:54:45.752 *WARN* [TarMK flush thread: repository]
> org.apache.jackrabbit.oak.plugins.segment.file.FileStore
> Failed to flush the TarMK at repository
> java.io.IOException: The process cannot access the file because another
> process has locked a portion of the file
> at java.nio.MappedByteBuffer.force0(Native Method)
> at java.nio.MappedByteBuffer.force(MappedByteBuffer.java:203)
> at
> org.apache.jackrabbit.oak.plugins.segment.file.MappedAccess.flush(MappedAccess.java:73)
> at
> org.apache.jackrabbit.oak.plugins.segment.file.TarFile.flush(TarFile.java:181)
> at
> org.apache.jackrabbit.oak.plugins.segment.file.FileStore.flush(FileStore.java:225)
> at
> org.apache.jackrabbit.oak.plugins.segment.file.FileStore$1.run(FileStore.java:196)
> at java.lang.Thread.run(Thread.java:744)
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.2#6252)