提交 55462095 authored 作者: Thomas Mueller's avatar Thomas Mueller

Opening large database is now faster.

上级 3fbbdb47
......@@ -306,21 +306,18 @@ public class DiskFile implements CacheWriter {
return;
}
stage++;
for (int i = 0, x = 0; i < b2 / 8; i++) {
int mask = in.read();
if (init) {
for (int j = 0; j < 8; j++, x++) {
if (used.get(x) != ((mask & (1 << j)) != 0)) {
throw Message.getInternalError("Redo failure, block: " + x + " expected in-use bit: " + used.get(x));
}
if (init) {
for (int x = 0; x < b2; x += 8) {
int mask = in.read();
if (mask != used.getByte(x)) {
throw Message.getInternalError("Redo failure, block: " + x + " expected: " + used.getByte(x) + " got: " + mask);
}
} else {
for (int j = 0; j < 8; j++, x++) {
if ((mask & (1 << j)) != 0) {
used.set(x);
}
}
}
}
} else {
for (int x = 0; x < b2; x += 8) {
int mask = in.read();
used.setByte(x, mask);
}
}
stage++;
int len = in.readInt();
......
......@@ -104,6 +104,34 @@ public class BitField {
}
return (data[addr] & getBitMask(i)) != 0;
}
/**
* Get the next 8 bits at the given index.
* The index must be a multiple of 8.
*
* @param i the index
* @return the next 8 bits
*/
public int getByte(int i) {
int addr = getAddress(i);
if (addr >= data.length) {
return 0;
}
return (int) (data[addr] >>> (i & (7 << 3)) & 255);
}
/**
* Combine the next 8 bits at the given index with OR.
* The index must be a multiple of 8.
*
* @param i the index
* @param x the next 8 bits (0 - 255)
*/
public void setByte(int i, int x) {
int addr = getAddress(i);
checkCapacity(addr);
data[addr] |= ((long) x) << (i & (7 << 3));
}
/**
* Set bit at the given index to 'true'.
......@@ -138,6 +166,12 @@ public class BitField {
}
private void checkCapacity(int size) {
if (size >= data.length) {
expandCapacity(size);
}
}
private void expandCapacity(int size) {
while (size >= data.length) {
int newSize = data.length == 0 ? 1 : data.length * 2;
long[] d = new long[newSize];
......
......@@ -9,6 +9,7 @@ package org.h2.util;
import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
......@@ -86,7 +87,10 @@ public class NetUtils {
if (ssl) {
return SecureSocketFactory.createSocket(address, port);
}
return new Socket(address, port);
Socket socket = new Socket();
socket.connect(new InetSocketAddress(address, port),
SysProperties.SOCKET_CONNECT_TIMEOUT);
return socket;
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论