提交 117b640f authored 作者: andrei's avatar andrei

Address synthetic access issues

上级 4ecab392
...@@ -118,7 +118,6 @@ public final class Cursor<K, V> implements Iterator<K> { ...@@ -118,7 +118,6 @@ public final class Cursor<K, V> implements Iterator<K> {
* *
* @param n the number of entries to skip * @param n the number of entries to skip
*/ */
@SuppressWarnings("unchecked")
public void skip(long n) { public void skip(long n) {
if (n < 10) { if (n < 10) {
while (n-- > 0 && hasNext()) { while (n-- > 0 && hasNext()) {
...@@ -126,10 +125,11 @@ public final class Cursor<K, V> implements Iterator<K> { ...@@ -126,10 +125,11 @@ public final class Cursor<K, V> implements Iterator<K> {
} }
} else if(hasNext()) { } else if(hasNext()) {
assert cursorPos != null; assert cursorPos != null;
CursorPos curPos = cursorPos; CursorPos cp = cursorPos;
CursorPos parent; CursorPos parent;
while ((parent = curPos.parent) != null) curPos = parent; while ((parent = cp.parent) != null) cp = parent;
Page root = curPos.page; Page root = cp.page;
@SuppressWarnings("unchecked")
MVMap<K, ?> map = (MVMap<K, ?>) root.map; MVMap<K, ?> map = (MVMap<K, ?>) root.map;
long index = map.getKeyIndex(next()); long index = map.getKeyIndex(next());
last = map.getKey(index + n); last = map.getKey(index + n);
......
...@@ -158,7 +158,7 @@ public final class MVStore { ...@@ -158,7 +158,7 @@ public final class MVStore {
private volatile boolean closed; private volatile boolean closed;
private final FileStore fileStore; final FileStore fileStore;
private final boolean fileStoreIsProvided; private final boolean fileStoreIsProvided;
private final int pageSplitSize; private final int pageSplitSize;
...@@ -170,14 +170,14 @@ public final class MVStore { ...@@ -170,14 +170,14 @@ public final class MVStore {
* It is split in 16 segments. The stack move distance is 2% of the expected * It is split in 16 segments. The stack move distance is 2% of the expected
* number of entries. * number of entries.
*/ */
private final CacheLongKeyLIRS<Page> cache; final CacheLongKeyLIRS<Page> cache;
/** /**
* The page chunk references cache. The default size is 4 MB, and the * The page chunk references cache. The default size is 4 MB, and the
* average size is 2 KB. It is split in 16 segments. The stack move distance * average size is 2 KB. It is split in 16 segments. The stack move distance
* is 2% of the expected number of entries. * is 2% of the expected number of entries.
*/ */
private final CacheLongKeyLIRS<int[]> cacheChunkRef; final CacheLongKeyLIRS<int[]> cacheChunkRef;
/** /**
* The newest chunk. If nothing was stored yet, this field is not set. * The newest chunk. If nothing was stored yet, this field is not set.
...@@ -511,9 +511,8 @@ public final class MVStore { ...@@ -511,9 +511,8 @@ public final class MVStore {
if (map == null) { if (map == null) {
String configAsString = meta.get(MVMap.getMapKey(id)); String configAsString = meta.get(MVMap.getMapKey(id));
if(configAsString != null) { if(configAsString != null) {
HashMap<String, Object> config = new HashMap<>(); HashMap<String, Object> config =
HashMap<String, String> cfg = DataUtils.parseMap(configAsString); new HashMap<String, Object>(DataUtils.parseMap(configAsString));
config.putAll(cfg);
config.put("id", id); config.put("id", id);
map = builder.create(this, config); map = builder.create(this, config);
map.init(); map.init();
...@@ -729,7 +728,8 @@ public final class MVStore { ...@@ -729,7 +728,8 @@ public final class MVStore {
int length = c.len * BLOCK_SIZE; int length = c.len * BLOCK_SIZE;
fileStore.markUsed(start, length); fileStore.markUsed(start, length);
} }
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() : fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse(); assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse();
// read all chunk headers and footers within the retention time, // read all chunk headers and footers within the retention time,
// to detect unwritten data after a power failure // to detect unwritten data after a power failure
} while((newest = verifyLastChunks()) != null); } while((newest = verifyLastChunks()) != null);
...@@ -989,7 +989,7 @@ public final class MVStore { ...@@ -989,7 +989,7 @@ public final class MVStore {
* @param pos the position * @param pos the position
* @return the chunk * @return the chunk
*/ */
private Chunk getChunk(long pos) { Chunk getChunk(long pos) {
Chunk c = getChunkIfFound(pos); Chunk c = getChunkIfFound(pos);
if (c == null) { if (c == null) {
int chunkId = DataUtils.getPageChunkId(pos); int chunkId = DataUtils.getPageChunkId(pos);
...@@ -1203,7 +1203,8 @@ public final class MVStore { ...@@ -1203,7 +1203,8 @@ public final class MVStore {
long filePos = allocateFileSpace(length, !reuseSpace); long filePos = allocateFileSpace(length, !reuseSpace);
c.block = filePos / BLOCK_SIZE; c.block = filePos / BLOCK_SIZE;
c.len = length / BLOCK_SIZE; c.len = length / BLOCK_SIZE;
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() : fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse() + " " + c; assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse() + " " + c;
c.metaRootPos = metaRoot.getPos(); c.metaRootPos = metaRoot.getPos();
// calculate and set the likely next position // calculate and set the likely next position
if (reuseSpace) { if (reuseSpace) {
...@@ -1311,7 +1312,8 @@ public final class MVStore { ...@@ -1311,7 +1312,8 @@ public final class MVStore {
long start = c.block * BLOCK_SIZE; long start = c.block * BLOCK_SIZE;
int length = c.len * BLOCK_SIZE; int length = c.len * BLOCK_SIZE;
fileStore.free(start, length); fileStore.free(start, length);
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() : fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse(); assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse();
} else { } else {
if (c.unused == 0) { if (c.unused == 0) {
c.unused = time; c.unused = time;
...@@ -1370,7 +1372,7 @@ public final class MVStore { ...@@ -1370,7 +1372,7 @@ public final class MVStore {
private ChunkIdsCollector child; private ChunkIdsCollector child;
private int mapId; private int mapId;
private ChunkIdsCollector(int mapId) { ChunkIdsCollector(int mapId) {
this.parent = null; this.parent = null;
this.mapId = mapId; this.mapId = mapId;
} }
...@@ -1448,7 +1450,7 @@ public final class MVStore { ...@@ -1448,7 +1450,7 @@ public final class MVStore {
"Negative position {0}; p={1}, c={2}", filePos, pos, chunk.toString()); "Negative position {0}; p={1}, c={2}", filePos, pos, chunk.toString());
} }
long maxPos = (chunk.block + chunk.len) * BLOCK_SIZE; long maxPos = (chunk.block + chunk.len) * BLOCK_SIZE;
Page.readChildrensPositions(fileStore, pos, filePos, maxPos, childCollector); Page.readChildrenPositions(fileStore, pos, filePos, maxPos, childCollector);
} }
// and cache resulting set of chunk ids // and cache resulting set of chunk ids
if (cacheChunkRef != null) { if (cacheChunkRef != null) {
...@@ -1476,9 +1478,9 @@ public final class MVStore { ...@@ -1476,9 +1478,9 @@ public final class MVStore {
private int[] getChunkIds() { private int[] getChunkIds() {
int chunkIds[] = new int[referenced.size()]; int chunkIds[] = new int[referenced.size()];
int indx = 0; int index = 0;
for (int chunkId : referenced) { for (int chunkId : referenced) {
chunkIds[indx++] = chunkId; chunkIds[index++] = chunkId;
} }
return chunkIds; return chunkIds;
} }
...@@ -2391,7 +2393,8 @@ public final class MVStore { ...@@ -2391,7 +2393,8 @@ public final class MVStore {
long start = c.block * BLOCK_SIZE; long start = c.block * BLOCK_SIZE;
int length = c.len * BLOCK_SIZE; int length = c.len * BLOCK_SIZE;
fileStore.free(start, length); fileStore.free(start, length);
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() : fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse(); assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse();
// overwrite the chunk, // overwrite the chunk,
// so it is not be used later on // so it is not be used later on
WriteBuffer buff = getWriteBuffer(); WriteBuffer buff = getWriteBuffer();
...@@ -2486,9 +2489,7 @@ public final class MVStore { ...@@ -2486,9 +2489,7 @@ public final class MVStore {
"Renaming the meta map is not allowed"); "Renaming the meta map is not allowed");
int id = map.getId(); int id = map.getId();
String oldName = getMapName(id); String oldName = getMapName(id);
if (oldName.equals(newName)) { if (oldName != null && !oldName.equals(newName)) {
return;
}
DataUtils.checkArgument( DataUtils.checkArgument(
!meta.containsKey("name." + newName), !meta.containsKey("name." + newName),
"A map named {0} already exists", newName); "A map named {0} already exists", newName);
...@@ -2497,6 +2498,7 @@ public final class MVStore { ...@@ -2497,6 +2498,7 @@ public final class MVStore {
meta.put("name." + newName, Integer.toHexString(id)); meta.put("name." + newName, Integer.toHexString(id));
markMetaChanged(); markMetaChanged();
} }
}
/** /**
* Remove a map. Please note rolling back this operation does not restore * Remove a map. Please note rolling back this operation does not restore
...@@ -2857,7 +2859,7 @@ public final class MVStore { ...@@ -2857,7 +2859,7 @@ public final class MVStore {
public final long version; public final long version;
public final AtomicInteger counter = new AtomicInteger(); public final AtomicInteger counter = new AtomicInteger();
private TxCounter(long version) { TxCounter(long version) {
this.version = version; this.version = version;
} }
...@@ -3136,7 +3138,5 @@ public final class MVStore { ...@@ -3136,7 +3138,5 @@ public final class MVStore {
// Cast from HashMap<String, String> to HashMap<String, Object> is safe // Cast from HashMap<String, String> to HashMap<String, Object> is safe
return new Builder((HashMap) DataUtils.parseMap(s)); return new Builder((HashMap) DataUtils.parseMap(s));
} }
} }
} }
...@@ -66,16 +66,33 @@ public abstract class Page implements Cloneable ...@@ -66,16 +66,33 @@ public abstract class Page implements Cloneable
private volatile boolean removedInMemory; private volatile boolean removedInMemory;
/** /**
* The estimated number of bytes used per page object. * The estimated number of bytes used per base page.
*/ */
private static final int PAGE_MEMORY = Constants.MEMORY_OBJECT + 2 * Constants.MEMORY_POINTER + Constants.MEMORY_ARRAY + 17; private static final int PAGE_MEMORY =
protected static final int PAGE_NODE_MEMORY = PAGE_MEMORY + Constants.MEMORY_POINTER + 8 + Constants.MEMORY_ARRAY; Constants.MEMORY_OBJECT + // this
protected static final int PAGE_LEAF_MEMORY = PAGE_MEMORY + Constants.MEMORY_POINTER + Constants.MEMORY_ARRAY; 2 * Constants.MEMORY_POINTER + // map, keys
Constants.MEMORY_ARRAY + // Object[] keys
17; // pos, cachedCompare, memory, removedInMemory
/**
* The estimated number of bytes used per empty internal page object.
*/
static final int PAGE_NODE_MEMORY =
PAGE_MEMORY + // super
Constants.MEMORY_POINTER + // children
Constants.MEMORY_ARRAY + // totalCount
8;
/**
* The estimated number of bytes used per empty leaf page.
*/
static final int PAGE_LEAF_MEMORY =
PAGE_MEMORY + // super
Constants.MEMORY_POINTER + // values
Constants.MEMORY_ARRAY; // Object[] values
/** /**
* The estimated number of bytes used per child entry. * The estimated number of bytes used per child entry.
*/ */
protected static final int PAGE_MEMORY_CHILD = Constants.MEMORY_POINTER + 16; // 16 = two longs static final int PAGE_MEMORY_CHILD = Constants.MEMORY_POINTER + 16; // 16 = two longs
/** /**
* An empty object array. * An empty object array.
...@@ -90,16 +107,16 @@ public abstract class Page implements Cloneable ...@@ -90,16 +107,16 @@ public abstract class Page implements Cloneable
private static final PageReference[] SINGLE_EMPTY = { PageReference.EMPTY }; private static final PageReference[] SINGLE_EMPTY = { PageReference.EMPTY };
private Page(MVMap<?, ?> map) { Page(MVMap<?, ?> map) {
this.map = map; this.map = map;
} }
private Page(MVMap<?, ?> map, Page source) { Page(MVMap<?, ?> map, Page source) {
this(map, source.keys); this(map, source.keys);
memory = source.memory; memory = source.memory;
} }
private Page(MVMap<?, ?> map, Object keys[]) { Page(MVMap<?, ?> map, Object keys[]) {
this.map = map; this.map = map;
this.keys = keys; this.keys = keys;
} }
...@@ -221,7 +238,7 @@ public abstract class Page implements Cloneable ...@@ -221,7 +238,7 @@ public abstract class Page implements Cloneable
* @param maxPos the maximum position (the end of the chunk) * @param maxPos the maximum position (the end of the chunk)
* @param collector to report child pages positions to * @param collector to report child pages positions to
*/ */
static void readChildrensPositions(FileStore fileStore, long pos, static void readChildrenPositions(FileStore fileStore, long pos,
long filePos, long maxPos, long filePos, long maxPos,
MVStore.ChunkIdsCollector collector) { MVStore.ChunkIdsCollector collector) {
ByteBuffer buff; ByteBuffer buff;
...@@ -291,9 +308,9 @@ public abstract class Page implements Cloneable ...@@ -291,9 +308,9 @@ public abstract class Page implements Cloneable
/** /**
* Create a copy of this page with potentially different owning map. * Create a copy of this page with potentially different owning map.
* This is used exclusively during bulk map copiing. * This is used exclusively during bulk map copying.
* Child page references for nodes are cleared (repointed to an empty page) * Child page references for nodes are cleared (re-pointed to an empty page)
* to be filled-in later to copiing procedure. This way it can be saved * to be filled-in later to copying procedure. This way it can be saved
* mid-process without tree integrity violation * mid-process without tree integrity violation
* *
* @param map new map to own resulting page * @param map new map to own resulting page
...@@ -468,7 +485,7 @@ public abstract class Page implements Cloneable ...@@ -468,7 +485,7 @@ public abstract class Page implements Cloneable
*/ */
abstract Page split(int at); abstract Page split(int at);
protected final Object[] splitKeys(int aCount, int bCount) { final Object[] splitKeys(int aCount, int bCount) {
assert aCount + bCount <= getKeyCount(); assert aCount + bCount <= getKeyCount();
Object aKeys[] = createKeyStorage(aCount); Object aKeys[] = createKeyStorage(aCount);
Object bKeys[] = createKeyStorage(bCount); Object bKeys[] = createKeyStorage(bCount);
...@@ -549,7 +566,7 @@ public abstract class Page implements Cloneable ...@@ -549,7 +566,7 @@ public abstract class Page implements Cloneable
public abstract void insertNode(int index, Object key, Page childPage); public abstract void insertNode(int index, Object key, Page childPage);
@SuppressWarnings("SuspiciousSystemArraycopy") @SuppressWarnings("SuspiciousSystemArraycopy")
protected final void insertKey(int index, Object key) { final void insertKey(int index, Object key) {
int keyCount = getKeyCount(); int keyCount = getKeyCount();
assert index <= keyCount : index + " > " + keyCount; assert index <= keyCount : index + " > " + keyCount;
Object[] newKeys = new Object[keyCount + 1]; Object[] newKeys = new Object[keyCount + 1];
...@@ -571,16 +588,15 @@ public abstract class Page implements Cloneable ...@@ -571,16 +588,15 @@ public abstract class Page implements Cloneable
public void remove(int index) { public void remove(int index) {
int keyCount = getKeyCount(); int keyCount = getKeyCount();
DataType keyType = map.getKeyType(); DataType keyType = map.getKeyType();
int indx = index; if (index == keyCount) {
if (indx == keyCount) { --index;
--indx;
} }
if(isPersistent()) { if(isPersistent()) {
Object old = getKey(indx); Object old = getKey(index);
addMemory(-keyType.getMemory(old)); addMemory(-keyType.getMemory(old));
} }
Object newKeys[] = new Object[keyCount - 1]; Object newKeys[] = new Object[keyCount - 1];
DataUtils.copyExcept(keys, newKeys, keyCount, indx); DataUtils.copyExcept(keys, newKeys, keyCount, index);
keys = newKeys; keys = newKeys;
} }
...@@ -792,7 +808,7 @@ public abstract class Page implements Cloneable ...@@ -792,7 +808,7 @@ public abstract class Page implements Cloneable
return 0; //getKeyCount(); return 0; //getKeyCount();
} }
protected final void addMemory(int mem) { final void addMemory(int mem) {
memory += mem; memory += mem;
} }
...@@ -826,7 +842,7 @@ public abstract class Page implements Cloneable ...@@ -826,7 +842,7 @@ public abstract class Page implements Cloneable
return new Object[size]; return new Object[size];
} }
protected final Object[] createValueStorage(int size) final Object[] createValueStorage(int size)
{ {
return new Object[size]; return new Object[size];
} }
...@@ -857,7 +873,7 @@ public abstract class Page implements Cloneable ...@@ -857,7 +873,7 @@ public abstract class Page implements Cloneable
this(page, page.getPos(), page.getTotalCount()); this(page, page.getPos(), page.getTotalCount());
} }
private PageReference(long pos, long count) { PageReference(long pos, long count) {
this(null, pos, count); this(null, pos, count);
assert pos != 0; assert pos != 0;
} }
...@@ -889,7 +905,7 @@ public abstract class Page implements Cloneable ...@@ -889,7 +905,7 @@ public abstract class Page implements Cloneable
*/ */
private long totalCount; private long totalCount;
private NonLeaf(MVMap<?, ?> map) { NonLeaf(MVMap<?, ?> map) {
super(map); super(map);
} }
...@@ -899,7 +915,7 @@ public abstract class Page implements Cloneable ...@@ -899,7 +915,7 @@ public abstract class Page implements Cloneable
this.totalCount = totalCount; this.totalCount = totalCount;
} }
private NonLeaf(MVMap<?, ?> map, Object keys[], PageReference children[], long totalCount) { NonLeaf(MVMap<?, ?> map, Object keys[], PageReference children[], long totalCount) {
super(map, keys); super(map, keys);
this.children = children; this.children = children;
this.totalCount = totalCount; this.totalCount = totalCount;
...@@ -945,6 +961,7 @@ public abstract class Page implements Cloneable ...@@ -945,6 +961,7 @@ public abstract class Page implements Cloneable
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
@SuppressWarnings("SuspiciousSystemArraycopy") @SuppressWarnings("SuspiciousSystemArraycopy")
public Page split(int at) { public Page split(int at) {
assert !isSaved(); assert !isSaved();
...@@ -1173,7 +1190,7 @@ public abstract class Page implements Cloneable ...@@ -1173,7 +1190,7 @@ public abstract class Page implements Cloneable
*/ */
private Object values[]; private Object values[];
private Leaf(MVMap<?, ?> map) { Leaf(MVMap<?, ?> map) {
super(map); super(map);
} }
...@@ -1182,7 +1199,7 @@ public abstract class Page implements Cloneable ...@@ -1182,7 +1199,7 @@ public abstract class Page implements Cloneable
this.values = source.values; this.values = source.values;
} }
private Leaf(MVMap<?, ?> map, Object keys[], Object values[]) { Leaf(MVMap<?, ?> map, Object keys[], Object values[]) {
super(map, keys); super(map, keys);
this.values = values; this.values = values;
} }
......
...@@ -26,7 +26,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -26,7 +26,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
/** /**
* The spatial key type. * The spatial key type.
*/ */
private final SpatialDataType keyType; final SpatialDataType keyType;
private boolean quadraticSplit; private boolean quadraticSplit;
...@@ -177,29 +177,29 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -177,29 +177,29 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
private V operate(Page p, Object key, V value, DecisionMaker<? super V> decisionMaker) { private V operate(Page p, Object key, V value, DecisionMaker<? super V> decisionMaker) {
V result = null; V result = null;
if (p.isLeaf()) { if (p.isLeaf()) {
int indx = -1; int index = -1;
int keyCount = p.getKeyCount(); int keyCount = p.getKeyCount();
for (int i = 0; i < keyCount; i++) { for (int i = 0; i < keyCount; i++) {
if (keyType.equals(p.getKey(i), key)) { if (keyType.equals(p.getKey(i), key)) {
indx = i; index = i;
} }
} }
result = indx < 0 ? null : (V)p.getValue(indx); result = index < 0 ? null : (V)p.getValue(index);
Decision decision = decisionMaker.decide(result, value); Decision decision = decisionMaker.decide(result, value);
switch (decision) { switch (decision) {
case ABORT: break; case ABORT: break;
case REMOVE: case REMOVE:
if(indx >= 0) { if(index >= 0) {
p.remove(indx); p.remove(index);
} }
break; break;
case PUT: case PUT:
value = decisionMaker.selectValue(result, value); value = decisionMaker.selectValue(result, value);
if(indx < 0) { if(index < 0) {
p.insertLeaf(p.getKeyCount(), key, value); p.insertLeaf(p.getKeyCount(), key, value);
} else { } else {
p.setKey(indx, key); p.setKey(index, key);
p.setValue(indx, value); p.setValue(index, value);
} }
break; break;
} }
...@@ -608,6 +608,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -608,6 +608,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
* @param valueType the key type * @param valueType the key type
* @return this * @return this
*/ */
@Override
public Builder<V> valueType(DataType valueType) { public Builder<V> valueType(DataType valueType) {
setValueType(valueType); setValueType(valueType);
return this; return this;
......
...@@ -1375,7 +1375,7 @@ public class TestMVStore extends TestBase { ...@@ -1375,7 +1375,7 @@ public class TestMVStore extends TestBase {
// This test tries to cast in bronze some peculiar behaviour, // This test tries to cast in bronze some peculiar behaviour,
// which is rather implementation artifact then intentional. // which is rather implementation artifact then intentional.
// Once store is closed, only one sinle version of the data // Once store is closed, only one single version of the data
// will exists upon re-opening - the latest. // will exists upon re-opening - the latest.
// I hope nobody relies on this "multi-versioning". // I hope nobody relies on this "multi-versioning".
/* /*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论