提交 9ac5a876 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 4445abd7
......@@ -43,7 +43,7 @@ public class ConnectionInfo {
String[] connectionTime = new String[]{
"PASSWORD", "USER", "STORAGE", "FILE_LOCK", "CIPHER", "DB_CLOSE_ON_EXIT",
"IGNORE_UNKNOWN_SETTINGS", "IFEXISTS", "RECOVER", "CREATE", "CACHE_TYPE",
"WRITE_MODE_LOG", "WRITE_MODE_DATA"
"ACCESS_MODE_LOG", "ACCESS_MODE_DATA"
};
for(int i=0; i<connectionTime.length; i++) {
String key = connectionTime[i];
......
......@@ -67,8 +67,8 @@ package org.h2.engine;
*/
public class Constants {
public static final int BUILD_ID = 46;
private static final String BUILD = "2007-04-29";
public static final int BUILD_ID = 47;
private static final String BUILD = "2007-06-13";
public static final int VERSION_MAJOR = 1;
public static final int VERSION_MINOR = 0;
......@@ -244,6 +244,7 @@ public class Constants {
public static final int OBJECT_CACHE_SIZE = getIntSetting("h2.objectCacheSize", 1024);
public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = getIntSetting("h2.objectCacheMaxPerElementSize", 4096);
public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/");
public static int MAX_FILE_RETRY = Math.max(1, getIntSetting("h2.maxFileRetry", 16));
public static boolean getBooleanSetting(String name, boolean defaultValue) {
String s = System.getProperty(name);
......
......@@ -135,7 +135,7 @@ public class Database implements DataHandler {
private String cacheType;
private boolean indexSummaryValid = true;
private Object lobSyncObject = new Object();
private String writeModeLog, writeModeData;
private String accessModeLog, accessModeData;
public static void setInitialPowerOffCount(int count) {
initialPowerOffCount = count;
......@@ -174,7 +174,7 @@ public class Database implements DataHandler {
}
throw Message.getSQLException(Message.FILE_VERSION_ERROR_1, fileName);
} catch(IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, fileName);
}
}
......@@ -313,11 +313,11 @@ public class Database implements DataHandler {
}
private void openFileData() throws SQLException {
fileData = new DiskFile(this, databaseName+Constants.SUFFIX_DATA_FILE, writeModeData, true, true, Constants.DEFAULT_CACHE_SIZE);
fileData = new DiskFile(this, databaseName+Constants.SUFFIX_DATA_FILE, accessModeData, true, true, Constants.DEFAULT_CACHE_SIZE);
}
private void openFileIndex() throws SQLException {
fileIndex = new DiskFile(this, databaseName+Constants.SUFFIX_INDEX_FILE, "rw", false, logIndexChanges, Constants.DEFAULT_CACHE_SIZE_INDEX);
fileIndex = new DiskFile(this, databaseName+Constants.SUFFIX_INDEX_FILE, accessModeData, false, logIndexChanges, Constants.DEFAULT_CACHE_SIZE_INDEX);
}
public DataPage getDataPage() {
......@@ -349,8 +349,8 @@ public class Database implements DataHandler {
this.databaseShortName = parseDatabaseShortName();
this.cipher = cipher;
String lockMethodName = ci.removeProperty("FILE_LOCK", null);
this.writeModeLog = ci.removeProperty("WRITE_MODE_LOG", "rw").toLowerCase();
this.writeModeData = ci.removeProperty("WRITE_MODE_DATA", "rw").toLowerCase();
this.accessModeLog = ci.removeProperty("ACCESS_MODE_LOG", "rw").toLowerCase();
this.accessModeData = ci.removeProperty("ACCESS_MODE_DATA", "rw").toLowerCase();
this.fileLockMethod = FileLock.getFileLockMethod(lockMethodName);
this.textStorage = ci.getTextStorage();
this.databaseURL = ci.getURL();
......@@ -426,7 +426,7 @@ public class Database implements DataHandler {
lock.lock(databaseName+Constants.SUFFIX_LOCK_FILE, fileLockMethod == FileLock.LOCK_SOCKET);
}
deleteOldTempFiles();
log = new LogSystem(this, databaseName, readOnly);
log = new LogSystem(this, databaseName, readOnly, accessModeLog);
openFileData();
openFileIndex();
if(!readOnly) {
......@@ -449,7 +449,7 @@ public class Database implements DataHandler {
writer = WriterThread.create(this, writeDelay);
} else {
traceSystem = new TraceSystem(null);
log = new LogSystem(null, null, false);
log = new LogSystem(null, null, false, null);
}
systemUser = new User(this, 0, Constants.DBA_NAME, true);
mainSchema = new Schema(this, 0, Constants.SCHEMA_MAIN, systemUser, true);
......@@ -1011,7 +1011,7 @@ public class Database implements DataHandler {
boolean inTempDir = readOnly;
return FileUtils.createTempFile(databaseName, Constants.SUFFIX_TEMP_FILE, true, inTempDir);
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, databaseName);
}
}
......@@ -1490,8 +1490,4 @@ public class Database implements DataHandler {
return lobSyncObject;
}
public String getWriteModeLog() {
return writeModeLog;
}
}
......@@ -325,7 +325,7 @@ public class SessionRemote implements SessionInterface, DataHandler {
try {
return FileUtils.createTempFile(databaseName, Constants.SUFFIX_TEMP_FILE, true, false);
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, databaseName);
}
}
......
......@@ -242,7 +242,7 @@ public class Message {
public static final int IO_EXCEPTION_1 = 90028;
public static final int NOT_ON_UPDATABLE_ROW = 90029;
public static final int FILE_CORRUPTED_1 = 90030;
public static final int IO_EXCEPTION_2 = 90031;
public static final int USER_NOT_FOUND_1 = 90032;
public static final int USER_ALREADY_EXISTS_1 = 90033;
public static final int LOG_FILE_ERROR_1 = 90034;
......@@ -369,6 +369,14 @@ public class Message {
}
return Message.getSQLException(Message.GENERAL_ERROR_1, new String[]{e.toString()}, e);
}
public static SQLException convertIOException(IOException e, String message) {
if(message == null) {
return Message.getSQLException(Message.IO_EXCEPTION_1, new String[]{e.toString()}, e);
} else {
return Message.getSQLException(Message.IO_EXCEPTION_2, new String[]{e.toString(), message}, e);
}
}
public static Error getInternalError() {
return getInternalError("unexpected code path");
......
......@@ -13,7 +13,7 @@
42000=Syntax error in SQL statement {0}
42001=Syntax error in SQL statement {0}; expected {1}
42S01=Table {0} already exists
42S02=Table {0} not found. Possible reasons: typo; the table is in another database or schema; case mismatch (use double quotes)
42S02=Table {0} not found.
42S11=Index {0} already exists
42S12=Index {0} not found
42S21=Duplicate column name {0}
......@@ -40,7 +40,7 @@
90017=Attempt to define a second primary key
90018=The connection was not closed by the application and is garbage collected
90019=Cannot drop the current user
90020=Database may be already in use: {0}. Possible solution: use the server mode
90020=Database may be already in use: {0}. Possible solutions: close all other connection(s); use the server mode
90021=Data conversion error converting {0}
90022=Function {0} not found
90023=Column {0} must not be nullable
......@@ -51,7 +51,7 @@
90028=IO Exception: {0}
90029=Currently not on an updatable row
90030=File corrupted while reading record: {0}. Possible solution: use the recovery tool
90031=IO Exception: {0}; {1}
90032=User {0} not found
90033=User {0} already exists
90034=Log file error: {0}
......
......@@ -120,7 +120,7 @@ public class ResultRemote implements ResultInterface {
session.traceOperation("RESULT_RESET", id);
transfer.writeInt(SessionRemote.RESULT_RESET).writeInt(id).flush();
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, null);
}
}
}
......@@ -236,7 +236,7 @@ public class ResultRemote implements ResultInterface {
return null;
}
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, null);
}
}
}
......
......@@ -117,8 +117,8 @@ Initial Developer: H2 Group
</table>
</form>
<p>
<form name="shutdown" method="post" action="/adminShutdown.do?jsessionid=${sessionId}">
<input type="submit" class="button" value="${text.adminShutdown}" />
</form>
<form name="shutdown" method="post" action="/adminShutdown.do?jsessionid=${sessionId}">
<input type="submit" class="button" value="${text.adminShutdown}" />
</form>
</p>
</body></html>
\ No newline at end of file
......@@ -119,16 +119,12 @@ public class DiskFile implements CacheWriter {
}
private void create() throws SQLException {
try {
file = database.openFile(fileName, mode, false);
DataPage header = DataPage.create(database, OFFSET);
file.seek(FileStore.HEADER_LENGTH);
header.fill(OFFSET);
header.updateChecksum();
file.write(header.getBytes(), 0, OFFSET);
} catch (Exception e) {
throw Message.convert(e);
}
file = database.openFile(fileName, mode, false);
DataPage header = DataPage.create(database, OFFSET);
file.seek(FileStore.HEADER_LENGTH);
header.fill(OFFSET);
header.updateChecksum();
file.write(header.getBytes(), 0, OFFSET);
}
private void freeUnusedPages() throws SQLException {
......@@ -275,43 +271,39 @@ public class DiskFile implements CacheWriter {
s.setRecordCount(0);
}
}
try {
int blockHeaderLen = Math.max(Constants.FILE_BLOCK_SIZE, 2 * rowBuff.getIntLen());
byte[] buff = new byte[blockHeaderLen];
DataPage s = DataPage.create(database, buff);
long time = 0;
for (int i = 0; i < fileBlockCount;) {
long t2 = System.currentTimeMillis();
if(t2 > time + 10) {
time = t2;
database.setProgress(DatabaseEventListener.STATE_SCAN_FILE, this.fileName, i, fileBlockCount);
}
go(i);
file.readFully(buff, 0, blockHeaderLen);
s.reset();
int blockCount = s.readInt();
if(Constants.CHECK && blockCount < 0) {
int blockHeaderLen = Math.max(Constants.FILE_BLOCK_SIZE, 2 * rowBuff.getIntLen());
byte[] buff = new byte[blockHeaderLen];
DataPage s = DataPage.create(database, buff);
long time = 0;
for (int i = 0; i < fileBlockCount;) {
long t2 = System.currentTimeMillis();
if(t2 > time + 10) {
time = t2;
database.setProgress(DatabaseEventListener.STATE_SCAN_FILE, this.fileName, i, fileBlockCount);
}
go(i);
file.readFully(buff, 0, blockHeaderLen);
s.reset();
int blockCount = s.readInt();
if(Constants.CHECK && blockCount < 0) {
throw Message.getInternalError();
}
if(blockCount == 0) {
setUnused(i, 1);
i++;
} else {
int id = s.readInt();
if(Constants.CHECK && id < 0) {
throw Message.getInternalError();
}
if(blockCount == 0) {
setUnused(i, 1);
i++;
} else {
int id = s.readInt();
if(Constants.CHECK && id < 0) {
throw Message.getInternalError();
}
Storage storage = database.getStorage(id, this);
setBlockOwner(storage, i, blockCount, true);
storage.incrementRecordCount();
i += blockCount;
}
Storage storage = database.getStorage(id, this);
setBlockOwner(storage, i, blockCount, true);
storage.incrementRecordCount();
i += blockCount;
}
database.setProgress(DatabaseEventListener.STATE_SCAN_FILE, this.fileName, fileBlockCount, fileBlockCount);
init = true;
} catch (Exception e) {
throw Message.convert(e);
}
database.setProgress(DatabaseEventListener.STATE_SCAN_FILE, this.fileName, fileBlockCount, fileBlockCount);
init = true;
}
synchronized void flush() throws SQLException {
......@@ -565,8 +557,8 @@ public class DiskFile implements CacheWriter {
cache.clear();
file.close();
FileUtils.delete(fileName);
} catch (Exception e) {
throw Message.convert(e);
} catch (IOException e) {
throw Message.convertIOException(e, fileName);
} finally {
file = null;
fileName = null;
......@@ -590,22 +582,18 @@ public class DiskFile implements CacheWriter {
writeCount++;
Record record = (Record) obj;
synchronized(this) {
try {
int blockCount = record.getBlockCount();
record.prepareWrite();
go(record.getPos());
DataPage buff = rowBuff;
buff.reset();
buff.checkCapacity(blockCount * BLOCK_SIZE);
buff.writeInt(blockCount);
buff.writeInt(record.getStorageId());
record.write(buff);
buff.fill(blockCount * BLOCK_SIZE);
buff.updateChecksum();
file.write(buff.getBytes(), 0, buff.length());
} catch (Exception e) {
throw Message.convert(e);
}
int blockCount = record.getBlockCount();
record.prepareWrite();
go(record.getPos());
DataPage buff = rowBuff;
buff.reset();
buff.checkCapacity(blockCount * BLOCK_SIZE);
buff.writeInt(blockCount);
buff.writeInt(record.getStorageId());
record.write(buff);
buff.fill(blockCount * BLOCK_SIZE);
buff.updateChecksum();
file.write(buff.getBytes(), 0, buff.length());
}
record.setChanged(false);
}
......@@ -618,54 +606,42 @@ public class DiskFile implements CacheWriter {
}
synchronized void updateRecord(Session session, Record record) throws SQLException {
try {
record.setChanged(true);
int pos = record.getPos();
Record old = (Record) cache.update(pos, record);
if(Constants.CHECK) {
if(old != null) {
if(old!=record) {
database.checkPowerOff();
throw Message.getInternalError("old != record old="+old+" new="+record);
}
int blockCount = record.getBlockCount();
for(int i=0; i<blockCount; i++) {
if(deleted.get(i + pos)) {
throw Message.getInternalError("update marked as deleted: " + (i+pos));
}
record.setChanged(true);
int pos = record.getPos();
Record old = (Record) cache.update(pos, record);
if(Constants.CHECK) {
if(old != null) {
if(old!=record) {
database.checkPowerOff();
throw Message.getInternalError("old != record old="+old+" new="+record);
}
int blockCount = record.getBlockCount();
for(int i=0; i<blockCount; i++) {
if(deleted.get(i + pos)) {
throw Message.getInternalError("update marked as deleted: " + (i+pos));
}
}
}
if(logChanges) {
log.add(session, this, record);
}
} catch (Exception e) {
throw Message.convert(e);
}
if(logChanges) {
log.add(session, this, record);
}
}
synchronized void writeDirectDeleted(int recordId, int blockCount) throws SQLException {
synchronized(this) {
try {
go(recordId);
for(int i=0; i<blockCount; i++) {
file.write(freeBlock.getBytes(), 0, freeBlock.length());
}
free(recordId, blockCount);
} catch (Exception e) {
throw Message.convert(e);
go(recordId);
for(int i=0; i<blockCount; i++) {
file.write(freeBlock.getBytes(), 0, freeBlock.length());
}
free(recordId, blockCount);
}
}
synchronized void writeDirect(Storage storage, int pos, byte[] data, int offset) throws SQLException {
try {
go(pos);
file.write(data, offset, BLOCK_SIZE);
setBlockOwner(storage, pos, 1, true);
} catch (Exception e) {
throw Message.convert(e);
}
go(pos);
file.write(data, offset, BLOCK_SIZE);
setBlockOwner(storage, pos, 1, true);
}
public synchronized int copyDirect(int pos, OutputStream out) throws SQLException {
......@@ -710,8 +686,8 @@ public class DiskFile implements CacheWriter {
}
out.write(s.getBytes(), 0, blockCount * blockSize);
return pos + blockCount;
} catch (Exception e) {
throw Message.convert(e);
} catch (IOException e) {
throw Message.convertIOException(e, fileName);
}
}
......
......@@ -157,7 +157,9 @@ public class FileLock {
private void lockFile() throws SQLException {
method = FILE;
properties = new Properties();
String random = ByteUtils.convertBytesToString(RandomUtils.getSecureBytes(RANDOM_BYTES));
byte[] bytes = RandomUtils.getSecureBytes(RANDOM_BYTES);
System.out.println("lockFile 2b" + fileName);
String random = ByteUtils.convertBytesToString(bytes);
properties.setProperty("id", Long.toHexString(System.currentTimeMillis())+random);
if (!FileUtils.createNewFile(fileName)) {
waitUntilOld();
......
......@@ -69,7 +69,7 @@ public class FileStore {
}
fileLength = file.length();
} catch(IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, "name: " + name +" mode: " + mode);
}
}
......@@ -177,7 +177,7 @@ public class FileStore {
try {
file.readFully(b, off, len);
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, name);
}
filePos += len;
}
......@@ -192,7 +192,7 @@ public class FileStore {
filePos = pos;
}
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, name);
}
}
......@@ -216,10 +216,10 @@ public class FileStore {
try {
file.write(b, off, len);
} catch (IOException e2) {
throw Message.convert(e2);
throw Message.convertIOException(e2, name);
}
} else {
throw Message.convert(e);
throw Message.convertIOException(e, name);
}
}
filePos += len;
......@@ -263,10 +263,10 @@ public class FileStore {
try {
FileUtils.setLength(file, newLength);
} catch (IOException e2) {
throw Message.convert(e2);
throw Message.convertIOException(e2, name);
}
} else {
throw Message.convert(e);
throw Message.convertIOException(e, name);
}
}
}
......@@ -288,7 +288,7 @@ public class FileStore {
}
return len;
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, name);
}
}
......@@ -299,7 +299,7 @@ public class FileStore {
throw Message.getInternalError();
}
} catch (IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, name);
}
}
return filePos;
......
......@@ -32,7 +32,7 @@ public class FileStoreInputStream extends InputStream {
fillBuffer();
}
} catch(IOException e) {
throw Message.convert(e);
throw Message.convertIOException(e, store.name);
}
}
......
......@@ -59,7 +59,7 @@ public class LogFile {
this.id = id;
this.fileNamePrefix = fileNamePrefix;
fileName = getFileName();
file = log.getDatabase().openFile(fileName, database.getWriteModeLog(), false);
file = log.getDatabase().openFile(fileName, log.getAccessMode(), false);
rowBuff = log.getRowBuffer();
buffer = new byte[BUFFER_SIZE];
unwritten = new ObjectArray();
......@@ -366,7 +366,7 @@ public class LogFile {
}
} catch (IOException e) {
if(closeException == null) {
closeException = Message.convert(e);
closeException = Message.convertIOException(e, fileName);
}
}
file = null;
......
......@@ -39,10 +39,12 @@ public class LogSystem {
private boolean disabled;
private int keepFiles;
private boolean closed;
private String accessMode;
public LogSystem(Database database, String fileNamePrefix, boolean readOnly) throws SQLException {
public LogSystem(Database database, String fileNamePrefix, boolean readOnly, String accessMode) throws SQLException {
this.database = database;
this.readOnly = readOnly;
this.accessMode = accessMode;
if (database == null || readOnly) {
return;
}
......@@ -465,4 +467,8 @@ public class LogSystem {
keepFiles += incrementDecrement;
}
String getAccessMode() {
return accessMode;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论