提交 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> ...@@ -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, * 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 * @return version
*/ */
...@@ -1136,10 +1136,10 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1136,10 +1136,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/ */
final void copyFrom(MVMap<K, V> sourceMap) { final void copyFrom(MVMap<K, V> sourceMap) {
// We are going to cheat a little bit in the copy() // We are going to cheat a little bit in the copy()
// by setting map's root to an arbitrary nodes // by temporary setting map's root to some arbitrary nodes.
// to allow for just created ones to be saved. // This will allow for newly created ones to be saved.
// That's why it's important to preserve all chunks // 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. // is set to a lower value, or even 0.
MVStore.TxCounter txCounter = store.registerVersionUsage(); MVStore.TxCounter txCounter = store.registerVersionUsage();
try { try {
...@@ -1170,6 +1170,11 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1170,6 +1170,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return target; 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() { public RootReference flushAppendBuffer() {
return flushAppendBuffer(null); return flushAppendBuffer(null);
} }
...@@ -1216,9 +1221,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1216,9 +1221,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
p = split; p = split;
} else { } else {
Object keys[] = new Object[] { key }; Object keys[] = new Object[] { key };
Page.PageReference children[] = new Page.PageReference[store.getKeysPerPage() + 1]; Page.PageReference children[] = new Page.PageReference[] {
children[0] = new Page.PageReference(p); new Page.PageReference(p),
children[1] = new Page.PageReference(split); new Page.PageReference(split)};
p = Page.create(this, keys, null, children, p.getTotalCount() + split.getTotalCount(), 0); p = Page.create(this, keys, null, children, p.getTotalCount() + split.getTotalCount(), 0);
} }
break; break;
...@@ -1231,7 +1236,8 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1231,7 +1236,8 @@ public class MVMap<K, V> extends AbstractMap<K, V>
p.setChild(index, split); p.setChild(index, split);
p.insertNode(index, key, c); p.insertNode(index, key, c);
int keyCount; 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; break;
} }
int at = keyCount - 2; int at = keyCount - 2;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论