Fix two bugs in DataTree::resizeNumBytes()

This commit is contained in:
Sebastian Messmer 2015-03-04 02:04:51 +01:00
parent 68182e523f
commit 13a76bd42a
2 changed files with 3 additions and 2 deletions

View File

@ -167,10 +167,10 @@ void DataTree::resizeNumBytes(uint64_t newNumBytes) {
uint64_t currentNumBytes = numStoredBytes();
assert(currentNumBytes % _nodeStore->layout().maxBytesPerLeaf() == 0);
uint32_t currentNumLeaves = currentNumBytes / _nodeStore->layout().maxBytesPerLeaf();
uint32_t newNumLeaves = utils::ceilDivision(newNumBytes, _nodeStore->layout().maxBytesPerLeaf());
uint32_t newNumLeaves = std::max(1u, utils::ceilDivision(newNumBytes, _nodeStore->layout().maxBytesPerLeaf()));
for(uint32_t i = currentNumLeaves; i < newNumLeaves; ++i) {
addDataLeaf();
addDataLeaf()->resize(_nodeStore->layout().maxBytesPerLeaf());
}
for(uint32_t i = currentNumLeaves; i > newNumLeaves; --i) {
removeLastDataLeaf();

View File

@ -32,6 +32,7 @@ public:
const blockstore::Key &key() const;
uint32_t maxBytesPerLeaf() const;
//TODO Remove flush() and instead call it implicitly on traverseLeaves()/resizeNumBytes()
void flush() const;
void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function<void (datanodestore::DataLeafNode*, uint32_t)> func);