2015-01-23 04:39:36 +01:00
|
|
|
#pragma once
|
2015-10-15 13:10:20 +02:00
|
|
|
#ifndef MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREE_H_
|
|
|
|
#define MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREE_H_
|
2015-01-23 04:39:36 +01:00
|
|
|
|
|
|
|
#include <memory>
|
2015-02-21 01:58:23 +01:00
|
|
|
#include <messmer/cpp-utils/macros.h>
|
2015-06-21 17:43:45 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/optional_ownership_ptr.h>
|
2015-02-26 20:19:12 +01:00
|
|
|
#include "../datanodestore/DataNodeView.h"
|
2015-04-09 16:10:57 +02:00
|
|
|
//TODO Replace with C++14 once std::shared_mutex is supported
|
|
|
|
#include <boost/thread/shared_mutex.hpp>
|
2015-04-09 20:07:21 +02:00
|
|
|
#include <messmer/blockstore/utils/Key.h>
|
2015-01-23 04:39:36 +01:00
|
|
|
|
|
|
|
namespace blobstore {
|
|
|
|
namespace onblocks {
|
|
|
|
namespace datanodestore {
|
|
|
|
class DataNodeStore;
|
|
|
|
class DataInnerNode;
|
|
|
|
class DataLeafNode;
|
|
|
|
class DataNode;
|
|
|
|
}
|
|
|
|
namespace datatreestore {
|
|
|
|
|
2015-02-26 20:19:12 +01:00
|
|
|
//TODO It is strange that DataLeafNode is still part in the public interface of DataTree. This should be separated somehow.
|
2015-11-27 14:06:48 +01:00
|
|
|
class DataTree final {
|
2015-01-23 04:39:36 +01:00
|
|
|
public:
|
2015-06-26 15:59:18 +02:00
|
|
|
DataTree(datanodestore::DataNodeStore *nodeStore, cpputils::unique_ref<datanodestore::DataNode> rootNode);
|
2015-11-27 14:06:48 +01:00
|
|
|
~DataTree();
|
2015-01-23 04:39:36 +01:00
|
|
|
|
2015-01-27 00:54:25 +01:00
|
|
|
const blockstore::Key &key() const;
|
2015-12-11 00:18:17 +01:00
|
|
|
//Returning uint64_t, because calculations handling this probably need to be done in 64bit to support >4GB blobs.
|
|
|
|
uint64_t maxBytesPerLeaf() const;
|
2015-01-28 01:02:32 +01:00
|
|
|
|
2015-02-25 01:31:16 +01:00
|
|
|
void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function<void (datanodestore::DataLeafNode*, uint32_t)> func);
|
2015-02-26 17:33:47 +01:00
|
|
|
void resizeNumBytes(uint64_t newNumBytes);
|
|
|
|
|
2015-04-10 21:52:30 +02:00
|
|
|
uint32_t numLeaves() const;
|
2015-03-04 03:17:59 +01:00
|
|
|
uint64_t numStoredBytes() const;
|
|
|
|
|
2015-04-09 23:29:29 +02:00
|
|
|
void flush() const;
|
|
|
|
|
2015-01-23 04:39:36 +01:00
|
|
|
private:
|
2015-04-09 16:10:57 +02:00
|
|
|
mutable boost::shared_mutex _mutex;
|
2015-01-23 04:39:36 +01:00
|
|
|
datanodestore::DataNodeStore *_nodeStore;
|
2015-06-26 15:59:18 +02:00
|
|
|
cpputils::unique_ref<datanodestore::DataNode> _rootNode;
|
2015-01-23 04:39:36 +01:00
|
|
|
|
2015-06-26 15:59:18 +02:00
|
|
|
cpputils::unique_ref<datanodestore::DataLeafNode> addDataLeaf();
|
2015-03-04 03:17:59 +01:00
|
|
|
void removeLastDataLeaf();
|
|
|
|
|
2015-06-26 15:59:18 +02:00
|
|
|
cpputils::unique_ref<datanodestore::DataNode> releaseRootNode();
|
2015-02-24 22:44:10 +01:00
|
|
|
friend class DataTreeStore;
|
|
|
|
|
2015-06-26 15:59:18 +02:00
|
|
|
cpputils::unique_ref<datanodestore::DataLeafNode> addDataLeafAt(datanodestore::DataInnerNode *insertPos);
|
2015-04-10 21:52:30 +02:00
|
|
|
cpputils::optional_ownership_ptr<datanodestore::DataNode> createChainOfInnerNodes(unsigned int num, datanodestore::DataNode *child);
|
2015-06-26 15:59:18 +02:00
|
|
|
cpputils::unique_ref<datanodestore::DataNode> createChainOfInnerNodes(unsigned int num, cpputils::unique_ref<datanodestore::DataNode> child);
|
|
|
|
cpputils::unique_ref<datanodestore::DataLeafNode> addDataLeafToFullTree();
|
2015-01-23 04:39:36 +01:00
|
|
|
|
2015-02-22 19:30:42 +01:00
|
|
|
void deleteLastChildSubtree(datanodestore::DataInnerNode *node);
|
|
|
|
void ifRootHasOnlyOneChildReplaceRootWithItsChild();
|
|
|
|
|
2015-04-09 16:30:36 +02:00
|
|
|
//TODO Use underscore for private methods
|
2015-04-10 21:52:30 +02:00
|
|
|
void _traverseLeaves(datanodestore::DataNode *root, uint32_t leafOffset, uint32_t beginIndex, uint32_t endIndex, std::function<void (datanodestore::DataLeafNode*, uint32_t)> func);
|
2015-02-25 23:08:16 +01:00
|
|
|
uint32_t leavesPerFullChild(const datanodestore::DataInnerNode &root) const;
|
2015-04-09 16:30:36 +02:00
|
|
|
uint64_t _numStoredBytes() const;
|
|
|
|
uint64_t _numStoredBytes(const datanodestore::DataNode &root) const;
|
2015-04-10 22:57:29 +02:00
|
|
|
uint32_t _numLeaves(const datanodestore::DataNode &node) const;
|
2015-02-26 17:33:47 +01:00
|
|
|
cpputils::optional_ownership_ptr<datanodestore::DataLeafNode> LastLeaf(datanodestore::DataNode *root);
|
2015-06-26 15:59:18 +02:00
|
|
|
cpputils::unique_ref<datanodestore::DataLeafNode> LastLeaf(cpputils::unique_ref<datanodestore::DataNode> root);
|
2015-04-10 21:52:30 +02:00
|
|
|
datanodestore::DataInnerNode* increaseTreeDepth(unsigned int levels);
|
2015-06-26 15:59:18 +02:00
|
|
|
std::vector<cpputils::unique_ref<datanodestore::DataNode>> getOrCreateChildren(datanodestore::DataInnerNode *node, uint32_t begin, uint32_t end);
|
|
|
|
cpputils::unique_ref<datanodestore::DataNode> addChildTo(datanodestore::DataInnerNode *node);
|
2015-02-25 01:31:16 +01:00
|
|
|
|
2015-01-23 04:39:36 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(DataTree);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|