提交 17d6dcba authored 作者: Andrei Tokar's avatar Andrei Tokar

fix bug with allocating redundant array elements

comments and formatting
上级 eb9faf52
......@@ -1038,7 +1038,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/**
* Get version of the map, which is the version of the store,
* at which map was modified last time.
* at the moment when map was modified last time.
*
* @return version
*/
......@@ -1136,10 +1136,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/
final void copyFrom(MVMap<K, V> sourceMap) {
// We are going to cheat a little bit in the copy()
// by setting map's root to an arbitrary nodes
// to allow for just created ones to be saved.
// by temporary setting map's root to some arbitrary nodes.
// This will allow for newly created ones to be saved.
// That's why it's important to preserve all chunks
// created in the process, especially it retention time
// created in the process, especially if retention time
// is set to a lower value, or even 0.
MVStore.TxCounter txCounter = store.registerVersionUsage();
try {
......@@ -1170,6 +1170,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return target;
}
/**
* If map was used in append mode, this method will ensure that append buffer
* is flushed - emptied with all entries inserted into map as a new leaf.
* @return potentially updated RootReference
*/
public RootReference flushAppendBuffer() {
return flushAppendBuffer(null);
}
......@@ -1216,9 +1221,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
p = split;
} else {
Object keys[] = new Object[] { key };
Page.PageReference children[] = new Page.PageReference[store.getKeysPerPage() + 1];
children[0] = new Page.PageReference(p);
children[1] = new Page.PageReference(split);
Page.PageReference children[] = new Page.PageReference[] {
new Page.PageReference(p),
new Page.PageReference(split)};
p = Page.create(this, keys, null, children, p.getTotalCount() + split.getTotalCount(), 0);
}
break;
......@@ -1231,7 +1236,8 @@ public class MVMap<K, V> extends AbstractMap<K, V>
p.setChild(index, split);
p.insertNode(index, key, c);
int keyCount;
if ((keyCount = p.getKeyCount()) <= store.getKeysPerPage() && (p.getMemory() < store.getMaxPageSize() || keyCount <= (p.isLeaf() ? 1 : 2))) {
if ((keyCount = p.getKeyCount()) <= store.getKeysPerPage() &&
(p.getMemory() < store.getMaxPageSize() || keyCount <= (p.isLeaf() ? 1 : 2))) {
break;
}
int at = keyCount - 2;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论