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

New experimental page store.

上级 a4afb494
......@@ -713,6 +713,9 @@ public class LogSystem {
* @return the write position
*/
public String getWritePos() {
if (pageStore != null) {
return "" + pageStore.getWriteCount();
}
return currentLog.getId() + "/" + currentLog.getPos();
}
......
......@@ -562,19 +562,15 @@ public class PageLog {
}
/**
* Close the log.
* Close without further writing.
*/
void close() throws SQLException {
try {
trace.debug("log close");
if (pageOut != null) {
pageOut.close();
pageOut = null;
}
out = null;
} catch (IOException e) {
throw Message.convertIOException(e, null);
void close() {
trace.debug("log close");
if (pageOut != null) {
pageOut.close();
pageOut = null;
}
out = null;
}
/**
......
......@@ -155,13 +155,7 @@ public class PageOutputStream extends OutputStream {
}
}
public void close() throws IOException {
flush();
try {
freeReserve();
} catch (SQLException e) {
throw Message.convertToIOException(e);
}
public void close() {
store = null;
}
......@@ -187,15 +181,6 @@ public class PageOutputStream extends OutputStream {
return pages * store.getPageSize();
}
private void freeReserve() throws SQLException {
for (int i = 0; i < reservedPages.size(); i++) {
int p = reservedPages.get(i);
store.freePage(p, false, null);
}
reservedPages = new IntArray();
remaining = 0;
}
/**
* Remove a trunk page from the stream.
*
......
......@@ -98,7 +98,11 @@ public class PageStore implements CacheWriter {
// TODO PageData and PageBtree addRowTry: try to simplify
// TODO test running out of disk space (using a special file system)
// TODO check for file size (exception if not exact size expected)
// TODO implement missing code for STORE_BTREE_ROWCOUNT (maybe enable, maybe not)
// TODO implement missing code for STORE_BTREE_ROWCOUNT (maybe enable)
// TODO delete: only log the key
// TODO update: only log the key and changed values
// TODO store dates differently in Data; test moving db to another timezone
// TODO online backup using bsdiff
// TODO when removing DiskFile:
// remove CacheObject.blockCount
......@@ -152,7 +156,7 @@ public class PageStore implements CacheWriter {
private String accessMode;
private int pageSize;
private int pageSizeShift;
private long writeCounter;
private long writeCount;
private int logFirstTrunkPage, logFirstDataPage;
private int cacheSize;
......@@ -321,6 +325,7 @@ public class PageStore implements CacheWriter {
if (!isUsed(i)) {
file.seek((long) i << pageSizeShift);
file.write(empty, 0, pageSize);
writeCount++;
}
}
// TODO shrink file if required here
......@@ -374,7 +379,7 @@ public class PageStore implements CacheWriter {
}
page.reset();
readPage(i, page);
writeCounter = page.readLong();
writeCount = page.readLong();
logFirstTrunkPage = page.readInt();
logFirstDataPage = page.readInt();
CRC32 crc = new CRC32();
......@@ -437,7 +442,7 @@ public class PageStore implements CacheWriter {
private void writeVariableHeader() throws SQLException {
Data page = Data.create(database, pageSize);
page.writeLong(writeCounter);
page.writeLong(writeCount);
page.writeInt(logFirstTrunkPage);
page.writeInt(logFirstDataPage);
CRC32 crc = new CRC32();
......@@ -447,32 +452,26 @@ public class PageStore implements CacheWriter {
file.write(page.getBytes(), 0, pageSize);
file.seek(pageSize + pageSize);
file.write(page.getBytes(), 0, pageSize);
writeCount++;
}
/**
* Close the file without writing anything.
* Close the file without further writing.
*/
public void close() throws SQLException {
Exception closeException = null;
try {
trace.debug("close");
if (log != null) {
log.close();
}
} catch (SQLException e) {
closeException = e;
trace.debug("close");
if (log != null) {
log.close();
log = null;
}
try {
if (file != null) {
if (file != null) {
try {
file.close();
} catch (IOException e) {
throw Message.convert(e);
} finally {
file = null;
}
} catch (IOException e) {
closeException = e;
}
log = null;
file = null;
if (closeException != null) {
throw Message.convert(closeException);
}
}
......@@ -597,6 +596,7 @@ public class PageStore implements CacheWriter {
pageCount += increment;
long newLength = (long) pageCount << pageSizeShift;
file.setLength(newLength);
writeCount++;
fileLength = newLength;
}
......@@ -703,6 +703,7 @@ public class PageStore implements CacheWriter {
synchronized (database) {
file.seek((long) pageId << pageSizeShift);
file.write(data.getBytes(), 0, pageSize);
writeCount++;
}
}
......@@ -1035,6 +1036,15 @@ public class PageStore implements CacheWriter {
return new SearchRow[entryCount];
}
/**
* Get the write count.
*
* @return the write count
*/
public long getWriteCount() {
return writeCount;
}
// TODO implement checksum
// private void updateChecksum(byte[] d, int pos) {
// int ps = pageSize;
......
......@@ -112,26 +112,21 @@ public class WriterThread implements Runnable {
if (database == null) {
break;
}
if (Constants.FLUSH_INDEX_DELAY != 0) {
boolean flush = Constants.FLUSH_INDEX_DELAY != 0;
if (flush) {
flushIndexesIfRequired(database);
}
// checkpoint if required
try {
database.checkpointIfRequired();
} catch (SQLException e) {
TraceSystem traceSystem = database.getTraceSystem();
if (traceSystem != null) {
traceSystem.getTrace(Trace.LOG).error("reconnectCheckpoint", e);
if (database.isFileLockSerialized()) {
database.checkpointIfRequired();
} else {
LogSystem log = database.getLog();
if (log == null) {
break;
}
log.flush();
}
}
LogSystem log = database.getLog();
if (log == null) {
break;
}
try {
log.flush();
} catch (SQLException e) {
TraceSystem traceSystem = database.getTraceSystem();
if (traceSystem != null) {
......
......@@ -346,9 +346,11 @@ public class TableData extends Table implements RecordReader {
Index index = indexes.get(i);
index.truncate(session);
if (SysProperties.CHECK) {
long rc = index.getRowCount(session);
if (rc != 0) {
Message.throwInternalError("rowCount expected 0 got " + rc);
if (!database.isPageStoreEnabled()) {
long rc = index.getRowCount(session);
if (rc != 0) {
Message.throwInternalError("rowCount expected 0 got " + rc);
}
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论