提交 54bbc678 authored 作者: Thomas Mueller's avatar Thomas Mueller

Memory mapped files: There was a bug in version 1.2.139 so that memory mapped…

Memory mapped files: There was a bug in version 1.2.139 so that memory mapped files could only be used together with split
上级 67123266
......@@ -47,29 +47,29 @@ public class FileObjectDiskMapped implements FileObject {
}
private void unMap() throws IOException {
if (mapped != null) {
if (mapped == null) {
return;
}
// first write all data
mapped.force();
// need to dispose old direct buffer, see bug
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038
boolean useSystemGc;
boolean useSystemGc = true;
if (SysProperties.NIO_CLEANER_HACK) {
try {
useSystemGc = false;
Method cleanerMethod = mapped.getClass().getMethod("cleaner");
cleanerMethod.setAccessible(true);
Object cleaner = cleanerMethod.invoke(mapped);
Method clearMethod = cleaner.getClass().getMethod("clear");
clearMethod.invoke(cleaner);
useSystemGc = false;
} catch (Throwable e) {
useSystemGc = true;
// useSystemGc is already true
} finally {
mapped = null;
}
} else {
useSystemGc = true;
}
if (useSystemGc) {
WeakReference<MappedByteBuffer> bufferWeakRef = new WeakReference<MappedByteBuffer>(mapped);
......@@ -85,7 +85,6 @@ public class FileObjectDiskMapped implements FileObject {
}
}
}
}
/**
* Re-map byte buffer into memory, called when file size has changed or file
......@@ -95,7 +94,6 @@ public class FileObjectDiskMapped implements FileObject {
int oldPos = 0;
if (mapped != null) {
oldPos = pos;
mapped.force();
unMap();
}
long length = file.length();
......@@ -141,6 +139,7 @@ public class FileObjectDiskMapped implements FileObject {
try {
mapped.position(pos);
mapped.get(b, off, len);
pos += len;
} catch (IllegalArgumentException e) {
EOFException e2 = new EOFException("EOF");
e2.initCause(e);
......@@ -159,8 +158,11 @@ public class FileObjectDiskMapped implements FileObject {
public void setFileLength(long newLength) throws IOException {
checkFileSizeLimit(newLength);
int oldPos = pos;
unMap();
IOUtils.setLength(file, newLength);
reMap();
pos = (int) Math.min(newLength, oldPos);
}
public void sync() throws IOException {
......@@ -175,6 +177,7 @@ public class FileObjectDiskMapped implements FileObject {
}
mapped.position(pos);
mapped.put(b, off, len);
pos += len;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论