提交 1f7ed15f authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting.

上级 9abf5e1d
......@@ -210,7 +210,7 @@ public class Database implements DataHandler {
Constants.CACHE_SIZE_DEFAULT);
this.cacheSize =
ci.getProperty("CACHE_SIZE", defaultCacheSize);
this.pageSize = ci.getProperty("PAGE_SIZE",
this.pageSize = ci.getProperty("PAGE_SIZE",
Constants.DEFAULT_PAGE_SIZE);
if ("r".equals(accessModeData)) {
readOnly = true;
......
......@@ -250,7 +250,8 @@ public class SysProperties {
Utils.getProperty("h2.maxReconnect", 3);
/**
* System property <code>h2.maxMemoryRows</code> (default: 40000 per GB of available RAM).<br />
* System property <code>h2.maxMemoryRows</code>
* (default: 40000 per GB of available RAM).<br />
* The default maximum number of rows to be kept in memory in a result set.
*/
public static final int MAX_MEMORY_ROWS =
......@@ -534,10 +535,12 @@ public class SysProperties {
public static String getScriptDirectory() {
return Utils.getProperty(H2_SCRIPT_DIRECTORY, "");
}
/**
* This method attempts to auto-scale some of our properties to take advantage of more powerful machines out of the box.
* We assume that our default properties are set correctly for approx. 1G of memory, and scale them up if we have more.
* This method attempts to auto-scale some of our properties to take
* advantage of more powerful machines out of the box. We assume that our
* default properties are set correctly for approx. 1G of memory, and scale
* them up if we have more.
*/
private static int getAutoScaledForMemoryProperty(String key, int defaultValue) {
String s = Utils.getProperty(key, null);
......@@ -550,5 +553,5 @@ public class SysProperties {
}
return Utils.scaleForAvailableMemory(defaultValue);
}
}
......@@ -361,7 +361,7 @@ public class FileStore {
/**
* Get the file name.
*
*
* @return the file name
*/
public String getFileName() {
......
......@@ -299,7 +299,7 @@ public class MVStore {
o = config.get("autoCompactFillRate");
autoCompactFillRate = o == null ? 80 : (Integer) o;
char[] encryptionKey = (char[]) config.get("encryptionKey");
try {
if (!fileStoreIsProvided) {
......@@ -1371,7 +1371,8 @@ public class MVStore {
* Chunks are overwritten irrespective of the current retention time. Before
* overwriting chunks and before resizing the file, syncFile() is called.
*
* @param targetFillRate do nothing if the file store fill rate is higher than this
* @param targetFillRate do nothing if the file store fill rate is higher
* than this
* @param moveSize the number of bytes to move
* @return if anything was written
*/
......@@ -2537,7 +2538,7 @@ public class MVStore {
public Builder autoCommitBufferSize(int kb) {
return set("autoCommitBufferSize", kb);
}
/**
* Set the auto-compact target fill rate. If the average fill rate (the
* percentage of the storage space that contains active data) of the
......@@ -2548,7 +2549,7 @@ public class MVStore {
* <p>
* The default value is 80 (80%). The value 0 disables auto-compacting.
* <p>
*
*
* @param percent the target fill rate
* @return this
*/
......@@ -2673,7 +2674,7 @@ public class MVStore {
* Please note that any kind of store (including an off-heap store) is
* considered a "persistence", while an "in-memory store" means objects
* are not persisted and fully kept in the JVM heap.
*
*
* @param store the file store
* @return this
*/
......
......@@ -283,7 +283,7 @@ public class MVStoreTool {
pw.printf("Chunk length: %d\n", chunkLength);
pw.printf("Chunk count: %d\n", chunks.size());
pw.printf("Used space: %d%%\n", 100 * chunkLength / fileLength);
pw.printf("Chunk fill rate: %d%%\n", maxLength == 0 ? 100 :
pw.printf("Chunk fill rate: %d%%\n", maxLength == 0 ? 100 :
100 * maxLengthLive / maxLength);
for (Entry<Integer, Chunk> e : chunks.entrySet()) {
Chunk c = e.getValue();
......@@ -316,7 +316,7 @@ public class MVStoreTool {
* the new file is renamed to ".newFile", then the old file is removed, and
* the new file is renamed. This might be interrupted, so it's better to
* compactCleanUp before opening a store, in case this method was used.
*
*
* @param fileName the file name
* @param compress whether to compress the data
*/
......@@ -334,13 +334,13 @@ public class MVStoreTool {
FileUtils.move(newName, fileName);
}
}
/**
* Clean up if needed, in a case a compact operation was interrupted due to
* killing the process or a power failure. This will delete temporary files
* (if any), and in case atomic file replacements were not used, rename the
* new file.
*
*
* @param fileName the file name
*/
public static void compactCleanUp(String fileName) {
......@@ -363,6 +363,7 @@ public class MVStoreTool {
*
* @param sourceFileName the name of the source store
* @param targetFileName the name of the target store
* @param compress whether to compress the data
*/
public static void compact(String sourceFileName, String targetFileName, boolean compress) {
MVStore source = new MVStore.Builder().
......@@ -380,7 +381,7 @@ public class MVStoreTool {
target.close();
source.close();
}
/**
* Copy all live pages from the source store to the target store.
*
......
......@@ -333,7 +333,7 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
* @return the row
*/
SearchRow convertToSearchRow(ValueArray key) {
Value[] array = key.getList();
Value[] array = key.getList();
SearchRow searchRow = mvTable.getTemplateRow();
searchRow.setKey((array[array.length - 1]).getLong());
Column[] cols = getColumns();
......
......@@ -124,8 +124,8 @@ public abstract class FilePath {
* Rename a file if this is allowed.
*
* @param newName the new fully qualified file name
* @param atomicReplace whether the move should be atomic, and the target file
* should be replaced if it exists and replacing is possible
* @param atomicReplace whether the move should be atomic, and the target
* file should be replaced if it exists and replacing is possible
*/
public abstract void moveTo(FilePath newName, boolean atomicReplace);
......
......@@ -90,7 +90,8 @@ public class FilePathDisk extends FilePath {
name + " (not found)",
newName.name);
}
// Java 7: use java.nio.file.Files.move(Path source, Path target, CopyOption... options)
// Java 7: use java.nio.file.Files.move(Path source, Path target,
// CopyOption... options)
// with CopyOptions "REPLACE_EXISTING" and "ATOMIC_MOVE".
if (atomicReplace) {
boolean ok = oldFile.renameTo(newFile);
......
......@@ -49,7 +49,7 @@ public class FilePathMem extends FilePath {
@Override
public void moveTo(FilePath newName, boolean atomicReplace) {
synchronized (MEMORY_FILES) {
if (!atomicReplace && !newName.name.equals(name) &&
if (!atomicReplace && !newName.name.equals(name) &&
MEMORY_FILES.containsKey(newName.name)) {
throw DbException.get(ErrorCode.FILE_RENAME_FAILED_2,
new String[] { name, newName + " (exists)" });
......
......@@ -48,7 +48,7 @@ public class FilePathNioMem extends FilePath {
@Override
public void moveTo(FilePath newName, boolean atomicReplace) {
synchronized (MEMORY_FILES) {
if (!atomicReplace && !name.equals(newName.name) &&
if (!atomicReplace && !name.equals(newName.name) &&
MEMORY_FILES.containsKey(newName.name)) {
throw DbException.get(ErrorCode.FILE_RENAME_FAILED_2,
new String[] { name, newName + " (exists)" });
......
......@@ -104,19 +104,19 @@ public class FileUtils {
/**
* Rename a file if this is allowed. This method is similar to Java 7
* <code>java.nio.file.Files.move</code>.
*
*
* @param source the old fully qualified file name
* @param target the new fully qualified file name
*/
public static void move(String source, String target) {
FilePath.get(source).moveTo(FilePath.get(target), false);
}
/**
* Rename a file if this is allowed, and try to atomically replace an
* existing file. This method is similar to Java 7
* <code>java.nio.file.Files.move</code>.
*
*
* @param source the old fully qualified file name
* @param target the new fully qualified file name
*/
......
......@@ -736,11 +736,12 @@ public class Utils {
}
return defaultValue;
}
/**
* Scale the value with the available memory. If 1 GB of RAM is available,
* the value is returned, if 2 GB are available, then twice the value, and so on.
*
* the value is returned, if 2 GB are available, then twice the value, and
* so on.
*
* @param value the value to scale
* @return the scaled value
*/
......@@ -753,12 +754,14 @@ public class Utils {
try {
OperatingSystemMXBean mxBean = ManagementFactory
.getOperatingSystemMXBean();
// this method is only available on the class com.sun.management.OperatingSystemMXBean, which mxBean
// is an instance of under the Oracle JDK, but it is not present on Android and other JDK's
// this method is only available on the class
// com.sun.management.OperatingSystemMXBean, which mxBean
// is an instance of under the Oracle JDK, but it is not present on
// Android and other JDK's
Method method = Class.forName(
"com.sun.management.OperatingSystemMXBean").
getMethod("getTotalPhysicalMemorySize");
long physicalMemorySize = ((Number) method.invoke(mxBean)).longValue();
long physicalMemorySize = ((Number) method.invoke(mxBean)).longValue();
return (int) (value * physicalMemorySize / (1024 * 1024 * 1024));
} catch (Exception e) {
// ignore
......
......@@ -111,17 +111,17 @@ public class TestMVStore extends TestBase {
// longer running tests
testLargerThan2G();
}
private void testProvidedFileStoreNotOpenedAndClosed() {
final AtomicInteger openClose = new AtomicInteger();
FileStore fileStore = new OffHeapStore() {
@Override
public void open(String fileName, boolean readOnly, char[] encryptionKey) {
openClose.incrementAndGet();
super.open(fileName, readOnly, encryptionKey);
}
@Override
public void close() {
openClose.incrementAndGet();
......
......@@ -75,7 +75,7 @@ public class TestMVStoreTool extends TestBase {
}
}
s.close();
MVStoreTool.compact(fileName, fileName + ".new", false);
MVStoreTool.compact(fileName, fileName + ".new.compress", true);
MVStore s1 = new MVStore.Builder().
......@@ -92,7 +92,8 @@ public class TestMVStoreTool extends TestBase {
long size1 = FileUtils.size(fileName);
long size2 = FileUtils.size(fileName + ".new");
long size3 = FileUtils.size(fileName + ".new.compress");
assertTrue("size1: " + size1 + " size2: " + size2 + " size3: " + size3, size2 < size1 && size3 < size2);
assertTrue("size1: " + size1 + " size2: " + size2 + " size3: " + size3,
size2 < size1 && size3 < size2);
MVStoreTool.compact(fileName, false);
assertEquals(size2, FileUtils.size(fileName));
MVStoreTool.compact(fileName, true);
......@@ -112,7 +113,7 @@ public class TestMVStoreTool extends TestBase {
Object x = mb.get(e.getKey());
assertEquals(e.getValue().toString(), x.toString());
}
} else {
MVMap<?, ?> ma = a.openMap(mapName);
MVMap<?, ?> mb = a.openMap(mapName);
......
......@@ -350,33 +350,33 @@ public class TestFileSystem extends TestBase {
}
private void testReadOnly(final String f) throws IOException {
new AssertThrows(IOException.class) {
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
FileUtils.newOutputStream(f, false);
}};
new AssertThrows(DbException.class) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(f, f);
}};
new AssertThrows(DbException.class) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(f, f);
}};
new AssertThrows(IOException.class) {
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
FileUtils.createTempFile(f, ".tmp", false, false);
}};
final FileChannel channel = FileUtils.open(f, "r");
new AssertThrows(IOException.class) {
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
channel.write(ByteBuffer.allocate(1));
}};
new AssertThrows(IOException.class) {
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
channel.truncate(0);
......@@ -419,12 +419,12 @@ public class TestFileSystem extends TestBase {
FileUtils.delete(fileName);
}
if (FileUtils.createFile(fileName)) {
new AssertThrows(DbException.class) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.createDirectory(fileName);
}};
new AssertThrows(DbException.class) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.createDirectories(fileName + "/test");
......@@ -442,14 +442,14 @@ public class TestFileSystem extends TestBase {
if (FileUtils.createFile(fileName)) {
FileUtils.move(fileName, fileName2);
FileUtils.createFile(fileName);
new AssertThrows(DbException.class) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(fileName2, fileName);
}};
FileUtils.delete(fileName);
FileUtils.delete(fileName2);
new AssertThrows(DbException.class) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(fileName, fileName2);
......@@ -464,32 +464,32 @@ public class TestFileSystem extends TestBase {
}
if (FileUtils.createFile(fileName)) {
final FileChannel channel = FileUtils.open(fileName, "rw");
new AssertThrows(UnsupportedOperationException.class) {
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.map(MapMode.PRIVATE, 0, channel.size());
}};
new AssertThrows(UnsupportedOperationException.class) {
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.read(new ByteBuffer[]{ByteBuffer.allocate(10)}, 0, 0);
}};
new AssertThrows(UnsupportedOperationException.class) {
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.write(new ByteBuffer[]{ByteBuffer.allocate(10)}, 0, 0);
}};
new AssertThrows(UnsupportedOperationException.class) {
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.transferFrom(channel, 0, 0);
}};
new AssertThrows(UnsupportedOperationException.class) {
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.transferTo(0, 0, channel);
}};
new AssertThrows(UnsupportedOperationException.class) {
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.lock();
......
......@@ -761,3 +761,4 @@ reinstated uninteresting dead defendant doctrines beat factual fair suspended
exploit noise ongoing disclaimers shrinks remedy party desirable timely construe
deque synchronizers affero kevent nikolaj hohmuth grajcar jens fogh hostnames
operate resized jni yjp ownable starvation reaper biased introduce epoll hangs
compaction aggressive powerful
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论