2015-01-22 23:37:03 +01:00
|
|
|
#include "DataLeafNode.h"
|
2015-01-24 00:54:27 +01:00
|
|
|
#include "DataInnerNode.h"
|
2014-12-09 18:53:11 +01:00
|
|
|
|
|
|
|
using std::unique_ptr;
|
2015-01-24 00:54:27 +01:00
|
|
|
using std::make_unique;
|
2014-12-09 18:53:11 +01:00
|
|
|
using blockstore::Block;
|
2014-12-10 16:48:00 +01:00
|
|
|
using blockstore::Data;
|
2014-12-13 19:17:08 +01:00
|
|
|
using blockstore::Key;
|
2014-12-09 18:53:11 +01:00
|
|
|
|
|
|
|
namespace blobstore {
|
|
|
|
namespace onblocks {
|
2014-12-13 19:17:08 +01:00
|
|
|
namespace datanodestore {
|
2014-12-09 18:53:11 +01:00
|
|
|
|
2015-01-24 22:27:14 +01:00
|
|
|
DataLeafNode::DataLeafNode(DataNodeView view)
|
|
|
|
: DataNode(std::move(view)) {
|
2015-02-20 19:46:52 +01:00
|
|
|
assert(*node().Depth() == 0);
|
2015-02-25 22:30:48 +01:00
|
|
|
assert(numBytes() <= maxStoreableBytes());
|
2014-12-09 18:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DataLeafNode::~DataLeafNode() {
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:46:52 +01:00
|
|
|
unique_ptr<DataLeafNode> DataLeafNode::InitializeNewNode(unique_ptr<Block> block) {
|
|
|
|
DataNodeView node(std::move(block));
|
|
|
|
*node.Depth() = 0;
|
|
|
|
*node.Size() = 0;
|
2014-12-11 00:20:23 +01:00
|
|
|
//fillDataWithZeroes(); not needed, because a newly created block will be zeroed out. DataLeafNodeTest.SpaceIsZeroFilledWhenGrowing ensures this.
|
2015-02-20 19:46:52 +01:00
|
|
|
return make_unique<DataLeafNode>(std::move(node));
|
2014-12-11 00:20:23 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 23:37:03 +01:00
|
|
|
void *DataLeafNode::data() {
|
|
|
|
return const_cast<void*>(const_cast<const DataLeafNode*>(this)->data());
|
2014-12-10 16:48:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 23:37:03 +01:00
|
|
|
const void *DataLeafNode::data() const {
|
|
|
|
return node().DataBegin<uint8_t>();
|
2014-12-09 18:53:11 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 23:37:03 +01:00
|
|
|
uint32_t DataLeafNode::numBytes() const {
|
|
|
|
return *node().Size();
|
|
|
|
}
|
2014-12-10 23:34:36 +01:00
|
|
|
|
2015-01-22 23:37:03 +01:00
|
|
|
void DataLeafNode::resize(uint32_t new_size) {
|
2015-02-25 22:30:48 +01:00
|
|
|
assert(new_size <= maxStoreableBytes());
|
2015-01-22 23:37:03 +01:00
|
|
|
uint32_t old_size = *node().Size();
|
|
|
|
if (new_size < old_size) {
|
|
|
|
fillDataWithZeroesFromTo(new_size, old_size);
|
2014-12-11 00:20:23 +01:00
|
|
|
}
|
2015-01-22 23:37:03 +01:00
|
|
|
*node().Size() = new_size;
|
|
|
|
}
|
2014-12-11 00:20:23 +01:00
|
|
|
|
2015-01-22 23:37:03 +01:00
|
|
|
void DataLeafNode::fillDataWithZeroesFromTo(off_t begin, off_t end) {
|
2015-01-24 00:54:27 +01:00
|
|
|
std::memset(node().DataBegin<uint8_t>()+begin, 0, end-begin);
|
2014-12-10 23:34:36 +01:00
|
|
|
}
|
|
|
|
|
2015-02-25 22:30:48 +01:00
|
|
|
uint32_t DataLeafNode::maxStoreableBytes() const {
|
|
|
|
return node().layout().maxBytesPerLeaf();
|
|
|
|
}
|
|
|
|
|
2014-12-09 18:53:11 +01:00
|
|
|
}
|
|
|
|
}
|
2014-12-13 19:17:08 +01:00
|
|
|
}
|