提交 5d9a00a9 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: rename pageSize to pageSplitSize

上级 54c3fc72
...@@ -125,7 +125,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -125,7 +125,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* @return the new sibling * @return the new sibling
*/ */
protected Page splitRootIfNeeded(Page p, long writeVersion) { protected Page splitRootIfNeeded(Page p, long writeVersion) {
if (p.getMemory() <= store.getPageSize() || p.getKeyCount() <= 1) { if (p.getMemory() <= store.getPageSplitSize() || p.getKeyCount() <= 1) {
return p; return p;
} }
int at = p.getKeyCount() / 2; int at = p.getKeyCount() / 2;
...@@ -167,7 +167,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -167,7 +167,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
index++; index++;
} }
Page c = copyOnWrite(p.getChildPage(index), writeVersion); Page c = copyOnWrite(p.getChildPage(index), writeVersion);
if (c.getMemory() > store.getPageSize() && c.getKeyCount() > 1) { if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 1) {
// split on the way down // split on the way down
int at = c.getKeyCount() / 2; int at = c.getKeyCount() / 2;
Object k = c.getKey(at); Object k = c.getKey(at);
...@@ -936,7 +936,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -936,7 +936,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
store.beforeWrite(); store.beforeWrite();
currentWriteVersion = writeVersion; currentWriteVersion = writeVersion;
} }
/** /**
* Check that no write operation is in progress. * Check that no write operation is in progress.
*/ */
...@@ -1138,7 +1138,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1138,7 +1138,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
afterWrite(); afterWrite();
} }
} }
void setWriteVersion(long writeVersion) { void setWriteVersion(long writeVersion) {
if (readOnly) { if (readOnly) {
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
......
...@@ -51,7 +51,7 @@ TestMVStoreDataLoss ...@@ -51,7 +51,7 @@ TestMVStoreDataLoss
TransactionStore: TransactionStore:
MVStore: MVStore:
- rolling docs review: at "Features" - rolling docs review: at "Transactions"
- move setters to the builder, except for setRetainVersion, setReuseSpace, - move setters to the builder, except for setRetainVersion, setReuseSpace,
and settings that are persistent (setStoreVersion) and settings that are persistent (setStoreVersion)
- automated 'kill process' and 'power failure' test - automated 'kill process' and 'power failure' test
...@@ -104,11 +104,13 @@ MVStore: ...@@ -104,11 +104,13 @@ MVStore:
- only retain the last version, unless explicitly set (setRetainVersion) - only retain the last version, unless explicitly set (setRetainVersion)
- support opening (existing) maps by id - support opening (existing) maps by id
- more consistent null handling (keys/values sometimes may be null) - more consistent null handling (keys/values sometimes may be null)
- autocommit (to avoid having to call commit, - autocommit (to avoid having to call commit,
as it could be called too often or it is easily forgotten) as it could be called too often or it is easily forgotten)
- remove features that are not really needed; simplify the code - remove features that are not really needed; simplify the code
possibly using a layering / tool mechanism possibly using a separate layer or tools
- rename "store" to "save", as store collides with storeVersion - rename "store" to "save", as "store" is used in "storeVersion"
- MVStoreTool.dump should dump the data if possible;
possibly using a callback for serialization
*/ */
...@@ -141,7 +143,7 @@ public class MVStore { ...@@ -141,7 +143,7 @@ public class MVStore {
private final String fileName; private final String fileName;
private final char[] filePassword; private final char[] filePassword;
private final int pageSize; private final int pageSplitSize;
private FileChannel file; private FileChannel file;
private FileLock fileLock; private FileLock fileLock;
...@@ -195,7 +197,7 @@ public class MVStore { ...@@ -195,7 +197,7 @@ public class MVStore {
private final Compressor compressor = new CompressLZF(); private final Compressor compressor = new CompressLZF();
private final boolean compress; private final boolean compress;
private final ExceptionListener backgroundExceptionListener; private final ExceptionListener backgroundExceptionListener;
private long currentVersion; private long currentVersion;
...@@ -250,15 +252,15 @@ public class MVStore { ...@@ -250,15 +252,15 @@ public class MVStore {
this.fileName = f; this.fileName = f;
this.readOnly = config.containsKey("readOnly"); this.readOnly = config.containsKey("readOnly");
this.compress = config.containsKey("compress"); this.compress = config.containsKey("compress");
Object o = config.get("pageSize"); Object o = config.get("pageSplitSize");
pageSize = o == null ? 6 * 1024 : (Integer) o; pageSplitSize = o == null ? 6 * 1024 : (Integer) o;
o = config.get("backgroundExceptionListener"); o = config.get("backgroundExceptionListener");
this.backgroundExceptionListener = (ExceptionListener) o; this.backgroundExceptionListener = (ExceptionListener) o;
if (fileName != null) { if (fileName != null) {
o = config.get("cacheSize"); o = config.get("cacheSize");
int mb = o == null ? 16 : (Integer) o; int mb = o == null ? 16 : (Integer) o;
int maxMemoryBytes = mb * 1024 * 1024; int maxMemoryBytes = mb * 1024 * 1024;
int averageMemory = pageSize / 2; int averageMemory = pageSplitSize / 2;
int segmentCount = 16; int segmentCount = 16;
int stackMoveDistance = maxMemoryBytes / averageMemory * 2 / 100; int stackMoveDistance = maxMemoryBytes / averageMemory * 2 / 100;
cache = new CacheLongKeyLIRS<Page>( cache = new CacheLongKeyLIRS<Page>(
...@@ -267,7 +269,7 @@ public class MVStore { ...@@ -267,7 +269,7 @@ public class MVStore {
o = config.get("writeBufferSize"); o = config.get("writeBufferSize");
mb = o == null ? 4 : (Integer) o; mb = o == null ? 4 : (Integer) o;
int writeBufferSize = mb * 1024 * 1024; int writeBufferSize = mb * 1024 * 1024;
maxUnsavedPages = writeBufferSize / pageSize; maxUnsavedPages = writeBufferSize / pageSplitSize;
o = config.get("writeDelay"); o = config.get("writeDelay");
writeDelay = o == null ? 1000 : (Integer) o; writeDelay = o == null ? 1000 : (Integer) o;
} else { } else {
...@@ -742,14 +744,14 @@ public class MVStore { ...@@ -742,14 +744,14 @@ public class MVStore {
if (closed) { if (closed) {
return; return;
} }
closed = true;
if (file == null) {
return;
}
// can not synchronize on this yet, because // can not synchronize on this yet, because
// the thread also synchronized on this, which // the thread also synchronized on this, which
// could result in a deadlock // could result in a deadlock
stopBackgroundThread(); stopBackgroundThread();
closed = true;
if (file == null) {
return;
}
synchronized (this) { synchronized (this) {
try { try {
if (shrinkIfPossible) { if (shrinkIfPossible) {
...@@ -799,7 +801,7 @@ public class MVStore { ...@@ -799,7 +801,7 @@ public class MVStore {
setWriteVersion(v); setWriteVersion(v);
return v; return v;
} }
private void setWriteVersion(long version) { private void setWriteVersion(long version) {
for (MVMap<?, ?> map : maps.values()) { for (MVMap<?, ?> map : maps.values()) {
map.setWriteVersion(version); map.setWriteVersion(version);
...@@ -889,7 +891,7 @@ public class MVStore { ...@@ -889,7 +891,7 @@ public class MVStore {
meta.remove("rollbackOnOpen"); meta.remove("rollbackOnOpen");
retainChunk = null; retainChunk = null;
} }
// the last chunk was not completely correct in the last store() // the last chunk was not completely correct in the last store()
// this needs to be updated now (it's better not to update right after // this needs to be updated now (it's better not to update right after
// storing, because that would modify the meta map again) // storing, because that would modify the meta map again)
...@@ -953,7 +955,7 @@ public class MVStore { ...@@ -953,7 +955,7 @@ public class MVStore {
meta.put("chunk." + c.id, c.asString()); meta.put("chunk." + c.id, c.asString());
meta.setWriteVersion(version); meta.setWriteVersion(version);
// this will (again) modify maxLengthLive, but // this will (again) modify maxLengthLive, but
// the correct value is written in the chunk header // the correct value is written in the chunk header
buff = meta.getRoot().writeUnsavedRecursive(c, buff); buff = meta.getRoot().writeUnsavedRecursive(c, buff);
...@@ -1355,12 +1357,12 @@ public class MVStore { ...@@ -1355,12 +1357,12 @@ public class MVStore {
unsavedPageCount = Math.max(0, unsavedPageCount - 1); unsavedPageCount = Math.max(0, unsavedPageCount - 1);
return; return;
} }
// This could result in a cache miss if the operation is rolled back, // This could result in a cache miss if the operation is rolled back,
// but we don't optimize for rollback. // but we don't optimize for rollback.
// We could also keep the page in the cache, as somebody could read it. // We could also keep the page in the cache, as somebody could read it.
cache.remove(pos); cache.remove(pos);
Chunk c = getChunk(pos); Chunk c = getChunk(pos);
long version = currentVersion; long version = currentVersion;
if (map == meta && currentStoreVersion >= 0) { if (map == meta && currentStoreVersion >= 0) {
...@@ -1407,9 +1409,9 @@ public class MVStore { ...@@ -1407,9 +1409,9 @@ public class MVStore {
boolean getCompress() { boolean getCompress() {
return compress; return compress;
} }
public int getPageSize() { public int getPageSplitSize() {
return pageSize; return pageSplitSize;
} }
public boolean getReuseSpace() { public boolean getReuseSpace() {
...@@ -1613,7 +1615,7 @@ public class MVStore { ...@@ -1613,7 +1615,7 @@ public class MVStore {
meta.rollbackTo(version); meta.rollbackTo(version);
metaChanged = false; metaChanged = false;
boolean loadFromFile = false; boolean loadFromFile = false;
// get the largest chunk with a version // get the largest chunk with a version
// higher or equal the requested version // higher or equal the requested version
int removeChunksNewerThan = -1; int removeChunksNewerThan = -1;
for (int chunkId = lastChunkId;; chunkId--) { for (int chunkId = lastChunkId;; chunkId--) {
...@@ -1666,7 +1668,7 @@ public class MVStore { ...@@ -1666,7 +1668,7 @@ public class MVStore {
m.setRootPos(root, -1); m.setRootPos(root, -1);
} }
} }
} }
currentVersion = version; currentVersion = version;
setWriteVersion(version); setWriteVersion(version);
...@@ -2027,22 +2029,24 @@ public class MVStore { ...@@ -2027,22 +2029,24 @@ public class MVStore {
} }
/** /**
* Set the amount of memory a page should contain at most, in bytes. Larger * Set the amount of memory a page should contain at most, in bytes,
* pages are split. The default is 6 KB. This is not a limit in the page * before it is split. The default is 6 KB. This is not a limit in the
* size (pages with one entry can get larger), it is just the point where * page size, as pages with one entry can get larger. It is just the
* pages are split. * point where pages that contain more than one entry are split.
* *
* @param pageSize the page size * @param pageSplitSize the page size
* @return this
*/ */
public Builder pageSize(int pageSize) { public Builder pageSplitSize(int pageSplitSize) {
return set("pageSize", pageSize); return set("pageSplitSize", pageSplitSize);
} }
/** /**
* Set the listener to be used for exceptions that occur in the background * Set the listener to be used for exceptions that occur in the background
* thread. * thread.
* *
* @param backgroundExceptionListener the listener * @param backgroundExceptionListener the listener
* @return this
*/ */
public Builder backgroundExceptionListener( public Builder backgroundExceptionListener(
ExceptionListener backgroundExceptionListener) { ExceptionListener backgroundExceptionListener) {
......
...@@ -43,12 +43,12 @@ public class TransactionStore { ...@@ -43,12 +43,12 @@ public class TransactionStore {
final MVMap<Long, Object[]> preparedTransactions; final MVMap<Long, Object[]> preparedTransactions;
/** /**
* The undo log. * The undo log.
* <p> * <p>
* If the first entry for a transaction doesn't have a logId * If the first entry for a transaction doesn't have a logId
* of 0, then the transaction is partially committed (which means rollback * of 0, then the transaction is partially committed (which means rollback
* is not possible). Log entries are written before the data is changed * is not possible). Log entries are written before the data is changed
* (write-ahead). * (write-ahead).
* <p> * <p>
* Key: [ transactionId, logId ], value: [ opType, mapId, key, oldValue ]. * Key: [ transactionId, logId ], value: [ opType, mapId, key, oldValue ].
*/ */
...@@ -234,7 +234,7 @@ public class TransactionStore { ...@@ -234,7 +234,7 @@ public class TransactionStore {
/** /**
* Remove a log entry. * Remove a log entry.
* *
* @param t the transaction * @param t the transaction
* @param logId the log id * @param logId the log id
*/ */
...@@ -598,7 +598,7 @@ public class TransactionStore { ...@@ -598,7 +598,7 @@ public class TransactionStore {
void log(int opType, int mapId, Object key, Object oldValue) { void log(int opType, int mapId, Object key, Object oldValue) {
store.log(this, logId++, opType, mapId, key, oldValue); store.log(this, logId++, opType, mapId, key, oldValue);
} }
/** /**
* Remove the last log entry. * Remove the last log entry.
*/ */
......
...@@ -227,9 +227,9 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -227,9 +227,9 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
Page p = copyOnWrite(root, v); Page p = copyOnWrite(root, v);
Object result; Object result;
if (alwaysAdd || get(key) == null) { if (alwaysAdd || get(key) == null) {
if (p.getMemory() > store.getPageSize() && p.getKeyCount() > 1) { if (p.getMemory() > store.getPageSplitSize() && p.getKeyCount() > 1) {
// only possible if this is the root, else we would have split earlier // only possible if this is the root, else we would have split earlier
// (this requires maxPageSize is fixed) // (this requires pageSplitSize is fixed)
long totalCount = p.getTotalCount(); long totalCount = p.getTotalCount();
Page split = split(p, v); Page split = split(p, v);
Object k1 = getBounds(p); Object k1 = getBounds(p);
...@@ -313,7 +313,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -313,7 +313,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
} }
} }
Page c = copyOnWrite(p.getChildPage(index), writeVersion); Page c = copyOnWrite(p.getChildPage(index), writeVersion);
if (c.getMemory() > store.getPageSize() && c.getKeyCount() > 1) { if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 1) {
// split on the way down // split on the way down
Page split = split(c, writeVersion); Page split = split(c, writeVersion);
p = copyOnWrite(p, writeVersion); p = copyOnWrite(p, writeVersion);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论