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

Address synthetic access issues

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