提交 2460e391 authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store: new write and read counters in the meta data table.

上级 2a1545d7
......@@ -18,7 +18,11 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The SQL syntax is documented using (railroad) diagrams.
<ul><li>Page store: new write and read counters in the meta data table. Use
SELECT * FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME IN(
'info.FILE_WRITE_TOTAL', 'info.FILE_WRITE', 'info.FILE_READ',
'info.CACHE_MAX_SIZE', 'info.CACHE_SIZE')
</li><li>The SQL syntax is documented using (railroad) diagrams.
The diagrams are HTML.
</li><li>The documentation is no longer available in Japanese because the
translation was too much out of sync. Please use the Google translation instead.
......
......@@ -205,6 +205,10 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Updatable result set on table without primary key or unique index
</li><li>Use LinkedList instead of ArrayList where applicable
</li><li>Support % operator (modulo)
</li><li>Support JMX: create an MBean for each database and server (support JConsole).
See http://thedevcloud.blogspot.com/2008/10/displaying-hsql-database-manager-in.html
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/ManagementFactory.html#getPlatformMBeanServer()
http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html
</li><li>Support 1+'2'=3, '1'+'2'='12' (MS SQL Server compatibility)
</li><li>Support nested transactions
</li><li>Add a benchmark for big databases, and one for many users
......@@ -241,10 +245,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Ability to resize the cache array when resizing the cache
</li><li>Time based cache writing (one second after writing the log)
</li><li>Check state of H2 driver for DDLUtils: https://issues.apache.org/jira/browse/DDLUTILS-185
</li><li>Support JMX: create an MBean for each database and server (support JConsole).
See http://thedevcloud.blogspot.com/2008/10/displaying-hsql-database-manager-in.html
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/ManagementFactory.html#getPlatformMBeanServer()
http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html
</li><li>Index usage for REGEXP LIKE.
</li><li>Compatibility: add a role DBA (like ADMIN).
</li><li>Better support multiple processors for in-memory databases.
......
......@@ -716,7 +716,7 @@ public class LogSystem {
*/
public String getWritePos() {
if (pageStore != null) {
return "" + pageStore.getWriteCount();
return "" + pageStore.getWriteCountTotal();
}
return currentLog.getId() + "/" + currentLog.getPos();
}
......
......@@ -72,7 +72,7 @@ import org.h2.value.ValueString;
* The format of page 1 and 2 is:
* <ul>
* <li>CRC32 of the remaining data: int (0-3)</li>
* <li>write counter (incremented each time the header changes): long (4-11)</li>
* <li>write counter (incremented each time something is written): long (4-11)</li>
* <li>log trunk key: int (12-15)</li>
* <li>log trunk page (0 for none): int (16-19)</li>
* <li>log data page (0 for none): int (20-23)</li>
......@@ -163,7 +163,7 @@ public class PageStore implements CacheWriter {
private String accessMode;
private int pageSize;
private int pageSizeShift;
private long writeCount;
private long writeCountBase, writeCount, readCount;
private int logKey, logFirstTrunkPage, logFirstDataPage;
private Cache cache;
......@@ -240,6 +240,7 @@ public class PageStore implements CacheWriter {
}
file.seek((long) pageId << pageSizeShift);
file.readFullyDirect(buffer, 0, pageSize);
readCount++;
out.write(buffer, 0, pageSize);
return pageId + 1;
} catch (IOException e) {
......@@ -411,7 +412,11 @@ public class PageStore implements CacheWriter {
// the easiest way to remove superfluous entries
freeLists.clear();
trace.debug("pageCount:" + pageCount);
file.setLength((long) pageCount << pageSizeShift);
long newLength = (long) pageCount << pageSizeShift;
if (file.length() != newLength) {
file.setLength(newLength);
writeCount++;
}
}
private void compact(int full) throws SQLException {
......@@ -546,6 +551,7 @@ public class PageStore implements CacheWriter {
file.seek(FileStore.HEADER_LENGTH);
Data page = Data.create(database, new byte[PAGE_SIZE_MIN - FileStore.HEADER_LENGTH]);
file.readFully(page.getBytes(), 0, PAGE_SIZE_MIN - FileStore.HEADER_LENGTH);
readCount++;
setPageSize(page.readInt());
int writeVersion = page.readByte();
int readVersion = page.readByte();
......@@ -573,7 +579,7 @@ public class PageStore implements CacheWriter {
int expected = (int) crc.getValue();
int got = page.readInt();
if (expected == got) {
writeCount = page.readLong();
writeCountBase = page.readLong();
logKey = page.readInt();
logFirstTrunkPage = page.readInt();
logFirstDataPage = page.readInt();
......@@ -616,6 +622,7 @@ public class PageStore implements CacheWriter {
page.writeByte((byte) READ_VERSION);
file.seek(FileStore.HEADER_LENGTH);
file.write(page.getBytes(), 0, pageSize - FileStore.HEADER_LENGTH);
writeCount++;
}
/**
......@@ -649,7 +656,7 @@ public class PageStore implements CacheWriter {
file.write(page.getBytes(), 0, pageSize);
file.seek(pageSize + pageSize);
file.write(page.getBytes(), 0, pageSize);
writeCount++;
// don't increment the write counter, because it was just written
}
/**
......@@ -927,6 +934,7 @@ public class PageStore implements CacheWriter {
}
file.seek((long) pos << pageSizeShift);
file.readFully(page.getBytes(), 0, pageSize);
readCount++;
}
}
......@@ -1430,7 +1438,16 @@ public class PageStore implements CacheWriter {
}
/**
* Get the write count.
* Get the file write count since the database was created.
*
* @return the write count
*/
public long getWriteCountTotal() {
return writeCount + writeCountBase;
}
/**
* Get the file write count since the database was opened.
*
* @return the write count
*/
......@@ -1438,6 +1455,15 @@ public class PageStore implements CacheWriter {
return writeCount;
}
/**
* Get the file read count since the database was opened.
*
* @return the read count
*/
public long getReadCount() {
return readCount;
}
/**
* A table is truncated.
*
......
......@@ -49,6 +49,7 @@ import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence;
import org.h2.schema.TriggerObject;
import org.h2.store.DiskFile;
import org.h2.store.PageStore;
import org.h2.tools.Csv;
import org.h2.util.MathUtils;
import org.h2.util.ObjectArray;
......@@ -868,6 +869,14 @@ public class MetaTable extends Table {
add(rows, "h2.serverCachedObjects", "" + SysProperties.SERVER_CACHED_OBJECTS);
add(rows, "h2.serverResultSetFetchSize", "" + SysProperties.SERVER_RESULT_SET_FETCH_SIZE);
add(rows, "h2.sortNullsHigh", "" + SysProperties.SORT_NULLS_HIGH);
if (database.isPageStoreEnabled() && database.isPersistent()) {
PageStore store = database.getPageStore();
add(rows, "info.FILE_WRITE_TOTAL", "" + store.getWriteCountTotal());
add(rows, "info.FILE_WRITE", "" + store.getWriteCount());
add(rows, "info.FILE_READ", "" + store.getReadCount());
add(rows, "info.CACHE_MAX_SIZE", "" + store.getCache().getMaxSize());
add(rows, "info.CACHE_SIZE", "" + store.getCache().getSize());
}
DiskFile dataFile = database.getDataFile();
if (dataFile != null) {
add(rows, "CACHE_TYPE", dataFile.getCache().getTypeName());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论