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

New experimental page store.

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