提交 27e607d4 authored 作者: Thomas Mueller's avatar Thomas Mueller

New system property "h2.syncMethod".

上级 c5c640b9
...@@ -536,6 +536,18 @@ public class SysProperties { ...@@ -536,6 +536,18 @@ public class SysProperties {
*/ */
public static final long SPLIT_FILE_SIZE_SHIFT = getIntSetting("h2.splitFileSizeShift", 30); public static final long SPLIT_FILE_SIZE_SHIFT = getIntSetting("h2.splitFileSizeShift", 30);
/**
* System property <code>h2.syncMethod</code> (default: sync).<br />
* What method to call when closing the database, on checkpoint, and on
* CHECKPOINT SYNC. The following options are supported:
* "sync" (default): RandomAccessFile.getFD().sync();
* "force": RandomAccessFile.getChannel().force(true);
* "forceFalse": RandomAccessFile.getChannel().force(false);
* "": do not call a method (fast but there is a risk of data loss
* on power failure).
*/
public static final String SYNC_METHOD = getStringSetting("h2.syncMethod", "sync");
/** /**
* System property <code>h2.traceIO</code> (default: false).<br /> * System property <code>h2.traceIO</code> (default: false).<br />
* Trace all I/O operations. * Trace all I/O operations.
......
...@@ -10,6 +10,7 @@ import java.io.FileNotFoundException; ...@@ -10,6 +10,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import org.h2.constant.SysProperties;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
/** /**
...@@ -25,7 +26,18 @@ public class FileObjectDisk extends RandomAccessFile implements FileObject { ...@@ -25,7 +26,18 @@ public class FileObjectDisk extends RandomAccessFile implements FileObject {
} }
public void sync() throws IOException { public void sync() throws IOException {
getFD().sync(); String m = SysProperties.SYNC_METHOD;
if ("".equals(m)) {
// do nothing
} else if ("sync".equals(m)) {
getFD().sync();
} else if ("force".equals(m)) {
getChannel().force(true);
} else if ("forceFalse".equals(m)) {
getChannel().force(false);
} else {
getFD().sync();
}
} }
public void setFileLength(long newLength) throws IOException { public void setFileLength(long newLength) throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论