From 5458af7c5293df4339488cdb2bdc259e6928ec3f Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sun, 17 Sep 2017 02:07:27 +0100 Subject: [PATCH] Rename blockstore::Key -> blockstore::BlockId --- .../implementations/onblocks/BlobOnBlocks.cpp | 8 +- .../implementations/onblocks/BlobOnBlocks.h | 2 +- .../onblocks/BlobStoreOnBlocks.cpp | 10 +- .../onblocks/BlobStoreOnBlocks.h | 4 +- .../onblocks/datanodestore/DataInnerNode.cpp | 16 +- .../onblocks/datanodestore/DataInnerNode.h | 8 +- .../datanodestore/DataInnerNode_ChildEntry.h | 10 +- .../onblocks/datanodestore/DataLeafNode.cpp | 6 +- .../onblocks/datanodestore/DataLeafNode.h | 2 +- .../onblocks/datanodestore/DataNode.cpp | 8 +- .../onblocks/datanodestore/DataNode.h | 2 +- .../onblocks/datanodestore/DataNodeStore.cpp | 30 +- .../onblocks/datanodestore/DataNodeStore.h | 12 +- .../onblocks/datanodestore/DataNodeView.h | 8 +- .../onblocks/datatreestore/DataTree.cpp | 14 +- .../onblocks/datatreestore/DataTree.h | 6 +- .../onblocks/datatreestore/DataTreeStore.cpp | 8 +- .../onblocks/datatreestore/DataTreeStore.h | 6 +- .../onblocks/datatreestore/LeafHandle.cpp | 10 +- .../onblocks/datatreestore/LeafHandle.h | 10 +- .../datatreestore/impl/LeafTraverser.cpp | 30 +- .../datatreestore/impl/LeafTraverser.h | 6 +- .../datatreestore/impl/algorithms.cpp | 8 +- .../parallelaccessdatatreestore/DataTreeRef.h | 6 +- .../ParallelAccessDataTreeStore.cpp | 18 +- .../ParallelAccessDataTreeStore.h | 8 +- .../ParallelAccessDataTreeStoreAdapter.h | 10 +- src/blobstore/interface/Blob.h | 6 +- src/blobstore/interface/BlobStore.h | 6 +- src/blockstore/CMakeLists.txt | 4 +- .../caching/CachingBlockStore2.cpp | 58 ++-- .../caching/CachingBlockStore2.h | 20 +- .../compressing/CompressedBlock.h | 14 +- .../compressing/CompressingBlockStore.h | 34 +- .../encrypted/EncryptedBlockStore2.h | 44 +-- .../inmemory/InMemoryBlockStore2.cpp | 38 +-- .../inmemory/InMemoryBlockStore2.h | 16 +- .../integrity/ClientIdAndBlockId.cpp | 1 + ...ntIdAndBlockKey.h => ClientIdAndBlockId.h} | 22 +- .../integrity/ClientIdAndBlockKey.cpp | 1 - .../integrity/IntegrityBlockStore2.cpp | 98 +++--- .../integrity/IntegrityBlockStore2.h | 26 +- .../integrity/KnownBlockVersions.cpp | 54 +-- .../integrity/KnownBlockVersions.h | 28 +- .../low2highlevel/LowToHighLevelBlock.cpp | 24 +- .../low2highlevel/LowToHighLevelBlock.h | 8 +- .../LowToHighLevelBlockStore.cpp | 24 +- .../low2highlevel/LowToHighLevelBlockStore.h | 12 +- .../implementations/mock/MockBlock.cpp | 4 +- .../implementations/mock/MockBlock.h | 2 +- .../implementations/mock/MockBlockStore.h | 68 ++-- .../ondisk/OnDiskBlockStore2.cpp | 34 +- .../ondisk/OnDiskBlockStore2.h | 12 +- .../implementations/parallelaccess/BlockRef.h | 6 +- .../ParallelAccessBlockStore.cpp | 34 +- .../parallelaccess/ParallelAccessBlockStore.h | 14 +- .../ParallelAccessBlockStoreAdapter.h | 10 +- .../implementations/testfake/FakeBlock.cpp | 6 +- .../implementations/testfake/FakeBlock.h | 2 +- .../testfake/FakeBlockStore.cpp | 36 +- .../implementations/testfake/FakeBlockStore.h | 18 +- src/blockstore/interface/Block.h | 10 +- src/blockstore/interface/BlockStore.h | 24 +- src/blockstore/interface/BlockStore2.h | 20 +- .../helpers/BlockStoreWithRandomKeys.h | 6 +- src/blockstore/utils/BlockId.cpp | 2 +- src/blockstore/utils/BlockId.h | 7 +- src/cryfs/config/CryConfigCreator.cpp | 4 +- src/cryfs/config/CryConfigCreator.h | 2 +- src/cryfs/filesystem/CryDevice.cpp | 66 ++-- src/cryfs/filesystem/CryDevice.h | 16 +- src/cryfs/filesystem/CryDir.cpp | 28 +- src/cryfs/filesystem/CryDir.h | 2 +- src/cryfs/filesystem/CryFile.cpp | 10 +- src/cryfs/filesystem/CryFile.h | 2 +- src/cryfs/filesystem/CryNode.cpp | 48 +-- src/cryfs/filesystem/CryNode.h | 6 +- src/cryfs/filesystem/CryOpenFile.cpp | 8 +- src/cryfs/filesystem/CrySymlink.cpp | 10 +- src/cryfs/filesystem/CrySymlink.h | 2 +- .../cachingfsblobstore/CachingFsBlobStore.cpp | 8 +- .../cachingfsblobstore/CachingFsBlobStore.h | 28 +- .../cachingfsblobstore/DirBlobRef.h | 64 ++-- .../cachingfsblobstore/FileBlobRef.h | 4 +- .../filesystem/cachingfsblobstore/FsBlobRef.h | 8 +- .../cachingfsblobstore/SymlinkBlobRef.h | 4 +- src/cryfs/filesystem/fsblobstore/DirBlob.cpp | 72 ++-- src/cryfs/filesystem/fsblobstore/DirBlob.h | 44 +-- src/cryfs/filesystem/fsblobstore/FileBlob.cpp | 6 +- src/cryfs/filesystem/fsblobstore/FileBlob.h | 2 +- src/cryfs/filesystem/fsblobstore/FsBlob.h | 20 +- .../filesystem/fsblobstore/FsBlobStore.cpp | 20 +- .../filesystem/fsblobstore/FsBlobStore.h | 32 +- .../filesystem/fsblobstore/FsBlobView.cpp | 6 +- src/cryfs/filesystem/fsblobstore/FsBlobView.h | 32 +- .../filesystem/fsblobstore/SymlinkBlob.cpp | 4 +- .../filesystem/fsblobstore/SymlinkBlob.h | 2 +- .../filesystem/fsblobstore/utils/DirEntry.cpp | 24 +- .../filesystem/fsblobstore/utils/DirEntry.h | 20 +- .../fsblobstore/utils/DirEntryList.cpp | 98 +++--- .../fsblobstore/utils/DirEntryList.h | 38 +-- .../parallelaccessfsblobstore/DirBlobRef.h | 68 ++-- .../parallelaccessfsblobstore/FileBlobRef.h | 10 +- .../parallelaccessfsblobstore/FsBlobRef.h | 8 +- .../ParallelAccessFsBlobStore.cpp | 24 +- .../ParallelAccessFsBlobStore.h | 22 +- .../ParallelAccessFsBlobStoreAdapter.h | 10 +- .../SymlinkBlobRef.h | 10 +- .../ParallelAccessBaseStore.h | 4 +- src/stats/main.cpp | 40 +-- .../implementations/onblocks/BigBlobsTest.cpp | 4 +- .../onblocks/BlobReadWriteTest.cpp | 8 +- .../implementations/onblocks/BlobSizeTest.cpp | 14 +- .../onblocks/BlobStoreTest.cpp | 28 +- .../datanodestore/DataInnerNodeTest.cpp | 114 +++---- .../datanodestore/DataLeafNodeTest.cpp | 72 ++-- .../datanodestore/DataNodeStoreTest.cpp | 38 +-- .../datanodestore/DataNodeViewTest.cpp | 16 +- .../datatreestore/DataTreeStoreTest.cpp | 42 +-- .../DataTreeTest_NumStoredBytes.cpp | 34 +- .../DataTreeTest_Performance.cpp | 130 +++---- .../DataTreeTest_ResizeByTraversing.cpp | 46 +-- .../DataTreeTest_ResizeNumBytes.cpp | 58 ++-- .../DataTreeTest_TraverseLeaves.cpp | 140 ++++---- ...derNodeWithLessThanKChildrenOrNullTest.cpp | 16 +- ...rderNodeWithMoreThanOneChildOrNullTest.cpp | 32 +- .../datatreestore/testutils/DataTreeTest.cpp | 68 ++-- .../datatreestore/testutils/DataTreeTest.h | 16 +- .../testutils/TwoLevelDataFixture.h | 2 +- .../onblocks/testutils/BlobStoreTest.h | 4 +- .../CachingBlockStore2Test_Specific.cpp | 12 +- .../EncryptedBlockStoreTest_Specific.cpp | 58 ++-- .../IntegrityBlockStoreTest_Specific.cpp | 150 ++++---- .../integrity/KnownBlockVersionsTest.cpp | 322 +++++++++--------- .../ondisk/OnDiskBlockStoreTest_Specific.cpp | 20 +- .../OnDiskBlockTest/OnDiskBlockCreateTest.cpp | 14 +- .../OnDiskBlockTest/OnDiskBlockFlushTest.cpp | 12 +- .../OnDiskBlockTest/OnDiskBlockLoadTest.cpp | 14 +- .../ParallelAccessBlockStoreTest_Specific.cpp | 12 +- .../helpers/BlockStoreWithRandomKeysTest.cpp | 68 ++-- test/blockstore/testutils/BlockStore2Test.h | 218 ++++++------ test/blockstore/testutils/BlockStoreTest.h | 58 ++-- .../testutils/BlockStoreTest_Data.h | 48 +-- .../testutils/BlockStoreTest_Size.h | 40 +-- .../testutils/BlockStoreWithRandomKeysTest.h | 22 +- test/cryfs/config/CryCipherTest.cpp | 22 +- 146 files changed, 2013 insertions(+), 2014 deletions(-) create mode 100644 src/blockstore/implementations/integrity/ClientIdAndBlockId.cpp rename src/blockstore/implementations/integrity/{ClientIdAndBlockKey.h => ClientIdAndBlockId.h} (65%) delete mode 100644 src/blockstore/implementations/integrity/ClientIdAndBlockKey.cpp diff --git a/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp b/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp index 50681ff9..f06d1b3c 100644 --- a/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp +++ b/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp @@ -15,7 +15,7 @@ using cpputils::unique_ref; using cpputils::Data; using blobstore::onblocks::datanodestore::DataLeafNode; using blobstore::onblocks::datanodestore::DataNodeLayout; -using blockstore::Key; +using blockstore::BlockId; using blobstore::onblocks::datatreestore::LeafHandle; namespace blobstore { @@ -131,7 +131,7 @@ void BlobOnBlocks::write(const void *source, uint64_t offset, uint64_t count) { if (leafDataOffset == 0 && leafDataSize == leaf.nodeStore()->layout().maxBytesPerLeaf()) { Data leafData(leafDataSize); std::memcpy(leafData.data(), (uint8_t*)source + indexOfFirstLeafByte - offset, leafDataSize); - leaf.nodeStore()->overwriteLeaf(leaf.key(), std::move(leafData)); + leaf.nodeStore()->overwriteLeaf(leaf.blockId(), std::move(leafData)); } else { //TODO Simplify formula, make it easier to understand leaf.node()->write((uint8_t *) source + indexOfFirstLeafByte - offset + leafDataOffset, leafDataOffset, @@ -152,8 +152,8 @@ void BlobOnBlocks::flush() { _datatree->flush(); } -const Key &BlobOnBlocks::key() const { - return _datatree->key(); +const BlockId &BlobOnBlocks::blockId() const { + return _datatree->blockId(); } unique_ref BlobOnBlocks::releaseTree() { diff --git a/src/blobstore/implementations/onblocks/BlobOnBlocks.h b/src/blobstore/implementations/onblocks/BlobOnBlocks.h index 0f375ffe..8941d7da 100644 --- a/src/blobstore/implementations/onblocks/BlobOnBlocks.h +++ b/src/blobstore/implementations/onblocks/BlobOnBlocks.h @@ -22,7 +22,7 @@ public: BlobOnBlocks(cpputils::unique_ref datatree); ~BlobOnBlocks(); - const blockstore::Key &key() const override; + const blockstore::BlockId &blockId() const override; uint64_t size() const override; void resize(uint64_t numBytes) override; diff --git a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp index 03166ab8..18660a2e 100644 --- a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp +++ b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp @@ -15,7 +15,7 @@ using cpputils::make_unique_ref; using blockstore::BlockStore; using blockstore::parallelaccess::ParallelAccessBlockStore; -using blockstore::Key; +using blockstore::BlockId; using cpputils::dynamic_pointer_move; using boost::optional; using boost::none; @@ -38,8 +38,8 @@ unique_ref BlobStoreOnBlocks::create() { return make_unique_ref(_dataTreeStore->createNewTree()); } -optional> BlobStoreOnBlocks::load(const Key &key) { - auto tree = _dataTreeStore->load(key); +optional> BlobStoreOnBlocks::load(const BlockId &blockId) { + auto tree = _dataTreeStore->load(blockId); if (tree == none) { return none; } @@ -52,8 +52,8 @@ void BlobStoreOnBlocks::remove(unique_ref blob) { _dataTreeStore->remove((*_blob)->releaseTree()); } -void BlobStoreOnBlocks::remove(const Key &key) { - _dataTreeStore->remove(key); +void BlobStoreOnBlocks::remove(const BlockId &blockId) { + _dataTreeStore->remove(blockId); } uint64_t BlobStoreOnBlocks::virtualBlocksizeBytes() const { diff --git a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h index 53fac8b4..41d9a33f 100644 --- a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h +++ b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h @@ -20,10 +20,10 @@ public: ~BlobStoreOnBlocks(); cpputils::unique_ref create() override; - boost::optional> load(const blockstore::Key &key) override; + boost::optional> load(const blockstore::BlockId &blockId) override; void remove(cpputils::unique_ref blob) override; - void remove(const blockstore::Key &key) override; + void remove(const blockstore::BlockId &blockId) override; //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft //virtual means "space we can use" as opposed to "space it takes on the disk" (i.e. virtual is without headers, checksums, ...) diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp index c87d8836..13f3f3b2 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp @@ -7,7 +7,7 @@ using blockstore::BlockStore; using cpputils::Data; using cpputils::unique_ref; using cpputils::make_unique_ref; -using blockstore::Key; +using blockstore::BlockId; using std::vector; namespace blobstore { @@ -25,25 +25,25 @@ DataInnerNode::DataInnerNode(DataNodeView view) DataInnerNode::~DataInnerNode() { } -unique_ref DataInnerNode::InitializeNewNode(unique_ref block, const DataNodeLayout &layout, uint8_t depth, const vector &children) { +unique_ref DataInnerNode::InitializeNewNode(unique_ref block, const DataNodeLayout &layout, uint8_t depth, const vector &children) { ASSERT(children.size() >= 1, "An inner node must have at least one child"); Data data = _serializeChildren(children); return make_unique_ref(DataNodeView::initialize(std::move(block), layout, DataNode::FORMAT_VERSION_HEADER, depth, children.size(), std::move(data))); } -unique_ref DataInnerNode::CreateNewNode(BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const vector &children) { +unique_ref DataInnerNode::CreateNewNode(BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const vector &children) { ASSERT(children.size() >= 1, "An inner node must have at least one child"); Data data = _serializeChildren(children); return make_unique_ref(DataNodeView::create(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, depth, children.size(), std::move(data))); } -Data DataInnerNode::_serializeChildren(const vector &children) { +Data DataInnerNode::_serializeChildren(const vector &children) { Data data(sizeof(ChildEntry) * children.size()); uint32_t i = 0; - for (const Key &child : children) { - reinterpret_cast(data.data())[i++].setKey(child); + for (const BlockId &child : children) { + reinterpret_cast(data.data())[i++].setBlockId(child); } return data; } @@ -89,12 +89,12 @@ void DataInnerNode::addChild(const DataNode &child) { ASSERT(numChildren() < maxStoreableChildren(), "Adding more children than we can store"); ASSERT(child.depth() == depth()-1, "The child that should be added has wrong depth"); node().setSize(node().Size()+1); - LastChild()->setKey(child.key()); + LastChild()->setBlockId(child.blockId()); } void DataInnerNode::removeLastChild() { ASSERT(node().Size() > 1, "There is no child to remove"); - LastChild()->setKey(Key::Null()); + LastChild()->setBlockId(BlockId::Null()); node().setSize(node().Size()-1); } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h index 72693f02..14bb2eef 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h @@ -11,8 +11,8 @@ namespace datanodestore { class DataInnerNode final: public DataNode { public: - static cpputils::unique_ref InitializeNewNode(cpputils::unique_ref block, const DataNodeLayout &layout, uint8_t depth, const std::vector &children); - static cpputils::unique_ref CreateNewNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const std::vector &children); + static cpputils::unique_ref InitializeNewNode(cpputils::unique_ref block, const DataNodeLayout &layout, uint8_t depth, const std::vector &children); + static cpputils::unique_ref CreateNewNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const std::vector &children); DataInnerNode(DataNodeView block); ~DataInnerNode(); @@ -26,7 +26,7 @@ public: uint32_t numChildren() const; - void addChild(const DataNode &child_key); + void addChild(const DataNode &child_blockId); void removeLastChild(); @@ -40,7 +40,7 @@ private: const ChildEntry *ChildrenBegin() const; const ChildEntry *ChildrenEnd() const; - static cpputils::Data _serializeChildren(const std::vector &children); + static cpputils::Data _serializeChildren(const std::vector &children); DISALLOW_COPY_AND_ASSIGN(DataInnerNode); }; diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode_ChildEntry.h b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode_ChildEntry.h index 51e7afc1..725720cf 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode_ChildEntry.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode_ChildEntry.h @@ -10,15 +10,15 @@ namespace datanodestore{ struct DataInnerNode_ChildEntry final { public: - blockstore::Key key() const { - return blockstore::Key::FromBinary(_keydata); + blockstore::BlockId blockId() const { + return blockstore::BlockId::FromBinary(_blockIdData); } private: - void setKey(const blockstore::Key &key) { - key.ToBinary(_keydata); + void setBlockId(const blockstore::BlockId &blockId) { + blockId.ToBinary(_blockIdData); } friend class DataInnerNode; - uint8_t _keydata[blockstore::Key::BINARY_LENGTH]; + uint8_t _blockIdData[blockstore::BlockId::BINARY_LENGTH]; DISALLOW_COPY_AND_ASSIGN(DataInnerNode_ChildEntry); }; diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp index 7f8b9335..4348596f 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp @@ -4,7 +4,7 @@ using blockstore::Block; using cpputils::Data; -using blockstore::Key; +using blockstore::BlockId; using blockstore::BlockStore; using cpputils::unique_ref; using cpputils::make_unique_ref; @@ -31,10 +31,10 @@ unique_ref DataLeafNode::CreateNewNode(BlockStore *blockStore, con return make_unique_ref(DataNodeView::create(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, 0, size, std::move(data))); } -unique_ref DataLeafNode::OverwriteNode(BlockStore *blockStore, const DataNodeLayout &layout, const Key &key, Data data) { +unique_ref DataLeafNode::OverwriteNode(BlockStore *blockStore, const DataNodeLayout &layout, const BlockId &blockId, Data data) { ASSERT(data.size() == layout.maxBytesPerLeaf(), "Data passed in is too large for one leaf."); uint32_t size = data.size(); - return make_unique_ref(DataNodeView::overwrite(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, 0, size, key, std::move(data))); + return make_unique_ref(DataNodeView::overwrite(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, 0, size, blockId, std::move(data))); } void DataLeafNode::read(void *target, uint64_t offset, uint64_t size) const { diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h index 3839a7ed..f6e20efc 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h @@ -12,7 +12,7 @@ class DataInnerNode; class DataLeafNode final: public DataNode { public: static cpputils::unique_ref CreateNewNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, cpputils::Data data); - static cpputils::unique_ref OverwriteNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, const blockstore::Key &key, cpputils::Data data); + static cpputils::unique_ref OverwriteNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, const blockstore::BlockId &blockId, cpputils::Data data); DataLeafNode(DataNodeView block); ~DataLeafNode(); diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp index bbcf346a..cd505fe2 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp @@ -5,7 +5,7 @@ #include using blockstore::Block; -using blockstore::Key; +using blockstore::BlockId; using std::runtime_error; using cpputils::unique_ref; @@ -31,8 +31,8 @@ const DataNodeView &DataNode::node() const { return _node; } -const Key &DataNode::key() const { - return _node.key(); +const BlockId &DataNode::blockId() const { + return _node.blockId(); } uint8_t DataNode::depth() const { @@ -43,7 +43,7 @@ unique_ref DataNode::convertToNewInnerNode(unique_ref n auto block = node->_node.releaseBlock(); blockstore::utils::fillWithZeroes(block.get()); - return DataInnerNode::InitializeNewNode(std::move(block), layout, first_child.depth()+1, {first_child.key()}); + return DataInnerNode::InitializeNewNode(std::move(block), layout, first_child.depth()+1, {first_child.blockId()}); } void DataNode::flush() const { diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataNode.h index 08558338..9fc45e42 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNode.h @@ -15,7 +15,7 @@ class DataNode { public: virtual ~DataNode(); - const blockstore::Key &key() const; + const blockstore::BlockId &blockId() const; uint8_t depth() const; diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp index 841a15ed..9ecfcdb8 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp @@ -8,7 +8,7 @@ using blockstore::BlockStore; using blockstore::Block; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using cpputils::unique_ref; using cpputils::make_unique_ref; @@ -41,7 +41,7 @@ unique_ref DataNodeStore::load(unique_ref block) { } } -unique_ref DataNodeStore::createNewInnerNode(uint8_t depth, const vector &children) { +unique_ref DataNodeStore::createNewInnerNode(uint8_t depth, const vector &children) { ASSERT(children.size() >= 1, "Inner node must have at least one child"); return DataInnerNode::CreateNewNode(_blockstore.get(), _layout, depth, children); } @@ -50,12 +50,12 @@ unique_ref DataNodeStore::createNewLeafNode(Data data) { return DataLeafNode::CreateNewNode(_blockstore.get(), _layout, std::move(data)); } -unique_ref DataNodeStore::overwriteLeaf(const Key &key, Data data) { - return DataLeafNode::OverwriteNode(_blockstore.get(), _layout, key, std::move(data)); +unique_ref DataNodeStore::overwriteLeaf(const BlockId &blockId, Data data) { + return DataLeafNode::OverwriteNode(_blockstore.get(), _layout, blockId, std::move(data)); } -optional> DataNodeStore::load(const Key &key) { - auto block = _blockstore->load(key); +optional> DataNodeStore::load(const BlockId &blockId) { + auto block = _blockstore->load(blockId); if (block == none) { return none; } else { @@ -80,13 +80,13 @@ unique_ref DataNodeStore::overwriteNodeWith(unique_ref targe } void DataNodeStore::remove(unique_ref node) { - Key key = node->key(); + BlockId blockId = node->blockId(); cpputils::destruct(std::move(node)); - remove(key); + remove(blockId); } -void DataNodeStore::remove(const Key &key) { - _blockstore->remove(key); +void DataNodeStore::remove(const BlockId &blockId) { + _blockstore->remove(blockId); } void DataNodeStore::removeSubtree(unique_ref node) { @@ -99,23 +99,23 @@ void DataNodeStore::removeSubtree(unique_ref node) { auto inner = dynamic_pointer_move(node); ASSERT(inner != none, "Is neither a leaf nor an inner node"); for (uint32_t i = 0; i < (*inner)->numChildren(); ++i) { - removeSubtree((*inner)->depth()-1, (*inner)->getChild(i)->key()); + removeSubtree((*inner)->depth()-1, (*inner)->getChild(i)->blockId()); } remove(std::move(*inner)); } -void DataNodeStore::removeSubtree(uint8_t depth, const Key &key) { +void DataNodeStore::removeSubtree(uint8_t depth, const BlockId &blockId) { if (depth == 0) { - remove(key); + remove(blockId); } else { - auto node = load(key); + auto node = load(blockId); ASSERT(node != none, "Node for removeSubtree not found"); auto inner = dynamic_pointer_move(*node); ASSERT(inner != none, "Is not an inner node, but depth was not zero"); ASSERT((*inner)->depth() == depth, "Wrong depth given"); for (uint32_t i = 0; i < (*inner)->numChildren(); ++i) { - removeSubtree(depth-1, (*inner)->getChild(i)->key()); + removeSubtree(depth-1, (*inner)->getChild(i)->blockId()); } remove(std::move(*inner)); } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h index 37d27f4d..8bb8c8ad 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h @@ -5,7 +5,7 @@ #include #include #include "DataNodeView.h" -#include +#include namespace blockstore{ class Block; @@ -28,21 +28,21 @@ public: DataNodeLayout layout() const; - boost::optional> load(const blockstore::Key &key); + boost::optional> load(const blockstore::BlockId &blockId); static cpputils::unique_ref load(cpputils::unique_ref block); cpputils::unique_ref createNewLeafNode(cpputils::Data data); - cpputils::unique_ref createNewInnerNode(uint8_t depth, const std::vector &children); + cpputils::unique_ref createNewInnerNode(uint8_t depth, const std::vector &children); cpputils::unique_ref createNewNodeAsCopyFrom(const DataNode &source); cpputils::unique_ref overwriteNodeWith(cpputils::unique_ref target, const DataNode &source); - cpputils::unique_ref overwriteLeaf(const blockstore::Key &key, cpputils::Data data); + cpputils::unique_ref overwriteLeaf(const blockstore::BlockId &blockId, cpputils::Data data); void remove(cpputils::unique_ref node); - void remove(const blockstore::Key &key); - void removeSubtree(uint8_t depth, const blockstore::Key &key); + void remove(const blockstore::BlockId &blockId); + void removeSubtree(uint8_t depth, const blockstore::BlockId &blockId); void removeSubtree(cpputils::unique_ref node); //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h b/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h index 2b55e7e7..9ab433a7 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h @@ -81,10 +81,10 @@ public: return DataNodeView(std::move(block)); } - static DataNodeView overwrite(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint16_t formatVersion, uint8_t depth, uint32_t size, const blockstore::Key &key, cpputils::Data data) { + static DataNodeView overwrite(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint16_t formatVersion, uint8_t depth, uint32_t size, const blockstore::BlockId &blockId, cpputils::Data data) { ASSERT(data.size() <= layout.datasizeBytes(), "Data is too large for node"); cpputils::Data serialized = _serialize(layout, formatVersion, depth, size, std::move(data)); - auto block = blockStore->overwrite(key, std::move(serialized)); + auto block = blockStore->overwrite(blockId, std::move(serialized)); return DataNodeView(std::move(block)); } @@ -145,8 +145,8 @@ public: return *_block; } - const blockstore::Key &key() const { - return _block->key(); + const blockstore::BlockId &blockId() const { + return _block->blockId(); } void flush() const { diff --git a/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp b/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp index 6b3572a4..0468a18b 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp @@ -13,7 +13,7 @@ #include #include "impl/LeafTraverser.h" -using blockstore::Key; +using blockstore::BlockId; using blobstore::onblocks::datanodestore::DataNodeStore; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataInnerNode; @@ -40,14 +40,14 @@ namespace onblocks { namespace datatreestore { DataTree::DataTree(DataNodeStore *nodeStore, unique_ref rootNode) - : _mutex(), _nodeStore(nodeStore), _rootNode(std::move(rootNode)), _key(_rootNode->key()), _numLeavesCache(none) { + : _mutex(), _nodeStore(nodeStore), _rootNode(std::move(rootNode)), _blockId(_rootNode->blockId()), _numLeavesCache(none) { } DataTree::~DataTree() { } -const Key &DataTree::key() const { - return _key; +const BlockId &DataTree::blockId() const { + return _blockId; } void DataTree::flush() const { @@ -89,7 +89,7 @@ uint32_t DataTree::_computeNumLeaves(const DataNode &node) const { const DataInnerNode &inner = dynamic_cast(node); uint64_t numLeavesInLeftChildren = (uint64_t)(inner.numChildren()-1) * leavesPerFullChild(inner); - auto lastChild = _nodeStore->load(inner.LastChild()->key()); + auto lastChild = _nodeStore->load(inner.LastChild()->blockId()); ASSERT(lastChild != none, "Couldn't load last child"); uint64_t numLeavesInRightChild = _computeNumLeaves(**lastChild); @@ -138,7 +138,7 @@ uint64_t DataTree::_numStoredBytes(const DataNode &root) const { const DataInnerNode &inner = dynamic_cast(root); uint64_t numBytesInLeftChildren = (inner.numChildren()-1) * leavesPerFullChild(inner) * _nodeStore->layout().maxBytesPerLeaf(); - auto lastChild = _nodeStore->load(inner.LastChild()->key()); + auto lastChild = _nodeStore->load(inner.LastChild()->blockId()); ASSERT(lastChild != none, "Couldn't load last child"); uint64_t numBytesInRightChild = _numStoredBytes(**lastChild); @@ -172,7 +172,7 @@ void DataTree::resizeNumBytes(uint64_t newNumBytes) { ASSERT(neededChildrenForRightBorderNode <= node->numChildren(), "Node has too few children"); // All children to the right of the new right-border-node are removed including their subtree. while(node->numChildren() > neededChildrenForRightBorderNode) { - _nodeStore->removeSubtree(node->depth()-1, node->LastChild()->key()); + _nodeStore->removeSubtree(node->depth()-1, node->LastChild()->blockId()); node->removeLastChild(); } }; diff --git a/src/blobstore/implementations/onblocks/datatreestore/DataTree.h b/src/blobstore/implementations/onblocks/datatreestore/DataTree.h index ae9bb80e..d3339504 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/DataTree.h +++ b/src/blobstore/implementations/onblocks/datatreestore/DataTree.h @@ -8,7 +8,7 @@ #include "../datanodestore/DataNodeView.h" //TODO Replace with C++14 once std::shared_mutex is supported #include -#include +#include #include "LeafHandle.h" namespace blobstore { @@ -27,7 +27,7 @@ public: DataTree(datanodestore::DataNodeStore *nodeStore, cpputils::unique_ref rootNode); ~DataTree(); - const blockstore::Key &key() const; + const blockstore::BlockId &blockId() const; //Returning uint64_t, because calculations handling this probably need to be done in 64bit to support >4GB blobs. uint64_t maxBytesPerLeaf() const; @@ -48,7 +48,7 @@ private: mutable boost::shared_mutex _mutex; datanodestore::DataNodeStore *_nodeStore; cpputils::unique_ref _rootNode; - blockstore::Key _key; // Key is stored in a member variable, since _rootNode is nullptr while traversing, but we still want to be able to return the key. + blockstore::BlockId _blockId; // BlockId is stored in a member variable, since _rootNode is nullptr while traversing, but we still want to be able to return the blockId. mutable boost::optional _numLeavesCache; cpputils::unique_ref releaseRootNode(); diff --git a/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.cpp b/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.cpp index 5d6610b0..e8164dc8 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.cpp @@ -22,8 +22,8 @@ DataTreeStore::DataTreeStore(unique_ref nodeStore) DataTreeStore::~DataTreeStore() { } -optional> DataTreeStore::load(const blockstore::Key &key) { - auto node = _nodeStore->load(key); +optional> DataTreeStore::load(const blockstore::BlockId &blockId) { + auto node = _nodeStore->load(blockId); if (node == none) { return none; } @@ -39,8 +39,8 @@ void DataTreeStore::remove(unique_ref tree) { _nodeStore->removeSubtree(tree->releaseRootNode()); } -void DataTreeStore::remove(const blockstore::Key &key) { - auto tree = load(key); +void DataTreeStore::remove(const blockstore::BlockId &blockId) { + auto tree = load(blockId); ASSERT(tree != none, "Tree to remove not found"); remove(std::move(*tree)); } diff --git a/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.h b/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.h index 1af464ee..8b487381 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.h +++ b/src/blobstore/implementations/onblocks/datatreestore/DataTreeStore.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include "../datanodestore/DataNodeStore.h" @@ -19,12 +19,12 @@ public: DataTreeStore(cpputils::unique_ref nodeStore); ~DataTreeStore(); - boost::optional> load(const blockstore::Key &key); + boost::optional> load(const blockstore::BlockId &blockId); cpputils::unique_ref createNewTree(); void remove(cpputils::unique_ref tree); - void remove(const blockstore::Key &key); + void remove(const blockstore::BlockId &blockId); //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft uint64_t virtualBlocksizeBytes() const; diff --git a/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.cpp b/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.cpp index 0e7e0e4b..98e2df25 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.cpp @@ -8,24 +8,24 @@ using boost::none; using cpputils::dynamic_pointer_move; using blobstore::onblocks::datanodestore::DataLeafNode; using blobstore::onblocks::datanodestore::DataNodeStore; -using blockstore::Key; +using blockstore::BlockId; namespace blobstore { namespace onblocks { namespace datatreestore { - LeafHandle::LeafHandle(DataNodeStore *nodeStore, const Key &key) - : _nodeStore(nodeStore), _key(key), _leaf(cpputils::null()) { + LeafHandle::LeafHandle(DataNodeStore *nodeStore, const BlockId &blockId) + : _nodeStore(nodeStore), _blockId(blockId), _leaf(cpputils::null()) { } LeafHandle::LeafHandle(DataNodeStore *nodeStore, DataLeafNode *node) - : _nodeStore(nodeStore), _key(node->key()), + : _nodeStore(nodeStore), _blockId(node->blockId()), _leaf(WithoutOwnership(node)) { } DataLeafNode *LeafHandle::node() { if (_leaf.get() == nullptr) { - auto loaded = _nodeStore->load(_key); + auto loaded = _nodeStore->load(_blockId); ASSERT(loaded != none, "Leaf not found"); auto leaf = dynamic_pointer_move(*loaded); ASSERT(leaf != none, "Loaded leaf is not leaf node"); diff --git a/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.h b/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.h index aba8c67f..b83dbfed 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.h +++ b/src/blobstore/implementations/onblocks/datatreestore/LeafHandle.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace blobstore { namespace onblocks { @@ -16,12 +16,12 @@ namespace blobstore { class LeafHandle final { public: - LeafHandle(datanodestore::DataNodeStore *nodeStore, const blockstore::Key &key); + LeafHandle(datanodestore::DataNodeStore *nodeStore, const blockstore::BlockId &blockId); LeafHandle(datanodestore::DataNodeStore *nodeStore, datanodestore::DataLeafNode *node); LeafHandle(LeafHandle &&rhs) = default; - const blockstore::Key &key() { - return _key; + const blockstore::BlockId &blockId() { + return _blockId; } datanodestore::DataLeafNode *node(); @@ -32,7 +32,7 @@ namespace blobstore { private: datanodestore::DataNodeStore *_nodeStore; - blockstore::Key _key; + blockstore::BlockId _blockId; cpputils::optional_ownership_ptr _leaf; DISALLOW_COPY_AND_ASSIGN(LeafHandle); diff --git a/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.cpp b/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.cpp index 59990f29..a6ae9a61 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.cpp @@ -78,11 +78,11 @@ namespace blobstore { return DataNode::convertToNewInnerNode(std::move(root), _nodeStore->layout(), *copyOfOldRoot); } - void LeafTraverser::_traverseExistingSubtree(const blockstore::Key &key, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, function onExistingLeaf, function onCreateLeaf, function onBacktrackFromSubtree) { + void LeafTraverser::_traverseExistingSubtree(const blockstore::BlockId &blockId, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, function onExistingLeaf, function onCreateLeaf, function onBacktrackFromSubtree) { if (depth == 0) { ASSERT(beginIndex <= 1 && endIndex <= 1, "If root node is a leaf, the (sub)tree has only one leaf - access indices must be 0 or 1."); - LeafHandle leafHandle(_nodeStore, key); + LeafHandle leafHandle(_nodeStore, blockId); if (growLastLeaf) { if (leafHandle.node()->numBytes() != _nodeStore->layout().maxBytesPerLeaf()) { leafHandle.node()->resize(_nodeStore->layout().maxBytesPerLeaf()); @@ -92,9 +92,9 @@ namespace blobstore { onExistingLeaf(leafOffset, isRightBorderNode, std::move(leafHandle)); } } else { - auto node = _nodeStore->load(key); + auto node = _nodeStore->load(blockId); if (node == none) { - throw std::runtime_error("Couldn't find child node " + key.ToString()); + throw std::runtime_error("Couldn't find child node " + blockId.ToString()); } auto inner = dynamic_pointer_move(*node); @@ -122,9 +122,9 @@ namespace blobstore { // we still have to descend to the last old child to fill it with leaves and grow the last old leaf. if (isLeftBorderOfTraversal && beginChild >= numChildren) { ASSERT(numChildren > 0, "Node doesn't have children."); - auto childKey = root->getChild(numChildren-1)->key(); + auto childBlockId = root->getChild(numChildren-1)->blockId(); uint32_t childOffset = (numChildren-1) * leavesPerChild; - _traverseExistingSubtree(childKey, root->depth()-1, leavesPerChild, leavesPerChild, childOffset, true, false, true, + _traverseExistingSubtree(childBlockId, root->depth()-1, leavesPerChild, leavesPerChild, childOffset, true, false, true, [] (uint32_t /*index*/, bool /*isRightBorderNode*/, LeafHandle /*leaf*/) {ASSERT(false, "We don't actually traverse any leaves.");}, [] (uint32_t /*index*/) -> Data {ASSERT(false, "We don't actually traverse any leaves.");}, [] (DataInnerNode* /*node*/) {ASSERT(false, "We don't actually traverse any leaves.");}); @@ -132,7 +132,7 @@ namespace blobstore { // Traverse existing children for (uint32_t childIndex = beginChild; childIndex < std::min(endChild, numChildren); ++childIndex) { - auto childKey = root->getChild(childIndex)->key(); + auto childBlockId = root->getChild(childIndex)->blockId(); uint32_t childOffset = childIndex * leavesPerChild; uint32_t localBeginIndex = utils::maxZeroSubtraction(beginIndex, childOffset); uint32_t localEndIndex = std::min(leavesPerChild, endIndex - childOffset); @@ -140,7 +140,7 @@ namespace blobstore { bool isLastExistingChild = (childIndex == numChildren - 1); bool isLastChild = isLastExistingChild && (numChildren == endChild); ASSERT(localEndIndex <= leavesPerChild, "We don't want the child to add a tree level because it doesn't have enough space for the traversal."); - _traverseExistingSubtree(childKey, root->depth()-1, localBeginIndex, localEndIndex, leafOffset + childOffset, isLeftBorderOfTraversal && isFirstChild, + _traverseExistingSubtree(childBlockId, root->depth()-1, localBeginIndex, localEndIndex, leafOffset + childOffset, isLeftBorderOfTraversal && isFirstChild, isRightBorderNode && isLastChild, shouldGrowLastExistingLeaf && isLastExistingChild, onExistingLeaf, onCreateLeaf, onBacktrackFromSubtree); } @@ -175,7 +175,7 @@ namespace blobstore { uint32_t beginChild = beginIndex/leavesPerChild; uint32_t endChild = utils::ceilDivision(endIndex, leavesPerChild); - vector children; + vector children; children.reserve(endChild); // TODO Remove redundancy of following two for loops by using min/max for calculating the parameters of the recursive call. // Create gap children (i.e. children before the traversal but after the current size) @@ -185,7 +185,7 @@ namespace blobstore { [] (uint32_t /*index*/)->Data {ASSERT(false, "We're only creating gap leaves here, not traversing any.");}, [] (DataInnerNode* /*node*/) {}); ASSERT(child->depth() == depth-1, "Created child node has wrong depth"); - children.push_back(child->key()); + children.push_back(child->blockId()); } // Create new children that are traversed for(uint32_t childIndex = beginChild; childIndex < endChild; ++childIndex) { @@ -194,7 +194,7 @@ namespace blobstore { uint32_t localEndIndex = std::min(leavesPerChild, endIndex - childOffset); auto child = _createNewSubtree(localBeginIndex, localEndIndex, leafOffset + childOffset, depth - 1, onCreateLeaf, onBacktrackFromSubtree); ASSERT(child->depth() == depth-1, "Created child node has wrong depth"); - children.push_back(child->key()); + children.push_back(child->blockId()); } ASSERT(children.size() > 0, "No children created"); @@ -221,7 +221,7 @@ namespace blobstore { unique_ref LeafTraverser::_whileRootHasOnlyOneChildReplaceRootWithItsChild(unique_ref root) { DataInnerNode *inner = dynamic_cast(root.get()); if (inner != nullptr && inner->numChildren() == 1) { - auto newRoot = _whileRootHasOnlyOneChildRemoveRootReturnChild(inner->getChild(0)->key()); + auto newRoot = _whileRootHasOnlyOneChildRemoveRootReturnChild(inner->getChild(0)->blockId()); auto result = _nodeStore->overwriteNodeWith(std::move(root), *newRoot); _nodeStore->remove(std::move(newRoot)); return result; @@ -230,14 +230,14 @@ namespace blobstore { } } - unique_ref LeafTraverser::_whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::Key &key) { - auto current = _nodeStore->load(key); + unique_ref LeafTraverser::_whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::BlockId &blockId) { + auto current = _nodeStore->load(blockId); ASSERT(current != none, "Node not found"); auto inner = dynamic_pointer_move(*current); if (inner == none) { return std::move(*current); } else if ((*inner)->numChildren() == 1) { - auto result = _whileRootHasOnlyOneChildRemoveRootReturnChild((*inner)->getChild(0)->key()); + auto result = _whileRootHasOnlyOneChildRemoveRootReturnChild((*inner)->getChild(0)->blockId()); _nodeStore->remove(std::move(*inner)); return result; } else { diff --git a/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.h b/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.h index 915eb6c4..4eb42864 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.h +++ b/src/blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include "blobstore/implementations/onblocks/datatreestore/LeafHandle.h" namespace blobstore { @@ -45,7 +45,7 @@ namespace blobstore { std::function onExistingLeaf, std::function onCreateLeaf, std::function onBacktrackFromSubtree); - void _traverseExistingSubtree(const blockstore::Key &key, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, + void _traverseExistingSubtree(const blockstore::BlockId &blockId, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, std::function onExistingLeaf, std::function onCreateLeaf, std::function onBacktrackFromSubtree); @@ -56,7 +56,7 @@ namespace blobstore { uint32_t _maxLeavesForTreeDepth(uint8_t depth) const; std::function _createMaxSizeLeaf() const; cpputils::unique_ref _whileRootHasOnlyOneChildReplaceRootWithItsChild(cpputils::unique_ref root); - cpputils::unique_ref _whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::Key &key); + cpputils::unique_ref _whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::BlockId &blockId); DISALLOW_COPY_AND_ASSIGN(LeafTraverser); }; diff --git a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp b/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp index 6f232700..687d1c64 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp @@ -1,6 +1,6 @@ #include "algorithms.h" #include -#include +#include #include "../../datanodestore/DataInnerNode.h" #include "../../datanodestore/DataNodeStore.h" @@ -13,7 +13,7 @@ using cpputils::unique_ref; using blobstore::onblocks::datanodestore::DataInnerNode; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataNodeStore; -using blockstore::Key; +using blockstore::BlockId; using boost::optional; using boost::none; @@ -23,8 +23,8 @@ namespace datatreestore { namespace algorithms { optional> getLastChildAsInnerNode(DataNodeStore *nodeStore, const DataInnerNode &node) { - Key key = node.LastChild()->key(); - auto lastChild = nodeStore->load(key); + BlockId blockId = node.LastChild()->blockId(); + auto lastChild = nodeStore->load(blockId); ASSERT(lastChild != none, "Couldn't load last child"); return dynamic_pointer_move(*lastChild); } diff --git a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/DataTreeRef.h b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/DataTreeRef.h index 26ac1f3e..aedb209a 100644 --- a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/DataTreeRef.h +++ b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/DataTreeRef.h @@ -10,12 +10,12 @@ namespace blobstore { namespace onblocks { namespace parallelaccessdatatreestore { -class DataTreeRef final: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { +class DataTreeRef final: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { public: DataTreeRef(datatreestore::DataTree *baseTree): _baseTree(baseTree) {} - const blockstore::Key &key() const { - return _baseTree->key(); + const blockstore::BlockId &blockId() const { + return _baseTree->blockId(); } uint64_t maxBytesPerLeaf() const { diff --git a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp index b7431f1f..ef65c7cc 100644 --- a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp +++ b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp @@ -9,7 +9,7 @@ using cpputils::make_unique_ref; using boost::optional; using blobstore::onblocks::datatreestore::DataTreeStore; -using blockstore::Key; +using blockstore::BlockId; namespace blobstore { namespace onblocks { @@ -26,23 +26,23 @@ ParallelAccessDataTreeStore::ParallelAccessDataTreeStore(unique_ref> ParallelAccessDataTreeStore::load(const blockstore::Key &key) { - return _parallelAccessStore.load(key); +optional> ParallelAccessDataTreeStore::load(const blockstore::BlockId &blockId) { + return _parallelAccessStore.load(blockId); } unique_ref ParallelAccessDataTreeStore::createNewTree() { auto dataTree = _dataTreeStore->createNewTree(); - Key key = dataTree->key(); - return _parallelAccessStore.add(key, std::move(dataTree)); + BlockId blockId = dataTree->blockId(); + return _parallelAccessStore.add(blockId, std::move(dataTree)); } void ParallelAccessDataTreeStore::remove(unique_ref tree) { - Key key = tree->key(); - return _parallelAccessStore.remove(key, std::move(tree)); + BlockId blockId = tree->blockId(); + return _parallelAccessStore.remove(blockId, std::move(tree)); } -void ParallelAccessDataTreeStore::remove(const Key &key) { - return _parallelAccessStore.remove(key); +void ParallelAccessDataTreeStore::remove(const BlockId &blockId) { + return _parallelAccessStore.remove(blockId); } diff --git a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.h b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.h index ef4e5408..e0387a4b 100644 --- a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.h +++ b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include "../datatreestore/DataTreeStore.h" @@ -20,12 +20,12 @@ public: ParallelAccessDataTreeStore(cpputils::unique_ref dataTreeStore); ~ParallelAccessDataTreeStore(); - boost::optional> load(const blockstore::Key &key); + boost::optional> load(const blockstore::BlockId &blockId); cpputils::unique_ref createNewTree(); void remove(cpputils::unique_ref tree); - void remove(const blockstore::Key &key); + void remove(const blockstore::BlockId &blockId); //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft uint64_t virtualBlocksizeBytes() const; @@ -34,7 +34,7 @@ public: private: cpputils::unique_ref _dataTreeStore; - parallelaccessstore::ParallelAccessStore _parallelAccessStore; + parallelaccessstore::ParallelAccessStore _parallelAccessStore; DISALLOW_COPY_AND_ASSIGN(ParallelAccessDataTreeStore); }; diff --git a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStoreAdapter.h b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStoreAdapter.h index ad1cf487..db7ce506 100644 --- a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStoreAdapter.h +++ b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStoreAdapter.h @@ -11,22 +11,22 @@ namespace blobstore { namespace onblocks { namespace parallelaccessdatatreestore { -class ParallelAccessDataTreeStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore { +class ParallelAccessDataTreeStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore { public: ParallelAccessDataTreeStoreAdapter(datatreestore::DataTreeStore *baseDataTreeStore) :_baseDataTreeStore(std::move(baseDataTreeStore)) { } - boost::optional> loadFromBaseStore(const blockstore::Key &key) override { - return _baseDataTreeStore->load(key); + boost::optional> loadFromBaseStore(const blockstore::BlockId &blockId) override { + return _baseDataTreeStore->load(blockId); } void removeFromBaseStore(cpputils::unique_ref dataTree) override { return _baseDataTreeStore->remove(std::move(dataTree)); } - void removeFromBaseStore(const blockstore::Key &key) override { - return _baseDataTreeStore->remove(key); + void removeFromBaseStore(const blockstore::BlockId &blockId) override { + return _baseDataTreeStore->remove(blockId); } private: diff --git a/src/blobstore/interface/Blob.h b/src/blobstore/interface/Blob.h index 972461dc..51b84e3d 100644 --- a/src/blobstore/interface/Blob.h +++ b/src/blobstore/interface/Blob.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace blobstore { @@ -13,8 +13,8 @@ class Blob { public: virtual ~Blob() {} - //TODO Use own Key class for blobstore - virtual const blockstore::Key &key() const = 0; + //TODO Use own Id class for blobstore + virtual const blockstore::BlockId &blockId() const = 0; virtual uint64_t size() const = 0; virtual void resize(uint64_t numBytes) = 0; diff --git a/src/blobstore/interface/BlobStore.h b/src/blobstore/interface/BlobStore.h index 5175ec61..e1cf3fed 100644 --- a/src/blobstore/interface/BlobStore.h +++ b/src/blobstore/interface/BlobStore.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include namespace blobstore { @@ -17,9 +17,9 @@ public: virtual ~BlobStore() {} virtual cpputils::unique_ref create() = 0; - virtual boost::optional> load(const blockstore::Key &key) = 0; + virtual boost::optional> load(const blockstore::BlockId &blockId) = 0; virtual void remove(cpputils::unique_ref blob) = 0; - virtual void remove(const blockstore::Key &key) = 0; + virtual void remove(const blockstore::BlockId &blockId) = 0; virtual uint64_t numBlocks() const = 0; virtual uint64_t estimateSpaceForNumBlocksLeft() const = 0; diff --git a/src/blockstore/CMakeLists.txt b/src/blockstore/CMakeLists.txt index 2e3b1e16..652b566f 100644 --- a/src/blockstore/CMakeLists.txt +++ b/src/blockstore/CMakeLists.txt @@ -1,7 +1,7 @@ project (blockstore) set(SOURCES - utils/Key.cpp + utils/BlockId.cpp utils/IdWrapper.cpp utils/BlockStoreUtils.cpp utils/FileDoesntExistException.cpp @@ -27,7 +27,7 @@ set(SOURCES implementations/low2highlevel/LowToHighLevelBlockStore.cpp implementations/integrity/IntegrityBlockStore2.cpp implementations/integrity/KnownBlockVersions.cpp - implementations/integrity/ClientIdAndBlockKey.cpp + implementations/integrity/ClientIdAndBlockId.cpp implementations/integrity/IntegrityViolationError.cpp implementations/mock/MockBlockStore.cpp implementations/mock/MockBlock.cpp diff --git a/src/blockstore/implementations/caching/CachingBlockStore2.cpp b/src/blockstore/implementations/caching/CachingBlockStore2.cpp index 1584ebb8..5ea99646 100644 --- a/src/blockstore/implementations/caching/CachingBlockStore2.cpp +++ b/src/blockstore/implementations/caching/CachingBlockStore2.cpp @@ -22,17 +22,17 @@ using std::mutex; namespace blockstore { namespace caching { -CachingBlockStore2::CachedBlock::CachedBlock(const CachingBlockStore2* blockStore, const Key& key, cpputils::Data data, bool isDirty) - : _blockStore(blockStore), _key(key), _data(std::move(data)), _dirty(isDirty) { +CachingBlockStore2::CachedBlock::CachedBlock(const CachingBlockStore2* blockStore, const BlockId &blockId, cpputils::Data data, bool isDirty) + : _blockStore(blockStore), _blockId(blockId), _data(std::move(data)), _dirty(isDirty) { } CachingBlockStore2::CachedBlock::~CachedBlock() { if (_dirty) { - _blockStore->_baseBlockStore->store(_key, _data); + _blockStore->_baseBlockStore->store(_blockId, _data); } // remove it from the list of blocks not in the base store, if it's on it unique_lock lock(_blockStore->_cachedBlocksNotInBaseStoreMutex); - _blockStore->_cachedBlocksNotInBaseStore.erase(_key); + _blockStore->_cachedBlocksNotInBaseStore.erase(_blockId); } const Data& CachingBlockStore2::CachedBlock::read() const { @@ -52,30 +52,30 @@ CachingBlockStore2::CachingBlockStore2(cpputils::unique_ref baseBlo : _baseBlockStore(std::move(baseBlockStore)), _cachedBlocksNotInBaseStoreMutex(), _cachedBlocksNotInBaseStore(), _cache() { } -bool CachingBlockStore2::tryCreate(const Key &key, const Data &data) { +bool CachingBlockStore2::tryCreate(const BlockId &blockId, const Data &data) { //TODO Check if block exists in base store? Performance hit? It's very unlikely it exists. - auto popped = _cache.pop(key); + auto popped = _cache.pop(blockId); if (popped != boost::none) { // entry already exists in cache - _cache.push(key, std::move(*popped)); // push the just popped element back to the cache + _cache.push(blockId, std::move(*popped)); // push the just popped element back to the cache return false; } else { - _cache.push(key, make_unique_ref(this, key, data.copy(), true)); + _cache.push(blockId, make_unique_ref(this, blockId, data.copy(), true)); unique_lock lock(_cachedBlocksNotInBaseStoreMutex); - _cachedBlocksNotInBaseStore.insert(key); + _cachedBlocksNotInBaseStore.insert(blockId); return true; } } -bool CachingBlockStore2::remove(const Key &key) { +bool CachingBlockStore2::remove(const BlockId &blockId) { // TODO Don't write-through but cache remove operations - auto popped = _cache.pop(key); + auto popped = _cache.pop(blockId); if (popped != boost::none) { // Remove from base store if it exists in the base store { unique_lock lock(_cachedBlocksNotInBaseStoreMutex); - if (_cachedBlocksNotInBaseStore.count(key) == 0) { - const bool existedInBaseStore = _baseBlockStore->remove(key); + if (_cachedBlocksNotInBaseStore.count(blockId) == 0) { + const bool existedInBaseStore = _baseBlockStore->remove(blockId); if (!existedInBaseStore) { throw std::runtime_error("Tried to remove block. Block existed in cache and stated it exists in base store, but wasn't found there."); } @@ -85,45 +85,45 @@ bool CachingBlockStore2::remove(const Key &key) { std::move(**popped).markNotDirty(); return true; } else { - return _baseBlockStore->remove(key); + return _baseBlockStore->remove(blockId); } } -optional> CachingBlockStore2::_loadFromCacheOrBaseStore(const Key &key) const { - auto popped = _cache.pop(key); +optional> CachingBlockStore2::_loadFromCacheOrBaseStore(const BlockId &blockId) const { + auto popped = _cache.pop(blockId); if (popped != boost::none) { return std::move(*popped); } else { - auto loaded = _baseBlockStore->load(key); + auto loaded = _baseBlockStore->load(blockId); if (loaded == boost::none) { return boost::none; } - return make_unique_ref(this, key, std::move(*loaded), false); + return make_unique_ref(this, blockId, std::move(*loaded), false); } } -optional CachingBlockStore2::load(const Key &key) const { - auto loaded = _loadFromCacheOrBaseStore(key); +optional CachingBlockStore2::load(const BlockId &blockId) const { + auto loaded = _loadFromCacheOrBaseStore(blockId); if (loaded == boost::none) { // TODO Cache non-existence? return boost::none; } optional result = (*loaded)->read().copy(); - _cache.push(key, std::move(*loaded)); + _cache.push(blockId, std::move(*loaded)); return result; } -void CachingBlockStore2::store(const Key &key, const Data &data) { - auto popped = _cache.pop(key); +void CachingBlockStore2::store(const BlockId &blockId, const Data &data) { + auto popped = _cache.pop(blockId); if (popped != boost::none) { (*popped)->write(data.copy()); } else { - popped = make_unique_ref(this, key, data.copy(), false); + popped = make_unique_ref(this, blockId, data.copy(), false); // TODO Instead of storing it to the base store, we could just keep it dirty in the cache // and (if it doesn't exist in base store yet) add it to _cachedBlocksNotInBaseStore - _baseBlockStore->store(key, data); + _baseBlockStore->store(blockId, data); } - _cache.push(key, std::move(*popped)); + _cache.push(blockId, std::move(*popped)); } uint64_t CachingBlockStore2::numBlocks() const { @@ -143,11 +143,11 @@ uint64_t CachingBlockStore2::blockSizeFromPhysicalBlockSize(uint64_t blockSize) return _baseBlockStore->blockSizeFromPhysicalBlockSize(blockSize); } -void CachingBlockStore2::forEachBlock(std::function callback) const { +void CachingBlockStore2::forEachBlock(std::function callback) const { { unique_lock lock(_cachedBlocksNotInBaseStoreMutex); - for (const Key &key : _cachedBlocksNotInBaseStore) { - callback(key); + for (const BlockId &blockId : _cachedBlocksNotInBaseStore) { + callback(blockId); } } _baseBlockStore->forEachBlock(std::move(callback)); diff --git a/src/blockstore/implementations/caching/CachingBlockStore2.h b/src/blockstore/implementations/caching/CachingBlockStore2.h index 81f52ca6..5ccf8664 100644 --- a/src/blockstore/implementations/caching/CachingBlockStore2.h +++ b/src/blockstore/implementations/caching/CachingBlockStore2.h @@ -14,14 +14,14 @@ class CachingBlockStore2 final: public BlockStore2 { public: CachingBlockStore2(cpputils::unique_ref baseBlockStore); - bool tryCreate(const Key &key, const cpputils::Data &data) override; - bool remove(const Key &key) override; - boost::optional load(const Key &key) const override; - void store(const Key &key, const cpputils::Data &data) override; + bool tryCreate(const BlockId &blockId, const cpputils::Data &data) override; + bool remove(const BlockId &blockId) override; + boost::optional load(const BlockId &blockId) const override; + void store(const BlockId &blockId, const cpputils::Data &data) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; void flush(); @@ -29,7 +29,7 @@ private: // TODO Is a cache implementation with onEvict callback instead of destructor simpler? class CachedBlock final { public: - CachedBlock(const CachingBlockStore2* blockStore, const Key& key, cpputils::Data data, bool isDirty); + CachedBlock(const CachingBlockStore2* blockStore, const BlockId &blockId, cpputils::Data data, bool isDirty); ~CachedBlock(); const cpputils::Data& read() const; @@ -37,22 +37,22 @@ private: void markNotDirty() &&; // only on rvalue because the destructor should be called after calling markNotDirty(). It shouldn't be put back into the cache. private: const CachingBlockStore2* _blockStore; - Key _key; + BlockId _blockId; cpputils::Data _data; bool _dirty; DISALLOW_COPY_AND_ASSIGN(CachedBlock); }; - boost::optional> _loadFromCacheOrBaseStore(const Key &key) const; + boost::optional> _loadFromCacheOrBaseStore(const BlockId &blockId) const; cpputils::unique_ref _baseBlockStore; friend class CachedBlock; // TODO Store CachedBlock directly, without unique_ref mutable std::mutex _cachedBlocksNotInBaseStoreMutex; - mutable std::unordered_set _cachedBlocksNotInBaseStore; - mutable Cache, 1000> _cache; + mutable std::unordered_set _cachedBlocksNotInBaseStore; + mutable Cache, 1000> _cache; DISALLOW_COPY_AND_ASSIGN(CachingBlockStore2); }; diff --git a/src/blockstore/implementations/compressing/CompressedBlock.h b/src/blockstore/implementations/compressing/CompressedBlock.h index 5098597d..84951d8d 100644 --- a/src/blockstore/implementations/compressing/CompressedBlock.h +++ b/src/blockstore/implementations/compressing/CompressedBlock.h @@ -18,8 +18,8 @@ template class CompressingBlockStore; template class CompressedBlock final: public Block { public: - static boost::optional> TryCreateNew(BlockStore *baseBlockStore, const Key &key, cpputils::Data decompressedData); - static cpputils::unique_ref Overwrite(BlockStore *baseBlockStore, const Key &key, cpputils::Data decompressedData); + static boost::optional> TryCreateNew(BlockStore *baseBlockStore, const BlockId &blockId, cpputils::Data decompressedData); + static cpputils::unique_ref Overwrite(BlockStore *baseBlockStore, const BlockId &blockId, cpputils::Data decompressedData); static cpputils::unique_ref Decompress(cpputils::unique_ref baseBlock); CompressedBlock(cpputils::unique_ref baseBlock, cpputils::Data decompressedData); @@ -47,9 +47,9 @@ private: }; template -boost::optional>> CompressedBlock::TryCreateNew(BlockStore *baseBlockStore, const Key &key, cpputils::Data decompressedData) { +boost::optional>> CompressedBlock::TryCreateNew(BlockStore *baseBlockStore, const BlockId &blockId, cpputils::Data decompressedData) { cpputils::Data compressed = Compressor::Compress(decompressedData); - auto baseBlock = baseBlockStore->tryCreate(key, std::move(compressed)); + auto baseBlock = baseBlockStore->tryCreate(blockId, std::move(compressed)); if (baseBlock == boost::none) { //TODO Test this code branch return boost::none; @@ -59,9 +59,9 @@ boost::optional>> CompressedBlo } template -cpputils::unique_ref> CompressedBlock::Overwrite(BlockStore *baseBlockStore, const Key &key, cpputils::Data decompressedData) { +cpputils::unique_ref> CompressedBlock::Overwrite(BlockStore *baseBlockStore, const BlockId &blockId, cpputils::Data decompressedData) { cpputils::Data compressed = Compressor::Compress(decompressedData); - auto baseBlock = baseBlockStore->overwrite(key, std::move(compressed)); + auto baseBlock = baseBlockStore->overwrite(blockId, std::move(compressed)); return cpputils::make_unique_ref>(std::move(baseBlock), std::move(decompressedData)); } @@ -74,7 +74,7 @@ cpputils::unique_ref> CompressedBlock::D template CompressedBlock::CompressedBlock(cpputils::unique_ref baseBlock, cpputils::Data decompressedData) - : Block(baseBlock->key()), + : Block(baseBlock->blockId()), _baseBlock(std::move(baseBlock)), _decompressedData(std::move(decompressedData)), _dataChanged(false) { diff --git a/src/blockstore/implementations/compressing/CompressingBlockStore.h b/src/blockstore/implementations/compressing/CompressingBlockStore.h index ef187b31..4fe258f8 100644 --- a/src/blockstore/implementations/compressing/CompressingBlockStore.h +++ b/src/blockstore/implementations/compressing/CompressingBlockStore.h @@ -14,15 +14,15 @@ public: CompressingBlockStore(cpputils::unique_ref baseBlockStore); ~CompressingBlockStore(); - Key createKey() override; - boost::optional> tryCreate(const Key &key, cpputils::Data data) override; - boost::optional> load(const Key &key) override; - cpputils::unique_ref overwrite(const blockstore::Key &key, cpputils::Data data) override; - void remove(const Key &key) override; + BlockId createBlockId() override; + boost::optional> tryCreate(const BlockId &blockId, cpputils::Data data) override; + boost::optional> load(const BlockId &blockId) override; + cpputils::unique_ref overwrite(const blockstore::BlockId &blockId, cpputils::Data data) override; + void remove(const BlockId &blockId) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; private: cpputils::unique_ref _baseBlockStore; @@ -40,13 +40,13 @@ CompressingBlockStore::~CompressingBlockStore() { } template -Key CompressingBlockStore::createKey() { - return _baseBlockStore->createKey(); +BlockId CompressingBlockStore::createBlockId() { + return _baseBlockStore->createBlockId(); } template -boost::optional> CompressingBlockStore::tryCreate(const Key &key, cpputils::Data data) { - auto result = CompressedBlock::TryCreateNew(_baseBlockStore.get(), key, std::move(data)); +boost::optional> CompressingBlockStore::tryCreate(const BlockId &blockId, cpputils::Data data) { + auto result = CompressedBlock::TryCreateNew(_baseBlockStore.get(), blockId, std::move(data)); if (result == boost::none) { return boost::none; } @@ -54,13 +54,13 @@ boost::optional> CompressingBlockStore:: } template -cpputils::unique_ref CompressingBlockStore::overwrite(const blockstore::Key &key, cpputils::Data data) { - return CompressedBlock::Overwrite(_baseBlockStore.get(), key, std::move(data)); +cpputils::unique_ref CompressingBlockStore::overwrite(const blockstore::BlockId &blockId, cpputils::Data data) { + return CompressedBlock::Overwrite(_baseBlockStore.get(), blockId, std::move(data)); } template -boost::optional> CompressingBlockStore::load(const Key &key) { - auto loaded = _baseBlockStore->load(key); +boost::optional> CompressingBlockStore::load(const BlockId &blockId) { + auto loaded = _baseBlockStore->load(blockId); if (loaded == boost::none) { return boost::none; } @@ -68,8 +68,8 @@ boost::optional> CompressingBlockStore:: } template -void CompressingBlockStore::remove(const Key &key) { - return _baseBlockStore->remove(key); +void CompressingBlockStore::remove(const BlockId &blockId) { + return _baseBlockStore->remove(blockId); } template @@ -83,7 +83,7 @@ uint64_t CompressingBlockStore::estimateNumFreeBytes() const { } template -void CompressingBlockStore::forEachBlock(std::function callback) const { +void CompressingBlockStore::forEachBlock(std::function callback) const { return _baseBlockStore->forEachBlock(callback); } diff --git a/src/blockstore/implementations/encrypted/EncryptedBlockStore2.h b/src/blockstore/implementations/encrypted/EncryptedBlockStore2.h index c9a6622c..4238d390 100644 --- a/src/blockstore/implementations/encrypted/EncryptedBlockStore2.h +++ b/src/blockstore/implementations/encrypted/EncryptedBlockStore2.h @@ -19,14 +19,14 @@ public: EncryptedBlockStore2(cpputils::unique_ref baseBlockStore, const typename Cipher::EncryptionKey &encKey); - bool tryCreate(const Key &key, const cpputils::Data &data) override; - bool remove(const Key &key) override; - boost::optional load(const Key &key) const override; - void store(const Key &key, const cpputils::Data &data) override; + bool tryCreate(const BlockId &blockId, const cpputils::Data &data) override; + bool remove(const BlockId &blockId) override; + boost::optional load(const BlockId &blockId) const override; + void store(const BlockId &blockId, const cpputils::Data &data) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; //This function should only be used by test cases void __setKey(const typename Cipher::EncryptionKey &encKey); @@ -40,11 +40,11 @@ private: static constexpr uint16_t FORMAT_VERSION_HEADER = 1; cpputils::Data _encrypt(const cpputils::Data &data) const; - boost::optional _tryDecrypt(const Key &key, const cpputils::Data &data) const; + boost::optional _tryDecrypt(const BlockId &blockId, const cpputils::Data &data) const; static cpputils::Data _prependFormatHeaderToData(const cpputils::Data &data); #ifndef CRYFS_NO_COMPATIBILITY - static bool _keyHeaderIsCorrect(const Key &key, const cpputils::Data &data); + static bool _blockIdHeaderIsCorrect(const BlockId &blockId, const cpputils::Data &data); static cpputils::Data _migrateBlock(const cpputils::Data &data); #endif static void _checkFormatHeader(const cpputils::Data &data); @@ -70,30 +70,30 @@ inline EncryptedBlockStore2::EncryptedBlockStore2(cpputils::unique_ref -inline bool EncryptedBlockStore2::tryCreate(const Key &key, const cpputils::Data &data) { +inline bool EncryptedBlockStore2::tryCreate(const BlockId &blockId, const cpputils::Data &data) { cpputils::Data encrypted = _encrypt(data); - return _baseBlockStore->tryCreate(key, encrypted); + return _baseBlockStore->tryCreate(blockId, encrypted); } template -inline bool EncryptedBlockStore2::remove(const Key &key) { - return _baseBlockStore->remove(key); +inline bool EncryptedBlockStore2::remove(const BlockId &blockId) { + return _baseBlockStore->remove(blockId); } template -inline boost::optional EncryptedBlockStore2::load(const Key &key) const { - auto loaded = _baseBlockStore->load(key); +inline boost::optional EncryptedBlockStore2::load(const BlockId &blockId) const { + auto loaded = _baseBlockStore->load(blockId); if (boost::none == loaded) { return boost::optional(boost::none); } - return _tryDecrypt(key, *loaded); + return _tryDecrypt(blockId, *loaded); } template -inline void EncryptedBlockStore2::store(const Key &key, const cpputils::Data &data) { +inline void EncryptedBlockStore2::store(const BlockId &blockId, const cpputils::Data &data) { cpputils::Data encrypted = _encrypt(data); - return _baseBlockStore->store(key, encrypted); + return _baseBlockStore->store(blockId, encrypted); } template @@ -116,7 +116,7 @@ inline uint64_t EncryptedBlockStore2::blockSizeFromPhysicalBlockSize(uin } template -inline void EncryptedBlockStore2::forEachBlock(std::function callback) const { +inline void EncryptedBlockStore2::forEachBlock(std::function callback) const { return _baseBlockStore->forEachBlock(std::move(callback)); } @@ -127,7 +127,7 @@ inline cpputils::Data EncryptedBlockStore2::_encrypt(const cpputils::Dat } template -inline boost::optional EncryptedBlockStore2::_tryDecrypt(const Key &key, const cpputils::Data &data) const { +inline boost::optional EncryptedBlockStore2::_tryDecrypt(const BlockId &blockId, const cpputils::Data &data) const { _checkFormatHeader(data); boost::optional decrypted = Cipher::decrypt((CryptoPP::byte*)data.dataOffset(sizeof(FORMAT_VERSION_HEADER)), data.size() - sizeof(FORMAT_VERSION_HEADER), _encKey); if (decrypted == boost::none) { @@ -137,7 +137,7 @@ inline boost::optional EncryptedBlockStore2::_tryDecrypt #ifndef CRYFS_NO_COMPATIBILITY if (FORMAT_VERSION_HEADER_OLD == _readFormatHeader(data)) { - if (!_keyHeaderIsCorrect(key, *decrypted)) { + if (!_blockIdHeaderIsCorrect(blockId, *decrypted)) { return boost::none; } *decrypted = _migrateBlock(*decrypted); @@ -152,12 +152,12 @@ inline boost::optional EncryptedBlockStore2::_tryDecrypt #ifndef CRYFS_NO_COMPATIBILITY template inline cpputils::Data EncryptedBlockStore2::_migrateBlock(const cpputils::Data &data) { - return data.copyAndRemovePrefix(Key::BINARY_LENGTH); + return data.copyAndRemovePrefix(BlockId::BINARY_LENGTH); } template -inline bool EncryptedBlockStore2::_keyHeaderIsCorrect(const Key &key, const cpputils::Data &data) { - return key == Key::FromBinary(data.data()); +inline bool EncryptedBlockStore2::_blockIdHeaderIsCorrect(const BlockId &blockId, const cpputils::Data &data) { + return blockId == BlockId::FromBinary(data.data()); } #endif diff --git a/src/blockstore/implementations/inmemory/InMemoryBlockStore2.cpp b/src/blockstore/implementations/inmemory/InMemoryBlockStore2.cpp index 4f093789..cb7da904 100644 --- a/src/blockstore/implementations/inmemory/InMemoryBlockStore2.cpp +++ b/src/blockstore/implementations/inmemory/InMemoryBlockStore2.cpp @@ -23,21 +23,21 @@ namespace inmemory { InMemoryBlockStore2::InMemoryBlockStore2() : _blocks() {} -bool InMemoryBlockStore2::tryCreate(const Key &key, const Data &data) { +bool InMemoryBlockStore2::tryCreate(const BlockId &blockId, const Data &data) { std::unique_lock lock(_mutex); - return _tryCreate(key, data); + return _tryCreate(blockId, data); } -bool InMemoryBlockStore2::_tryCreate(const Key &key, const Data &data) { - auto result = _blocks.insert(make_pair(key, data.copy())); - return result.second; // Return if insertion was successful (i.e. key didn't exist yet) +bool InMemoryBlockStore2::_tryCreate(const BlockId &blockId, const Data &data) { + auto result = _blocks.insert(make_pair(blockId, data.copy())); + return result.second; // Return if insertion was successful (i.e. blockId didn't exist yet) } -bool InMemoryBlockStore2::remove(const Key &key) { +bool InMemoryBlockStore2::remove(const BlockId &blockId) { std::unique_lock lock(_mutex); - auto found = _blocks.find(key); + auto found = _blocks.find(blockId); if (found == _blocks.end()) { - // Key not found + // BlockId not found return false; } @@ -45,20 +45,20 @@ bool InMemoryBlockStore2::remove(const Key &key) { return true; } -optional InMemoryBlockStore2::load(const Key &key) const { +optional InMemoryBlockStore2::load(const BlockId &blockId) const { std::unique_lock lock(_mutex); - auto found = _blocks.find(key); + auto found = _blocks.find(blockId); if (found == _blocks.end()) { return boost::none; } return found->second.copy(); } -void InMemoryBlockStore2::store(const Key &key, const Data &data) { +void InMemoryBlockStore2::store(const BlockId &blockId, const Data &data) { std::unique_lock lock(_mutex); - auto found = _blocks.find(key); + auto found = _blocks.find(blockId); if (found == _blocks.end()) { - bool success = _tryCreate(key, data); + bool success = _tryCreate(blockId, data); if (!success) { throw std::runtime_error("Could neither save nor create the block in InMemoryBlockStore::store()"); } @@ -81,9 +81,9 @@ uint64_t InMemoryBlockStore2::blockSizeFromPhysicalBlockSize(uint64_t blockSize) return blockSize; } -vector InMemoryBlockStore2::_allBlockKeys() const { +vector InMemoryBlockStore2::_allBlockIds() const { std::unique_lock lock(_mutex); - vector result; + vector result; result.reserve(_blocks.size()); for (const auto &entry : _blocks) { result.push_back(entry.first); @@ -91,10 +91,10 @@ vector InMemoryBlockStore2::_allBlockKeys() const { return result; } -void InMemoryBlockStore2::forEachBlock(std::function callback) const { - auto keys = _allBlockKeys(); - for (const auto &key : keys) { - callback(key); +void InMemoryBlockStore2::forEachBlock(std::function callback) const { + auto blockIds = _allBlockIds(); + for (const auto &blockId : blockIds) { + callback(blockId); } } diff --git a/src/blockstore/implementations/inmemory/InMemoryBlockStore2.h b/src/blockstore/implementations/inmemory/InMemoryBlockStore2.h index ffbeb6d2..68701b59 100644 --- a/src/blockstore/implementations/inmemory/InMemoryBlockStore2.h +++ b/src/blockstore/implementations/inmemory/InMemoryBlockStore2.h @@ -13,20 +13,20 @@ class InMemoryBlockStore2 final: public BlockStore2 { public: InMemoryBlockStore2(); - bool tryCreate(const Key &key, const cpputils::Data &data) override; - bool remove(const Key &key) override; - boost::optional load(const Key &key) const override; - void store(const Key &key, const cpputils::Data &data) override; + bool tryCreate(const BlockId &blockId, const cpputils::Data &data) override; + bool remove(const BlockId &blockId) override; + boost::optional load(const BlockId &blockId) const override; + void store(const BlockId &blockId, const cpputils::Data &data) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; private: - std::vector _allBlockKeys() const; - bool _tryCreate(const Key &key, const cpputils::Data &data); + std::vector _allBlockIds() const; + bool _tryCreate(const BlockId &blockId, const cpputils::Data &data); - std::unordered_map _blocks; + std::unordered_map _blocks; mutable std::mutex _mutex; DISALLOW_COPY_AND_ASSIGN(InMemoryBlockStore2); diff --git a/src/blockstore/implementations/integrity/ClientIdAndBlockId.cpp b/src/blockstore/implementations/integrity/ClientIdAndBlockId.cpp new file mode 100644 index 00000000..11ab813f --- /dev/null +++ b/src/blockstore/implementations/integrity/ClientIdAndBlockId.cpp @@ -0,0 +1 @@ +#include "ClientIdAndBlockId.h" \ No newline at end of file diff --git a/src/blockstore/implementations/integrity/ClientIdAndBlockKey.h b/src/blockstore/implementations/integrity/ClientIdAndBlockId.h similarity index 65% rename from src/blockstore/implementations/integrity/ClientIdAndBlockKey.h rename to src/blockstore/implementations/integrity/ClientIdAndBlockId.h index 43155bb4..edde23a5 100644 --- a/src/blockstore/implementations/integrity/ClientIdAndBlockKey.h +++ b/src/blockstore/implementations/integrity/ClientIdAndBlockId.h @@ -1,16 +1,16 @@ #pragma once -#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_INTEGRITY_CLIENTIDANDBLOCKKEY_H_ -#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_INTEGRITY_CLIENTIDANDBLOCKKEY_H_ +#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_INTEGRITY_CLIENTIDANDBLOCKID_H_ +#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_INTEGRITY_CLIENTIDANDBLOCKID_H_ #include -#include "../../utils/Key.h" +#include "blockstore/utils/BlockId.h" namespace blockstore { namespace integrity { - struct ClientIdAndBlockKey { + struct ClientIdAndBlockId { uint32_t clientId; - Key blockKey; + BlockId blockId; }; } @@ -18,15 +18,15 @@ namespace blockstore { // Allow using it in std::unordered_set / std::unordered_map namespace std { - template<> struct hash { - size_t operator()(const blockstore::integrity::ClientIdAndBlockKey &ref) const { - return std::hash()(ref.clientId) ^ std::hash()(ref.blockKey); + template<> struct hash { + size_t operator()(const blockstore::integrity::ClientIdAndBlockId &ref) const { + return std::hash()(ref.clientId) ^ std::hash()(ref.blockId); } }; - template<> struct equal_to { - size_t operator()(const blockstore::integrity::ClientIdAndBlockKey &lhs, const blockstore::integrity::ClientIdAndBlockKey &rhs) const { - return lhs.clientId == rhs.clientId && lhs.blockKey == rhs.blockKey; + template<> struct equal_to { + size_t operator()(const blockstore::integrity::ClientIdAndBlockId &lhs, const blockstore::integrity::ClientIdAndBlockId &rhs) const { + return lhs.clientId == rhs.clientId && lhs.blockId == rhs.blockId; } }; } diff --git a/src/blockstore/implementations/integrity/ClientIdAndBlockKey.cpp b/src/blockstore/implementations/integrity/ClientIdAndBlockKey.cpp deleted file mode 100644 index 00f00d4c..00000000 --- a/src/blockstore/implementations/integrity/ClientIdAndBlockKey.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "ClientIdAndBlockKey.h" \ No newline at end of file diff --git a/src/blockstore/implementations/integrity/IntegrityBlockStore2.cpp b/src/blockstore/implementations/integrity/IntegrityBlockStore2.cpp index 6697611f..27fe4ceb 100644 --- a/src/blockstore/implementations/integrity/IntegrityBlockStore2.cpp +++ b/src/blockstore/implementations/integrity/IntegrityBlockStore2.cpp @@ -22,21 +22,21 @@ constexpr unsigned int IntegrityBlockStore2::CLIENTID_HEADER_OFFSET; constexpr unsigned int IntegrityBlockStore2::VERSION_HEADER_OFFSET; constexpr unsigned int IntegrityBlockStore2::HEADER_LENGTH; -Data IntegrityBlockStore2::_prependHeaderToData(const Key& key, uint32_t myClientId, uint64_t version, const Data &data) { - static_assert(HEADER_LENGTH == sizeof(FORMAT_VERSION_HEADER) + Key::BINARY_LENGTH + sizeof(myClientId) + sizeof(version), "Wrong header length"); +Data IntegrityBlockStore2::_prependHeaderToData(const BlockId& blockId, uint32_t myClientId, uint64_t version, const Data &data) { + static_assert(HEADER_LENGTH == sizeof(FORMAT_VERSION_HEADER) + BlockId::BINARY_LENGTH + sizeof(myClientId) + sizeof(version), "Wrong header length"); Data result(data.size() + HEADER_LENGTH); std::memcpy(result.dataOffset(0), &FORMAT_VERSION_HEADER, sizeof(FORMAT_VERSION_HEADER)); - std::memcpy(result.dataOffset(ID_HEADER_OFFSET), key.data().data(), Key::BINARY_LENGTH); + std::memcpy(result.dataOffset(ID_HEADER_OFFSET), blockId.data().data(), BlockId::BINARY_LENGTH); std::memcpy(result.dataOffset(CLIENTID_HEADER_OFFSET), &myClientId, sizeof(myClientId)); std::memcpy(result.dataOffset(VERSION_HEADER_OFFSET), &version, sizeof(version)); std::memcpy((uint8_t*)result.dataOffset(HEADER_LENGTH), data.data(), data.size()); return result; } -void IntegrityBlockStore2::_checkHeader(const Key &key, const Data &data) const { +void IntegrityBlockStore2::_checkHeader(const BlockId &blockId, const Data &data) const { _checkFormatHeader(data); - _checkIdHeader(key, data); - _checkVersionHeader(key, data); + _checkIdHeader(blockId, data); + _checkVersionHeader(blockId, data); } void IntegrityBlockStore2::_checkFormatHeader(const Data &data) const { @@ -45,19 +45,19 @@ void IntegrityBlockStore2::_checkFormatHeader(const Data &data) const { } } -void IntegrityBlockStore2::_checkVersionHeader(const Key &key, const Data &data) const { +void IntegrityBlockStore2::_checkVersionHeader(const BlockId &blockId, const Data &data) const { uint32_t clientId = _readClientId(data); uint64_t version = _readVersion(data); - if(!_knownBlockVersions.checkAndUpdateVersion(clientId, key, version)) { + if(!_knownBlockVersions.checkAndUpdateVersion(clientId, blockId, version)) { integrityViolationDetected("The block version number is too low. Did an attacker try to roll back the block or to re-introduce a deleted block?"); } } -void IntegrityBlockStore2::_checkIdHeader(const Key &expectedKey, const Data &data) const { - Key actualKey = _readBlockId(data); - if (expectedKey != actualKey) { - integrityViolationDetected("The block key is wrong. Did an attacker try to rename some blocks?"); +void IntegrityBlockStore2::_checkIdHeader(const BlockId &expectedBlockId, const Data &data) const { + BlockId actualBlockId = _readBlockId(data); + if (expectedBlockId != actualBlockId) { + integrityViolationDetected("The block id is wrong. Did an attacker try to rename some blocks?"); } } @@ -71,8 +71,8 @@ uint32_t IntegrityBlockStore2::_readClientId(const Data &data) { return clientId; } -Key IntegrityBlockStore2::_readBlockId(const Data &data) { - return Key::FromBinary(data.dataOffset(ID_HEADER_OFFSET)); +BlockId IntegrityBlockStore2::_readBlockId(const Data &data) { + return BlockId::FromBinary(data.dataOffset(ID_HEADER_OFFSET)); } uint64_t IntegrityBlockStore2::_readVersion(const Data &data) { @@ -108,57 +108,57 @@ IntegrityBlockStore2::IntegrityBlockStore2(unique_ref baseBlockStor : _baseBlockStore(std::move(baseBlockStore)), _knownBlockVersions(integrityFilePath, myClientId), _noIntegrityChecks(noIntegrityChecks), _missingBlockIsIntegrityViolation(missingBlockIsIntegrityViolation), _integrityViolationDetected(false) { } -bool IntegrityBlockStore2::tryCreate(const Key &key, const Data &data) { +bool IntegrityBlockStore2::tryCreate(const BlockId &blockId, const Data &data) { _checkNoPastIntegrityViolations(); - uint64_t version = _knownBlockVersions.incrementVersion(key); - Data dataWithHeader = _prependHeaderToData(key, _knownBlockVersions.myClientId(), version, data); - return _baseBlockStore->tryCreate(key, dataWithHeader); + uint64_t version = _knownBlockVersions.incrementVersion(blockId); + Data dataWithHeader = _prependHeaderToData(blockId, _knownBlockVersions.myClientId(), version, data); + return _baseBlockStore->tryCreate(blockId, dataWithHeader); } -bool IntegrityBlockStore2::remove(const Key &key) { +bool IntegrityBlockStore2::remove(const BlockId &blockId) { _checkNoPastIntegrityViolations(); - _knownBlockVersions.markBlockAsDeleted(key); - return _baseBlockStore->remove(key); + _knownBlockVersions.markBlockAsDeleted(blockId); + return _baseBlockStore->remove(blockId); } -optional IntegrityBlockStore2::load(const Key &key) const { +optional IntegrityBlockStore2::load(const BlockId &blockId) const { _checkNoPastIntegrityViolations(); - auto loaded = _baseBlockStore->load(key); + auto loaded = _baseBlockStore->load(blockId); if (none == loaded) { - if (_missingBlockIsIntegrityViolation && _knownBlockVersions.blockShouldExist(key)) { + if (_missingBlockIsIntegrityViolation && _knownBlockVersions.blockShouldExist(blockId)) { integrityViolationDetected("A block that should exist wasn't found. Did an attacker delete it?"); } return optional(none); } #ifndef CRYFS_NO_COMPATIBILITY if (FORMAT_VERSION_HEADER_OLD == _readFormatHeader(*loaded)) { - Data migrated = _migrateBlock(key, *loaded); - _checkHeader(key, migrated); + Data migrated = _migrateBlock(blockId, *loaded); + _checkHeader(blockId, migrated); Data content = _removeHeader(migrated); - const_cast(this)->store(key, content); + const_cast(this)->store(blockId, content); return optional(_removeHeader(migrated)); } #endif - _checkHeader(key, *loaded); + _checkHeader(blockId, *loaded); return optional(_removeHeader(*loaded)); } #ifndef CRYFS_NO_COMPATIBILITY -Data IntegrityBlockStore2::_migrateBlock(const Key &key, const Data &data) { - Data migrated(data.size() + Key::BINARY_LENGTH); +Data IntegrityBlockStore2::_migrateBlock(const BlockId &blockId, const Data &data) { + Data migrated(data.size() + BlockId::BINARY_LENGTH); std::memcpy(migrated.dataOffset(0), &FORMAT_VERSION_HEADER, sizeof(FORMAT_VERSION_HEADER)); - std::memcpy(migrated.dataOffset(ID_HEADER_OFFSET), key.data().data(), Key::BINARY_LENGTH); - std::memcpy(migrated.dataOffset(ID_HEADER_OFFSET + Key::BINARY_LENGTH), data.dataOffset(sizeof(FORMAT_VERSION_HEADER)), data.size() - sizeof(FORMAT_VERSION_HEADER)); - ASSERT(migrated.size() == sizeof(FORMAT_VERSION_HEADER) + Key::BINARY_LENGTH + (data.size() - sizeof(FORMAT_VERSION_HEADER)), "Wrong offset computation"); + std::memcpy(migrated.dataOffset(ID_HEADER_OFFSET), blockId.data().data(), BlockId::BINARY_LENGTH); + std::memcpy(migrated.dataOffset(ID_HEADER_OFFSET + BlockId::BINARY_LENGTH), data.dataOffset(sizeof(FORMAT_VERSION_HEADER)), data.size() - sizeof(FORMAT_VERSION_HEADER)); + ASSERT(migrated.size() == sizeof(FORMAT_VERSION_HEADER) + BlockId::BINARY_LENGTH + (data.size() - sizeof(FORMAT_VERSION_HEADER)), "Wrong offset computation"); return migrated; } #endif -void IntegrityBlockStore2::store(const Key &key, const Data &data) { +void IntegrityBlockStore2::store(const BlockId &blockId, const Data &data) { _checkNoPastIntegrityViolations(); - uint64_t version = _knownBlockVersions.incrementVersion(key); - Data dataWithHeader = _prependHeaderToData(key, _knownBlockVersions.myClientId(), version, data); - return _baseBlockStore->store(key, dataWithHeader); + uint64_t version = _knownBlockVersions.incrementVersion(blockId); + Data dataWithHeader = _prependHeaderToData(blockId, _knownBlockVersions.myClientId(), version, data); + return _baseBlockStore->store(blockId, dataWithHeader); } uint64_t IntegrityBlockStore2::numBlocks() const { @@ -177,16 +177,16 @@ uint64_t IntegrityBlockStore2::blockSizeFromPhysicalBlockSize(uint64_t blockSize return baseBlockSize - HEADER_LENGTH; } -void IntegrityBlockStore2::forEachBlock(std::function callback) const { +void IntegrityBlockStore2::forEachBlock(std::function callback) const { if (!_missingBlockIsIntegrityViolation) { return _baseBlockStore->forEachBlock(std::move(callback)); } - std::unordered_set existingBlocks = _knownBlockVersions.existingBlocks(); - _baseBlockStore->forEachBlock([&existingBlocks, callback] (const Key &key) { - callback(key); + std::unordered_set existingBlocks = _knownBlockVersions.existingBlocks(); + _baseBlockStore->forEachBlock([&existingBlocks, callback] (const BlockId &blockId) { + callback(blockId); - auto found = existingBlocks.find(key); + auto found = existingBlocks.find(blockId); if (found != existingBlocks.end()) { existingBlocks.erase(found); } @@ -200,23 +200,23 @@ void IntegrityBlockStore2::forEachBlock(std::function callba void IntegrityBlockStore2::migrateFromBlockstoreWithoutVersionNumbers(BlockStore2 *baseBlockStore, const boost::filesystem::path &integrityFilePath, uint32_t myClientId) { std::cout << "Migrating file system for integrity features. Please don't interrupt this process. This can take a while..." << std::flush; KnownBlockVersions knownBlockVersions(integrityFilePath, myClientId); - baseBlockStore->forEachBlock([&baseBlockStore, &knownBlockVersions] (const Key &key) { - migrateBlockFromBlockstoreWithoutVersionNumbers(baseBlockStore, key, &knownBlockVersions); + baseBlockStore->forEachBlock([&baseBlockStore, &knownBlockVersions] (const BlockId &blockId) { + migrateBlockFromBlockstoreWithoutVersionNumbers(baseBlockStore, blockId, &knownBlockVersions); }); std::cout << "done" << std::endl; } -void IntegrityBlockStore2::migrateBlockFromBlockstoreWithoutVersionNumbers(blockstore::BlockStore2* baseBlockStore, const blockstore::Key& key, KnownBlockVersions *knownBlockVersions) { - uint64_t version = knownBlockVersions->incrementVersion(key); +void IntegrityBlockStore2::migrateBlockFromBlockstoreWithoutVersionNumbers(blockstore::BlockStore2* baseBlockStore, const blockstore::BlockId& blockId, KnownBlockVersions *knownBlockVersions) { + uint64_t version = knownBlockVersions->incrementVersion(blockId); - auto data_ = baseBlockStore->load(key); + auto data_ = baseBlockStore->load(blockId); if (data_ == boost::none) { LOG(WARN, "Block not found, but was returned from forEachBlock before"); return; } cpputils::Data data = std::move(*data_); - cpputils::Data dataWithHeader = _prependHeaderToData(key, knownBlockVersions->myClientId(), version, std::move(data)); - baseBlockStore->store(key, std::move(dataWithHeader)); + cpputils::Data dataWithHeader = _prependHeaderToData(blockId, knownBlockVersions->myClientId(), version, std::move(data)); + baseBlockStore->store(blockId, std::move(dataWithHeader)); } #endif diff --git a/src/blockstore/implementations/integrity/IntegrityBlockStore2.h b/src/blockstore/implementations/integrity/IntegrityBlockStore2.h index d82c1fdf..166b15a9 100644 --- a/src/blockstore/implementations/integrity/IntegrityBlockStore2.h +++ b/src/blockstore/implementations/integrity/IntegrityBlockStore2.h @@ -18,14 +18,14 @@ class IntegrityBlockStore2 final: public BlockStore2 { public: IntegrityBlockStore2(cpputils::unique_ref baseBlockStore, const boost::filesystem::path &integrityFilePath, uint32_t myClientId, bool noIntegrityChecks, bool missingBlockIsIntegrityViolation); - bool tryCreate(const Key &key, const cpputils::Data &data) override; - bool remove(const Key &key) override; - boost::optional load(const Key &key) const override; - void store(const Key &key, const cpputils::Data &data) override; + bool tryCreate(const BlockId &blockId, const cpputils::Data &data) override; + bool remove(const BlockId &blockId) override; + boost::optional load(const BlockId &blockId) const override; + void store(const BlockId &blockId, const cpputils::Data &data) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; private: // This format version is prepended to blocks to allow future versions to have compatibility. @@ -37,28 +37,28 @@ private: public: static constexpr uint64_t VERSION_ZERO = 0; static constexpr unsigned int ID_HEADER_OFFSET = sizeof(FORMAT_VERSION_HEADER); - static constexpr unsigned int CLIENTID_HEADER_OFFSET = ID_HEADER_OFFSET + Key::BINARY_LENGTH; + static constexpr unsigned int CLIENTID_HEADER_OFFSET = ID_HEADER_OFFSET + BlockId::BINARY_LENGTH; static constexpr unsigned int VERSION_HEADER_OFFSET = CLIENTID_HEADER_OFFSET + sizeof(uint32_t); static constexpr unsigned int HEADER_LENGTH = VERSION_HEADER_OFFSET + sizeof(VERSION_ZERO); #ifndef CRYFS_NO_COMPATIBILITY static void migrateFromBlockstoreWithoutVersionNumbers(BlockStore2 *baseBlockStore, const boost::filesystem::path &integrityFilePath, uint32_t myClientId); - static void migrateBlockFromBlockstoreWithoutVersionNumbers(BlockStore2* baseBlockStore, const blockstore::Key& key, KnownBlockVersions *knownBlockVersions); + static void migrateBlockFromBlockstoreWithoutVersionNumbers(BlockStore2* baseBlockStore, const blockstore::BlockId &blockId, KnownBlockVersions *knownBlockVersions); #endif private: - static cpputils::Data _prependHeaderToData(const Key& key, uint32_t myClientId, uint64_t version, const cpputils::Data &data); - void _checkHeader(const Key &key, const cpputils::Data &data) const; + static cpputils::Data _prependHeaderToData(const BlockId &blockId, uint32_t myClientId, uint64_t version, const cpputils::Data &data); + void _checkHeader(const BlockId &blockId, const cpputils::Data &data) const; void _checkFormatHeader(const cpputils::Data &data) const; - void _checkIdHeader(const Key &expectedKey, const cpputils::Data &data) const; - void _checkVersionHeader(const Key &key, const cpputils::Data &data) const; + void _checkIdHeader(const BlockId &expectedBlockId, const cpputils::Data &data) const; + void _checkVersionHeader(const BlockId &blockId, const cpputils::Data &data) const; static uint16_t _readFormatHeader(const cpputils::Data &data); static uint32_t _readClientId(const cpputils::Data &data); - static Key _readBlockId(const cpputils::Data &data); + static BlockId _readBlockId(const cpputils::Data &data); static uint64_t _readVersion(const cpputils::Data &data); #ifndef CRYFS_NO_COMPATIBILITY - static cpputils::Data _migrateBlock(const Key &key, const cpputils::Data &data); + static cpputils::Data _migrateBlock(const BlockId &blockId, const cpputils::Data &data); #endif static cpputils::Data _removeHeader(const cpputils::Data &data); void _checkNoPastIntegrityViolations() const; diff --git a/src/blockstore/implementations/integrity/KnownBlockVersions.cpp b/src/blockstore/implementations/integrity/KnownBlockVersions.cpp index 60ea9bef..9ad111a7 100644 --- a/src/blockstore/implementations/integrity/KnownBlockVersions.cpp +++ b/src/blockstore/implementations/integrity/KnownBlockVersions.cpp @@ -47,22 +47,22 @@ KnownBlockVersions::~KnownBlockVersions() { } } -bool KnownBlockVersions::checkAndUpdateVersion(uint32_t clientId, const Key &key, uint64_t version) { +bool KnownBlockVersions::checkAndUpdateVersion(uint32_t clientId, const BlockId &blockId, uint64_t version) { unique_lock lock(_mutex); ASSERT(clientId != CLIENT_ID_FOR_DELETED_BLOCK, "This is not a valid client id"); ASSERT(version > 0, "Version has to be >0"); // Otherwise we wouldn't handle notexisting entries correctly. ASSERT(_valid, "Object not valid due to a std::move"); - uint64_t &found = _knownVersions[{clientId, key}]; // If the entry doesn't exist, this creates it with value 0. + uint64_t &found = _knownVersions[{clientId, blockId}]; // If the entry doesn't exist, this creates it with value 0. if (found > version) { // This client already published a newer block version. Rollbacks are not allowed. return false; } - uint32_t &lastUpdateClientId = _lastUpdateClientId[key]; // If entry doesn't exist, this creates it with value 0. However, in this case, found == 0 (and version > 0), which means found != version. + uint32_t &lastUpdateClientId = _lastUpdateClientId[blockId]; // If entry doesn't exist, this creates it with value 0. However, in this case, found == 0 (and version > 0), which means found != version. if (found == version && lastUpdateClientId != clientId) { - // This is a roll back to the "newest" block of client [clientId], which was since then superseded by a version from client _lastUpdateClientId[key]. + // This is a roll back to the "newest" block of client [clientId], which was since then superseded by a version from client _lastUpdateClientId[blockId]. // This is not allowed. return false; } @@ -72,16 +72,16 @@ bool KnownBlockVersions::checkAndUpdateVersion(uint32_t clientId, const Key &key return true; } -uint64_t KnownBlockVersions::incrementVersion(const Key &key) { +uint64_t KnownBlockVersions::incrementVersion(const BlockId &blockId) { unique_lock lock(_mutex); - uint64_t &found = _knownVersions[{_myClientId, key}]; // If the entry doesn't exist, this creates it with value 0. + uint64_t &found = _knownVersions[{_myClientId, blockId}]; // If the entry doesn't exist, this creates it with value 0. uint64_t newVersion = found + 1; if (newVersion == std::numeric_limits::max()) { // It's *very* unlikely we ever run out of version numbers in 64bit...but just to be sure... throw std::runtime_error("Version overflow"); } found = newVersion; - _lastUpdateClientId[key] = _myClientId; + _lastUpdateClientId[blockId] = _myClientId; return found; } @@ -106,8 +106,8 @@ void KnownBlockVersions::_loadStateFile() { void KnownBlockVersions::_saveStateFile() const { Serializer serializer( Serializer::StringSize(HEADER) + - sizeof(uint64_t) + _knownVersions.size() * (sizeof(uint32_t) + Key::BINARY_LENGTH + sizeof(uint64_t)) + - sizeof(uint64_t) + _lastUpdateClientId.size() * (Key::BINARY_LENGTH + sizeof(uint32_t))); + sizeof(uint64_t) + _knownVersions.size() * (sizeof(uint32_t) + BlockId::BINARY_LENGTH + sizeof(uint64_t)) + + sizeof(uint64_t) + _lastUpdateClientId.size() * (BlockId::BINARY_LENGTH + sizeof(uint32_t))); serializer.writeString(HEADER); _serializeKnownVersions(&serializer); _serializeLastUpdateClientIds(&serializer); @@ -134,17 +134,17 @@ void KnownBlockVersions::_serializeKnownVersions(Serializer *serializer) const { } } -pair KnownBlockVersions::_deserializeKnownVersionsEntry(Deserializer *deserializer) { +pair KnownBlockVersions::_deserializeKnownVersionsEntry(Deserializer *deserializer) { uint32_t clientId = deserializer->readUint32(); - Key blockKey(deserializer->readFixedSizeData()); + BlockId blockId(deserializer->readFixedSizeData()); uint64_t version = deserializer->readUint64(); - return {{clientId, blockKey}, version}; + return {{clientId, blockId}, version}; }; -void KnownBlockVersions::_serializeKnownVersionsEntry(Serializer *serializer, const pair &entry) { +void KnownBlockVersions::_serializeKnownVersionsEntry(Serializer *serializer, const pair &entry) { serializer->writeUint32(entry.first.clientId); - serializer->writeFixedSizeData(entry.first.blockKey.data()); + serializer->writeFixedSizeData(entry.first.blockId.data()); serializer->writeUint64(entry.second); } @@ -167,15 +167,15 @@ void KnownBlockVersions::_serializeLastUpdateClientIds(Serializer *serializer) c } } -pair KnownBlockVersions::_deserializeLastUpdateClientIdEntry(Deserializer *deserializer) { - Key blockKey(deserializer->readFixedSizeData()); +pair KnownBlockVersions::_deserializeLastUpdateClientIdEntry(Deserializer *deserializer) { + BlockId blockId(deserializer->readFixedSizeData()); uint32_t clientId = deserializer->readUint32(); - return {blockKey, clientId}; + return {blockId, clientId}; }; -void KnownBlockVersions::_serializeLastUpdateClientIdEntry(Serializer *serializer, const pair &entry) { - serializer->writeFixedSizeData(entry.first.data()); +void KnownBlockVersions::_serializeLastUpdateClientIdEntry(Serializer *serializer, const pair &entry) { + serializer->writeFixedSizeData(entry.first.data()); serializer->writeUint32(entry.second); } @@ -183,17 +183,17 @@ uint32_t KnownBlockVersions::myClientId() const { return _myClientId; } -uint64_t KnownBlockVersions::getBlockVersion(uint32_t clientId, const Key &key) const { +uint64_t KnownBlockVersions::getBlockVersion(uint32_t clientId, const BlockId &blockId) const { unique_lock lock(_mutex); - return _knownVersions.at({clientId, key}); + return _knownVersions.at({clientId, blockId}); } -void KnownBlockVersions::markBlockAsDeleted(const Key &key) { - _lastUpdateClientId[key] = CLIENT_ID_FOR_DELETED_BLOCK; +void KnownBlockVersions::markBlockAsDeleted(const BlockId &blockId) { + _lastUpdateClientId[blockId] = CLIENT_ID_FOR_DELETED_BLOCK; } -bool KnownBlockVersions::blockShouldExist(const Key &key) const { - auto found = _lastUpdateClientId.find(key); +bool KnownBlockVersions::blockShouldExist(const BlockId &blockId) const { + auto found = _lastUpdateClientId.find(blockId); if (found == _lastUpdateClientId.end()) { // We've never seen (i.e. loaded) this block. So we can't say it has to exist. return false; @@ -202,8 +202,8 @@ bool KnownBlockVersions::blockShouldExist(const Key &key) const { return found->second != CLIENT_ID_FOR_DELETED_BLOCK; } -std::unordered_set KnownBlockVersions::existingBlocks() const { - std::unordered_set result; +std::unordered_set KnownBlockVersions::existingBlocks() const { + std::unordered_set result; for (const auto &entry : _lastUpdateClientId) { if (entry.second != CLIENT_ID_FOR_DELETED_BLOCK) { result.insert(entry.first); diff --git a/src/blockstore/implementations/integrity/KnownBlockVersions.h b/src/blockstore/implementations/integrity/KnownBlockVersions.h index b06a3a42..b0d966ad 100644 --- a/src/blockstore/implementations/integrity/KnownBlockVersions.h +++ b/src/blockstore/implementations/integrity/KnownBlockVersions.h @@ -3,10 +3,10 @@ #define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_INTEGRITY_KNOWNBLOCKVERSIONS_H_ #include -#include +#include #include #include -#include "ClientIdAndBlockKey.h" +#include "ClientIdAndBlockId.h" #include #include #include @@ -22,16 +22,16 @@ namespace blockstore { ~KnownBlockVersions(); __attribute__((warn_unused_result)) - bool checkAndUpdateVersion(uint32_t clientId, const Key &key, uint64_t version); + bool checkAndUpdateVersion(uint32_t clientId, const BlockId &blockId, uint64_t version); - uint64_t incrementVersion(const Key &key); + uint64_t incrementVersion(const BlockId &blockId); - void markBlockAsDeleted(const Key &key); + void markBlockAsDeleted(const BlockId &blockId); - bool blockShouldExist(const Key &key) const; - std::unordered_set existingBlocks() const; + bool blockShouldExist(const BlockId &blockId) const; + std::unordered_set existingBlocks() const; - uint64_t getBlockVersion(uint32_t clientId, const Key &key) const; + uint64_t getBlockVersion(uint32_t clientId, const BlockId &blockId) const; uint32_t myClientId() const; const boost::filesystem::path &path() const; @@ -39,8 +39,8 @@ namespace blockstore { static constexpr uint32_t CLIENT_ID_FOR_DELETED_BLOCK = 0; private: - std::unordered_map _knownVersions; - std::unordered_map _lastUpdateClientId; // The client who last updated the block + std::unordered_map _knownVersions; + std::unordered_map _lastUpdateClientId; // The client who last updated the block boost::filesystem::path _stateFilePath; uint32_t _myClientId; @@ -55,14 +55,14 @@ namespace blockstore { void _deserializeKnownVersions(cpputils::Deserializer *deserializer); void _serializeKnownVersions(cpputils::Serializer *serializer) const; - static std::pair _deserializeKnownVersionsEntry(cpputils::Deserializer *deserializer); - static void _serializeKnownVersionsEntry(cpputils::Serializer *serializer, const std::pair &entry); + static std::pair _deserializeKnownVersionsEntry(cpputils::Deserializer *deserializer); + static void _serializeKnownVersionsEntry(cpputils::Serializer *serializer, const std::pair &entry); void _deserializeLastUpdateClientIds(cpputils::Deserializer *deserializer); void _serializeLastUpdateClientIds(cpputils::Serializer *serializer) const; - static std::pair _deserializeLastUpdateClientIdEntry(cpputils::Deserializer *deserializer); - static void _serializeLastUpdateClientIdEntry(cpputils::Serializer *serializer, const std::pair &entry); + static std::pair _deserializeLastUpdateClientIdEntry(cpputils::Deserializer *deserializer); + static void _serializeLastUpdateClientIdEntry(cpputils::Serializer *serializer, const std::pair &entry); DISALLOW_COPY_AND_ASSIGN(KnownBlockVersions); }; diff --git a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.cpp b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.cpp index d41c0a0c..2e2abda8 100644 --- a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.cpp +++ b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.cpp @@ -12,30 +12,30 @@ using std::mutex; namespace blockstore { namespace lowtohighlevel { -optional> LowToHighLevelBlock::TryCreateNew(BlockStore2 *baseBlockStore, const Key &key, Data data) { - bool success = baseBlockStore->tryCreate(key, data); +optional> LowToHighLevelBlock::TryCreateNew(BlockStore2 *baseBlockStore, const BlockId &blockId, Data data) { + bool success = baseBlockStore->tryCreate(blockId, data); if (!success) { return none; } - return make_unique_ref(key, std::move(data), baseBlockStore); + return make_unique_ref(blockId, std::move(data), baseBlockStore); } -unique_ref LowToHighLevelBlock::Overwrite(BlockStore2 *baseBlockStore, const Key &key, Data data) { - baseBlockStore->store(key, data); // TODO Does it make sense to not store here, but only write back in the destructor of LowToHighLevelBlock? Also: What about tryCreate? - return make_unique_ref(key, std::move(data), baseBlockStore); +unique_ref LowToHighLevelBlock::Overwrite(BlockStore2 *baseBlockStore, const BlockId &blockId, Data data) { + baseBlockStore->store(blockId, data); // TODO Does it make sense to not store here, but only write back in the destructor of LowToHighLevelBlock? Also: What about tryCreate? + return make_unique_ref(blockId, std::move(data), baseBlockStore); } -optional> LowToHighLevelBlock::Load(BlockStore2 *baseBlockStore, const Key &key) { - optional loadedData = baseBlockStore->load(key); +optional> LowToHighLevelBlock::Load(BlockStore2 *baseBlockStore, const BlockId &blockId) { + optional loadedData = baseBlockStore->load(blockId); if (loadedData == none) { return none; } - return make_unique_ref(key, std::move(*loadedData), baseBlockStore); + return make_unique_ref(blockId, std::move(*loadedData), baseBlockStore); } -LowToHighLevelBlock::LowToHighLevelBlock(const Key& key, Data data, BlockStore2 *baseBlockStore) - :Block(key), +LowToHighLevelBlock::LowToHighLevelBlock(const BlockId &blockId, Data data, BlockStore2 *baseBlockStore) + :Block(blockId), _baseBlockStore(baseBlockStore), _data(std::move(data)), _dataChanged(false), @@ -73,7 +73,7 @@ void LowToHighLevelBlock::resize(size_t newSize) { void LowToHighLevelBlock::_storeToBaseBlock() { if (_dataChanged) { - _baseBlockStore->store(key(), _data); + _baseBlockStore->store(blockId(), _data); _dataChanged = false; } } diff --git a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.h b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.h index 6df95fd4..7606d649 100644 --- a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.h +++ b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlock.h @@ -23,11 +23,11 @@ namespace lowtohighlevel { class LowToHighLevelBlock final: public Block { public: - static boost::optional> TryCreateNew(BlockStore2 *baseBlockStore, const Key &key, cpputils::Data data); - static cpputils::unique_ref Overwrite(BlockStore2 *baseBlockStore, const Key &key, cpputils::Data data); - static boost::optional> Load(BlockStore2 *baseBlockStore, const Key &key); + static boost::optional> TryCreateNew(BlockStore2 *baseBlockStore, const BlockId &blockId, cpputils::Data data); + static cpputils::unique_ref Overwrite(BlockStore2 *baseBlockStore, const BlockId &blockId, cpputils::Data data); + static boost::optional> Load(BlockStore2 *baseBlockStore, const BlockId &blockId); - LowToHighLevelBlock(const Key& key, cpputils::Data data, BlockStore2 *baseBlockStore); + LowToHighLevelBlock(const BlockId &blockId, cpputils::Data data, BlockStore2 *baseBlockStore); ~LowToHighLevelBlock(); const void *data() const override; diff --git a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.cpp b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.cpp index 8156a382..75b48daa 100644 --- a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.cpp +++ b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.cpp @@ -17,38 +17,38 @@ LowToHighLevelBlockStore::LowToHighLevelBlockStore(unique_ref baseB : _baseBlockStore(std::move(baseBlockStore)) { } -Key LowToHighLevelBlockStore::createKey() { +BlockId LowToHighLevelBlockStore::createBlockId() { // TODO Is this the right way? - return Key::Random(); + return BlockId::Random(); } -optional> LowToHighLevelBlockStore::tryCreate(const Key &key, Data data) { +optional> LowToHighLevelBlockStore::tryCreate(const BlockId &blockId, Data data) { //TODO Easier implementation? This is only so complicated because of the cast LowToHighLevelBlock -> Block - auto result = LowToHighLevelBlock::TryCreateNew(_baseBlockStore.get(), key, std::move(data)); + auto result = LowToHighLevelBlock::TryCreateNew(_baseBlockStore.get(), blockId, std::move(data)); if (result == none) { return none; } return unique_ref(std::move(*result)); } -unique_ref LowToHighLevelBlockStore::overwrite(const Key &key, Data data) { +unique_ref LowToHighLevelBlockStore::overwrite(const BlockId &blockId, Data data) { return unique_ref( - LowToHighLevelBlock::Overwrite(_baseBlockStore.get(), key, std::move(data)) + LowToHighLevelBlock::Overwrite(_baseBlockStore.get(), blockId, std::move(data)) ); } -optional> LowToHighLevelBlockStore::load(const Key &key) { - auto result = optional>(LowToHighLevelBlock::Load(_baseBlockStore.get(), key)); +optional> LowToHighLevelBlockStore::load(const BlockId &blockId) { + auto result = optional>(LowToHighLevelBlock::Load(_baseBlockStore.get(), blockId)); if (result == none) { return none; } return unique_ref(std::move(*result)); } -void LowToHighLevelBlockStore::remove(const Key &key) { - bool success = _baseBlockStore->remove(key); +void LowToHighLevelBlockStore::remove(const BlockId &blockId) { + bool success = _baseBlockStore->remove(blockId); if (!success) { - throw std::runtime_error("Couldn't delete block with id " + key.ToString()); + throw std::runtime_error("Couldn't delete block with id " + blockId.ToString()); } } @@ -64,7 +64,7 @@ uint64_t LowToHighLevelBlockStore::blockSizeFromPhysicalBlockSize(uint64_t block return _baseBlockStore->blockSizeFromPhysicalBlockSize(blockSize); } -void LowToHighLevelBlockStore::forEachBlock(std::function callback) const { +void LowToHighLevelBlockStore::forEachBlock(std::function callback) const { _baseBlockStore->forEachBlock(std::move(callback)); } diff --git a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.h b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.h index 7f76bc0b..395ee776 100644 --- a/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.h +++ b/src/blockstore/implementations/low2highlevel/LowToHighLevelBlockStore.h @@ -20,15 +20,15 @@ class LowToHighLevelBlockStore final: public BlockStore { public: LowToHighLevelBlockStore(cpputils::unique_ref baseBlockStore); - Key createKey() override; - boost::optional> tryCreate(const Key &key, cpputils::Data data) override; - cpputils::unique_ref overwrite(const blockstore::Key &key, cpputils::Data data) override; - boost::optional> load(const Key &key) override; - void remove(const Key &key) override; + BlockId createBlockId() override; + boost::optional> tryCreate(const BlockId &blockId, cpputils::Data data) override; + cpputils::unique_ref overwrite(const blockstore::BlockId &blockId, cpputils::Data data) override; + boost::optional> load(const BlockId &blockId) override; + void remove(const BlockId &blockId) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; private: cpputils::unique_ref _baseBlockStore; diff --git a/src/blockstore/implementations/mock/MockBlock.cpp b/src/blockstore/implementations/mock/MockBlock.cpp index 31655e05..fbfe3463 100644 --- a/src/blockstore/implementations/mock/MockBlock.cpp +++ b/src/blockstore/implementations/mock/MockBlock.cpp @@ -5,12 +5,12 @@ namespace blockstore { namespace mock { void MockBlock::write(const void *source, uint64_t offset, uint64_t size) { - _blockStore->_increaseNumWrittenBlocks(key()); + _blockStore->_increaseNumWrittenBlocks(blockId()); return _baseBlock->write(source, offset, size); } void MockBlock::resize(size_t newSize) { - _blockStore->_increaseNumResizedBlocks(key()); + _blockStore->_increaseNumResizedBlocks(blockId()); return _baseBlock->resize(newSize); } diff --git a/src/blockstore/implementations/mock/MockBlock.h b/src/blockstore/implementations/mock/MockBlock.h index adf943ab..fc5deff3 100644 --- a/src/blockstore/implementations/mock/MockBlock.h +++ b/src/blockstore/implementations/mock/MockBlock.h @@ -13,7 +13,7 @@ namespace blockstore { class MockBlock final : public blockstore::Block { public: MockBlock(cpputils::unique_ref baseBlock, MockBlockStore *blockStore) - :Block(baseBlock->key()), _baseBlock(std::move(baseBlock)), _blockStore(blockStore) { + :Block(baseBlock->blockId()), _baseBlock(std::move(baseBlock)), _blockStore(blockStore) { } const void *data() const override { diff --git a/src/blockstore/implementations/mock/MockBlockStore.h b/src/blockstore/implementations/mock/MockBlockStore.h index 0cce756b..7ad4e23a 100644 --- a/src/blockstore/implementations/mock/MockBlockStore.h +++ b/src/blockstore/implementations/mock/MockBlockStore.h @@ -19,36 +19,36 @@ namespace blockstore { : _mutex(), _baseBlockStore(std::move(baseBlockStore)), _loadedBlocks(), _createdBlocks(0), _writtenBlocks(), _resizedBlocks(), _removedBlocks() { } - Key createKey() override { - return _baseBlockStore->createKey(); + BlockId createBlockId() override { + return _baseBlockStore->createBlockId(); } - boost::optional> tryCreate(const Key &key, cpputils::Data data) override { + boost::optional> tryCreate(const BlockId &blockId, cpputils::Data data) override { _increaseNumCreatedBlocks(); - auto base = _baseBlockStore->tryCreate(key, std::move(data)); + auto base = _baseBlockStore->tryCreate(blockId, std::move(data)); if (base == boost::none) { return boost::none; } return boost::optional>(cpputils::make_unique_ref(std::move(*base), this)); } - boost::optional> load(const Key &key) override { - _increaseNumLoadedBlocks(key); - auto base = _baseBlockStore->load(key); + boost::optional> load(const BlockId &blockId) override { + _increaseNumLoadedBlocks(blockId); + auto base = _baseBlockStore->load(blockId); if (base == boost::none) { return boost::none; } return boost::optional>(cpputils::make_unique_ref(std::move(*base), this)); } - cpputils::unique_ref overwrite(const Key &key, cpputils::Data data) override { - _increaseNumWrittenBlocks(key); - return _baseBlockStore->overwrite(key, std::move(data)); + cpputils::unique_ref overwrite(const BlockId &blockId, cpputils::Data data) override { + _increaseNumWrittenBlocks(blockId); + return _baseBlockStore->overwrite(blockId, std::move(data)); } - void remove(const Key &key) override { - _increaseNumRemovedBlocks(key); - return _baseBlockStore->remove(key); + void remove(const BlockId &blockId) override { + _increaseNumRemovedBlocks(blockId); + return _baseBlockStore->remove(blockId); } uint64_t numBlocks() const override { @@ -63,12 +63,12 @@ namespace blockstore { return _baseBlockStore->blockSizeFromPhysicalBlockSize(blockSize); } - void forEachBlock(std::function callback) const override { + void forEachBlock(std::function callback) const override { return _baseBlockStore->forEachBlock(callback); } void remove(cpputils::unique_ref block) override { - _increaseNumRemovedBlocks(block->key()); + _increaseNumRemovedBlocks(block->blockId()); auto mockBlock = cpputils::dynamic_pointer_move(block); ASSERT(mockBlock != boost::none, "Wrong block type"); return _baseBlockStore->remove((*mockBlock)->releaseBaseBlock()); @@ -86,25 +86,25 @@ namespace blockstore { return _createdBlocks; } - const std::vector &loadedBlocks() const { + const std::vector &loadedBlocks() const { return _loadedBlocks; } - const std::vector &removedBlocks() const { + const std::vector &removedBlocks() const { return _removedBlocks; } - const std::vector &resizedBlocks() const { + const std::vector &resizedBlocks() const { return _resizedBlocks; } - const std::vector &writtenBlocks() const { + const std::vector &writtenBlocks() const { return _writtenBlocks; } - std::vector distinctWrittenBlocks() const { - std::vector result(_writtenBlocks); - std::sort(result.begin(), result.end(), [](const Key &lhs, const Key &rhs) { + std::vector distinctWrittenBlocks() const { + std::vector result(_writtenBlocks); + std::sort(result.begin(), result.end(), [](const BlockId &lhs, const BlockId &rhs) { return std::memcmp(lhs.data().data(), rhs.data().data(), lhs.BINARY_LENGTH) < 0; }); result.erase(std::unique(result.begin(), result.end() ), result.end()); @@ -117,24 +117,24 @@ namespace blockstore { _createdBlocks += 1; } - void _increaseNumLoadedBlocks(const Key &key) { + void _increaseNumLoadedBlocks(const BlockId &blockId) { std::unique_lock lock(_mutex); - _loadedBlocks.push_back(key); + _loadedBlocks.push_back(blockId); } - void _increaseNumRemovedBlocks(const Key &key) { + void _increaseNumRemovedBlocks(const BlockId &blockId) { std::unique_lock lock(_mutex); - _removedBlocks.push_back(key); + _removedBlocks.push_back(blockId); } - void _increaseNumResizedBlocks(const Key &key) { + void _increaseNumResizedBlocks(const BlockId &blockId) { std::unique_lock lock(_mutex); - _resizedBlocks.push_back(key); + _resizedBlocks.push_back(blockId); } - void _increaseNumWrittenBlocks(const Key &key) { + void _increaseNumWrittenBlocks(const BlockId &blockId) { std::unique_lock lock(_mutex); - _writtenBlocks.push_back(key); + _writtenBlocks.push_back(blockId); } friend class MockBlock; @@ -142,11 +142,11 @@ namespace blockstore { std::mutex _mutex; cpputils::unique_ref _baseBlockStore; - std::vector _loadedBlocks; + std::vector _loadedBlocks; uint64_t _createdBlocks; - std::vector _writtenBlocks; - std::vector _resizedBlocks; - std::vector _removedBlocks; + std::vector _writtenBlocks; + std::vector _resizedBlocks; + std::vector _removedBlocks; DISALLOW_COPY_AND_ASSIGN(MockBlockStore); }; diff --git a/src/blockstore/implementations/ondisk/OnDiskBlockStore2.cpp b/src/blockstore/implementations/ondisk/OnDiskBlockStore2.cpp index 714d9b15..888312e2 100644 --- a/src/blockstore/implementations/ondisk/OnDiskBlockStore2.cpp +++ b/src/blockstore/implementations/ondisk/OnDiskBlockStore2.cpp @@ -12,9 +12,9 @@ namespace ondisk { const string OnDiskBlockStore2::FORMAT_VERSION_HEADER_PREFIX = "cryfs;block;"; const string OnDiskBlockStore2::FORMAT_VERSION_HEADER = OnDiskBlockStore2::FORMAT_VERSION_HEADER_PREFIX + "0"; -boost::filesystem::path OnDiskBlockStore2::_getFilepath(const Key &key) const { - std::string keyStr = key.ToString(); - return _rootDir / keyStr.substr(0,3) / keyStr.substr(3); +boost::filesystem::path OnDiskBlockStore2::_getFilepath(const BlockId &blockId) const { + std::string blockIdStr = blockId.ToString(); + return _rootDir / blockIdStr.substr(0,3) / blockIdStr.substr(3); } Data OnDiskBlockStore2::_checkAndRemoveHeader(const Data &data) { @@ -45,24 +45,24 @@ unsigned int OnDiskBlockStore2::formatVersionHeaderSize() { OnDiskBlockStore2::OnDiskBlockStore2(const boost::filesystem::path& path) : _rootDir(path) {} -bool OnDiskBlockStore2::tryCreate(const Key &key, const Data &data) { - auto filepath = _getFilepath(key); +bool OnDiskBlockStore2::tryCreate(const BlockId &blockId, const Data &data) { + auto filepath = _getFilepath(blockId); if (boost::filesystem::exists(filepath)) { return false; } - store(key, data); + store(blockId, data); return true; } -bool OnDiskBlockStore2::remove(const Key &key) { - auto filepath = _getFilepath(key); +bool OnDiskBlockStore2::remove(const BlockId &blockId) { + auto filepath = _getFilepath(blockId); if (!boost::filesystem::is_regular_file(filepath)) { // TODO Is this branch necessary? return false; } bool retval = boost::filesystem::remove(filepath); if (!retval) { - cpputils::logging::LOG(cpputils::logging::ERROR, "Couldn't find block {} to remove", key.ToString()); + cpputils::logging::LOG(cpputils::logging::ERROR, "Couldn't find block {} to remove", blockId.ToString()); return false; } if (boost::filesystem::is_empty(filepath.parent_path())) { @@ -71,19 +71,19 @@ bool OnDiskBlockStore2::remove(const Key &key) { return true; } -optional OnDiskBlockStore2::load(const Key &key) const { - auto fileContent = Data::LoadFromFile(_getFilepath(key)); +optional OnDiskBlockStore2::load(const BlockId &blockId) const { + auto fileContent = Data::LoadFromFile(_getFilepath(blockId)); if (fileContent == none) { return boost::none; } return _checkAndRemoveHeader(std::move(*fileContent)); } -void OnDiskBlockStore2::store(const Key &key, const Data &data) { +void OnDiskBlockStore2::store(const BlockId &blockId, const Data &data) { Data fileContent(formatVersionHeaderSize() + data.size()); std::memcpy(fileContent.data(), FORMAT_VERSION_HEADER.c_str(), formatVersionHeaderSize()); std::memcpy(fileContent.dataOffset(formatVersionHeaderSize()), data.data(), data.size()); - auto filepath = _getFilepath(key); + auto filepath = _getFilepath(blockId); boost::filesystem::create_directory(filepath.parent_path()); // TODO Instead create all of them once at fs creation time? fileContent.StoreToFile(filepath); } @@ -114,13 +114,13 @@ uint64_t OnDiskBlockStore2::blockSizeFromPhysicalBlockSize(uint64_t blockSize) c return blockSize - formatVersionHeaderSize(); } -void OnDiskBlockStore2::forEachBlock(std::function callback) const { +void OnDiskBlockStore2::forEachBlock(std::function callback) const { for (auto prefixDir = boost::filesystem::directory_iterator(_rootDir); prefixDir != boost::filesystem::directory_iterator(); ++prefixDir) { if (boost::filesystem::is_directory(prefixDir->path())) { - std::string blockKeyPrefix = prefixDir->path().filename().native(); + std::string blockIdPrefix = prefixDir->path().filename().native(); for (auto block = boost::filesystem::directory_iterator(prefixDir->path()); block != boost::filesystem::directory_iterator(); ++block) { - std::string blockKeyPostfix = block->path().filename().native(); - callback(Key::FromString(blockKeyPrefix + blockKeyPostfix)); + std::string blockIdPostfix = block->path().filename().native(); + callback(BlockId::FromString(blockIdPrefix + blockIdPostfix)); } } } diff --git a/src/blockstore/implementations/ondisk/OnDiskBlockStore2.h b/src/blockstore/implementations/ondisk/OnDiskBlockStore2.h index d45f8ee7..d8b9ea4c 100644 --- a/src/blockstore/implementations/ondisk/OnDiskBlockStore2.h +++ b/src/blockstore/implementations/ondisk/OnDiskBlockStore2.h @@ -16,14 +16,14 @@ class OnDiskBlockStore2 final: public BlockStore2 { public: explicit OnDiskBlockStore2(const boost::filesystem::path& path); - bool tryCreate(const Key &key, const cpputils::Data &data) override; - bool remove(const Key &key) override; - boost::optional load(const Key &key) const override; - void store(const Key &key, const cpputils::Data &data) override; + bool tryCreate(const BlockId &blockId, const cpputils::Data &data) override; + bool remove(const BlockId &blockId) override; + boost::optional load(const BlockId &blockId) const override; + void store(const BlockId &blockId, const cpputils::Data &data) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; private: boost::filesystem::path _rootDir; @@ -31,7 +31,7 @@ private: static const std::string FORMAT_VERSION_HEADER_PREFIX; static const std::string FORMAT_VERSION_HEADER; - boost::filesystem::path _getFilepath(const Key &key) const; + boost::filesystem::path _getFilepath(const BlockId &blockId) const; static cpputils::Data _checkAndRemoveHeader(const cpputils::Data &data); static bool _isAcceptedCryfsHeader(const cpputils::Data &data); static bool _isOtherCryfsHeader(const cpputils::Data &data); diff --git a/src/blockstore/implementations/parallelaccess/BlockRef.h b/src/blockstore/implementations/parallelaccess/BlockRef.h index a4f742bb..75038885 100644 --- a/src/blockstore/implementations/parallelaccess/BlockRef.h +++ b/src/blockstore/implementations/parallelaccess/BlockRef.h @@ -11,10 +11,10 @@ namespace blockstore { namespace parallelaccess { class ParallelAccessBlockStore; -class BlockRef final: public Block, public parallelaccessstore::ParallelAccessStore::ResourceRefBase { +class BlockRef final: public Block, public parallelaccessstore::ParallelAccessStore::ResourceRefBase { public: - //TODO Unneccessarily storing Key twice here (in parent class and in _baseBlock). - explicit BlockRef(Block *baseBlock): Block(baseBlock->key()), _baseBlock(baseBlock) {} + //TODO Unneccessarily storing BlockId twice here (in parent class and in _baseBlock). + explicit BlockRef(Block *baseBlock): Block(baseBlock->blockId()), _baseBlock(baseBlock) {} const void *data() const override { return _baseBlock->data(); diff --git a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp index 39521c91..76019375 100644 --- a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp +++ b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp @@ -23,50 +23,50 @@ ParallelAccessBlockStore::ParallelAccessBlockStore(unique_ref baseBl : _baseBlockStore(std::move(baseBlockStore)), _parallelAccessStore(make_unique_ref(_baseBlockStore.get())) { } -Key ParallelAccessBlockStore::createKey() { - return _baseBlockStore->createKey(); +BlockId ParallelAccessBlockStore::createBlockId() { + return _baseBlockStore->createBlockId(); } -optional> ParallelAccessBlockStore::tryCreate(const Key &key, Data data) { - ASSERT(!_parallelAccessStore.isOpened(key), ("Key "+key.ToString()+"already exists").c_str()); - auto block = _baseBlockStore->tryCreate(key, std::move(data)); +optional> ParallelAccessBlockStore::tryCreate(const BlockId &blockId, Data data) { + ASSERT(!_parallelAccessStore.isOpened(blockId), ("BlockId "+blockId.ToString()+"already exists").c_str()); + auto block = _baseBlockStore->tryCreate(blockId, std::move(data)); if (block == none) { //TODO Test this code branch return none; } - return unique_ref(_parallelAccessStore.add(key, std::move(*block))); + return unique_ref(_parallelAccessStore.add(blockId, std::move(*block))); } -optional> ParallelAccessBlockStore::load(const Key &key) { - auto block = _parallelAccessStore.load(key); +optional> ParallelAccessBlockStore::load(const BlockId &blockId) { + auto block = _parallelAccessStore.load(blockId); if (block == none) { return none; } return unique_ref(std::move(*block)); } -unique_ref ParallelAccessBlockStore::overwrite(const Key &key, Data data) { +unique_ref ParallelAccessBlockStore::overwrite(const BlockId &blockId, Data data) { auto onExists = [&data] (BlockRef *block) { if (block->size() != data.size()) { block->resize(data.size()); } block->write(data.data(), 0, data.size()); }; - auto onAdd = [this, key, &data] { - return _baseBlockStore->overwrite(key, data.copy()); // TODO Without copy? + auto onAdd = [this, blockId, &data] { + return _baseBlockStore->overwrite(blockId, data.copy()); // TODO Without copy? }; - return _parallelAccessStore.loadOrAdd(key, onExists, onAdd); + return _parallelAccessStore.loadOrAdd(blockId, onExists, onAdd); } void ParallelAccessBlockStore::remove(unique_ref block) { - Key key = block->key(); + BlockId blockId = block->blockId(); auto block_ref = dynamic_pointer_move(block); ASSERT(block_ref != none, "Block is not a BlockRef"); - return _parallelAccessStore.remove(key, std::move(*block_ref)); + return _parallelAccessStore.remove(blockId, std::move(*block_ref)); } -void ParallelAccessBlockStore::remove(const Key &key) { - return _parallelAccessStore.remove(key); +void ParallelAccessBlockStore::remove(const BlockId &blockId) { + return _parallelAccessStore.remove(blockId); } uint64_t ParallelAccessBlockStore::numBlocks() const { @@ -81,7 +81,7 @@ uint64_t ParallelAccessBlockStore::blockSizeFromPhysicalBlockSize(uint64_t block return _baseBlockStore->blockSizeFromPhysicalBlockSize(blockSize); } -void ParallelAccessBlockStore::forEachBlock(std::function callback) const { +void ParallelAccessBlockStore::forEachBlock(std::function callback) const { return _baseBlockStore->forEachBlock(callback); } diff --git a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.h b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.h index 09bc774e..a1b3aea6 100644 --- a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.h +++ b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.h @@ -15,20 +15,20 @@ class ParallelAccessBlockStore final: public BlockStore { public: explicit ParallelAccessBlockStore(cpputils::unique_ref baseBlockStore); - Key createKey() override; - boost::optional> tryCreate(const Key &key, cpputils::Data data) override; - boost::optional> load(const Key &key) override; - cpputils::unique_ref overwrite(const Key &key, cpputils::Data data) override; - void remove(const Key &key) override; + BlockId createBlockId() override; + boost::optional> tryCreate(const BlockId &blockId, cpputils::Data data) override; + boost::optional> load(const BlockId &blockId) override; + cpputils::unique_ref overwrite(const BlockId &blockId, cpputils::Data data) override; + void remove(const BlockId &blockId) override; void remove(cpputils::unique_ref node) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; private: cpputils::unique_ref _baseBlockStore; - parallelaccessstore::ParallelAccessStore _parallelAccessStore; + parallelaccessstore::ParallelAccessStore _parallelAccessStore; DISALLOW_COPY_AND_ASSIGN(ParallelAccessBlockStore); }; diff --git a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h index 4f0ed8f9..a77a98cc 100644 --- a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h +++ b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h @@ -9,22 +9,22 @@ namespace blockstore { namespace parallelaccess { -class ParallelAccessBlockStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore { +class ParallelAccessBlockStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore { public: explicit ParallelAccessBlockStoreAdapter(BlockStore *baseBlockStore) :_baseBlockStore(std::move(baseBlockStore)) { } - boost::optional> loadFromBaseStore(const Key &key) override { - return _baseBlockStore->load(key); + boost::optional> loadFromBaseStore(const BlockId &blockId) override { + return _baseBlockStore->load(blockId); } void removeFromBaseStore(cpputils::unique_ref block) override { return _baseBlockStore->remove(std::move(block)); } - void removeFromBaseStore(const Key &key) override { - return _baseBlockStore->remove(key); + void removeFromBaseStore(const BlockId &blockId) override { + return _baseBlockStore->remove(blockId); } private: diff --git a/src/blockstore/implementations/testfake/FakeBlock.cpp b/src/blockstore/implementations/testfake/FakeBlock.cpp index 8ce97fe3..57a2e241 100644 --- a/src/blockstore/implementations/testfake/FakeBlock.cpp +++ b/src/blockstore/implementations/testfake/FakeBlock.cpp @@ -16,8 +16,8 @@ using cpputils::Data; namespace blockstore { namespace testfake { -FakeBlock::FakeBlock(FakeBlockStore *store, const Key &key, shared_ptr data, bool dirty) - : Block(key), _store(store), _data(data), _dataChanged(dirty) { +FakeBlock::FakeBlock(FakeBlockStore *store, const BlockId &blockId, shared_ptr data, bool dirty) + : Block(blockId), _store(store), _data(data), _dataChanged(dirty) { } FakeBlock::~FakeBlock() { @@ -45,7 +45,7 @@ void FakeBlock::resize(size_t newSize) { void FakeBlock::flush() { if(_dataChanged) { - _store->updateData(key(), *_data); + _store->updateData(blockId(), *_data); _dataChanged = false; } } diff --git a/src/blockstore/implementations/testfake/FakeBlock.h b/src/blockstore/implementations/testfake/FakeBlock.h index e025d3e5..6fa0c2f2 100644 --- a/src/blockstore/implementations/testfake/FakeBlock.h +++ b/src/blockstore/implementations/testfake/FakeBlock.h @@ -13,7 +13,7 @@ class FakeBlockStore; class FakeBlock final: public Block { public: - FakeBlock(FakeBlockStore *store, const Key &key, std::shared_ptr data, bool dirty); + FakeBlock(FakeBlockStore *store, const BlockId &blockId, std::shared_ptr data, bool dirty); ~FakeBlock(); const void *data() const override; diff --git a/src/blockstore/implementations/testfake/FakeBlockStore.cpp b/src/blockstore/implementations/testfake/FakeBlockStore.cpp index 8bc08160..9cb9cb03 100644 --- a/src/blockstore/implementations/testfake/FakeBlockStore.cpp +++ b/src/blockstore/implementations/testfake/FakeBlockStore.cpp @@ -19,21 +19,21 @@ namespace testfake { FakeBlockStore::FakeBlockStore() : _blocks(), _used_dataregions_for_blocks(), _mutex() {} -optional> FakeBlockStore::tryCreate(const Key &key, Data data) { +optional> FakeBlockStore::tryCreate(const BlockId &blockId, Data data) { std::unique_lock lock(_mutex); - auto insert_result = _blocks.emplace(key, std::move(data)); + auto insert_result = _blocks.emplace(blockId, std::move(data)); if (!insert_result.second) { return none; } //Return a copy of the stored data - return _load(key); + return _load(blockId); } -unique_ref FakeBlockStore::overwrite(const Key &key, Data data) { +unique_ref FakeBlockStore::overwrite(const BlockId &blockId, Data data) { std::unique_lock lock(_mutex); - auto insert_result = _blocks.emplace(key, data.copy()); + auto insert_result = _blocks.emplace(blockId, data.copy()); if (!insert_result.second) { // If block already exists, overwrite it. @@ -41,42 +41,42 @@ unique_ref FakeBlockStore::overwrite(const Key &key, Data data) { } //Return a pointer to the stored FakeBlock - auto loaded = _load(key); + auto loaded = _load(blockId); ASSERT(loaded != none, "Block was just created or written. Should exist."); return std::move(*loaded); } -optional> FakeBlockStore::load(const Key &key) { +optional> FakeBlockStore::load(const BlockId &blockId) { std::unique_lock lock(_mutex); - return _load(key); + return _load(blockId); } -optional> FakeBlockStore::_load(const Key &key) { +optional> FakeBlockStore::_load(const BlockId &blockId) { //Return a copy of the stored data try { - return makeFakeBlockFromData(key, _blocks.at(key), false); + return makeFakeBlockFromData(blockId, _blocks.at(blockId), false); } catch (const std::out_of_range &e) { return none; } } -void FakeBlockStore::remove(const Key &key) { +void FakeBlockStore::remove(const BlockId &blockId) { std::unique_lock lock(_mutex); - int numRemoved = _blocks.erase(key); + int numRemoved = _blocks.erase(blockId); ASSERT(numRemoved == 1, "Block not found"); } -unique_ref FakeBlockStore::makeFakeBlockFromData(const Key &key, const Data &data, bool dirty) { +unique_ref FakeBlockStore::makeFakeBlockFromData(const BlockId &blockId, const Data &data, bool dirty) { auto newdata = make_shared(data.copy()); _used_dataregions_for_blocks.push_back(newdata); - return make_unique_ref(this, key, newdata, dirty); + return make_unique_ref(this, blockId, newdata, dirty); } -void FakeBlockStore::updateData(const Key &key, const Data &data) { +void FakeBlockStore::updateData(const BlockId &blockId, const Data &data) { std::unique_lock lock(_mutex); - auto found = _blocks.find(key); + auto found = _blocks.find(blockId); if (found == _blocks.end()) { - auto insertResult = _blocks.emplace(key, data.copy()); + auto insertResult = _blocks.emplace(blockId, data.copy()); ASSERT(true == insertResult.second, "Inserting didn't work"); found = insertResult.first; } @@ -97,7 +97,7 @@ uint64_t FakeBlockStore::blockSizeFromPhysicalBlockSize(uint64_t blockSize) cons return blockSize; } -void FakeBlockStore::forEachBlock(std::function callback) const { +void FakeBlockStore::forEachBlock(std::function callback) const { for (const auto &entry : _blocks) { callback(entry.first); } diff --git a/src/blockstore/implementations/testfake/FakeBlockStore.h b/src/blockstore/implementations/testfake/FakeBlockStore.h index 3d17af38..d5dea019 100644 --- a/src/blockstore/implementations/testfake/FakeBlockStore.h +++ b/src/blockstore/implementations/testfake/FakeBlockStore.h @@ -31,19 +31,19 @@ class FakeBlockStore final: public BlockStoreWithRandomKeys { public: FakeBlockStore(); - boost::optional> tryCreate(const Key &key, cpputils::Data data) override; - cpputils::unique_ref overwrite(const blockstore::Key &key, cpputils::Data data) override; - boost::optional> load(const Key &key) override; - void remove(const Key &key) override; + boost::optional> tryCreate(const BlockId &blockId, cpputils::Data data) override; + cpputils::unique_ref overwrite(const blockstore::BlockId &blockId, cpputils::Data data) override; + boost::optional> load(const BlockId &blockId) override; + void remove(const BlockId &blockId) override; uint64_t numBlocks() const override; uint64_t estimateNumFreeBytes() const override; uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const override; - void forEachBlock(std::function callback) const override; + void forEachBlock(std::function callback) const override; - void updateData(const Key &key, const cpputils::Data &data); + void updateData(const BlockId &blockId, const cpputils::Data &data); private: - std::unordered_map _blocks; + std::unordered_map _blocks; //This vector keeps a handle of the data regions for all created FakeBlock objects. //This way, it is ensured that no two created FakeBlock objects will work on the @@ -54,8 +54,8 @@ private: mutable std::mutex _mutex; - cpputils::unique_ref makeFakeBlockFromData(const Key &key, const cpputils::Data &data, bool dirty); - boost::optional> _load(const Key &key); + cpputils::unique_ref makeFakeBlockFromData(const BlockId &blockId, const cpputils::Data &data, bool dirty); + boost::optional> _load(const BlockId &blockId); DISALLOW_COPY_AND_ASSIGN(FakeBlockStore); }; diff --git a/src/blockstore/interface/Block.h b/src/blockstore/interface/Block.h index 0261a097..c5755777 100644 --- a/src/blockstore/interface/Block.h +++ b/src/blockstore/interface/Block.h @@ -2,7 +2,7 @@ #ifndef MESSMER_BLOCKSTORE_INTERFACE_BLOCK_H_ #define MESSMER_BLOCKSTORE_INTERFACE_BLOCK_H_ -#include "../utils/Key.h" +#include "blockstore/utils/BlockId.h" #include namespace blockstore { @@ -24,15 +24,15 @@ public: //TODO Test resize() virtual void resize(size_t newSize) = 0; - const Key &key() const { - return _key; + const BlockId &blockId() const { + return _blockId; } protected: - Block(const Key &key) : _key(key) {} + Block(const BlockId &blockId) : _blockId(blockId) {} private: - const Key _key; + const BlockId _blockId; }; } diff --git a/src/blockstore/interface/BlockStore.h b/src/blockstore/interface/BlockStore.h index 9bd0767a..9681cccf 100644 --- a/src/blockstore/interface/BlockStore.h +++ b/src/blockstore/interface/BlockStore.h @@ -14,15 +14,15 @@ class BlockStore { public: virtual ~BlockStore() {} - virtual Key createKey() = 0; - //Returns boost::none if key already exists + virtual BlockId createBlockId() = 0; + //Returns boost::none if id already exists // TODO Can we make data passed in by ref? - virtual boost::optional> tryCreate(const Key &key, cpputils::Data data) = 0; - //TODO Use boost::optional (if key doesn't exist) - // Return nullptr if block with this key doesn't exists - virtual boost::optional> load(const Key &key) = 0; - virtual cpputils::unique_ref overwrite(const blockstore::Key &key, cpputils::Data data) = 0; - virtual void remove(const Key &key) = 0; + virtual boost::optional> tryCreate(const BlockId &blockId, cpputils::Data data) = 0; + //TODO Use boost::optional (if id doesn't exist) + // Return nullptr if block with this id doesn't exists + virtual boost::optional> load(const BlockId &blockId) = 0; + virtual cpputils::unique_ref overwrite(const blockstore::BlockId &blockId, cpputils::Data data) = 0; + virtual void remove(const BlockId &blockId) = 0; virtual uint64_t numBlocks() const = 0; //TODO Test estimateNumFreeBytes in all block stores virtual uint64_t estimateNumFreeBytes() const = 0; @@ -31,18 +31,18 @@ public: // This can be used to create blocks with a certain physical block size. virtual uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const = 0; // TODO Test - virtual void forEachBlock(std::function callback) const = 0; + virtual void forEachBlock(std::function callback) const = 0; virtual void remove(cpputils::unique_ref block) { - Key key = block->key(); + BlockId blockId = block->blockId(); cpputils::destruct(std::move(block)); - remove(key); + remove(blockId); } cpputils::unique_ref create(const cpputils::Data &data) { while(true) { //TODO Copy (data.copy()) necessary? - auto block = tryCreate(createKey(), data.copy()); + auto block = tryCreate(createBlockId(), data.copy()); if (block != boost::none) { return std::move(*block); } diff --git a/src/blockstore/interface/BlockStore2.h b/src/blockstore/interface/BlockStore2.h index aa34ba31..48c54866 100644 --- a/src/blockstore/interface/BlockStore2.h +++ b/src/blockstore/interface/BlockStore2.h @@ -16,21 +16,21 @@ public: virtual ~BlockStore2() {} __attribute__((warn_unused_result)) - virtual bool tryCreate(const Key &key, const cpputils::Data &data) = 0; + virtual bool tryCreate(const BlockId &blockId, const cpputils::Data &data) = 0; __attribute__((warn_unused_result)) - virtual bool remove(const Key &key) = 0; + virtual bool remove(const BlockId &blockId) = 0; __attribute__((warn_unused_result)) - virtual boost::optional load(const Key &key) const = 0; + virtual boost::optional load(const BlockId &blockId) const = 0; - // Store the block with the given key. If it doesn't exist, it is created. - virtual void store(const Key &key, const cpputils::Data &data) = 0; + // Store the block with the given blockId. If it doesn't exist, it is created. + virtual void store(const BlockId &blockId, const cpputils::Data &data) = 0; - Key create(const cpputils::Data& data) { - Key key = Key::Random(); - bool success = tryCreate(key, data); + BlockId create(const cpputils::Data& data) { + BlockId blockId = BlockId::Random(); + bool success = tryCreate(blockId, data); if (success) { - return key; + return blockId; } else { return create(data); } @@ -40,7 +40,7 @@ public: //TODO Test estimateNumFreeBytes virtual uint64_t estimateNumFreeBytes() const = 0; virtual uint64_t blockSizeFromPhysicalBlockSize(uint64_t blockSize) const = 0; // TODO Test - virtual void forEachBlock(std::function callback) const = 0; + virtual void forEachBlock(std::function callback) const = 0; }; } diff --git a/src/blockstore/interface/helpers/BlockStoreWithRandomKeys.h b/src/blockstore/interface/helpers/BlockStoreWithRandomKeys.h index e366e4df..e2ebb0ca 100644 --- a/src/blockstore/interface/helpers/BlockStoreWithRandomKeys.h +++ b/src/blockstore/interface/helpers/BlockStoreWithRandomKeys.h @@ -8,14 +8,14 @@ namespace blockstore { -// This is an implementation helpers for BlockStores that use random block keys. +// This is an implementation helpers for BlockStores that use random block ids. // You should never give this static type to the client. The client should always // work with the BlockStore interface instead. // TODO Delete this class class BlockStoreWithRandomKeys: public BlockStore { public: - Key createKey() final { - return Key::Random(); + BlockId createBlockId() final { + return BlockId::Random(); } }; diff --git a/src/blockstore/utils/BlockId.cpp b/src/blockstore/utils/BlockId.cpp index f22451aa..d4cf13df 100644 --- a/src/blockstore/utils/BlockId.cpp +++ b/src/blockstore/utils/BlockId.cpp @@ -1 +1 @@ -#include "Key.h" +#include "BlockId.h" diff --git a/src/blockstore/utils/BlockId.h b/src/blockstore/utils/BlockId.h index b94bccda..b12b9a44 100644 --- a/src/blockstore/utils/BlockId.h +++ b/src/blockstore/utils/BlockId.h @@ -1,14 +1,13 @@ #pragma once -#ifndef MESSMER_BLOCKSTORE_UTILS_KEY_H_ -#define MESSMER_BLOCKSTORE_UTILS_KEY_H_ +#ifndef MESSMER_BLOCKSTORE_UTILS_BLOCKID_H_ +#define MESSMER_BLOCKSTORE_UTILS_BLOCKID_H_ #include "IdWrapper.h" namespace blockstore { struct _BlockIdTag final {}; -// A key here is NOT a key for encryption, but a key as used in key->value mappings ("access handle for a block"). -// TODO Rename to BlockId and split from a BlobId (i.e. IdWrapper) +// TODO Split from a BlobId (i.e. IdWrapper) using BlockId = IdWrapper<_BlockIdTag>; } diff --git a/src/cryfs/config/CryConfigCreator.cpp b/src/cryfs/config/CryConfigCreator.cpp index 7bec0dc6..1eed1c53 100644 --- a/src/cryfs/config/CryConfigCreator.cpp +++ b/src/cryfs/config/CryConfigCreator.cpp @@ -27,7 +27,7 @@ namespace cryfs { config.SetVersion(gitversion::VersionString()); config.SetCreatedWithVersion(gitversion::VersionString()); config.SetBlocksizeBytes(_generateBlocksizeBytes(blocksizeBytesFromCommandLine)); - config.SetRootBlob(_generateRootBlobKey()); + config.SetRootBlob(_generateRootBlobId()); config.SetEncryptionKey(_generateEncKey(config.Cipher())); config.SetFilesystemId(_generateFilesystemID()); uint32_t myClientId = MyClientId(LocalStateDir::forFilesystemId(config.FilesystemId())).loadOrGenerate(); @@ -78,7 +78,7 @@ namespace cryfs { return key; } - string CryConfigCreator::_generateRootBlobKey() { + string CryConfigCreator::_generateRootBlobId() { //An empty root blob entry will tell CryDevice to create a new root blob return ""; } diff --git a/src/cryfs/config/CryConfigCreator.h b/src/cryfs/config/CryConfigCreator.h index e83e132e..549da6dc 100644 --- a/src/cryfs/config/CryConfigCreator.h +++ b/src/cryfs/config/CryConfigCreator.h @@ -23,7 +23,7 @@ namespace cryfs { private: std::string _generateCipher(const boost::optional &cipherFromCommandLine); std::string _generateEncKey(const std::string &cipher); - std::string _generateRootBlobKey(); + std::string _generateRootBlobId(); uint32_t _generateBlocksizeBytes(const boost::optional &blocksizeBytesFromCommandLine); CryConfig::FilesystemID _generateFilesystemID(); boost::optional _generateExclusiveClientId(const boost::optional &missingBlockIsIntegrityViolationFromCommandLine, uint32_t myClientId); diff --git a/src/cryfs/filesystem/CryDevice.cpp b/src/cryfs/filesystem/CryDevice.cpp index 7e372095..95e57fd0 100644 --- a/src/cryfs/filesystem/CryDevice.cpp +++ b/src/cryfs/filesystem/CryDevice.cpp @@ -30,7 +30,7 @@ using fspp::fuse::FuseErrnoException; using blockstore::BlockStore; using blockstore::BlockStore2; -using blockstore::Key; +using blockstore::BlockId; using blockstore::encrypted::EncryptedBlockStore2; using blobstore::BlobStore; using blockstore::lowtohighlevel::LowToHighLevelBlockStore; @@ -59,7 +59,7 @@ namespace cryfs { CryDevice::CryDevice(CryConfigFile configFile, unique_ref blockStore, uint32_t myClientId, bool noIntegrityChecks, bool missingBlockIsIntegrityViolation) : _fsBlobStore(CreateFsBlobStore(std::move(blockStore), &configFile, myClientId, noIntegrityChecks, missingBlockIsIntegrityViolation)), - _rootKey(GetOrCreateRootKey(&configFile)), + _rootBlobId(GetOrCreateRootBlobId(&configFile)), _onFsAction() { } @@ -81,11 +81,11 @@ unique_ref CryDevice::Crea #ifndef CRYFS_NO_COMPATIBILITY unique_ref CryDevice::MigrateOrCreateFsBlobStore(unique_ref blobStore, CryConfigFile *configFile) { - string rootBlobKey = configFile->config()->RootBlob(); - if ("" == rootBlobKey) { + string rootBlobId = configFile->config()->RootBlob(); + if ("" == rootBlobId) { return make_unique_ref(std::move(blobStore)); } - return FsBlobStore::migrateIfNeeded(std::move(blobStore), Key::FromString(rootBlobKey)); + return FsBlobStore::migrateIfNeeded(std::move(blobStore), BlockId::FromString(rootBlobId)); } #endif @@ -119,10 +119,10 @@ unique_ref CryDevice::CreateIntegrityEncryptedBlockStore(unique_ref return make_unique_ref(std::move(encryptedBlockStore), integrityFilePath, myClientId, noIntegrityChecks, missingBlockIsIntegrityViolation); } -Key CryDevice::CreateRootBlobAndReturnKey() { - auto rootBlob = _fsBlobStore->createDirBlob(blockstore::Key::Null()); +BlockId CryDevice::CreateRootBlobAndReturnId() { + auto rootBlob = _fsBlobStore->createDirBlob(blockstore::BlockId::Null()); rootBlob->flush(); // Don't cache, but directly write the root blob (this causes it to fail early if the base directory is not accessible) - return rootBlob->key(); + return rootBlob->blockId(); } optional> CryDevice::LoadFile(const bf::path &path) { @@ -170,7 +170,7 @@ optional> CryDevice::Load(const bf::path &path) { if (path.parent_path().empty()) { //We are asked to load the base directory '/'. - return optional>(make_unique_ref(this, none, none, _rootKey)); + return optional>(make_unique_ref(this, none, none, _rootBlobId)); } auto parentWithGrandparent = LoadDirBlobWithParent(path.parent_path()); @@ -185,11 +185,11 @@ optional> CryDevice::Load(const bf::path &path) { switch(entry.type()) { case fspp::Dir::EntryType::DIR: - return optional>(make_unique_ref(this, std::move(parent), std::move(grandparent), entry.key())); + return optional>(make_unique_ref(this, std::move(parent), std::move(grandparent), entry.blockId())); case fspp::Dir::EntryType::FILE: - return optional>(make_unique_ref(this, std::move(parent), std::move(grandparent), entry.key())); + return optional>(make_unique_ref(this, std::move(parent), std::move(grandparent), entry.blockId())); case fspp::Dir::EntryType::SYMLINK: - return optional>(make_unique_ref(this, std::move(parent), std::move(grandparent), entry.key())); + return optional>(make_unique_ref(this, std::move(parent), std::move(grandparent), entry.blockId())); } ASSERT(false, "Switch/case not exhaustive"); } @@ -205,13 +205,13 @@ CryDevice::DirBlobWithParent CryDevice::LoadDirBlobWithParent(const bf::path &pa CryDevice::BlobWithParent CryDevice::LoadBlobWithParent(const bf::path &path) { optional> parentBlob = none; - optional> currentBlobOpt = _fsBlobStore->load(_rootKey); + optional> currentBlobOpt = _fsBlobStore->load(_rootBlobId); if (currentBlobOpt == none) { LOG(ERROR, "Could not load root blob. Is the base directory accessible?"); throw FuseErrnoException(EIO); } unique_ref currentBlob = std::move(*currentBlobOpt); - ASSERT(currentBlob->parentPointer() == Key::Null(), "Root Blob should have a nullptr as parent"); + ASSERT(currentBlob->parentPointer() == BlockId::Null(), "Root Blob should have a nullptr as parent"); for (const bf::path &component : path.relative_path()) { auto currentDir = dynamic_pointer_move(currentBlob); @@ -223,14 +223,14 @@ CryDevice::BlobWithParent CryDevice::LoadBlobWithParent(const bf::path &path) { if (childOpt == boost::none) { throw FuseErrnoException(ENOENT); // Child entry in directory not found } - Key childKey = childOpt->key(); - auto nextBlob = _fsBlobStore->load(childKey); + BlockId childId = childOpt->blockId(); + auto nextBlob = _fsBlobStore->load(childId); if (nextBlob == none) { throw FuseErrnoException(ENOENT); // Blob for directory entry not found } parentBlob = std::move(*currentDir); currentBlob = std::move(*nextBlob); - ASSERT(currentBlob->parentPointer() == (*parentBlob)->key(), "Blob has wrong parent pointer"); + ASSERT(currentBlob->parentPointer() == (*parentBlob)->blockId(), "Blob has wrong parent pointer"); } return BlobWithParent{std::move(currentBlob), std::move(parentBlob)}; @@ -258,46 +258,46 @@ void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) { fsstat->f_frsize = fsstat->f_bsize; // even though this is supposed to be ignored, osxfuse needs it. } -unique_ref CryDevice::CreateFileBlob(const blockstore::Key &parent) { +unique_ref CryDevice::CreateFileBlob(const blockstore::BlockId &parent) { return _fsBlobStore->createFileBlob(parent); } -unique_ref CryDevice::CreateDirBlob(const blockstore::Key &parent) { +unique_ref CryDevice::CreateDirBlob(const blockstore::BlockId &parent) { return _fsBlobStore->createDirBlob(parent); } -unique_ref CryDevice::CreateSymlinkBlob(const bf::path &target, const blockstore::Key &parent) { +unique_ref CryDevice::CreateSymlinkBlob(const bf::path &target, const blockstore::BlockId &parent) { return _fsBlobStore->createSymlinkBlob(target, parent); } -unique_ref CryDevice::LoadBlob(const blockstore::Key &key) { - auto blob = _fsBlobStore->load(key); +unique_ref CryDevice::LoadBlob(const blockstore::BlockId &blockId) { + auto blob = _fsBlobStore->load(blockId); if (blob == none) { - LOG(ERROR, "Could not load blob {}. Is the base directory accessible?", key.ToString()); + LOG(ERROR, "Could not load blob {}. Is the base directory accessible?", blockId.ToString()); throw FuseErrnoException(EIO); } return std::move(*blob); } -void CryDevice::RemoveBlob(const blockstore::Key &key) { - auto blob = _fsBlobStore->load(key); +void CryDevice::RemoveBlob(const blockstore::BlockId &blockId) { + auto blob = _fsBlobStore->load(blockId); if (blob == none) { - LOG(ERROR, "Could not load blob. Is the base directory accessible?", key.ToString()); + LOG(ERROR, "Could not load blob {}. Is the base directory accessible?", blockId.ToString()); throw FuseErrnoException(EIO); } _fsBlobStore->remove(std::move(*blob)); } -Key CryDevice::GetOrCreateRootKey(CryConfigFile *configFile) { - string root_key = configFile->config()->RootBlob(); - if (root_key == "") { - auto new_key = CreateRootBlobAndReturnKey(); - configFile->config()->SetRootBlob(new_key.ToString()); +BlockId CryDevice::GetOrCreateRootBlobId(CryConfigFile *configFile) { + string root_blockId = configFile->config()->RootBlob(); + if (root_blockId == "") { + auto new_blockId = CreateRootBlobAndReturnId(); + configFile->config()->SetRootBlob(new_blockId.ToString()); configFile->save(); - return new_key; + return new_blockId; } - return Key::FromString(root_key); + return BlockId::FromString(root_blockId); } cpputils::unique_ref CryDevice::CreateEncryptedBlockStore(const CryConfig &config, unique_ref baseBlockStore) { diff --git a/src/cryfs/filesystem/CryDevice.h b/src/cryfs/filesystem/CryDevice.h index 98caecd3..54b86d83 100644 --- a/src/cryfs/filesystem/CryDevice.h +++ b/src/cryfs/filesystem/CryDevice.h @@ -22,16 +22,16 @@ public: void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override; - cpputils::unique_ref CreateFileBlob(const blockstore::Key &parent); - cpputils::unique_ref CreateDirBlob(const blockstore::Key &parent); - cpputils::unique_ref CreateSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent); - cpputils::unique_ref LoadBlob(const blockstore::Key &key); + cpputils::unique_ref CreateFileBlob(const blockstore::BlockId &parent); + cpputils::unique_ref CreateDirBlob(const blockstore::BlockId &parent); + cpputils::unique_ref CreateSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent); + cpputils::unique_ref LoadBlob(const blockstore::BlockId &blockId); struct DirBlobWithParent { cpputils::unique_ref blob; boost::optional> parent; }; DirBlobWithParent LoadDirBlobWithParent(const boost::filesystem::path &path); - void RemoveBlob(const blockstore::Key &key); + void RemoveBlob(const blockstore::BlockId &blockId); void onFsAction(std::function callback); @@ -48,11 +48,11 @@ private: cpputils::unique_ref _fsBlobStore; - blockstore::Key _rootKey; + blockstore::BlockId _rootBlobId; std::vector> _onFsAction; - blockstore::Key GetOrCreateRootKey(CryConfigFile *config); - blockstore::Key CreateRootBlobAndReturnKey(); + blockstore::BlockId GetOrCreateRootBlobId(CryConfigFile *config); + blockstore::BlockId CreateRootBlobAndReturnId(); static cpputils::unique_ref CreateFsBlobStore(cpputils::unique_ref blockStore, CryConfigFile *configFile, uint32_t myClientId, bool noIntegrityChecks, bool missingBlockIsIntegrityViolation); #ifndef CRYFS_NO_COMPATIBILITY static cpputils::unique_ref MigrateOrCreateFsBlobStore(cpputils::unique_ref blobStore, CryConfigFile *configFile); diff --git a/src/cryfs/filesystem/CryDir.cpp b/src/cryfs/filesystem/CryDir.cpp index a534709f..e5151281 100644 --- a/src/cryfs/filesystem/CryDir.cpp +++ b/src/cryfs/filesystem/CryDir.cpp @@ -21,7 +21,7 @@ namespace bf = boost::filesystem; using std::string; using std::vector; -using blockstore::Key; +using blockstore::BlockId; using cpputils::unique_ref; using cpputils::make_unique_ref; using cpputils::dynamic_pointer_move; @@ -31,8 +31,8 @@ using cryfs::parallelaccessfsblobstore::DirBlobRef; namespace cryfs { -CryDir::CryDir(CryDevice *device, optional> parent, optional> grandparent, const Key &key) -: CryNode(device, std::move(parent), std::move(grandparent), key) { +CryDir::CryDir(CryDevice *device, optional> parent, optional> grandparent, const BlockId &blockId) +: CryNode(device, std::move(parent), std::move(grandparent), blockId) { } CryDir::~CryDir() { @@ -42,12 +42,12 @@ unique_ref CryDir::createAndOpenFile(const string &name, mode_t device()->callFsActionCallbacks(); if (!isRootDir()) { //TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function) - parent()->updateModificationTimestampForChild(key()); + parent()->updateModificationTimestampForChild(blockId()); } - auto child = device()->CreateFileBlob(key()); + auto child = device()->CreateFileBlob(blockId()); auto now = cpputils::time::now(); auto dirBlob = LoadBlob(); - dirBlob->AddChildFile(name, child->key(), mode, uid, gid, now, now); + dirBlob->AddChildFile(name, child->blockId(), mode, uid, gid, now, now); return make_unique_ref(device(), std::move(dirBlob), std::move(child)); } @@ -55,12 +55,12 @@ void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) { device()->callFsActionCallbacks(); if (!isRootDir()) { //TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function) - parent()->updateModificationTimestampForChild(key()); + parent()->updateModificationTimestampForChild(blockId()); } auto blob = LoadBlob(); - auto child = device()->CreateDirBlob(key()); + auto child = device()->CreateDirBlob(blockId()); auto now = cpputils::time::now(); - blob->AddChildDir(name, child->key(), mode, uid, gid, now, now); + blob->AddChildDir(name, child->blockId(), mode, uid, gid, now, now); } unique_ref CryDir::LoadBlob() const { @@ -74,7 +74,7 @@ unique_ref> CryDir::children() { device()->callFsActionCallbacks(); if (!isRootDir()) { //TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function) - parent()->updateAccessTimestampForChild(key(), fsblobstore::TimestampUpdateBehavior::RELATIME); + parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME); } auto children = make_unique_ref>(); children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, ".")); @@ -93,19 +93,19 @@ void CryDir::createSymlink(const string &name, const bf::path &target, uid_t uid device()->callFsActionCallbacks(); if (!isRootDir()) { //TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function) - parent()->updateModificationTimestampForChild(key()); + parent()->updateModificationTimestampForChild(blockId()); } auto blob = LoadBlob(); - auto child = device()->CreateSymlinkBlob(target, key()); + auto child = device()->CreateSymlinkBlob(target, blockId()); auto now = cpputils::time::now(); - blob->AddChildSymlink(name, child->key(), uid, gid, now, now); + blob->AddChildSymlink(name, child->blockId(), uid, gid, now, now); } void CryDir::remove() { device()->callFsActionCallbacks(); if (grandparent() != none) { //TODO Instead of doing nothing when we're in the root directory, handle timestamps in the root dir correctly - (*grandparent())->updateModificationTimestampForChild(parent()->key()); + (*grandparent())->updateModificationTimestampForChild(parent()->blockId()); } { auto blob = LoadBlob(); diff --git a/src/cryfs/filesystem/CryDir.h b/src/cryfs/filesystem/CryDir.h index 35492ca6..6380cd8a 100644 --- a/src/cryfs/filesystem/CryDir.h +++ b/src/cryfs/filesystem/CryDir.h @@ -10,7 +10,7 @@ namespace cryfs { class CryDir final: public fspp::Dir, public CryNode { public: - CryDir(CryDevice *device, boost::optional> parent, boost::optional> grandparent, const blockstore::Key &key); + CryDir(CryDevice *device, boost::optional> parent, boost::optional> grandparent, const blockstore::BlockId &blockId); ~CryDir(); //TODO return type variance to CryFile/CryDir? diff --git a/src/cryfs/filesystem/CryFile.cpp b/src/cryfs/filesystem/CryFile.cpp index e9bfde30..c7422072 100644 --- a/src/cryfs/filesystem/CryFile.cpp +++ b/src/cryfs/filesystem/CryFile.cpp @@ -10,7 +10,7 @@ namespace bf = boost::filesystem; using fspp::fuse::CHECK_RETVAL; using fspp::fuse::FuseErrnoException; -using blockstore::Key; +using blockstore::BlockId; using boost::none; using boost::optional; using cpputils::unique_ref; @@ -21,8 +21,8 @@ using cryfs::parallelaccessfsblobstore::FileBlobRef; namespace cryfs { -CryFile::CryFile(CryDevice *device, unique_ref parent, optional> grandparent, const Key &key) -: CryNode(device, std::move(parent), std::move(grandparent), key) { +CryFile::CryFile(CryDevice *device, unique_ref parent, optional> grandparent, const BlockId &blockId) +: CryNode(device, std::move(parent), std::move(grandparent), blockId) { } CryFile::~CryFile() { @@ -47,7 +47,7 @@ void CryFile::truncate(off_t size) { device()->callFsActionCallbacks(); auto blob = LoadBlob(); blob->resize(size); - parent()->updateModificationTimestampForChild(key()); + parent()->updateModificationTimestampForChild(blockId()); } fspp::Dir::EntryType CryFile::getType() const { @@ -59,7 +59,7 @@ void CryFile::remove() { device()->callFsActionCallbacks(); if (grandparent() != none) { //TODO Instead of doing nothing when we're in the root directory, handle timestamps in the root dir correctly - (*grandparent())->updateModificationTimestampForChild(parent()->key()); + (*grandparent())->updateModificationTimestampForChild(parent()->blockId()); } removeNode(); } diff --git a/src/cryfs/filesystem/CryFile.h b/src/cryfs/filesystem/CryFile.h index 886780d9..6e5c38fd 100644 --- a/src/cryfs/filesystem/CryFile.h +++ b/src/cryfs/filesystem/CryFile.h @@ -11,7 +11,7 @@ namespace cryfs { class CryFile final: public fspp::File, public CryNode { public: - CryFile(CryDevice *device, cpputils::unique_ref parent, boost::optional> grandparent, const blockstore::Key &key); + CryFile(CryDevice *device, cpputils::unique_ref parent, boost::optional> grandparent, const blockstore::BlockId &blockId); ~CryFile(); cpputils::unique_ref open(int flags) override; diff --git a/src/cryfs/filesystem/CryNode.cpp b/src/cryfs/filesystem/CryNode.cpp index 05b6044f..df17e7ab 100644 --- a/src/cryfs/filesystem/CryNode.cpp +++ b/src/cryfs/filesystem/CryNode.cpp @@ -13,7 +13,7 @@ namespace bf = boost::filesystem; -using blockstore::Key; +using blockstore::BlockId; using blobstore::Blob; using cpputils::dynamic_pointer_move; using cpputils::unique_ref; @@ -30,11 +30,11 @@ using fspp::fuse::FuseErrnoException; namespace cryfs { -CryNode::CryNode(CryDevice *device, optional> parent, optional> grandparent, const Key &key) +CryNode::CryNode(CryDevice *device, optional> parent, optional> grandparent, const BlockId &blockId) : _device(device), _parent(none), _grandparent(none), - _key(key) { + _blockId(blockId) { ASSERT(parent != none || grandparent == none, "Grandparent can only be set when parent is not none"); @@ -85,24 +85,24 @@ void CryNode::rename(const bf::path &to) { auto targetDir = std::move(targetDirWithParent.blob); auto targetDirParent = std::move(targetDirWithParent.parent); - auto old = (*_parent)->GetChild(_key); + auto old = (*_parent)->GetChild(_blockId); if (old == boost::none) { throw FuseErrnoException(EIO); } fsblobstore::DirEntry oldEntry = *old; // Copying this (instead of only keeping the reference) is necessary, because the operations below (i.e. RenameChild()) might make a reference invalid. - auto onOverwritten = [this] (const blockstore::Key &key) { - device()->RemoveBlob(key); + auto onOverwritten = [this] (const blockstore::BlockId &blockId) { + device()->RemoveBlob(blockId); }; _updateParentModificationTimestamp(); - if (targetDir->key() == (*_parent)->key()) { - targetDir->RenameChild(oldEntry.key(), to.filename().native(), onOverwritten); + if (targetDir->blockId() == (*_parent)->blockId()) { + targetDir->RenameChild(oldEntry.blockId(), to.filename().native(), onOverwritten); } else { _updateTargetDirModificationTimestamp(*targetDir, std::move(targetDirParent)); - targetDir->AddOrOverwriteChild(to.filename().native(), oldEntry.key(), oldEntry.type(), oldEntry.mode(), oldEntry.uid(), oldEntry.gid(), + targetDir->AddOrOverwriteChild(to.filename().native(), oldEntry.blockId(), oldEntry.type(), oldEntry.mode(), oldEntry.uid(), oldEntry.gid(), oldEntry.lastAccessTime(), oldEntry.lastModificationTime(), onOverwritten); (*_parent)->RemoveChild(oldEntry.name()); // targetDir is now the new parent for this node. Adapt to it, so we can call further operations on this node object. - LoadBlob()->setParentPointer(targetDir->key()); + LoadBlob()->setParentPointer(targetDir->blockId()); _parent = std::move(targetDir); } } @@ -111,14 +111,14 @@ void CryNode::_updateParentModificationTimestamp() { if (_grandparent != none) { // TODO Handle timestamps of the root directory (_grandparent == none) correctly. ASSERT(_parent != none, "Grandparent is set, so also parent has to be set"); - (*_grandparent)->updateModificationTimestampForChild((*_parent)->key()); + (*_grandparent)->updateModificationTimestampForChild((*_parent)->blockId()); } } void CryNode::_updateTargetDirModificationTimestamp(const DirBlobRef &targetDir, optional> targetDirParent) { if (targetDirParent != none) { // TODO Handle timestamps of the root directory (targetDirParent == none) correctly. - (*targetDirParent)->updateModificationTimestampForChild(targetDir.key()); + (*targetDirParent)->updateModificationTimestampForChild(targetDir.blockId()); } } @@ -130,7 +130,7 @@ void CryNode::utimens(timespec lastAccessTime, timespec lastModificationTime) { //TODO What should we do? throw FuseErrnoException(EIO); } - (*_parent)->utimensChild(_key, lastAccessTime, lastModificationTime); + (*_parent)->utimensChild(_blockId, lastAccessTime, lastModificationTime); } void CryNode::removeNode() { @@ -140,8 +140,8 @@ void CryNode::removeNode() { //TODO What should we do? throw FuseErrnoException(EIO); } - (*_parent)->RemoveChild(_key); - _device->RemoveBlob(_key); + (*_parent)->RemoveChild(_blockId); + _device->RemoveBlob(_blockId); } CryDevice *CryNode::device() { @@ -153,13 +153,13 @@ const CryDevice *CryNode::device() const { } unique_ref CryNode::LoadBlob() const { - auto blob = _device->LoadBlob(_key); - ASSERT(_parent == none || blob->parentPointer() == (*_parent)->key(), "Blob has wrong parent pointer."); + auto blob = _device->LoadBlob(_blockId); + ASSERT(_parent == none || blob->parentPointer() == (*_parent)->blockId(), "Blob has wrong parent pointer."); return blob; } -const blockstore::Key &CryNode::key() const { - return _key; +const blockstore::BlockId &CryNode::blockId() const { + return _blockId; } void CryNode::stat(struct ::stat *result) const { @@ -179,7 +179,7 @@ void CryNode::stat(struct ::stat *result) const { result->st_mtim = now; result->st_ctim = now; } else { - (*_parent)->statChild(_key, result); + (*_parent)->statChild(_blockId, result); } } @@ -190,7 +190,7 @@ void CryNode::chmod(mode_t mode) { //TODO What should we do? throw FuseErrnoException(EIO); } - (*_parent)->chmodChild(_key, mode); + (*_parent)->chmodChild(_blockId, mode); } void CryNode::chown(uid_t uid, gid_t gid) { @@ -200,15 +200,15 @@ void CryNode::chown(uid_t uid, gid_t gid) { //TODO What should we do? throw FuseErrnoException(EIO); } - (*_parent)->chownChild(_key, uid, gid); + (*_parent)->chownChild(_blockId, uid, gid); } bool CryNode::checkParentPointer() { auto parentPointer = LoadBlob()->parentPointer(); if (_parent == none) { - return parentPointer == Key::Null(); + return parentPointer == BlockId::Null(); } else { - return parentPointer == (*_parent)->key(); + return parentPointer == (*_parent)->blockId(); } } diff --git a/src/cryfs/filesystem/CryNode.h b/src/cryfs/filesystem/CryNode.h index 7fe8a28a..2e362ca1 100644 --- a/src/cryfs/filesystem/CryNode.h +++ b/src/cryfs/filesystem/CryNode.h @@ -15,7 +15,7 @@ public: virtual ~CryNode(); // TODO grandparent is only needed to set the timestamps of the parent directory on rename and remove. Delete grandparent parameter once we store timestamps in the blob itself instead of in the directory listing. - CryNode(CryDevice *device, boost::optional> parent, boost::optional> grandparent, const blockstore::Key &key); + CryNode(CryDevice *device, boost::optional> parent, boost::optional> grandparent, const blockstore::BlockId &blockId); void access(int mask) const override; void stat(struct ::stat *result) const override; void chmod(mode_t mode) override; @@ -31,7 +31,7 @@ protected: CryDevice *device(); const CryDevice *device() const; - const blockstore::Key &key() const; + const blockstore::BlockId &blockId() const; cpputils::unique_ref LoadBlob() const; bool isRootDir() const; std::shared_ptr parent() const; @@ -49,7 +49,7 @@ private: CryDevice *_device; boost::optional> _parent; boost::optional> _grandparent; - blockstore::Key _key; + blockstore::BlockId _blockId; DISALLOW_COPY_AND_ASSIGN(CryNode); }; diff --git a/src/cryfs/filesystem/CryOpenFile.cpp b/src/cryfs/filesystem/CryOpenFile.cpp index a35a40e7..b0b68f06 100644 --- a/src/cryfs/filesystem/CryOpenFile.cpp +++ b/src/cryfs/filesystem/CryOpenFile.cpp @@ -36,24 +36,24 @@ void CryOpenFile::flush() { void CryOpenFile::stat(struct ::stat *result) const { _device->callFsActionCallbacks(); result->st_size = _fileBlob->size(); - _parent->statChildWithSizeAlreadySet(_fileBlob->key(), result); + _parent->statChildWithSizeAlreadySet(_fileBlob->blockId(), result); } void CryOpenFile::truncate(off_t size) const { _device->callFsActionCallbacks(); _fileBlob->resize(size); - _parent->updateModificationTimestampForChild(_fileBlob->key()); + _parent->updateModificationTimestampForChild(_fileBlob->blockId()); } size_t CryOpenFile::read(void *buf, size_t count, off_t offset) const { _device->callFsActionCallbacks(); - _parent->updateAccessTimestampForChild(_fileBlob->key(), fsblobstore::TimestampUpdateBehavior::RELATIME); + _parent->updateAccessTimestampForChild(_fileBlob->blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME); return _fileBlob->read(buf, offset, count); } void CryOpenFile::write(const void *buf, size_t count, off_t offset) { _device->callFsActionCallbacks(); - _parent->updateModificationTimestampForChild(_fileBlob->key()); + _parent->updateModificationTimestampForChild(_fileBlob->blockId()); _fileBlob->write(buf, offset, count); } diff --git a/src/cryfs/filesystem/CrySymlink.cpp b/src/cryfs/filesystem/CrySymlink.cpp index 40d70717..7677a4e8 100644 --- a/src/cryfs/filesystem/CrySymlink.cpp +++ b/src/cryfs/filesystem/CrySymlink.cpp @@ -15,7 +15,7 @@ namespace bf = boost::filesystem; using std::string; using std::vector; -using blockstore::Key; +using blockstore::BlockId; using boost::none; using boost::optional; using cpputils::unique_ref; @@ -26,8 +26,8 @@ using cryfs::parallelaccessfsblobstore::DirBlobRef; namespace cryfs { -CrySymlink::CrySymlink(CryDevice *device, unique_ref parent, optional> grandparent, const Key &key) -: CryNode(device, std::move(parent), std::move(grandparent), key) { +CrySymlink::CrySymlink(CryDevice *device, unique_ref parent, optional> grandparent, const BlockId &blockId) +: CryNode(device, std::move(parent), std::move(grandparent), blockId) { } CrySymlink::~CrySymlink() { @@ -47,7 +47,7 @@ fspp::Dir::EntryType CrySymlink::getType() const { bf::path CrySymlink::target() { device()->callFsActionCallbacks(); - parent()->updateAccessTimestampForChild(key(), fsblobstore::TimestampUpdateBehavior::RELATIME); + parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME); auto blob = LoadBlob(); return blob->target(); } @@ -56,7 +56,7 @@ void CrySymlink::remove() { device()->callFsActionCallbacks(); if (grandparent() != none) { //TODO Instead of doing nothing when we're in the root directory, handle timestamps in the root dir correctly - (*grandparent())->updateModificationTimestampForChild(parent()->key()); + (*grandparent())->updateModificationTimestampForChild(parent()->blockId()); } removeNode(); } diff --git a/src/cryfs/filesystem/CrySymlink.h b/src/cryfs/filesystem/CrySymlink.h index dc6bcc29..e9aa7ca9 100644 --- a/src/cryfs/filesystem/CrySymlink.h +++ b/src/cryfs/filesystem/CrySymlink.h @@ -11,7 +11,7 @@ namespace cryfs { class CrySymlink final: public fspp::Symlink, public CryNode { public: - CrySymlink(CryDevice *device, cpputils::unique_ref parent, boost::optional> grandparent, const blockstore::Key &key); + CrySymlink(CryDevice *device, cpputils::unique_ref parent, boost::optional> grandparent, const blockstore::BlockId &blockId); ~CrySymlink(); boost::filesystem::path target() override; diff --git a/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp b/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp index 94029201..7bbf6303 100644 --- a/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp +++ b/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp @@ -6,7 +6,7 @@ using cpputils::unique_ref; using cpputils::make_unique_ref; using cpputils::dynamic_pointer_move; using blobstore::BlobStore; -using blockstore::Key; +using blockstore::BlockId; using boost::optional; using boost::none; using std::function; @@ -19,12 +19,12 @@ using cryfs::fsblobstore::SymlinkBlob; namespace cryfs { namespace cachingfsblobstore { - optional> CachingFsBlobStore::load(const Key &key) { - auto fromCache = _cache.pop(key); + optional> CachingFsBlobStore::load(const BlockId &blockId) { + auto fromCache = _cache.pop(blockId); if (fromCache != none) { return _makeRef(std::move(*fromCache)); } - auto fromBaseStore = _baseBlobStore->load(key); + auto fromBaseStore = _baseBlobStore->load(blockId); if (fromBaseStore != none) { return _makeRef(std::move(*fromBaseStore)); } diff --git a/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.h b/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.h index 31f98d62..2e881d40 100644 --- a/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.h +++ b/src/cryfs/filesystem/cachingfsblobstore/CachingFsBlobStore.h @@ -19,12 +19,12 @@ namespace cryfs { CachingFsBlobStore(cpputils::unique_ref baseBlobStore); ~CachingFsBlobStore(); - cpputils::unique_ref createFileBlob(const blockstore::Key &parent); - cpputils::unique_ref createDirBlob(const blockstore::Key &parent); - cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent); - boost::optional> load(const blockstore::Key &key); + cpputils::unique_ref createFileBlob(const blockstore::BlockId &parent); + cpputils::unique_ref createDirBlob(const blockstore::BlockId &parent); + cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent); + boost::optional> load(const blockstore::BlockId &blockId); void remove(cpputils::unique_ref blob); - void remove(const blockstore::Key &key); + void remove(const blockstore::BlockId &blockId); uint64_t virtualBlocksizeBytes() const; uint64_t numBlocks() const; uint64_t estimateSpaceForNumBlocksLeft() const; @@ -38,7 +38,7 @@ namespace cryfs { //TODO Move Cache to some common location, not in blockstore //TODO Use other cache config (i.e. smaller max number of entries) here than in blockstore - blockstore::caching::Cache, 50> _cache; + blockstore::caching::Cache, 50> _cache; DISALLOW_COPY_AND_ASSIGN(CachingFsBlobStore); }; @@ -51,21 +51,21 @@ namespace cryfs { inline CachingFsBlobStore::~CachingFsBlobStore() { } - inline cpputils::unique_ref CachingFsBlobStore::createFileBlob(const blockstore::Key &parent) { + inline cpputils::unique_ref CachingFsBlobStore::createFileBlob(const blockstore::BlockId &parent) { // This already creates the file blob in the underlying blobstore. // We could also cache this operation, but that is more complicated (blockstore::CachingBlockStore does it) // and probably not worth it here. return cpputils::make_unique_ref(_baseBlobStore->createFileBlob(parent), this); } - inline cpputils::unique_ref CachingFsBlobStore::createDirBlob(const blockstore::Key &parent) { + inline cpputils::unique_ref CachingFsBlobStore::createDirBlob(const blockstore::BlockId &parent) { // This already creates the file blob in the underlying blobstore. // We could also cache this operation, but that is more complicated (blockstore::CachingBlockStore does it) // and probably not worth it here. return cpputils::make_unique_ref(_baseBlobStore->createDirBlob(parent), this); } - inline cpputils::unique_ref CachingFsBlobStore::createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent) { + inline cpputils::unique_ref CachingFsBlobStore::createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent) { // This already creates the file blob in the underlying blobstore. // We could also cache this operation, but that is more complicated (blockstore::CachingBlockStore does it) // and probably not worth it here. @@ -77,18 +77,18 @@ namespace cryfs { return _baseBlobStore->remove(std::move(baseBlob)); } - inline void CachingFsBlobStore::remove(const blockstore::Key &key) { - auto fromCache = _cache.pop(key); + inline void CachingFsBlobStore::remove(const blockstore::BlockId &blockId) { + auto fromCache = _cache.pop(blockId); if (fromCache != boost::none) { remove(_makeRef(std::move(*fromCache))); } else { - _baseBlobStore->remove(key); + _baseBlobStore->remove(blockId); } } inline void CachingFsBlobStore::releaseForCache(cpputils::unique_ref baseBlob) { - blockstore::Key key = baseBlob->key(); - _cache.push(key, std::move(baseBlob)); + blockstore::BlockId blockId = baseBlob->blockId(); + _cache.push(blockId, std::move(baseBlob)); } inline uint64_t CachingFsBlobStore::virtualBlocksizeBytes() const { diff --git a/src/cryfs/filesystem/cachingfsblobstore/DirBlobRef.h b/src/cryfs/filesystem/cachingfsblobstore/DirBlobRef.h index 0b7b7bbb..9fe4f448 100644 --- a/src/cryfs/filesystem/cachingfsblobstore/DirBlobRef.h +++ b/src/cryfs/filesystem/cachingfsblobstore/DirBlobRef.h @@ -23,16 +23,16 @@ public: return _base->GetChild(name); } - boost::optional GetChild(const blockstore::Key &key) const { - return _base->GetChild(key); + boost::optional GetChild(const blockstore::BlockId &blockId) const { + return _base->GetChild(blockId); } size_t NumChildren() const { return _base->NumChildren(); } - void RemoveChild(const blockstore::Key &key) { - return _base->RemoveChild(key); + void RemoveChild(const blockstore::BlockId &blockId) { + return _base->RemoveChild(blockId); } void RemoveChild(const std::string &name) { @@ -43,69 +43,69 @@ public: return _base->flush(); } - void AddOrOverwriteChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, + void AddOrOverwriteChild(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType type, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, - std::function onOverwritten) { - return _base->AddOrOverwriteChild(name, blobKey, type, mode, uid, gid, lastAccessTime, lastModificationTime, onOverwritten); + std::function onOverwritten) { + return _base->AddOrOverwriteChild(name, blobId, type, mode, uid, gid, lastAccessTime, lastModificationTime, onOverwritten); } - void RenameChild(const blockstore::Key &key, const std::string &newName, std::function onOverwritten) { - return _base->RenameChild(key, newName, onOverwritten); + void RenameChild(const blockstore::BlockId &blockId, const std::string &newName, std::function onOverwritten) { + return _base->RenameChild(blockId, newName, onOverwritten); } - void statChild(const blockstore::Key &key, struct ::stat *result) const { - return _base->statChild(key, result); + void statChild(const blockstore::BlockId &blockId, struct ::stat *result) const { + return _base->statChild(blockId, result); } - void statChildWithSizeAlreadySet(const blockstore::Key &key, struct ::stat *result) const { - return _base->statChildWithSizeAlreadySet(key, result); + void statChildWithSizeAlreadySet(const blockstore::BlockId &blockId, struct ::stat *result) const { + return _base->statChildWithSizeAlreadySet(blockId, result); } - void updateAccessTimestampForChild(const blockstore::Key &key, fsblobstore::TimestampUpdateBehavior timestampUpdateBehavior) { - return _base->updateAccessTimestampForChild(key, timestampUpdateBehavior); + void updateAccessTimestampForChild(const blockstore::BlockId &blockId, fsblobstore::TimestampUpdateBehavior timestampUpdateBehavior) { + return _base->updateAccessTimestampForChild(blockId, timestampUpdateBehavior); } - void updateModificationTimestampForChild(const blockstore::Key &key) { - return _base->updateModificationTimestampForChild(key); + void updateModificationTimestampForChild(const blockstore::BlockId &blockId) { + return _base->updateModificationTimestampForChild(blockId); } - void chmodChild(const blockstore::Key &key, mode_t mode) { - return _base->chmodChild(key, mode); + void chmodChild(const blockstore::BlockId &blockId, mode_t mode) { + return _base->chmodChild(blockId, mode); } - void chownChild(const blockstore::Key &key, uid_t uid, gid_t gid) { - return _base->chownChild(key, uid, gid); + void chownChild(const blockstore::BlockId &blockId, uid_t uid, gid_t gid) { + return _base->chownChild(blockId, uid, gid); } - void utimensChild(const blockstore::Key &key, timespec lastAccessTime, timespec lastModificationTime) { - return _base->utimensChild(key, lastAccessTime, lastModificationTime); + void utimensChild(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime) { + return _base->utimensChild(blockId, lastAccessTime, lastModificationTime); } - void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - return _base->AddChildDir(name, blobKey, mode, uid, gid, lastAccessTime, lastModificationTime); + void AddChildDir(const std::string &name, const blockstore::BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { + return _base->AddChildDir(name, blobId, mode, uid, gid, lastAccessTime, lastModificationTime); } - void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - return _base->AddChildFile(name, blobKey, mode, uid, gid, lastAccessTime, lastModificationTime); + void AddChildFile(const std::string &name, const blockstore::BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { + return _base->AddChildFile(name, blobId, mode, uid, gid, lastAccessTime, lastModificationTime); } - void AddChildSymlink(const std::string &name, const blockstore::Key &blobKey, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - return _base->AddChildSymlink(name, blobKey, uid, gid, lastAccessTime, lastModificationTime); + void AddChildSymlink(const std::string &name, const blockstore::BlockId &blobId, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { + return _base->AddChildSymlink(name, blobId, uid, gid, lastAccessTime, lastModificationTime); } void AppendChildrenTo(std::vector *result) const { return _base->AppendChildrenTo(result); } - const blockstore::Key &key() const { - return _base->key(); + const blockstore::BlockId &blockId() const { + return _base->blockId(); } off_t lstat_size() const { return _base->lstat_size(); } - void setLstatSizeGetter(std::function getLstatSize) { + void setLstatSizeGetter(std::function getLstatSize) { return _base->setLstatSizeGetter(getLstatSize); } diff --git a/src/cryfs/filesystem/cachingfsblobstore/FileBlobRef.h b/src/cryfs/filesystem/cachingfsblobstore/FileBlobRef.h index e28e5027..502dfd0d 100644 --- a/src/cryfs/filesystem/cachingfsblobstore/FileBlobRef.h +++ b/src/cryfs/filesystem/cachingfsblobstore/FileBlobRef.h @@ -36,8 +36,8 @@ public: return _base->flush(); } - const blockstore::Key &key() const { - return _base->key(); + const blockstore::BlockId &blockId() const { + return _base->blockId(); } off_t lstat_size() const { diff --git a/src/cryfs/filesystem/cachingfsblobstore/FsBlobRef.h b/src/cryfs/filesystem/cachingfsblobstore/FsBlobRef.h index e20b89e2..111fe336 100644 --- a/src/cryfs/filesystem/cachingfsblobstore/FsBlobRef.h +++ b/src/cryfs/filesystem/cachingfsblobstore/FsBlobRef.h @@ -12,15 +12,15 @@ class CachingFsBlobStore; class FsBlobRef { public: virtual ~FsBlobRef(); - virtual const blockstore::Key &key() const = 0; + virtual const blockstore::BlockId &blockId() const = 0; virtual off_t lstat_size() const = 0; - const blockstore::Key &parentPointer() const { + const blockstore::BlockId &parentPointer() const { return _baseBlob->parentPointer(); } - void setParentPointer(const blockstore::Key &parentKey) { - return _baseBlob->setParentPointer(parentKey); + void setParentPointer(const blockstore::BlockId &parentBlobId) { + return _baseBlob->setParentPointer(parentBlobId); } cpputils::unique_ref releaseBaseBlob() { diff --git a/src/cryfs/filesystem/cachingfsblobstore/SymlinkBlobRef.h b/src/cryfs/filesystem/cachingfsblobstore/SymlinkBlobRef.h index 2fb65a90..b26a8410 100644 --- a/src/cryfs/filesystem/cachingfsblobstore/SymlinkBlobRef.h +++ b/src/cryfs/filesystem/cachingfsblobstore/SymlinkBlobRef.h @@ -20,8 +20,8 @@ public: return _base->target(); } - const blockstore::Key &key() const { - return _base->key(); + const blockstore::BlockId &blockId() const { + return _base->blockId(); } off_t lstat_size() const { diff --git a/src/cryfs/filesystem/fsblobstore/DirBlob.cpp b/src/cryfs/filesystem/fsblobstore/DirBlob.cpp index d6481a10..4f0a9c21 100644 --- a/src/cryfs/filesystem/fsblobstore/DirBlob.cpp +++ b/src/cryfs/filesystem/fsblobstore/DirBlob.cpp @@ -17,7 +17,7 @@ using std::pair; using std::make_pair; using blobstore::Blob; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using cpputils::unique_ref; using cpputils::make_unique_ref; @@ -28,7 +28,7 @@ namespace fsblobstore { constexpr off_t DirBlob::DIR_LSTAT_SIZE; -DirBlob::DirBlob(FsBlobStore *fsBlobStore, unique_ref blob, std::function getLstatSize) : +DirBlob::DirBlob(FsBlobStore *fsBlobStore, unique_ref blob, std::function getLstatSize) : FsBlob(std::move(blob)), _fsBlobStore(fsBlobStore), _getLstatSize(getLstatSize), _entries(), _mutex(), _changed(false) { ASSERT(baseBlob().blobType() == FsBlobView::BlobType::DIR, "Loaded blob is not a directory"); _readEntriesFromBlob(); @@ -45,7 +45,7 @@ void DirBlob::flush() { baseBlob().flush(); } -unique_ref DirBlob::InitializeEmptyDir(FsBlobStore *fsBlobStore, unique_ref blob, const blockstore::Key &parent, std::function getLstatSize) { +unique_ref DirBlob::InitializeEmptyDir(FsBlobStore *fsBlobStore, unique_ref blob, const blockstore::BlockId &parent, std::function getLstatSize) { InitializeBlob(blob.get(), FsBlobView::BlobType::DIR, parent); return make_unique_ref(fsBlobStore, std::move(blob), getLstatSize); } @@ -65,38 +65,38 @@ void DirBlob::_readEntriesFromBlob() { _entries.deserializeFrom(static_cast(data.data()), data.size()); } -void DirBlob::AddChildDir(const std::string &name, const Key &blobKey, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { +void DirBlob::AddChildDir(const std::string &name, const BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { std::unique_lock lock(_mutex); - _addChild(name, blobKey, fspp::Dir::EntryType::DIR, mode, uid, gid, lastAccessTime, lastModificationTime); + _addChild(name, blobId, fspp::Dir::EntryType::DIR, mode, uid, gid, lastAccessTime, lastModificationTime); } -void DirBlob::AddChildFile(const std::string &name, const Key &blobKey, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { +void DirBlob::AddChildFile(const std::string &name, const BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { std::unique_lock lock(_mutex); - _addChild(name, blobKey, fspp::Dir::EntryType::FILE, mode, uid, gid, lastAccessTime, lastModificationTime); + _addChild(name, blobId, fspp::Dir::EntryType::FILE, mode, uid, gid, lastAccessTime, lastModificationTime); } -void DirBlob::AddChildSymlink(const std::string &name, const blockstore::Key &blobKey, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { +void DirBlob::AddChildSymlink(const std::string &name, const blockstore::BlockId &blobId, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { std::unique_lock lock(_mutex); - _addChild(name, blobKey, fspp::Dir::EntryType::SYMLINK, S_IFLNK | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH, uid, gid, lastAccessTime, lastModificationTime); + _addChild(name, blobId, fspp::Dir::EntryType::SYMLINK, S_IFLNK | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH, uid, gid, lastAccessTime, lastModificationTime); } -void DirBlob::_addChild(const std::string &name, const Key &blobKey, +void DirBlob::_addChild(const std::string &name, const BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - _entries.add(name, blobKey, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); + _entries.add(name, blobId, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); _changed = true; } -void DirBlob::AddOrOverwriteChild(const std::string &name, const Key &blobKey, fspp::Dir::EntryType entryType, +void DirBlob::AddOrOverwriteChild(const std::string &name, const BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, - std::function onOverwritten) { + std::function onOverwritten) { std::unique_lock lock(_mutex); - _entries.addOrOverwrite(name, blobKey, entryType, mode, uid, gid, lastAccessTime, lastModificationTime, onOverwritten); + _entries.addOrOverwrite(name, blobId, entryType, mode, uid, gid, lastAccessTime, lastModificationTime, onOverwritten); _changed = true; } -void DirBlob::RenameChild(const blockstore::Key &key, const std::string &newName, std::function onOverwritten) { +void DirBlob::RenameChild(const blockstore::BlockId &blockId, const std::string &newName, std::function onOverwritten) { std::unique_lock lock(_mutex); - _entries.rename(key, newName, onOverwritten); + _entries.rename(blockId, newName, onOverwritten); _changed = true; } @@ -105,9 +105,9 @@ boost::optional DirBlob::GetChild(const string &name) const { return _entries.get(name); } -boost::optional DirBlob::GetChild(const Key &key) const { +boost::optional DirBlob::GetChild(const BlockId &blockId) const { std::unique_lock lock(_mutex); - return _entries.get(key); + return _entries.get(blockId); } void DirBlob::RemoveChild(const string &name) { @@ -116,9 +116,9 @@ void DirBlob::RemoveChild(const string &name) { _changed = true; } -void DirBlob::RemoveChild(const Key &key) { +void DirBlob::RemoveChild(const BlockId &blockId) { std::unique_lock lock(_mutex); - _entries.remove(key); + _entries.remove(blockId); _changed = true; } @@ -134,13 +134,13 @@ off_t DirBlob::lstat_size() const { return DIR_LSTAT_SIZE; } -void DirBlob::statChild(const Key &key, struct ::stat *result) const { - result->st_size = _getLstatSize(key); - statChildWithSizeAlreadySet(key, result); +void DirBlob::statChild(const BlockId &blockId, struct ::stat *result) const { + result->st_size = _getLstatSize(blockId); + statChildWithSizeAlreadySet(blockId, result); } -void DirBlob::statChildWithSizeAlreadySet(const Key &key, struct ::stat *result) const { - auto childOpt = GetChild(key); +void DirBlob::statChildWithSizeAlreadySet(const BlockId &blockId, struct ::stat *result) const { + auto childOpt = GetChild(blockId); if (childOpt == boost::none) { throw fspp::fuse::FuseErrnoException(ENOENT); } @@ -158,39 +158,39 @@ void DirBlob::statChildWithSizeAlreadySet(const Key &key, struct ::stat *result) result->st_blksize = _fsBlobStore->virtualBlocksizeBytes(); } -void DirBlob::updateAccessTimestampForChild(const Key &key, TimestampUpdateBehavior timestampUpdateBehavior) { +void DirBlob::updateAccessTimestampForChild(const BlockId &blockId, TimestampUpdateBehavior timestampUpdateBehavior) { std::unique_lock lock(_mutex); - if (_entries.updateAccessTimestampForChild(key, timestampUpdateBehavior)) { + if (_entries.updateAccessTimestampForChild(blockId, timestampUpdateBehavior)) { _changed = true; } } -void DirBlob::updateModificationTimestampForChild(const Key &key) { +void DirBlob::updateModificationTimestampForChild(const BlockId &blockId) { std::unique_lock lock(_mutex); - _entries.updateModificationTimestampForChild(key); + _entries.updateModificationTimestampForChild(blockId); _changed = true; } -void DirBlob::chmodChild(const Key &key, mode_t mode) { +void DirBlob::chmodChild(const BlockId &blockId, mode_t mode) { std::unique_lock lock(_mutex); - _entries.setMode(key, mode); + _entries.setMode(blockId, mode); _changed = true; } -void DirBlob::chownChild(const Key &key, uid_t uid, gid_t gid) { +void DirBlob::chownChild(const BlockId &blockId, uid_t uid, gid_t gid) { std::unique_lock lock(_mutex); - if(_entries.setUidGid(key, uid, gid)) { + if(_entries.setUidGid(blockId, uid, gid)) { _changed = true; } } -void DirBlob::utimensChild(const Key &key, timespec lastAccessTime, timespec lastModificationTime) { +void DirBlob::utimensChild(const BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime) { std::unique_lock lock(_mutex); - _entries.setAccessTimes(key, lastAccessTime, lastModificationTime); + _entries.setAccessTimes(blockId, lastAccessTime, lastModificationTime); _changed = true; } -void DirBlob::setLstatSizeGetter(std::function getLstatSize) { +void DirBlob::setLstatSizeGetter(std::function getLstatSize) { std::unique_lock lock(_mutex); _getLstatSize = getLstatSize; } diff --git a/src/cryfs/filesystem/fsblobstore/DirBlob.h b/src/cryfs/filesystem/fsblobstore/DirBlob.h index 3b81c5da..a80c99b5 100644 --- a/src/cryfs/filesystem/fsblobstore/DirBlob.h +++ b/src/cryfs/filesystem/fsblobstore/DirBlob.h @@ -2,7 +2,7 @@ #ifndef MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_DIRBLOB_H_ #define MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_DIRBLOB_H_ -#include +#include #include #include #include "FsBlob.h" @@ -18,10 +18,10 @@ namespace cryfs { constexpr static off_t DIR_LSTAT_SIZE = 4096; static cpputils::unique_ref InitializeEmptyDir(FsBlobStore *fsBlobStore, cpputils::unique_ref blob, - const blockstore::Key &parent, - std::function getLstatSize); + const blockstore::BlockId &parent, + std::function getLstatSize); - DirBlob(FsBlobStore *fsBlobStore, cpputils::unique_ref blob, std::function getLstatSize); + DirBlob(FsBlobStore *fsBlobStore, cpputils::unique_ref blob, std::function getLstatSize); ~DirBlob(); @@ -34,47 +34,47 @@ namespace cryfs { boost::optional GetChild(const std::string &name) const; - boost::optional GetChild(const blockstore::Key &key) const; + boost::optional GetChild(const blockstore::BlockId &blobId) const; - void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, + void AddChildDir(const std::string &name, const blockstore::BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); - void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, + void AddChildFile(const std::string &name, const blockstore::BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); - void AddChildSymlink(const std::string &name, const blockstore::Key &blobKey, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); + void AddChildSymlink(const std::string &name, const blockstore::BlockId &blobId, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); - void AddOrOverwriteChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, + void AddOrOverwriteChild(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType type, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, - std::function onOverwritten); + std::function onOverwritten); - void RenameChild(const blockstore::Key &key, const std::string &newName, std::function onOverwritten); + void RenameChild(const blockstore::BlockId &blockId, const std::string &newName, std::function onOverwritten); void RemoveChild(const std::string &name); - void RemoveChild(const blockstore::Key &key); + void RemoveChild(const blockstore::BlockId &blockId); void flush(); - void statChild(const blockstore::Key &key, struct ::stat *result) const; + void statChild(const blockstore::BlockId &blockId, struct ::stat *result) const; - void statChildWithSizeAlreadySet(const blockstore::Key &key, struct ::stat *result) const; + void statChildWithSizeAlreadySet(const blockstore::BlockId &blockId, struct ::stat *result) const; - void updateAccessTimestampForChild(const blockstore::Key &key, TimestampUpdateBehavior timestampUpdateBehavior); + void updateAccessTimestampForChild(const blockstore::BlockId &blockId, TimestampUpdateBehavior timestampUpdateBehavior); - void updateModificationTimestampForChild(const blockstore::Key &key); + void updateModificationTimestampForChild(const blockstore::BlockId &blockId); - void chmodChild(const blockstore::Key &key, mode_t mode); + void chmodChild(const blockstore::BlockId &blockId, mode_t mode); - void chownChild(const blockstore::Key &key, uid_t uid, gid_t gid); + void chownChild(const blockstore::BlockId &blockId, uid_t uid, gid_t gid); - void utimensChild(const blockstore::Key &key, timespec lastAccessTime, timespec lastModificationTime); + void utimensChild(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime); - void setLstatSizeGetter(std::function getLstatSize); + void setLstatSizeGetter(std::function getLstatSize); private: - void _addChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, + void _addChild(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType type, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); void _readEntriesFromBlob(); void _writeEntriesToBlob(); @@ -82,7 +82,7 @@ namespace cryfs { cpputils::unique_ref releaseBaseBlob() override; FsBlobStore *_fsBlobStore; - std::function _getLstatSize; + std::function _getLstatSize; DirEntryList _entries; mutable std::mutex _mutex; bool _changed; diff --git a/src/cryfs/filesystem/fsblobstore/FileBlob.cpp b/src/cryfs/filesystem/fsblobstore/FileBlob.cpp index 6aeca632..d23f6725 100644 --- a/src/cryfs/filesystem/fsblobstore/FileBlob.cpp +++ b/src/cryfs/filesystem/fsblobstore/FileBlob.cpp @@ -1,12 +1,12 @@ #include "FileBlob.h" -#include +#include #include using blobstore::Blob; using cpputils::unique_ref; using cpputils::make_unique_ref; -using blockstore::Key; +using blockstore::BlockId; namespace cryfs { namespace fsblobstore { @@ -16,7 +16,7 @@ FileBlob::FileBlob(unique_ref blob) ASSERT(baseBlob().blobType() == FsBlobView::BlobType::FILE, "Loaded blob is not a file"); } -unique_ref FileBlob::InitializeEmptyFile(unique_ref blob, const blockstore::Key &parent) { +unique_ref FileBlob::InitializeEmptyFile(unique_ref blob, const blockstore::BlockId &parent) { InitializeBlob(blob.get(), FsBlobView::BlobType::FILE, parent); return make_unique_ref(std::move(blob)); } diff --git a/src/cryfs/filesystem/fsblobstore/FileBlob.h b/src/cryfs/filesystem/fsblobstore/FileBlob.h index bf781c0b..a8ee311b 100644 --- a/src/cryfs/filesystem/fsblobstore/FileBlob.h +++ b/src/cryfs/filesystem/fsblobstore/FileBlob.h @@ -9,7 +9,7 @@ namespace cryfs { class FileBlob final: public FsBlob { public: - static cpputils::unique_ref InitializeEmptyFile(cpputils::unique_ref blob, const blockstore::Key &parent); + static cpputils::unique_ref InitializeEmptyFile(cpputils::unique_ref blob, const blockstore::BlockId &parent); FileBlob(cpputils::unique_ref blob); diff --git a/src/cryfs/filesystem/fsblobstore/FsBlob.h b/src/cryfs/filesystem/fsblobstore/FsBlob.h index 3db3f0d6..6442cf1a 100644 --- a/src/cryfs/filesystem/fsblobstore/FsBlob.h +++ b/src/cryfs/filesystem/fsblobstore/FsBlob.h @@ -13,9 +13,9 @@ namespace cryfs { virtual ~FsBlob(); virtual off_t lstat_size() const = 0; - const blockstore::Key &key() const; - const blockstore::Key &parentPointer() const; - void setParentPointer(const blockstore::Key &parentKey); + const blockstore::BlockId &blockId() const; + const blockstore::BlockId &parentPointer() const; + void setParentPointer(const blockstore::BlockId &parentId); protected: FsBlob(cpputils::unique_ref baseBlob); @@ -23,7 +23,7 @@ namespace cryfs { FsBlobView &baseBlob(); const FsBlobView &baseBlob() const; - static void InitializeBlob(blobstore::Blob *blob, FsBlobView::BlobType magicNumber, const blockstore::Key &parent); + static void InitializeBlob(blobstore::Blob *blob, FsBlobView::BlobType magicNumber, const blockstore::BlockId &parent); friend class FsBlobStore; virtual cpputils::unique_ref releaseBaseBlob(); @@ -47,8 +47,8 @@ namespace cryfs { inline FsBlob::~FsBlob() { } - inline const blockstore::Key &FsBlob::key() const { - return _baseBlob.key(); + inline const blockstore::BlockId &FsBlob::blockId() const { + return _baseBlob.blockId(); } inline const FsBlobView &FsBlob::baseBlob() const { @@ -59,7 +59,7 @@ namespace cryfs { return _baseBlob; } - inline void FsBlob::InitializeBlob(blobstore::Blob *blob, FsBlobView::BlobType magicNumber, const blockstore::Key &parent) { + inline void FsBlob::InitializeBlob(blobstore::Blob *blob, FsBlobView::BlobType magicNumber, const blockstore::BlockId &parent) { FsBlobView::InitializeBlob(blob, magicNumber, parent); } @@ -67,12 +67,12 @@ namespace cryfs { return _baseBlob.releaseBaseBlob(); } - inline const blockstore::Key &FsBlob::parentPointer() const { + inline const blockstore::BlockId &FsBlob::parentPointer() const { return _baseBlob.parentPointer(); } - inline void FsBlob::setParentPointer(const blockstore::Key &parentKey) { - return _baseBlob.setParentPointer(parentKey); + inline void FsBlob::setParentPointer(const blockstore::BlockId &parentId) { + return _baseBlob.setParentPointer(parentId); } } } diff --git a/src/cryfs/filesystem/fsblobstore/FsBlobStore.cpp b/src/cryfs/filesystem/fsblobstore/FsBlobStore.cpp index 3a163f1c..e781090c 100644 --- a/src/cryfs/filesystem/fsblobstore/FsBlobStore.cpp +++ b/src/cryfs/filesystem/fsblobstore/FsBlobStore.cpp @@ -7,7 +7,7 @@ namespace bf = boost::filesystem; using cpputils::unique_ref; using cpputils::make_unique_ref; using blobstore::BlobStore; -using blockstore::Key; +using blockstore::BlockId; using boost::none; using std::function; using std::vector; @@ -15,8 +15,8 @@ using std::vector; namespace cryfs { namespace fsblobstore { -boost::optional> FsBlobStore::load(const blockstore::Key &key) { - auto blob = _baseBlobStore->load(key); +boost::optional> FsBlobStore::load(const blockstore::BlockId &blockId) { + auto blob = _baseBlobStore->load(blockId); if (blob == none) { return none; } @@ -33,8 +33,8 @@ boost::optional> FsBlobStore::load(const blockstore::Key &key } #ifndef CRYFS_NO_COMPATIBILITY - unique_ref FsBlobStore::migrateIfNeeded(unique_ref blobStore, const blockstore::Key &rootKey) { - auto rootBlob = blobStore->load(rootKey); + unique_ref FsBlobStore::migrateIfNeeded(unique_ref blobStore, const blockstore::BlockId &rootBlobId) { + auto rootBlob = blobStore->load(rootBlobId); ASSERT(rootBlob != none, "Could not load root blob"); uint16_t format = FsBlobView::getFormatVersionHeader(**rootBlob); @@ -42,14 +42,14 @@ boost::optional> FsBlobStore::load(const blockstore::Key &key if (format == 0) { // migration needed std::cout << "Migrating file system for conflict resolution features. Please don't interrupt this process. This can take a while..." << std::flush; - fsBlobStore->_migrate(std::move(*rootBlob), blockstore::Key::Null()); + fsBlobStore->_migrate(std::move(*rootBlob), blockstore::BlockId::Null()); std::cout << "done" << std::endl; } return fsBlobStore; } - void FsBlobStore::_migrate(unique_ref node, const blockstore::Key &parentKey) { - FsBlobView::migrate(node.get(), parentKey); + void FsBlobStore::_migrate(unique_ref node, const blockstore::BlockId &parentId) { + FsBlobView::migrate(node.get(), parentId); if (FsBlobView::blobType(*node) == FsBlobView::BlobType::DIR) { DirBlob dir(this, std::move(node), _getLstatSize()); vector children; @@ -57,9 +57,9 @@ boost::optional> FsBlobStore::load(const blockstore::Key &key for (const auto &child : children) { auto childEntry = dir.GetChild(child.name); ASSERT(childEntry != none, "Couldn't load child, although it was returned as a child in the lsit."); - auto childBlob = _baseBlobStore->load(childEntry->key()); + auto childBlob = _baseBlobStore->load(childEntry->blockId()); ASSERT(childBlob != none, "Couldn't load child blob"); - _migrate(std::move(*childBlob), dir.key()); + _migrate(std::move(*childBlob), dir.blockId()); } } } diff --git a/src/cryfs/filesystem/fsblobstore/FsBlobStore.h b/src/cryfs/filesystem/fsblobstore/FsBlobStore.h index 53cb3bed..65818200 100644 --- a/src/cryfs/filesystem/fsblobstore/FsBlobStore.h +++ b/src/cryfs/filesystem/fsblobstore/FsBlobStore.h @@ -17,28 +17,28 @@ namespace cryfs { public: FsBlobStore(cpputils::unique_ref baseBlobStore); - cpputils::unique_ref createFileBlob(const blockstore::Key &parent); - cpputils::unique_ref createDirBlob(const blockstore::Key &parent); - cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent); - boost::optional> load(const blockstore::Key &key); + cpputils::unique_ref createFileBlob(const blockstore::BlockId &parent); + cpputils::unique_ref createDirBlob(const blockstore::BlockId &parent); + cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent); + boost::optional> load(const blockstore::BlockId &blockId); void remove(cpputils::unique_ref blob); - void remove(const blockstore::Key &key); + void remove(const blockstore::BlockId &blockId); uint64_t numBlocks() const; uint64_t estimateSpaceForNumBlocksLeft() const; uint64_t virtualBlocksizeBytes() const; #ifndef CRYFS_NO_COMPATIBILITY - static cpputils::unique_ref migrateIfNeeded(cpputils::unique_ref blobStore, const blockstore::Key &rootKey); + static cpputils::unique_ref migrateIfNeeded(cpputils::unique_ref blobStore, const blockstore::BlockId &blockId); #endif private: #ifndef CRYFS_NO_COMPATIBILITY - void _migrate(cpputils::unique_ref node, const blockstore::Key &parentKey); + void _migrate(cpputils::unique_ref node, const blockstore::BlockId &parentId); #endif - std::function _getLstatSize(); + std::function _getLstatSize(); cpputils::unique_ref _baseBlobStore; @@ -49,17 +49,17 @@ namespace cryfs { : _baseBlobStore(std::move(baseBlobStore)) { } - inline cpputils::unique_ref FsBlobStore::createFileBlob(const blockstore::Key &parent) { + inline cpputils::unique_ref FsBlobStore::createFileBlob(const blockstore::BlockId &parent) { auto blob = _baseBlobStore->create(); return FileBlob::InitializeEmptyFile(std::move(blob), parent); } - inline cpputils::unique_ref FsBlobStore::createDirBlob(const blockstore::Key &parent) { + inline cpputils::unique_ref FsBlobStore::createDirBlob(const blockstore::BlockId &parent) { auto blob = _baseBlobStore->create(); return DirBlob::InitializeEmptyDir(this, std::move(blob), parent, _getLstatSize()); } - inline cpputils::unique_ref FsBlobStore::createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent) { + inline cpputils::unique_ref FsBlobStore::createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent) { auto blob = _baseBlobStore->create(); return SymlinkBlob::InitializeSymlink(std::move(blob), target, parent); } @@ -76,13 +76,13 @@ namespace cryfs { _baseBlobStore->remove(blob->releaseBaseBlob()); } - inline void FsBlobStore::remove(const blockstore::Key &key) { - _baseBlobStore->remove(key); + inline void FsBlobStore::remove(const blockstore::BlockId &blockId) { + _baseBlobStore->remove(blockId); } - inline std::function FsBlobStore::_getLstatSize() { - return [this] (const blockstore::Key &key) { - auto blob = load(key); + inline std::function FsBlobStore::_getLstatSize() { + return [this] (const blockstore::BlockId &blockId) { + auto blob = load(blockId); ASSERT(blob != boost::none, "Blob not found"); return (*blob)->lstat_size(); }; diff --git a/src/cryfs/filesystem/fsblobstore/FsBlobView.cpp b/src/cryfs/filesystem/fsblobstore/FsBlobView.cpp index d8c1be38..32d59240 100644 --- a/src/cryfs/filesystem/fsblobstore/FsBlobView.cpp +++ b/src/cryfs/filesystem/fsblobstore/FsBlobView.cpp @@ -7,16 +7,16 @@ namespace cryfs { constexpr unsigned int FsBlobView::HEADER_SIZE; #ifndef CRYFS_NO_COMPATIBILITY - void FsBlobView::migrate(blobstore::Blob *blob, const blockstore::Key &parentKey) { + void FsBlobView::migrate(blobstore::Blob *blob, const blockstore::BlockId &parentId) { constexpr unsigned int OLD_HEADER_SIZE = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t); ASSERT(FsBlobView::getFormatVersionHeader(*blob) == 0, "Block already migrated"); // Resize blob and move data back cpputils::Data data = blob->readAll(); - blob->resize(blob->size() + blockstore::Key::BINARY_LENGTH); + blob->resize(blob->size() + blockstore::BlockId::BINARY_LENGTH); blob->write(data.dataOffset(OLD_HEADER_SIZE), HEADER_SIZE, data.size() - OLD_HEADER_SIZE); // Write parent pointer - blob->write(parentKey.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::Key::BINARY_LENGTH); + blob->write(parentId.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::BlockId::BINARY_LENGTH); // Update format version number blob->write(&FORMAT_VERSION_HEADER, 0, sizeof(FORMAT_VERSION_HEADER)); } diff --git a/src/cryfs/filesystem/fsblobstore/FsBlobView.h b/src/cryfs/filesystem/fsblobstore/FsBlobView.h index aa74a9f1..2194b082 100644 --- a/src/cryfs/filesystem/fsblobstore/FsBlobView.h +++ b/src/cryfs/filesystem/fsblobstore/FsBlobView.h @@ -17,18 +17,18 @@ namespace cryfs { SYMLINK = 0x02 }; - FsBlobView(cpputils::unique_ref baseBlob): _baseBlob(std::move(baseBlob)), _parentPointer(blockstore::Key::Null()) { + FsBlobView(cpputils::unique_ref baseBlob): _baseBlob(std::move(baseBlob)), _parentPointer(blockstore::BlockId::Null()) { _checkHeader(*_baseBlob); _loadParentPointer(); } - static void InitializeBlob(blobstore::Blob *baseBlob, BlobType blobType, const blockstore::Key &parent) { + static void InitializeBlob(blobstore::Blob *baseBlob, BlobType blobType, const blockstore::BlockId &parent) { baseBlob->resize(sizeof(FORMAT_VERSION_HEADER) + 1); baseBlob->write(&FORMAT_VERSION_HEADER, 0, sizeof(FORMAT_VERSION_HEADER)); uint8_t blobTypeInt = static_cast(blobType); baseBlob->write(&blobTypeInt, sizeof(FORMAT_VERSION_HEADER), sizeof(uint8_t)); - baseBlob->write(parent.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::Key::BINARY_LENGTH); - static_assert(HEADER_SIZE == sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t) + blockstore::Key::BINARY_LENGTH, "If this fails, the header is not initialized correctly in this function."); + baseBlob->write(parent.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::BlockId::BINARY_LENGTH); + static_assert(HEADER_SIZE == sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t) + blockstore::BlockId::BINARY_LENGTH, "If this fails, the header is not initialized correctly in this function."); } static BlobType blobType(const blobstore::Blob &blob) { @@ -40,17 +40,17 @@ namespace cryfs { return _blobType(*_baseBlob); } - const blockstore::Key &parentPointer() const { + const blockstore::BlockId &parentPointer() const { return _parentPointer; } - void setParentPointer(const blockstore::Key &parentKey) { - _parentPointer = parentKey; + void setParentPointer(const blockstore::BlockId &parentId) { + _parentPointer = parentId; _storeParentPointer(); } - const blockstore::Key &key() const override { - return _baseBlob->key(); + const blockstore::BlockId &blockId() const override { + return _baseBlob->blockId(); } uint64_t size() const override { @@ -97,12 +97,12 @@ namespace cryfs { } #ifndef CRYFS_NO_COMPATIBILITY - static void migrate(blobstore::Blob *blob, const blockstore::Key &parentKey); + static void migrate(blobstore::Blob *blob, const blockstore::BlockId &parentId); #endif private: static constexpr uint16_t FORMAT_VERSION_HEADER = 1; - static constexpr unsigned int HEADER_SIZE = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t) + blockstore::Key::BINARY_LENGTH; + static constexpr unsigned int HEADER_SIZE = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t) + blockstore::BlockId::BINARY_LENGTH; static void _checkHeader(const blobstore::Blob &blob) { uint16_t actualFormatVersion = getFormatVersionHeader(blob); @@ -118,18 +118,18 @@ namespace cryfs { } void _loadParentPointer() { - auto idData = cpputils::FixedSizeData::Null(); - _baseBlob->read(idData.data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::Key::BINARY_LENGTH); - _parentPointer = blockstore::Key(idData); + auto idData = cpputils::FixedSizeData::Null(); + _baseBlob->read(idData.data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::BlockId::BINARY_LENGTH); + _parentPointer = blockstore::BlockId(idData); } void _storeParentPointer() { - _baseBlob->write(_parentPointer.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::Key::BINARY_LENGTH); + _baseBlob->write(_parentPointer.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::BlockId::BINARY_LENGTH); } cpputils::unique_ref _baseBlob; - blockstore::Key _parentPointer; + blockstore::BlockId _parentPointer; DISALLOW_COPY_AND_ASSIGN(FsBlobView); }; diff --git a/src/cryfs/filesystem/fsblobstore/SymlinkBlob.cpp b/src/cryfs/filesystem/fsblobstore/SymlinkBlob.cpp index 09bdcdce..55a9e5dc 100644 --- a/src/cryfs/filesystem/fsblobstore/SymlinkBlob.cpp +++ b/src/cryfs/filesystem/fsblobstore/SymlinkBlob.cpp @@ -1,6 +1,6 @@ #include "SymlinkBlob.h" -#include +#include #include using std::string; @@ -18,7 +18,7 @@ SymlinkBlob::SymlinkBlob(unique_ref blob) ASSERT(baseBlob().blobType() == FsBlobView::BlobType::SYMLINK, "Loaded blob is not a symlink"); } -unique_ref SymlinkBlob::InitializeSymlink(unique_ref blob, const bf::path &target, const blockstore::Key &parent) { +unique_ref SymlinkBlob::InitializeSymlink(unique_ref blob, const bf::path &target, const blockstore::BlockId &parent) { InitializeBlob(blob.get(), FsBlobView::BlobType::SYMLINK, parent); FsBlobView symlinkBlobView(std::move(blob)); string targetStr = target.native(); diff --git a/src/cryfs/filesystem/fsblobstore/SymlinkBlob.h b/src/cryfs/filesystem/fsblobstore/SymlinkBlob.h index 1a36f6f7..318cbb32 100644 --- a/src/cryfs/filesystem/fsblobstore/SymlinkBlob.h +++ b/src/cryfs/filesystem/fsblobstore/SymlinkBlob.h @@ -11,7 +11,7 @@ namespace cryfs { class SymlinkBlob final: public FsBlob { public: static cpputils::unique_ref InitializeSymlink(cpputils::unique_ref blob, - const boost::filesystem::path &target, const blockstore::Key &parent); + const boost::filesystem::path &target, const blockstore::BlockId &parent); SymlinkBlob(cpputils::unique_ref blob); diff --git a/src/cryfs/filesystem/fsblobstore/utils/DirEntry.cpp b/src/cryfs/filesystem/fsblobstore/utils/DirEntry.cpp index 69300c36..7b493ff6 100644 --- a/src/cryfs/filesystem/fsblobstore/utils/DirEntry.cpp +++ b/src/cryfs/filesystem/fsblobstore/utils/DirEntry.cpp @@ -2,7 +2,7 @@ using std::vector; using std::string; -using blockstore::Key; +using blockstore::BlockId; namespace cryfs { namespace fsblobstore { @@ -23,7 +23,7 @@ namespace cryfs { offset += _serializeTimeValue(dest + offset, _lastModificationTime); offset += _serializeTimeValue(dest + offset, _lastMetadataChangeTime); offset += _serializeString(dest + offset, _name); - offset += _serializeKey(dest + offset, _key); + offset += _serializeBlockId(dest + offset, _blockId); ASSERT(offset == serializedSize(), "Didn't write correct number of elements"); } @@ -36,9 +36,9 @@ namespace cryfs { timespec lastModificationTime = _deserializeTimeValue(&pos); timespec lastMetadataChangeTime = _deserializeTimeValue(&pos); string name = _deserializeString(&pos); - Key key = _deserializeKey(&pos); + BlockId blockId = _deserializeBlockId(&pos); - result->emplace_back(type, name, key, mode, uid, gid, lastAccessTime, lastModificationTime, lastMetadataChangeTime); + result->emplace_back(type, name, blockId, mode, uid, gid, lastAccessTime, lastModificationTime, lastMetadataChangeTime); return pos; } @@ -99,20 +99,20 @@ namespace cryfs { return value; } - unsigned int DirEntry::_serializeKey(uint8_t *dest, const Key &key) { - key.ToBinary(dest); - return key.BINARY_LENGTH; + unsigned int DirEntry::_serializeBlockId(uint8_t *dest, const BlockId &blockId) { + blockId.ToBinary(dest); + return blockId.BINARY_LENGTH; } - Key DirEntry::_deserializeKey(const char **pos) { - Key key = Key::FromBinary(*pos); - *pos += Key::BINARY_LENGTH; - return key; + BlockId DirEntry::_deserializeBlockId(const char **pos) { + BlockId blockId = BlockId::FromBinary(*pos); + *pos += BlockId::BINARY_LENGTH; + return blockId; } size_t DirEntry::serializedSize() const { return 1 + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + 3*_serializedTimeValueSize() + ( - _name.size() + 1) + _key.BINARY_LENGTH; + _name.size() + 1) + _blockId.BINARY_LENGTH; } } } diff --git a/src/cryfs/filesystem/fsblobstore/utils/DirEntry.h b/src/cryfs/filesystem/fsblobstore/utils/DirEntry.h index 4f3f04a8..41acb6a3 100644 --- a/src/cryfs/filesystem/fsblobstore/utils/DirEntry.h +++ b/src/cryfs/filesystem/fsblobstore/utils/DirEntry.h @@ -2,7 +2,7 @@ #ifndef MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_UTILS_DIRENTRY_H #define MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_UTILS_DIRENTRY_H -#include +#include #include #include #include @@ -12,7 +12,7 @@ namespace cryfs { class DirEntry final { public: - DirEntry(fspp::Dir::EntryType type, const std::string &name, const blockstore::Key &key, mode_t mode, + DirEntry(fspp::Dir::EntryType type, const std::string &name, const blockstore::BlockId &blockId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, timespec lastMetadataChangeTime); @@ -26,7 +26,7 @@ namespace cryfs { const std::string &name() const; void setName(const std::string &value); - const blockstore::Key &key() const; + const blockstore::BlockId &blockId() const; mode_t mode() const; void setMode(mode_t value); @@ -51,18 +51,18 @@ namespace cryfs { static unsigned int _serializeUint8(uint8_t *dest, uint8_t value); static unsigned int _serializeUint32(uint8_t *dest, uint32_t value); static unsigned int _serializeString(uint8_t *dest, const std::string &value); - static unsigned int _serializeKey(uint8_t *dest, const blockstore::Key &value); + static unsigned int _serializeBlockId(uint8_t *dest, const blockstore::BlockId &value); static timespec _deserializeTimeValue(const char **pos); static uint8_t _deserializeUint8(const char **pos); static uint32_t _deserializeUint32(const char **pos); static std::string _deserializeString(const char **pos); - static blockstore::Key _deserializeKey(const char **pos); + static blockstore::BlockId _deserializeBlockId(const char **pos); void _updateLastMetadataChangeTime(); fspp::Dir::EntryType _type; std::string _name; - blockstore::Key _key; + blockstore::BlockId _blockId; mode_t _mode; uid_t _uid; gid_t _gid; @@ -71,10 +71,10 @@ namespace cryfs { timespec _lastMetadataChangeTime; }; - inline DirEntry::DirEntry(fspp::Dir::EntryType type, const std::string &name, const blockstore::Key &key, mode_t mode, + inline DirEntry::DirEntry(fspp::Dir::EntryType type, const std::string &name, const blockstore::BlockId &blockId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, timespec lastMetadataChangeTime) - : _type(type), _name(name), _key(key), _mode(mode), _uid(uid), _gid(gid), _lastAccessTime(lastAccessTime), + : _type(type), _name(name), _blockId(blockId), _mode(mode), _uid(uid), _gid(gid), _lastAccessTime(lastAccessTime), _lastModificationTime(lastModificationTime), _lastMetadataChangeTime(lastMetadataChangeTime) { switch (_type) { case fspp::Dir::EntryType::FILE: @@ -100,8 +100,8 @@ namespace cryfs { return _name; } - inline const blockstore::Key &DirEntry::key() const { - return _key; + inline const blockstore::BlockId &DirEntry::blockId() const { + return _blockId; } inline mode_t DirEntry::mode() const { diff --git a/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.cpp b/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.cpp index 8fb0f900..583d6fc8 100644 --- a/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.cpp +++ b/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.cpp @@ -8,7 +8,7 @@ using cpputils::Data; using std::string; using std::vector; -using blockstore::Key; +using blockstore::BlockId; namespace cryfs { namespace fsblobstore { @@ -20,7 +20,7 @@ Data DirEntryList::serialize() const { Data serialized(_serializedSize()); unsigned int offset = 0; for (auto iter = _entries.begin(); iter != _entries.end(); ++iter) { - ASSERT(iter == _entries.begin() || std::less()((iter-1)->key(), iter->key()), "Invariant hurt: Directory entries should be ordered by key and not have duplicate keys."); + ASSERT(iter == _entries.begin() || std::less()((iter-1)->blockId(), iter->blockId()), "Invariant hurt: Directory entries should be ordered by blockId and not have duplicate blockIds."); iter->serialize(static_cast(serialized.dataOffset(offset))); offset += iter->serializedSize(); } @@ -40,7 +40,7 @@ void DirEntryList::deserializeFrom(const void *data, uint64_t size) { const char *pos = static_cast(data); while (pos < static_cast(data) + size) { pos = DirEntry::deserializeAndAddToVector(pos, &_entries); - ASSERT(_entries.size() == 1 || std::less()(_entries[_entries.size()-2].key(), _entries[_entries.size()-1].key()), "Invariant hurt: Directory entries should be ordered by key and not have duplicate keys."); + ASSERT(_entries.size() == 1 || std::less()(_entries[_entries.size()-2].blockId(), _entries[_entries.size()-1].blockId()), "Invariant hurt: Directory entries should be ordered by blockId and not have duplicate blockIds."); } } @@ -48,41 +48,41 @@ bool DirEntryList::_hasChild(const string &name) const { return _entries.end() != _findByName(name); } -void DirEntryList::add(const string &name, const Key &blobKey, fspp::Dir::EntryType entryType, mode_t mode, +void DirEntryList::add(const string &name, const BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { if (_hasChild(name)) { throw fspp::fuse::FuseErrnoException(EEXIST); } - _add(name, blobKey, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); + _add(name, blobId, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); } -void DirEntryList::_add(const string &name, const Key &blobKey, fspp::Dir::EntryType entryType, mode_t mode, +void DirEntryList::_add(const string &name, const BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - auto insert_pos = _findUpperBound(blobKey); - _entries.emplace(insert_pos, entryType, name, blobKey, mode, uid, gid, lastAccessTime, lastModificationTime, cpputils::time::now()); + auto insert_pos = _findUpperBound(blobId); + _entries.emplace(insert_pos, entryType, name, blobId, mode, uid, gid, lastAccessTime, lastModificationTime, cpputils::time::now()); } -void DirEntryList::addOrOverwrite(const string &name, const Key &blobKey, fspp::Dir::EntryType entryType, mode_t mode, +void DirEntryList::addOrOverwrite(const string &name, const BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, - std::function onOverwritten) { + std::function onOverwritten) { auto found = _findByName(name); if (found != _entries.end()) { - onOverwritten(found->key()); - _overwrite(found, name, blobKey, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); + onOverwritten(found->blockId()); + _overwrite(found, name, blobId, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); } else { - _add(name, blobKey, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); + _add(name, blobId, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); } } -void DirEntryList::rename(const blockstore::Key &key, const std::string &name, std::function onOverwritten) { +void DirEntryList::rename(const blockstore::BlockId &blockId, const std::string &name, std::function onOverwritten) { auto foundSameName = _findByName(name); - if (foundSameName != _entries.end() && foundSameName->key() != key) { - _checkAllowedOverwrite(foundSameName->type(), _findByKey(key)->type()); - onOverwritten(foundSameName->key()); + if (foundSameName != _entries.end() && foundSameName->blockId() != blockId) { + _checkAllowedOverwrite(foundSameName->type(), _findById(blockId)->type()); + onOverwritten(foundSameName->blockId()); _entries.erase(foundSameName); } - _findByKey(key)->setName(name); + _findById(blockId)->setName(name); } void DirEntryList::_checkAllowedOverwrite(fspp::Dir::EntryType oldType, fspp::Dir::EntryType newType) { @@ -98,13 +98,13 @@ void DirEntryList::_checkAllowedOverwrite(fspp::Dir::EntryType oldType, fspp::Di } } -void DirEntryList::_overwrite(vector::iterator entry, const string &name, const Key &blobKey, fspp::Dir::EntryType entryType, mode_t mode, +void DirEntryList::_overwrite(vector::iterator entry, const string &name, const BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { _checkAllowedOverwrite(entry->type(), entryType); - // The new entry has possibly a different key, so it has to be in a different list position (list is ordered by keys). + // The new entry has possibly a different blockId, so it has to be in a different list position (list is ordered by blockIds). // That's why we remove-and-add instead of just modifying the existing entry. _entries.erase(entry); - _add(name, blobKey, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); + _add(name, blobId, entryType, mode, uid, gid, lastAccessTime, lastModificationTime); } boost::optional DirEntryList::get(const string &name) const { @@ -115,8 +115,8 @@ boost::optional DirEntryList::get(const string &name) const { return *found; } -boost::optional DirEntryList::get(const Key &key) const { - auto found = _findByKey(key); +boost::optional DirEntryList::get(const BlockId &blockId) const { + auto found = _findById(blockId); if (found == _entries.end()) { return boost::none; } @@ -131,10 +131,10 @@ void DirEntryList::remove(const string &name) { _entries.erase(found); } -void DirEntryList::remove(const Key &key) { - auto lowerBound = _findLowerBound(key); - auto upperBound = std::find_if(lowerBound, _entries.end(), [&key] (const DirEntry &entry) { - return entry.key() != key; +void DirEntryList::remove(const BlockId &blockId) { + auto lowerBound = _findLowerBound(blockId); + auto upperBound = std::find_if(lowerBound, _entries.end(), [&blockId] (const DirEntry &entry) { + return entry.blockId() != blockId; }); _entries.erase(lowerBound, upperBound); } @@ -149,27 +149,27 @@ vector::const_iterator DirEntryList::_findByName(const string &name) c return const_cast(this)->_findByName(name); } -vector::iterator DirEntryList::_findByKey(const Key &key) { - auto found = _findLowerBound(key); - if (found == _entries.end() || found->key() != key) { +vector::iterator DirEntryList::_findById(const BlockId &blockId) { + auto found = _findLowerBound(blockId); + if (found == _entries.end() || found->blockId() != blockId) { throw fspp::fuse::FuseErrnoException(ENOENT); } return found; } -vector::iterator DirEntryList::_findLowerBound(const Key &key) { - return _findFirst(key, [&key] (const DirEntry &entry) { - return !std::less()(entry.key(), key); +vector::iterator DirEntryList::_findLowerBound(const BlockId &blockId) { + return _findFirst(blockId, [&blockId] (const DirEntry &entry) { + return !std::less()(entry.blockId(), blockId); }); } -vector::iterator DirEntryList::_findUpperBound(const Key &key) { - return _findFirst(key, [&key] (const DirEntry &entry) { - return std::less()(key, entry.key()); +vector::iterator DirEntryList::_findUpperBound(const BlockId &blockId) { + return _findFirst(blockId, [&blockId] (const DirEntry &entry) { + return std::less()(blockId, entry.blockId()); }); } -vector::iterator DirEntryList::_findFirst(const Key &hint, std::function pred) { +vector::iterator DirEntryList::_findFirst(const BlockId &hint, std::function pred) { //TODO Factor out a datastructure that keeps a sorted std::vector and allows these _findLowerBound()/_findUpperBound operations using this hinted linear search if (_entries.size() == 0) { return _entries.end(); @@ -186,8 +186,8 @@ vector::iterator DirEntryList::_findFirst(const Key &hint, std::functi return iter; } -vector::const_iterator DirEntryList::_findByKey(const Key &key) const { - return const_cast(this)->_findByKey(key); +vector::const_iterator DirEntryList::_findById(const BlockId &blockId) const { + return const_cast(this)->_findById(blockId); } size_t DirEntryList::size() const { @@ -202,14 +202,14 @@ DirEntryList::const_iterator DirEntryList::end() const { return _entries.end(); } -void DirEntryList::setMode(const Key &key, mode_t mode) { - auto found = _findByKey(key); +void DirEntryList::setMode(const BlockId &blockId, mode_t mode) { + auto found = _findById(blockId); ASSERT ((S_ISREG(mode) && S_ISREG(found->mode())) || (S_ISDIR(mode) && S_ISDIR(found->mode())) || (S_ISLNK(mode)), "Unknown mode in entry"); found->setMode(mode); } -bool DirEntryList::setUidGid(const Key &key, uid_t uid, gid_t gid) { - auto found = _findByKey(key); +bool DirEntryList::setUidGid(const BlockId &blockId, uid_t uid, gid_t gid) { + auto found = _findById(blockId); bool changed = false; if (uid != (uid_t)-1) { found->setUid(uid); @@ -222,15 +222,15 @@ bool DirEntryList::setUidGid(const Key &key, uid_t uid, gid_t gid) { return changed; } -void DirEntryList::setAccessTimes(const blockstore::Key &key, timespec lastAccessTime, timespec lastModificationTime) { - auto found = _findByKey(key); +void DirEntryList::setAccessTimes(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime) { + auto found = _findById(blockId); found->setLastAccessTime(lastAccessTime); found->setLastModificationTime(lastModificationTime); } -bool DirEntryList::updateAccessTimestampForChild(const blockstore::Key &key, TimestampUpdateBehavior timestampUpdateBehavior) { +bool DirEntryList::updateAccessTimestampForChild(const blockstore::BlockId &blockId, TimestampUpdateBehavior timestampUpdateBehavior) { ASSERT(timestampUpdateBehavior == TimestampUpdateBehavior::RELATIME, "Currently only relatime supported"); - auto found = _findByKey(key); + auto found = _findById(blockId); const timespec lastAccessTime = found->lastAccessTime(); const timespec lastModificationTime = found->lastModificationTime(); const timespec now = cpputils::time::now(); @@ -246,8 +246,8 @@ bool DirEntryList::updateAccessTimestampForChild(const blockstore::Key &key, Tim return changed; } -void DirEntryList::updateModificationTimestampForChild(const blockstore::Key &key) { - auto found = _findByKey(key); +void DirEntryList::updateModificationTimestampForChild(const blockstore::BlockId &blockId) { + auto found = _findById(blockId); found->setLastModificationTime(cpputils::time::now()); } diff --git a/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.h b/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.h index a3973263..8c5b7a91 100644 --- a/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.h +++ b/src/cryfs/filesystem/fsblobstore/utils/DirEntryList.h @@ -8,7 +8,7 @@ #include #include "TimestampUpdateBehavior.h" -//TODO Address elements by name instead of by key when accessing them. Who knows whether there is two hard links for the same blob. +//TODO Address elements by name instead of by blockId when accessing them. Who knows whether there is two hard links for the same blob. namespace cryfs { namespace fsblobstore { @@ -22,40 +22,40 @@ namespace cryfs { cpputils::Data serialize() const; void deserializeFrom(const void *data, uint64_t size); - void add(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType entryType, + void add(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); - void addOrOverwrite(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType entryType, + void addOrOverwrite(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, - std::function onOverwritten); - void rename(const blockstore::Key &key, const std::string &name, std::function onOverwritten); + std::function onOverwritten); + void rename(const blockstore::BlockId &blockId, const std::string &name, std::function onOverwritten); boost::optional get(const std::string &name) const; - boost::optional get(const blockstore::Key &key) const; + boost::optional get(const blockstore::BlockId &blockId) const; void remove(const std::string &name); - void remove(const blockstore::Key &key); + void remove(const blockstore::BlockId &blockId); size_t size() const; const_iterator begin() const; const_iterator end() const; - void setMode(const blockstore::Key &key, mode_t mode); - bool setUidGid(const blockstore::Key &key, uid_t uid, gid_t gid); - void setAccessTimes(const blockstore::Key &key, timespec lastAccessTime, timespec lastModificationTime); - bool updateAccessTimestampForChild(const blockstore::Key &key, TimestampUpdateBehavior timestampUpdateBehavior); - void updateModificationTimestampForChild(const blockstore::Key &key); + void setMode(const blockstore::BlockId &blockId, mode_t mode); + bool setUidGid(const blockstore::BlockId &blockId, uid_t uid, gid_t gid); + void setAccessTimes(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime); + bool updateAccessTimestampForChild(const blockstore::BlockId &blockId, TimestampUpdateBehavior timestampUpdateBehavior); + void updateModificationTimestampForChild(const blockstore::BlockId &blockId); private: uint64_t _serializedSize() const; bool _hasChild(const std::string &name) const; std::vector::iterator _findByName(const std::string &name); std::vector::const_iterator _findByName(const std::string &name) const; - std::vector::iterator _findByKey(const blockstore::Key &key); - std::vector::const_iterator _findByKey(const blockstore::Key &key) const; - std::vector::iterator _findUpperBound(const blockstore::Key &key); - std::vector::iterator _findLowerBound(const blockstore::Key &key); - std::vector::iterator _findFirst(const blockstore::Key &hint, std::function pred); - void _add(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType entryType, + std::vector::iterator _findById(const blockstore::BlockId &blockId); + std::vector::const_iterator _findById(const blockstore::BlockId &blockId) const; + std::vector::iterator _findUpperBound(const blockstore::BlockId &blockId); + std::vector::iterator _findLowerBound(const blockstore::BlockId &blockId); + std::vector::iterator _findFirst(const blockstore::BlockId &hint, std::function pred); + void _add(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); - void _overwrite(std::vector::iterator entry, const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType entryType, + void _overwrite(std::vector::iterator entry, const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime); static void _checkAllowedOverwrite(fspp::Dir::EntryType oldType, fspp::Dir::EntryType newType); diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/DirBlobRef.h b/src/cryfs/filesystem/parallelaccessfsblobstore/DirBlobRef.h index 7aa5ff64..039bcea9 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/DirBlobRef.h +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/DirBlobRef.h @@ -19,16 +19,16 @@ public: return _base->GetChild(name); } - boost::optional GetChild(const blockstore::Key &key) const { - return _base->GetChild(key); + boost::optional GetChild(const blockstore::BlockId &blockId) const { + return _base->GetChild(blockId); } size_t NumChildren() const { return _base->NumChildren(); } - void RemoveChild(const blockstore::Key &key) { - return _base->RemoveChild(key); + void RemoveChild(const blockstore::BlockId &blockId) { + return _base->RemoveChild(blockId); } void RemoveChild(const std::string &name) { @@ -39,74 +39,74 @@ public: return _base->flush(); } - void AddOrOverwriteChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, + void AddOrOverwriteChild(const std::string &name, const blockstore::BlockId &blobId, fspp::Dir::EntryType type, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime, - std::function onOverwritten) { - return _base->AddOrOverwriteChild(name, blobKey, type, mode, uid, gid, lastAccessTime, lastModificationTime, onOverwritten); + std::function onOverwritten) { + return _base->AddOrOverwriteChild(name, blobId, type, mode, uid, gid, lastAccessTime, lastModificationTime, onOverwritten); } - void RenameChild(const blockstore::Key &key, const std::string &newName, std::function onOverwritten) { - return _base->RenameChild(key, newName, onOverwritten); + void RenameChild(const blockstore::BlockId &blockId, const std::string &newName, std::function onOverwritten) { + return _base->RenameChild(blockId, newName, onOverwritten); } - void statChild(const blockstore::Key &key, struct ::stat *result) const { - return _base->statChild(key, result); + void statChild(const blockstore::BlockId &blockId, struct ::stat *result) const { + return _base->statChild(blockId, result); } - void statChildWithSizeAlreadySet(const blockstore::Key &key, struct ::stat *result) const { - return _base->statChildWithSizeAlreadySet(key, result); + void statChildWithSizeAlreadySet(const blockstore::BlockId &blockId, struct ::stat *result) const { + return _base->statChildWithSizeAlreadySet(blockId, result); } - void updateAccessTimestampForChild(const blockstore::Key &key, fsblobstore::TimestampUpdateBehavior timestampUpdateBehavior) { - return _base->updateAccessTimestampForChild(key, timestampUpdateBehavior); + void updateAccessTimestampForChild(const blockstore::BlockId &blockId, fsblobstore::TimestampUpdateBehavior timestampUpdateBehavior) { + return _base->updateAccessTimestampForChild(blockId, timestampUpdateBehavior); } - void updateModificationTimestampForChild(const blockstore::Key &key) { - return _base->updateModificationTimestampForChild(key); + void updateModificationTimestampForChild(const blockstore::BlockId &blockId) { + return _base->updateModificationTimestampForChild(blockId); } - void chmodChild(const blockstore::Key &key, mode_t mode) { - return _base->chmodChild(key, mode); + void chmodChild(const blockstore::BlockId &blockId, mode_t mode) { + return _base->chmodChild(blockId, mode); } - void chownChild(const blockstore::Key &key, uid_t uid, gid_t gid) { - return _base->chownChild(key, uid, gid); + void chownChild(const blockstore::BlockId &blockId, uid_t uid, gid_t gid) { + return _base->chownChild(blockId, uid, gid); } - void utimensChild(const blockstore::Key &key, timespec lastAccessTime, timespec lastModificationTime) { - return _base->utimensChild(key, lastAccessTime, lastModificationTime); + void utimensChild(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime) { + return _base->utimensChild(blockId, lastAccessTime, lastModificationTime); } - void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - return _base->AddChildDir(name, blobKey, mode, uid, gid, lastAccessTime, lastModificationTime); + void AddChildDir(const std::string &name, const blockstore::BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { + return _base->AddChildDir(name, blobId, mode, uid, gid, lastAccessTime, lastModificationTime); } - void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - return _base->AddChildFile(name, blobKey, mode, uid, gid, lastAccessTime, lastModificationTime); + void AddChildFile(const std::string &name, const blockstore::BlockId &blobId, mode_t mode, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { + return _base->AddChildFile(name, blobId, mode, uid, gid, lastAccessTime, lastModificationTime); } - void AddChildSymlink(const std::string &name, const blockstore::Key &blobKey, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { - return _base->AddChildSymlink(name, blobKey, uid, gid, lastAccessTime, lastModificationTime); + void AddChildSymlink(const std::string &name, const blockstore::BlockId &blobId, uid_t uid, gid_t gid, timespec lastAccessTime, timespec lastModificationTime) { + return _base->AddChildSymlink(name, blobId, uid, gid, lastAccessTime, lastModificationTime); } void AppendChildrenTo(std::vector *result) const { return _base->AppendChildrenTo(result); } - const blockstore::Key &key() const override { - return _base->key(); + const blockstore::BlockId &blockId() const override { + return _base->blockId(); } off_t lstat_size() const override { return _base->lstat_size(); } - const blockstore::Key &parentPointer() const override { + const blockstore::BlockId &parentPointer() const override { return _base->parentPointer(); } - void setParentPointer(const blockstore::Key &parentKey) override { - return _base->setParentPointer(parentKey); + void setParentPointer(const blockstore::BlockId &parentId) override { + return _base->setParentPointer(parentId); } private: diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/FileBlobRef.h b/src/cryfs/filesystem/parallelaccessfsblobstore/FileBlobRef.h index 1372a399..8cb4f62f 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/FileBlobRef.h +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/FileBlobRef.h @@ -32,20 +32,20 @@ public: return _base->flush(); } - const blockstore::Key &key() const override { - return _base->key(); + const blockstore::BlockId &blockId() const override { + return _base->blockId(); } off_t lstat_size() const override { return _base->lstat_size(); } - const blockstore::Key &parentPointer() const override { + const blockstore::BlockId &parentPointer() const override { return _base->parentPointer(); } - void setParentPointer(const blockstore::Key &parentKey) override { - return _base->setParentPointer(parentKey); + void setParentPointer(const blockstore::BlockId &parentId) override { + return _base->setParentPointer(parentId); } private: diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/FsBlobRef.h b/src/cryfs/filesystem/parallelaccessfsblobstore/FsBlobRef.h index faffb159..62e8e124 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/FsBlobRef.h +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/FsBlobRef.h @@ -8,13 +8,13 @@ namespace cryfs { namespace parallelaccessfsblobstore { -class FsBlobRef: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { +class FsBlobRef: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { public: virtual ~FsBlobRef() {} - virtual const blockstore::Key &key() const = 0; + virtual const blockstore::BlockId &blockId() const = 0; virtual off_t lstat_size() const = 0; - virtual const blockstore::Key &parentPointer() const = 0; - virtual void setParentPointer(const blockstore::Key &parentKey) = 0; + virtual const blockstore::BlockId &parentPointer() const = 0; + virtual void setParentPointer(const blockstore::BlockId &parentId) = 0; protected: FsBlobRef() {} diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp index 212a8a4b..02089ef7 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp @@ -12,13 +12,13 @@ using cpputils::unique_ref; using cpputils::make_unique_ref; using boost::optional; using boost::none; -using blockstore::Key; +using blockstore::BlockId; namespace cryfs { namespace parallelaccessfsblobstore { -optional> ParallelAccessFsBlobStore::load(const Key &key) { - return _parallelAccessStore.load(key, [this] (cachingfsblobstore::FsBlobRef *blob) { +optional> ParallelAccessFsBlobStore::load(const BlockId &blockId) { + return _parallelAccessStore.load(blockId, [this] (cachingfsblobstore::FsBlobRef *blob) { cachingfsblobstore::FileBlobRef *fileBlob = dynamic_cast(blob); if (fileBlob != nullptr) { return unique_ref(make_unique_ref(fileBlob)); @@ -36,31 +36,31 @@ optional> ParallelAccessFsBlobStore::load(const Key &key) }); } -unique_ref ParallelAccessFsBlobStore::createDirBlob(const blockstore::Key &parent) { +unique_ref ParallelAccessFsBlobStore::createDirBlob(const blockstore::BlockId &parent) { auto blob = _baseBlobStore->createDirBlob(parent); blob->setLstatSizeGetter(_getLstatSize()); - Key key = blob->key(); - return _parallelAccessStore.add(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { + BlockId blockId = blob->blockId(); + return _parallelAccessStore.add(blockId, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { auto dirBlob = dynamic_cast(resource); ASSERT(dirBlob != nullptr, "Wrong resource given"); return make_unique_ref(dirBlob); }); } -unique_ref ParallelAccessFsBlobStore::createFileBlob(const blockstore::Key &parent) { +unique_ref ParallelAccessFsBlobStore::createFileBlob(const blockstore::BlockId &parent) { auto blob = _baseBlobStore->createFileBlob(parent); - Key key = blob->key(); - return _parallelAccessStore.add(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { + BlockId blockId = blob->blockId(); + return _parallelAccessStore.add(blockId, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { auto fileBlob = dynamic_cast(resource); ASSERT(fileBlob != nullptr, "Wrong resource given"); return make_unique_ref(fileBlob); }); } -unique_ref ParallelAccessFsBlobStore::createSymlinkBlob(const bf::path &target, const blockstore::Key &parent) { +unique_ref ParallelAccessFsBlobStore::createSymlinkBlob(const bf::path &target, const blockstore::BlockId &parent) { auto blob = _baseBlobStore->createSymlinkBlob(target, parent); - Key key = blob->key(); - return _parallelAccessStore.add(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { + BlockId blockId = blob->blockId(); + return _parallelAccessStore.add(blockId, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { auto symlinkBlob = dynamic_cast(resource); ASSERT(symlinkBlob != nullptr, "Wrong resource given"); return make_unique_ref(symlinkBlob); diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h index d011ac88..bad2c308 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h @@ -21,10 +21,10 @@ namespace cryfs { public: ParallelAccessFsBlobStore(cpputils::unique_ref baseBlobStore); - cpputils::unique_ref createFileBlob(const blockstore::Key &parent); - cpputils::unique_ref createDirBlob(const blockstore::Key &parent); - cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent); - boost::optional> load(const blockstore::Key &key); + cpputils::unique_ref createFileBlob(const blockstore::BlockId &parent); + cpputils::unique_ref createDirBlob(const blockstore::BlockId &parent); + cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent); + boost::optional> load(const blockstore::BlockId &blockId); void remove(cpputils::unique_ref blob); uint64_t virtualBlocksizeBytes() const; uint64_t numBlocks() const; @@ -33,9 +33,9 @@ namespace cryfs { private: cpputils::unique_ref _baseBlobStore; - parallelaccessstore::ParallelAccessStore _parallelAccessStore; + parallelaccessstore::ParallelAccessStore _parallelAccessStore; - std::function _getLstatSize(); + std::function _getLstatSize(); DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStore); }; @@ -46,13 +46,13 @@ namespace cryfs { } inline void ParallelAccessFsBlobStore::remove(cpputils::unique_ref blob) { - blockstore::Key key = blob->key(); - return _parallelAccessStore.remove(key, std::move(blob)); + blockstore::BlockId blockId = blob->blockId(); + return _parallelAccessStore.remove(blockId, std::move(blob)); } - inline std::function ParallelAccessFsBlobStore::_getLstatSize() { - return [this] (const blockstore::Key &key) { - auto blob = load(key); + inline std::function ParallelAccessFsBlobStore::_getLstatSize() { + return [this] (const blockstore::BlockId &blockId) { + auto blob = load(blockId); ASSERT(blob != boost::none, "Blob not found"); return (*blob)->lstat_size(); }; diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h index 36df2ae2..57b0623f 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h @@ -9,22 +9,22 @@ namespace cryfs { namespace parallelaccessfsblobstore { -class ParallelAccessFsBlobStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore { +class ParallelAccessFsBlobStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore { public: explicit ParallelAccessFsBlobStoreAdapter(cachingfsblobstore::CachingFsBlobStore *baseBlobStore) :_baseBlobStore(std::move(baseBlobStore)) { } - boost::optional> loadFromBaseStore(const blockstore::Key &key) override { - return _baseBlobStore->load(key); + boost::optional> loadFromBaseStore(const blockstore::BlockId &blockId) override { + return _baseBlobStore->load(blockId); } void removeFromBaseStore(cpputils::unique_ref block) override { return _baseBlobStore->remove(std::move(block)); } - void removeFromBaseStore(const blockstore::Key &key) override { - return _baseBlobStore->remove(key); + void removeFromBaseStore(const blockstore::BlockId &blockId) override { + return _baseBlobStore->remove(blockId); } private: diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h b/src/cryfs/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h index e8179da1..ff72c774 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h @@ -16,20 +16,20 @@ public: return _base->target(); } - const blockstore::Key &key() const override { - return _base->key(); + const blockstore::BlockId &blockId() const override { + return _base->blockId(); } off_t lstat_size() const override { return _base->lstat_size(); } - const blockstore::Key &parentPointer() const override { + const blockstore::BlockId &parentPointer() const override { return _base->parentPointer(); } - void setParentPointer(const blockstore::Key &parentKey) override { - return _base->setParentPointer(parentKey); + void setParentPointer(const blockstore::BlockId &parentId) override { + return _base->setParentPointer(parentId); } private: diff --git a/src/parallelaccessstore/ParallelAccessBaseStore.h b/src/parallelaccessstore/ParallelAccessBaseStore.h index d42c49b6..5483741a 100644 --- a/src/parallelaccessstore/ParallelAccessBaseStore.h +++ b/src/parallelaccessstore/ParallelAccessBaseStore.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace parallelaccessstore { @@ -14,7 +14,7 @@ public: virtual ~ParallelAccessBaseStore() {} virtual boost::optional> loadFromBaseStore(const Key &key) = 0; virtual void removeFromBaseStore(cpputils::unique_ref block) = 0; - virtual void removeFromBaseStore(const blockstore::Key &key) = 0; + virtual void removeFromBaseStore(const blockstore::BlockId &blockId) = 0; }; } diff --git a/src/stats/main.cpp b/src/stats/main.cpp index 2f2d9d4b..5cee0ccc 100644 --- a/src/stats/main.cpp +++ b/src/stats/main.cpp @@ -25,7 +25,7 @@ using namespace blobstore::onblocks::datanodestore; using namespace cryfs::fsblobstore; void printNode(unique_ref node) { - std::cout << "Key: " << node->key().ToString() << ", Depth: " << node->depth() << " "; + std::cout << "BlockId: " << node->blockId().ToString() << ", Depth: " << node->depth() << " "; auto innerNode = dynamic_pointer_move(node); if (innerNode != none) { std::cout << "Type: inner\n"; @@ -38,12 +38,12 @@ void printNode(unique_ref node) { } } -set _getBlockstoreUnaccountedBlocks(const CryConfig &config) { +set _getBlockstoreUnaccountedBlocks(const CryConfig &config) { auto onDiskBlockStore = make_unique_ref("/home/heinzi/basedir"); auto encryptedBlockStore = CryCiphers::find(config.Cipher()).createEncryptedBlockstore(std::move(onDiskBlockStore), config.EncryptionKey()); auto highLevelBlockStore = make_unique_ref(std::move(encryptedBlockStore)); auto nodeStore = make_unique_ref(std::move(highLevelBlockStore), config.BlocksizeBytes()); - std::set unaccountedBlocks; + std::set unaccountedBlocks; uint32_t numBlocks = nodeStore->numNodes(); uint32_t i = 0; cout << "There are " << nodeStore->numNodes() << " blocks." << std::endl; @@ -51,24 +51,24 @@ set _getBlockstoreUnaccountedBlocks(const CryConfig &config) { for (auto file = directory_iterator("/home/heinzi/basedir"); file != directory_iterator(); ++file) { cout << "\r" << (++i) << "/" << numBlocks << flush; if (file->path().filename() != "cryfs.config") { - auto key = Key::FromString(file->path().filename().c_str()); - unaccountedBlocks.insert(key); + auto blockId = BlockId::FromString(file->path().filename().c_str()); + unaccountedBlocks.insert(blockId); } } i = 0; cout << "\nRemove blocks that have a parent" << endl; //Remove root block from unaccountedBlocks - unaccountedBlocks.erase(Key::FromString(config.RootBlob())); + unaccountedBlocks.erase(BlockId::FromString(config.RootBlob())); //Remove all blocks that have a parent node from unaccountedBlocks for (auto file = directory_iterator("/home/heinzi/basedir"); file != directory_iterator(); ++file) { cout << "\r" << (++i) << "/" << numBlocks << flush; if (file->path().filename() != "cryfs.config") { - auto key = Key::FromString(file->path().filename().c_str()); - auto node = nodeStore->load(key); + auto blockId = BlockId::FromString(file->path().filename().c_str()); + auto node = nodeStore->load(blockId); auto innerNode = dynamic_pointer_move(*node); if (innerNode != none) { for (uint32_t childIndex = 0; childIndex < (*innerNode)->numChildren(); ++childIndex) { - auto child = (*innerNode)->getChild(childIndex)->key(); + auto child = (*innerNode)->getChild(childIndex)->blockId(); unaccountedBlocks.erase(child); } } @@ -77,28 +77,28 @@ set _getBlockstoreUnaccountedBlocks(const CryConfig &config) { return unaccountedBlocks; } -set _getBlocksReferencedByDirEntries(const CryConfig &config) { +set _getBlocksReferencedByDirEntries(const CryConfig &config) { auto onDiskBlockStore = make_unique_ref("/home/heinzi/basedir"); auto encryptedBlockStore = CryCiphers::find(config.Cipher()).createEncryptedBlockstore(std::move(onDiskBlockStore), config.EncryptionKey()); auto highLevelBlockStore = make_unique_ref(std::move(encryptedBlockStore)); auto fsBlobStore = make_unique_ref(make_unique_ref(std::move(highLevelBlockStore), config.BlocksizeBytes())); - set blocksReferencedByDirEntries; + set blocksReferencedByDirEntries; uint32_t numBlocks = fsBlobStore->numBlocks(); uint32_t i = 0; cout << "\nRemove blocks referenced by dir entries" << endl; for (auto file = directory_iterator("/home/heinzi/basedir"); file != directory_iterator(); ++file) { cout << "\r" << (++i) << "/" << numBlocks << flush; if (file->path().filename() != "cryfs.config") { - auto key = Key::FromString(file->path().filename().c_str()); + auto blockId = BlockId::FromString(file->path().filename().c_str()); try { - auto blob = fsBlobStore->load(key); + auto blob = fsBlobStore->load(blockId); if (blob != none) { auto dir = dynamic_pointer_move(*blob); if (dir != none) { vector children; (*dir)->AppendChildrenTo(&children); for (const auto &child : children) { - blocksReferencedByDirEntries.insert((*dir)->GetChild(child.name)->key()); + blocksReferencedByDirEntries.insert((*dir)->GetChild(child.name)->blockId()); } } } @@ -115,11 +115,11 @@ int main() { getline(cin, password); cout << "Loading config" << endl; auto config = CryConfigFile::load("/home/heinzi/basedir/cryfs.config", password); - set unaccountedBlocks = _getBlockstoreUnaccountedBlocks(*config->config()); + set unaccountedBlocks = _getBlockstoreUnaccountedBlocks(*config->config()); //Remove all blocks that are referenced by a directory entry from unaccountedBlocks - set blocksReferencedByDirEntries = _getBlocksReferencedByDirEntries(*config->config()); - for (const auto &key : blocksReferencedByDirEntries) { - unaccountedBlocks.erase(key); + set blocksReferencedByDirEntries = _getBlocksReferencedByDirEntries(*config->config()); + for (const auto &blockId : blocksReferencedByDirEntries) { + unaccountedBlocks.erase(blockId); } cout << "\nCalculate statistics" << endl; @@ -133,9 +133,9 @@ int main() { uint32_t numLeaves = 0; uint32_t numInner = 0; cout << "\nUnaccounted blocks: " << unaccountedBlocks.size() << endl; - for (const auto &key : unaccountedBlocks) { + for (const auto &blockId : unaccountedBlocks) { std::cout << "\r" << (numLeaves+numInner) << "/" << numUnaccountedBlocks << flush; - auto node = nodeStore->load(key); + auto node = nodeStore->load(blockId); auto innerNode = dynamic_pointer_move(*node); if (innerNode != none) { ++numInner; diff --git a/test/blobstore/implementations/onblocks/BigBlobsTest.cpp b/test/blobstore/implementations/onblocks/BigBlobsTest.cpp index 2d90630d..1d6d01b0 100644 --- a/test/blobstore/implementations/onblocks/BigBlobsTest.cpp +++ b/test/blobstore/implementations/onblocks/BigBlobsTest.cpp @@ -65,11 +65,11 @@ TEST_F(BigBlobsTest, Resize) { blob->flush(); //Destruct >4GB blob - auto key = blob->key(); + auto blockId = blob->blockId(); cpputils::destruct(std::move(blob)); //Load >4GB blob - blob = blobStore->load(key).value(); + blob = blobStore->load(blockId).value(); //Remove >4GB blob blobStore->remove(std::move(blob)); diff --git a/test/blobstore/implementations/onblocks/BlobReadWriteTest.cpp b/test/blobstore/implementations/onblocks/BlobReadWriteTest.cpp index e6459acb..9a6d995b 100644 --- a/test/blobstore/implementations/onblocks/BlobReadWriteTest.cpp +++ b/test/blobstore/implementations/onblocks/BlobReadWriteTest.cpp @@ -9,7 +9,7 @@ using ::testing::Values; using namespace blobstore; using blobstore::onblocks::datanodestore::DataNodeLayout; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using cpputils::DataFixture; @@ -45,14 +45,14 @@ constexpr DataNodeLayout BlobReadWriteTest::LAYOUT; TEST_F(BlobReadWriteTest, WritingImmediatelyFlushes_SmallSize) { blob->resize(5); blob->write(randomData.data(), 0, 5); - auto loaded = loadBlob(blob->key()); + auto loaded = loadBlob(blob->blockId()); EXPECT_DATA_READS_AS(randomData, *loaded, 0, 5); } TEST_F(BlobReadWriteTest, WritingImmediatelyFlushes_LargeSize) { blob->resize(LARGE_SIZE); blob->write(randomData.data(), 0, LARGE_SIZE); - auto loaded = loadBlob(blob->key()); + auto loaded = loadBlob(blob->blockId()); EXPECT_DATA_READS_AS(randomData, *loaded, 0, LARGE_SIZE); } @@ -133,7 +133,7 @@ TEST_P(BlobReadWriteDataTest, WriteAndReadImmediately) { TEST_P(BlobReadWriteDataTest, WriteAndReadAfterLoading) { blob->resize(GetParam().blobsize); blob->write(this->foregroundData.data(), GetParam().offset, GetParam().count); - auto loaded = loadBlob(blob->key()); + auto loaded = loadBlob(blob->blockId()); EXPECT_DATA_READS_AS(this->foregroundData, *loaded, GetParam().offset, GetParam().count); EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(*loaded, GetParam().offset, GetParam().count); diff --git a/test/blobstore/implementations/onblocks/BlobSizeTest.cpp b/test/blobstore/implementations/onblocks/BlobSizeTest.cpp index f8935610..5b7320f1 100644 --- a/test/blobstore/implementations/onblocks/BlobSizeTest.cpp +++ b/test/blobstore/implementations/onblocks/BlobSizeTest.cpp @@ -3,7 +3,7 @@ #include using namespace blobstore; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using cpputils::DataFixture; using cpputils::unique_ref; @@ -64,17 +64,17 @@ TEST_F(BlobSizeTest, ResizingToItself_Large) { } TEST_F(BlobSizeTest, EmptyBlobStaysEmptyWhenLoading) { - Key key = blob->key(); + BlockId blockId = blob->blockId(); reset(std::move(blob)); - auto loaded = loadBlob(key); + auto loaded = loadBlob(blockId); EXPECT_EQ(0u, loaded->size()); } TEST_F(BlobSizeTest, BlobSizeStaysIntactWhenLoading) { blob->resize(LARGE_SIZE); - Key key = blob->key(); + BlockId blockId = blob->blockId(); reset(std::move(blob)); - auto loaded = loadBlob(key); + auto loaded = loadBlob(blockId); EXPECT_EQ(LARGE_SIZE, loaded->size()); } @@ -113,7 +113,7 @@ TEST_F(BlobSizeTest, WritingAfterEndOfBlobGrowsBlob_NonEmpty) { TEST_F(BlobSizeTest, ChangingSizeImmediatelyFlushes) { blob->resize(LARGE_SIZE); - auto loaded = loadBlob(blob->key()); + auto loaded = loadBlob(blob->blockId()); EXPECT_EQ(LARGE_SIZE, loaded->size()); } @@ -143,7 +143,7 @@ TEST_F(BlobSizeDataTest, BlobIsZeroedOutAfterGrowing) { TEST_F(BlobSizeDataTest, BlobIsZeroedOutAfterGrowingAndLoading) { blob->resize(LARGE_SIZE); - auto loaded = loadBlob(blob->key()); + auto loaded = loadBlob(blob->blockId()); EXPECT_EQ(0, std::memcmp(readBlob(*loaded).data(), ZEROES.data(), LARGE_SIZE)); } diff --git a/test/blobstore/implementations/onblocks/BlobStoreTest.cpp b/test/blobstore/implementations/onblocks/BlobStoreTest.cpp index 05bf9d26..dc84f698 100644 --- a/test/blobstore/implementations/onblocks/BlobStoreTest.cpp +++ b/test/blobstore/implementations/onblocks/BlobStoreTest.cpp @@ -1,45 +1,45 @@ #include "testutils/BlobStoreTest.h" #include -using blockstore::Key; +using blockstore::BlockId; using cpputils::unique_ref; using blobstore::Blob; using boost::none; TEST_F(BlobStoreTest, LoadNonexistingKeyOnEmptyBlobstore) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_EQ(none, blobStore->load(key)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_EQ(none, blobStore->load(blockId)); } TEST_F(BlobStoreTest, LoadNonexistingKeyOnNonEmptyBlobstore) { blobStore->create(); - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_EQ(none, blobStore->load(key)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_EQ(none, blobStore->load(blockId)); } TEST_F(BlobStoreTest, TwoCreatedBlobsHaveDifferentKeys) { auto blob1 = blobStore->create(); auto blob2 = blobStore->create(); - EXPECT_NE(blob1->key(), blob2->key()); + EXPECT_NE(blob1->blockId(), blob2->blockId()); } TEST_F(BlobStoreTest, BlobIsNotLoadableAfterDeletion_DeleteDirectly) { auto blob = blobStore->create(); - Key key = blob->key(); + BlockId blockId = blob->blockId(); blobStore->remove(std::move(blob)); - EXPECT_FALSE((bool)blobStore->load(key)); + EXPECT_FALSE((bool)blobStore->load(blockId)); } TEST_F(BlobStoreTest, BlobIsNotLoadableAfterDeletion_DeleteByKey) { - auto key = blobStore->create()->key(); - blobStore->remove(key); - EXPECT_FALSE((bool)blobStore->load(key)); + auto blockId = blobStore->create()->blockId(); + blobStore->remove(blockId); + EXPECT_FALSE((bool)blobStore->load(blockId)); } TEST_F(BlobStoreTest, BlobIsNotLoadableAfterDeletion_DeleteAfterLoading) { auto blob = blobStore->create(); - Key key = blob->key(); + BlockId blockId = blob->blockId(); reset(std::move(blob)); - blobStore->remove(loadBlob(key)); - EXPECT_FALSE((bool)blobStore->load(key)); + blobStore->remove(loadBlob(blockId)); + EXPECT_FALSE((bool)blobStore->load(blockId)); } diff --git a/test/blobstore/implementations/onblocks/datanodestore/DataInnerNodeTest.cpp b/test/blobstore/implementations/onblocks/datanodestore/DataInnerNodeTest.cpp index 084e43f6..35d8343c 100644 --- a/test/blobstore/implementations/onblocks/datanodestore/DataInnerNodeTest.cpp +++ b/test/blobstore/implementations/onblocks/datanodestore/DataInnerNodeTest.cpp @@ -14,7 +14,7 @@ using ::testing::Test; using cpputils::dynamic_pointer_move; -using blockstore::Key; +using blockstore::BlockId; using blockstore::testfake::FakeBlockStore; using blockstore::BlockStore; using cpputils::Data; @@ -36,56 +36,56 @@ public: nodeStore(make_unique_ref(std::move(_blockStore), BLOCKSIZE_BYTES)), ZEROES(nodeStore->layout().maxBytesPerLeaf()), leaf(nodeStore->createNewLeafNode(Data(0))), - node(nodeStore->createNewInnerNode(1, {leaf->key()})) { + node(nodeStore->createNewInnerNode(1, {leaf->blockId()})) { ZEROES.FillWithZeroes(); } - unique_ref LoadInnerNode(const Key &key) { - auto node = nodeStore->load(key).value(); + unique_ref LoadInnerNode(const BlockId &blockId) { + auto node = nodeStore->load(blockId).value(); return dynamic_pointer_move(node).value(); } - Key CreateNewInnerNodeReturnKey(const DataNode &firstChild) { - return nodeStore->createNewInnerNode(firstChild.depth()+1, {firstChild.key()})->key(); + BlockId CreateNewInnerNodeReturnKey(const DataNode &firstChild) { + return nodeStore->createNewInnerNode(firstChild.depth()+1, {firstChild.blockId()})->blockId(); } unique_ref CreateNewInnerNode() { auto new_leaf = nodeStore->createNewLeafNode(Data(0)); - return nodeStore->createNewInnerNode(1, {new_leaf->key()}); + return nodeStore->createNewInnerNode(1, {new_leaf->blockId()}); } unique_ref CreateAndLoadNewInnerNode(const DataNode &firstChild) { - auto key = CreateNewInnerNodeReturnKey(firstChild); - return LoadInnerNode(key); + auto blockId = CreateNewInnerNodeReturnKey(firstChild); + return LoadInnerNode(blockId); } - unique_ref CreateNewInnerNode(uint8_t depth, const vector &children) { + unique_ref CreateNewInnerNode(uint8_t depth, const vector &children) { return nodeStore->createNewInnerNode(depth, children); } - Key CreateNewInnerNodeReturnKey(uint8_t depth, const vector &children) { - return CreateNewInnerNode(depth, children)->key(); + BlockId CreateNewInnerNodeReturnKey(uint8_t depth, const vector &children) { + return CreateNewInnerNode(depth, children)->blockId(); } - unique_ref CreateAndLoadNewInnerNode(uint8_t depth, const vector &children) { - auto key = CreateNewInnerNodeReturnKey(depth, children); - return LoadInnerNode(key); + unique_ref CreateAndLoadNewInnerNode(uint8_t depth, const vector &children) { + auto blockId = CreateNewInnerNodeReturnKey(depth, children); + return LoadInnerNode(blockId); } - Key AddALeafTo(DataInnerNode *node) { + BlockId AddALeafTo(DataInnerNode *node) { auto leaf2 = nodeStore->createNewLeafNode(Data(0)); node->addChild(*leaf2); - return leaf2->key(); + return leaf2->blockId(); } - Key CreateNodeWithDataConvertItToInnerNodeAndReturnKey() { + BlockId CreateNodeWithDataConvertItToInnerNodeAndReturnKey() { auto node = CreateNewInnerNode(); AddALeafTo(node.get()); AddALeafTo(node.get()); auto child = nodeStore->createNewLeafNode(Data(0)); unique_ref converted = DataNode::convertToNewInnerNode(std::move(node), nodeStore->layout(), *child); - return converted->key(); + return converted->blockId(); } unique_ref CopyInnerNode(const DataInnerNode &node) { @@ -93,10 +93,10 @@ public: return dynamic_pointer_move(copied).value(); } - Key InitializeInnerNodeAddLeafReturnKey() { - auto node = DataInnerNode::CreateNewNode(blockStore, nodeStore->layout(), 1, {leaf->key()}); + BlockId InitializeInnerNodeAddLeafReturnKey() { + auto node = DataInnerNode::CreateNewNode(blockStore, nodeStore->layout(), 1, {leaf->blockId()}); AddALeafTo(node.get()); - return node->key(); + return node->blockId(); } unique_ref _blockStore; @@ -114,96 +114,96 @@ private: constexpr uint32_t DataInnerNodeTest::BLOCKSIZE_BYTES; TEST_F(DataInnerNodeTest, CorrectKeyReturnedAfterLoading) { - Key key = DataInnerNode::CreateNewNode(blockStore, nodeStore->layout(), 1, {leaf->key()})->key(); + BlockId blockId = DataInnerNode::CreateNewNode(blockStore, nodeStore->layout(), 1, {leaf->blockId()})->blockId(); - auto loaded = nodeStore->load(key).value(); - EXPECT_EQ(key, loaded->key()); + auto loaded = nodeStore->load(blockId).value(); + EXPECT_EQ(blockId, loaded->blockId()); } TEST_F(DataInnerNodeTest, InitializesCorrectly) { - auto node = DataInnerNode::CreateNewNode(blockStore, nodeStore->layout(), 1, {leaf->key()}); + auto node = DataInnerNode::CreateNewNode(blockStore, nodeStore->layout(), 1, {leaf->blockId()}); EXPECT_EQ(1u, node->numChildren()); - EXPECT_EQ(leaf->key(), node->getChild(0)->key()); + EXPECT_EQ(leaf->blockId(), node->getChild(0)->blockId()); } TEST_F(DataInnerNodeTest, ReinitializesCorrectly) { - auto key = DataLeafNode::CreateNewNode(blockStore, nodeStore->layout(), Data(0))->key(); - auto node = DataInnerNode::InitializeNewNode(blockStore->load(key).value(), nodeStore->layout(), 1, {leaf->key()}); + auto blockId = DataLeafNode::CreateNewNode(blockStore, nodeStore->layout(), Data(0))->blockId(); + auto node = DataInnerNode::InitializeNewNode(blockStore->load(blockId).value(), nodeStore->layout(), 1, {leaf->blockId()}); EXPECT_EQ(1u, node->numChildren()); - EXPECT_EQ(leaf->key(), node->getChild(0)->key()); + EXPECT_EQ(leaf->blockId(), node->getChild(0)->blockId()); } TEST_F(DataInnerNodeTest, IsCorrectlyInitializedAfterLoading) { auto loaded = CreateAndLoadNewInnerNode(*leaf); EXPECT_EQ(1u, loaded->numChildren()); - EXPECT_EQ(leaf->key(), loaded->getChild(0)->key()); + EXPECT_EQ(leaf->blockId(), loaded->getChild(0)->blockId()); } TEST_F(DataInnerNodeTest, AddingASecondLeaf) { - Key leaf2_key = AddALeafTo(node.get()); + BlockId leaf2_blockId = AddALeafTo(node.get()); EXPECT_EQ(2u, node->numChildren()); - EXPECT_EQ(leaf->key(), node->getChild(0)->key()); - EXPECT_EQ(leaf2_key, node->getChild(1)->key()); + EXPECT_EQ(leaf->blockId(), node->getChild(0)->blockId()); + EXPECT_EQ(leaf2_blockId, node->getChild(1)->blockId()); } TEST_F(DataInnerNodeTest, AddingASecondLeafAndReload) { auto leaf2 = nodeStore->createNewLeafNode(Data(0)); - auto loaded = CreateAndLoadNewInnerNode(1, {leaf->key(), leaf2->key()}); + auto loaded = CreateAndLoadNewInnerNode(1, {leaf->blockId(), leaf2->blockId()}); EXPECT_EQ(2u, loaded->numChildren()); - EXPECT_EQ(leaf->key(), loaded->getChild(0)->key()); - EXPECT_EQ(leaf2->key(), loaded->getChild(1)->key()); + EXPECT_EQ(leaf->blockId(), loaded->getChild(0)->blockId()); + EXPECT_EQ(leaf2->blockId(), loaded->getChild(1)->blockId()); } TEST_F(DataInnerNodeTest, BuildingAThreeLevelTree) { auto node2 = CreateNewInnerNode(); - auto parent = CreateNewInnerNode(node->depth()+1, {node->key(), node2->key()}); + auto parent = CreateNewInnerNode(node->depth()+1, {node->blockId(), node2->blockId()}); EXPECT_EQ(2u, parent->numChildren()); - EXPECT_EQ(node->key(), parent->getChild(0)->key()); - EXPECT_EQ(node2->key(), parent->getChild(1)->key()); + EXPECT_EQ(node->blockId(), parent->getChild(0)->blockId()); + EXPECT_EQ(node2->blockId(), parent->getChild(1)->blockId()); } TEST_F(DataInnerNodeTest, BuildingAThreeLevelTreeAndReload) { auto node2 = CreateNewInnerNode(); - auto parent = CreateAndLoadNewInnerNode(node->depth()+1, {node->key(), node2->key()}); + auto parent = CreateAndLoadNewInnerNode(node->depth()+1, {node->blockId(), node2->blockId()}); EXPECT_EQ(2u, parent->numChildren()); - EXPECT_EQ(node->key(), parent->getChild(0)->key()); - EXPECT_EQ(node2->key(), parent->getChild(1)->key()); + EXPECT_EQ(node->blockId(), parent->getChild(0)->blockId()); + EXPECT_EQ(node2->blockId(), parent->getChild(1)->blockId()); } TEST_F(DataInnerNodeTest, ConvertToInternalNode) { auto child = nodeStore->createNewLeafNode(Data(0)); - Key node_key = node->key(); + BlockId node_blockId = node->blockId(); unique_ref converted = DataNode::convertToNewInnerNode(std::move(node), nodeStore->layout(), *child); EXPECT_EQ(1u, converted->numChildren()); - EXPECT_EQ(child->key(), converted->getChild(0)->key()); - EXPECT_EQ(node_key, converted->key()); + EXPECT_EQ(child->blockId(), converted->getChild(0)->blockId()); + EXPECT_EQ(node_blockId, converted->blockId()); } TEST_F(DataInnerNodeTest, ConvertToInternalNodeZeroesOutChildrenRegion) { - Key key = CreateNodeWithDataConvertItToInnerNodeAndReturnKey(); + BlockId blockId = CreateNodeWithDataConvertItToInnerNodeAndReturnKey(); - auto block = blockStore->load(key).value(); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(0, std::memcmp(ZEROES.data(), (uint8_t*)block->data()+DataNodeLayout::HEADERSIZE_BYTES+sizeof(DataInnerNode::ChildEntry), nodeStore->layout().maxBytesPerLeaf()-sizeof(DataInnerNode::ChildEntry))); } TEST_F(DataInnerNodeTest, CopyingCreatesNewNode) { auto copied = CopyInnerNode(*node); - EXPECT_NE(node->key(), copied->key()); + EXPECT_NE(node->blockId(), copied->blockId()); } TEST_F(DataInnerNodeTest, CopyInnerNodeWithOneChild) { auto copied = CopyInnerNode(*node); EXPECT_EQ(node->numChildren(), copied->numChildren()); - EXPECT_EQ(node->getChild(0)->key(), copied->getChild(0)->key()); + EXPECT_EQ(node->getChild(0)->blockId(), copied->getChild(0)->blockId()); } TEST_F(DataInnerNodeTest, CopyInnerNodeWithTwoChildren) { @@ -211,21 +211,21 @@ TEST_F(DataInnerNodeTest, CopyInnerNodeWithTwoChildren) { auto copied = CopyInnerNode(*node); EXPECT_EQ(node->numChildren(), copied->numChildren()); - EXPECT_EQ(node->getChild(0)->key(), copied->getChild(0)->key()); - EXPECT_EQ(node->getChild(1)->key(), copied->getChild(1)->key()); + EXPECT_EQ(node->getChild(0)->blockId(), copied->getChild(0)->blockId()); + EXPECT_EQ(node->getChild(1)->blockId(), copied->getChild(1)->blockId()); } TEST_F(DataInnerNodeTest, LastChildWhenOneChild) { - EXPECT_EQ(leaf->key(), node->LastChild()->key()); + EXPECT_EQ(leaf->blockId(), node->LastChild()->blockId()); } TEST_F(DataInnerNodeTest, LastChildWhenTwoChildren) { - Key key = AddALeafTo(node.get()); - EXPECT_EQ(key, node->LastChild()->key()); + BlockId blockId = AddALeafTo(node.get()); + EXPECT_EQ(blockId, node->LastChild()->blockId()); } TEST_F(DataInnerNodeTest, LastChildWhenThreeChildren) { AddALeafTo(node.get()); - Key key = AddALeafTo(node.get()); - EXPECT_EQ(key, node->LastChild()->key()); + BlockId blockId = AddALeafTo(node.get()); + EXPECT_EQ(blockId, node->LastChild()->blockId()); } diff --git a/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp b/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp index bfcd7fbe..9b101907 100644 --- a/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp +++ b/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp @@ -25,7 +25,7 @@ using cpputils::dynamic_pointer_move; using blockstore::BlockStore; using cpputils::Data; -using blockstore::Key; +using blockstore::BlockId; using blockstore::testfake::FakeBlockStore; using namespace blobstore; using namespace blobstore::onblocks; @@ -60,11 +60,11 @@ public: return data; } - Key WriteDataToNewLeafBlockAndReturnKey() { + BlockId WriteDataToNewLeafBlockAndReturnKey() { auto newleaf = nodeStore->createNewLeafNode(Data(0)); newleaf->resize(randomData.size()); newleaf->write(randomData.data(), 0, randomData.size()); - return newleaf->key(); + return newleaf->blockId(); } void FillLeafBlockWithData() { @@ -76,23 +76,23 @@ public: leaf_to_fill->write(randomData.data(), 0, randomData.size()); } - unique_ref LoadLeafNode(const Key &key) { - auto leaf = nodeStore->load(key).value(); + unique_ref LoadLeafNode(const BlockId &blockId) { + auto leaf = nodeStore->load(blockId).value(); return dynamic_pointer_move(leaf).value(); } - void ResizeLeaf(const Key &key, size_t size) { - auto leaf = LoadLeafNode(key); + void ResizeLeaf(const BlockId &blockId, size_t size) { + auto leaf = LoadLeafNode(blockId); EXPECT_IS_PTR_TYPE(DataLeafNode, leaf.get()); leaf->resize(size); } - Key CreateLeafWithDataConvertItToInnerNodeAndReturnKey() { + BlockId CreateLeafWithDataConvertItToInnerNodeAndReturnKey() { auto leaf = nodeStore->createNewLeafNode(Data(0)); FillLeafBlockWithData(leaf.get()); auto child = nodeStore->createNewLeafNode(Data(0)); unique_ref converted = DataNode::convertToNewInnerNode(std::move(leaf), LAYOUT, *child); - return converted->key(); + return converted->blockId(); } unique_ref CopyLeafNode(const DataLeafNode &node) { @@ -100,10 +100,10 @@ public: return dynamic_pointer_move(copied).value(); } - Key InitializeLeafGrowAndReturnKey() { + BlockId InitializeLeafGrowAndReturnKey() { auto leaf = DataLeafNode::CreateNewNode(blockStore, LAYOUT, Data(LAYOUT.maxBytesPerLeaf())); leaf->resize(5); - return leaf->key(); + return leaf->blockId(); } unique_ref _blockStore; @@ -121,10 +121,10 @@ constexpr uint32_t DataLeafNodeTest::BLOCKSIZE_BYTES; constexpr DataNodeLayout DataLeafNodeTest::LAYOUT; TEST_F(DataLeafNodeTest, CorrectKeyReturnedAfterLoading) { - Key key = DataLeafNode::CreateNewNode(blockStore, LAYOUT, Data(LAYOUT.maxBytesPerLeaf()))->key(); + BlockId blockId = DataLeafNode::CreateNewNode(blockStore, LAYOUT, Data(LAYOUT.maxBytesPerLeaf()))->blockId(); - auto loaded = nodeStore->load(key).value(); - EXPECT_EQ(key, loaded->key()); + auto loaded = nodeStore->load(blockId).value(); + EXPECT_EQ(blockId, loaded->blockId()); } TEST_F(DataLeafNodeTest, InitializesCorrectly) { @@ -133,9 +133,9 @@ TEST_F(DataLeafNodeTest, InitializesCorrectly) { } TEST_F(DataLeafNodeTest, ReadWrittenDataAfterReloadingBlock) { - Key key = WriteDataToNewLeafBlockAndReturnKey(); + BlockId blockId = WriteDataToNewLeafBlockAndReturnKey(); - auto loaded = LoadLeafNode(key); + auto loaded = LoadLeafNode(blockId); EXPECT_EQ(randomData.size(), loaded->numBytes()); EXPECT_EQ(randomData, loadData(*loaded)); @@ -146,18 +146,18 @@ TEST_F(DataLeafNodeTest, NewLeafNodeHasSizeZero) { } TEST_F(DataLeafNodeTest, NewLeafNodeHasSizeZero_AfterLoading) { - Key key = nodeStore->createNewLeafNode(Data(0))->key(); - auto leaf = LoadLeafNode(key); + BlockId blockId = nodeStore->createNewLeafNode(Data(0))->blockId(); + auto leaf = LoadLeafNode(blockId); EXPECT_EQ(0u, leaf->numBytes()); } class DataLeafNodeSizeTest: public DataLeafNodeTest, public WithParamInterface { public: - Key CreateLeafResizeItAndReturnKey() { + BlockId CreateLeafResizeItAndReturnKey() { auto leaf = nodeStore->createNewLeafNode(Data(0)); leaf->resize(GetParam()); - return leaf->key(); + return leaf->blockId(); } }; INSTANTIATE_TEST_CASE_P(DataLeafNodeSizeTest, DataLeafNodeSizeTest, Values(0, 1, 5, 16, 32, 512, DataNodeLayout(DataLeafNodeTest::BLOCKSIZE_BYTES).maxBytesPerLeaf())); @@ -168,9 +168,9 @@ TEST_P(DataLeafNodeSizeTest, ResizeNode_ReadSizeImmediately) { } TEST_P(DataLeafNodeSizeTest, ResizeNode_ReadSizeAfterLoading) { - Key key = CreateLeafResizeItAndReturnKey(); + BlockId blockId = CreateLeafResizeItAndReturnKey(); - auto leaf = LoadLeafNode(key); + auto leaf = LoadLeafNode(blockId); EXPECT_EQ(GetParam(), leaf->numBytes()); } @@ -191,18 +191,18 @@ TEST_F(DataLeafNodeTest, SpaceGetsZeroFilledWhenShrinkingAndRegrowing) { } TEST_F(DataLeafNodeTest, DataGetsZeroFilledWhenShrinking) { - Key key = WriteDataToNewLeafBlockAndReturnKey(); + BlockId blockId = WriteDataToNewLeafBlockAndReturnKey(); uint32_t smaller_size = randomData.size() - 100; { //At first, we expect there to be random data in the underlying data block - auto block = blockStore->load(key).value(); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(0, std::memcmp((char*)randomData.data()+smaller_size, (uint8_t*)block->data()+DataNodeLayout::HEADERSIZE_BYTES+smaller_size, 100)); } //After shrinking, we expect there to be zeroes in the underlying data block - ResizeLeaf(key, smaller_size); + ResizeLeaf(blockId, smaller_size); { - auto block = blockStore->load(key).value(); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(0, std::memcmp(ZEROES.data(), (uint8_t*)block->data()+DataNodeLayout::HEADERSIZE_BYTES+smaller_size, 100)); } } @@ -218,24 +218,24 @@ TEST_F(DataLeafNodeTest, ShrinkingDoesntDestroyValidDataRegion) { TEST_F(DataLeafNodeTest, ConvertToInternalNode) { auto child = nodeStore->createNewLeafNode(Data(0)); - Key leaf_key = leaf->key(); + BlockId leaf_blockId = leaf->blockId(); unique_ref converted = DataNode::convertToNewInnerNode(std::move(leaf), LAYOUT, *child); EXPECT_EQ(1u, converted->numChildren()); - EXPECT_EQ(child->key(), converted->getChild(0)->key()); - EXPECT_EQ(leaf_key, converted->key()); + EXPECT_EQ(child->blockId(), converted->getChild(0)->blockId()); + EXPECT_EQ(leaf_blockId, converted->blockId()); } TEST_F(DataLeafNodeTest, ConvertToInternalNodeZeroesOutChildrenRegion) { - Key key = CreateLeafWithDataConvertItToInnerNodeAndReturnKey(); + BlockId blockId = CreateLeafWithDataConvertItToInnerNodeAndReturnKey(); - auto block = blockStore->load(key).value(); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(0, std::memcmp(ZEROES.data(), (uint8_t*)block->data()+DataNodeLayout::HEADERSIZE_BYTES+sizeof(DataInnerNode::ChildEntry), nodeStore->layout().maxBytesPerLeaf()-sizeof(DataInnerNode::ChildEntry))); } TEST_F(DataLeafNodeTest, CopyingCreatesANewLeaf) { auto copied = CopyLeafNode(*leaf); - EXPECT_NE(leaf->key(), copied->key()); + EXPECT_NE(leaf->blockId(), copied->blockId()); } TEST_F(DataLeafNodeTest, CopyEmptyLeaf) { @@ -274,12 +274,12 @@ public: backgroundData(DataFixture::generate(GetParam().leafsize, 1)) { } - Key CreateLeafWriteToItAndReturnKey(const Data &to_write) { + BlockId CreateLeafWriteToItAndReturnKey(const Data &to_write) { auto newleaf = nodeStore->createNewLeafNode(Data(0)); newleaf->resize(GetParam().leafsize); newleaf->write(to_write.data(), GetParam().offset, GetParam().count); - return newleaf->key(); + return newleaf->blockId(); } void EXPECT_DATA_READS_AS(const Data &expected, const DataLeafNode &leaf, off_t offset, size_t count) { @@ -325,9 +325,9 @@ TEST_P(DataLeafNodeDataTest, WriteAndReadImmediately) { } TEST_P(DataLeafNodeDataTest, WriteAndReadAfterLoading) { - Key key = CreateLeafWriteToItAndReturnKey(this->foregroundData); + BlockId blockId = CreateLeafWriteToItAndReturnKey(this->foregroundData); - auto loaded_leaf = LoadLeafNode(key); + auto loaded_leaf = LoadLeafNode(blockId); EXPECT_DATA_READS_AS(this->foregroundData, *loaded_leaf, GetParam().offset, GetParam().count); EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(*loaded_leaf, GetParam().offset, GetParam().count); } diff --git a/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp b/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp index 30c007c0..19dc4981 100644 --- a/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp +++ b/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp @@ -17,7 +17,7 @@ using boost::none; using blockstore::BlockStore; using blockstore::testfake::FakeBlockStore; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using namespace blobstore; using namespace blobstore::onblocks; @@ -44,55 +44,55 @@ TEST_F(DataNodeStoreTest, CreateLeafNodeCreatesLeafNode) { TEST_F(DataNodeStoreTest, CreateInnerNodeCreatesInnerNode) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto node = nodeStore->createNewInnerNode(1, {leaf->key()}); + auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()}); EXPECT_IS_PTR_TYPE(DataInnerNode, node.get()); } TEST_F(DataNodeStoreTest, LeafNodeIsRecognizedAfterStoreAndLoad) { - Key key = nodeStore->createNewLeafNode(Data(0))->key(); + BlockId blockId = nodeStore->createNewLeafNode(Data(0))->blockId(); - auto loaded_node = nodeStore->load(key).value(); + auto loaded_node = nodeStore->load(blockId).value(); EXPECT_IS_PTR_TYPE(DataLeafNode, loaded_node.get()); } TEST_F(DataNodeStoreTest, InnerNodeWithDepth1IsRecognizedAfterStoreAndLoad) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - Key key = nodeStore->createNewInnerNode(1, {leaf->key()})->key(); + BlockId blockId = nodeStore->createNewInnerNode(1, {leaf->blockId()})->blockId(); - auto loaded_node = nodeStore->load(key).value(); + auto loaded_node = nodeStore->load(blockId).value(); EXPECT_IS_PTR_TYPE(DataInnerNode, loaded_node.get()); } TEST_F(DataNodeStoreTest, InnerNodeWithDepth2IsRecognizedAfterStoreAndLoad) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto inner = nodeStore->createNewInnerNode(1, {leaf->key()}); - Key key = nodeStore->createNewInnerNode(2, {inner->key()})->key(); + auto inner = nodeStore->createNewInnerNode(1, {leaf->blockId()}); + BlockId blockId = nodeStore->createNewInnerNode(2, {inner->blockId()})->blockId(); - auto loaded_node = nodeStore->load(key).value(); + auto loaded_node = nodeStore->load(blockId).value(); EXPECT_IS_PTR_TYPE(DataInnerNode, loaded_node.get()); } TEST_F(DataNodeStoreTest, DataNodeCrashesOnLoadIfDepthIsTooHigh) { auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); - Key key = block->key(); + BlockId blockId = block->blockId(); { DataNodeView view(std::move(block)); view.setDepth(DataNodeStore::MAX_DEPTH + 1); } EXPECT_ANY_THROW( - nodeStore->load(key) + nodeStore->load(blockId) ); } TEST_F(DataNodeStoreTest, CreatedInnerNodeIsInitialized) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto node = nodeStore->createNewInnerNode(1, {leaf->key()}); + auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()}); EXPECT_EQ(1u, node->numChildren()); - EXPECT_EQ(leaf->key(), node->getChild(0)->key()); + EXPECT_EQ(leaf->blockId(), node->getChild(0)->blockId()); } TEST_F(DataNodeStoreTest, CreatedLeafNodeIsInitialized) { @@ -101,7 +101,7 @@ TEST_F(DataNodeStoreTest, CreatedLeafNodeIsInitialized) { } TEST_F(DataNodeStoreTest, NodeIsNotLoadableAfterDeleting) { - auto nodekey = nodeStore->createNewLeafNode(Data(0))->key(); + auto nodekey = nodeStore->createNewLeafNode(Data(0))->blockId(); auto node = nodeStore->load(nodekey); EXPECT_NE(none, node); nodeStore->remove(std::move(*node)); @@ -125,26 +125,26 @@ TEST_F(DataNodeStoreTest, NumNodesIsCorrectAfterRemovingTheLastNode) { TEST_F(DataNodeStoreTest, NumNodesIsCorrectAfterAddingTwoNodes) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto node = nodeStore->createNewInnerNode(1, {leaf->key()}); + auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()}); EXPECT_EQ(2u, nodeStore->numNodes()); } TEST_F(DataNodeStoreTest, NumNodesIsCorrectAfterRemovingANode) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto node = nodeStore->createNewInnerNode(1, {leaf->key()}); + auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()}); nodeStore->remove(std::move(node)); EXPECT_EQ(1u, nodeStore->numNodes()); } TEST_F(DataNodeStoreTest, PhysicalBlockSize_Leaf) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto block = blockStore->load(leaf->key()).value(); + auto block = blockStore->load(leaf->blockId()).value(); EXPECT_EQ(BLOCKSIZE_BYTES, block->size()); } TEST_F(DataNodeStoreTest, PhysicalBlockSize_Inner) { auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto node = nodeStore->createNewInnerNode(1, {leaf->key()}); - auto block = blockStore->load(node->key()).value(); + auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()}); + auto block = blockStore->load(node->blockId()).value(); EXPECT_EQ(BLOCKSIZE_BYTES, block->size()); } \ No newline at end of file diff --git a/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp b/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp index 3f31b31e..b24f07a2 100644 --- a/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp +++ b/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp @@ -35,12 +35,12 @@ INSTANTIATE_TEST_CASE_P(DataNodeViewDepthTest, DataNodeViewDepthTest, Values(0, TEST_P(DataNodeViewDepthTest, DepthIsStored) { auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); - auto key = block->key(); + auto blockId = block->blockId(); { DataNodeView view(std::move(block)); view.setDepth(GetParam()); } - DataNodeView view(blockStore->load(key).value()); + DataNodeView view(blockStore->load(blockId).value()); EXPECT_EQ(GetParam(), view.Depth()); } @@ -50,38 +50,38 @@ INSTANTIATE_TEST_CASE_P(DataNodeViewSizeTest, DataNodeViewSizeTest, Values(0, 50 TEST_P(DataNodeViewSizeTest, SizeIsStored) { auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); - auto key = block->key(); + auto blockId = block->blockId(); { DataNodeView view(std::move(block)); view.setSize(GetParam()); } - DataNodeView view(blockStore->load(key).value()); + DataNodeView view(blockStore->load(blockId).value()); EXPECT_EQ(GetParam(), view.Size()); } TEST_F(DataNodeViewTest, DataIsStored) { Data randomData = DataFixture::generate(DATASIZE_BYTES); auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); - auto key = block->key(); + auto blockId = block->blockId(); { DataNodeView view(std::move(block)); view.write(randomData.data(), 0, randomData.size()); } - DataNodeView view(blockStore->load(key).value()); + DataNodeView view(blockStore->load(blockId).value()); EXPECT_EQ(0, std::memcmp(view.data(), randomData.data(), randomData.size())); } TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) { Data randomData = DataFixture::generate(DATASIZE_BYTES); auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); - auto key = block->key(); + auto blockId = block->blockId(); { DataNodeView view(std::move(block)); view.setDepth(3); view.setSize(1000000000u); view.write(randomData.data(), 0, DATASIZE_BYTES); } - DataNodeView view(blockStore->load(key).value()); + DataNodeView view(blockStore->load(blockId).value()); EXPECT_EQ(3, view.Depth()); EXPECT_EQ(1000000000u, view.Size()); EXPECT_EQ(0, std::memcmp(view.data(), randomData.data(), DATASIZE_BYTES)); diff --git a/test/blobstore/implementations/onblocks/datatreestore/DataTreeStoreTest.cpp b/test/blobstore/implementations/onblocks/datatreestore/DataTreeStoreTest.cpp index 865857db..f01fba87 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/DataTreeStoreTest.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/DataTreeStoreTest.cpp @@ -6,7 +6,7 @@ #include using blockstore::testfake::FakeBlockStore; -using blockstore::Key; +using blockstore::BlockId; using blobstore::onblocks::datanodestore::DataNodeStore; using boost::none; @@ -16,56 +16,56 @@ class DataTreeStoreTest: public DataTreeTest { }; TEST_F(DataTreeStoreTest, CorrectKeyReturned) { - Key key = treeStore.createNewTree()->key(); - auto tree = treeStore.load(key).value(); - EXPECT_EQ(key, tree->key()); + BlockId blockId = treeStore.createNewTree()->blockId(); + auto tree = treeStore.load(blockId).value(); + EXPECT_EQ(blockId, tree->blockId()); } TEST_F(DataTreeStoreTest, CreatedTreeIsLoadable) { - auto key = treeStore.createNewTree()->key(); - auto loaded = treeStore.load(key); + auto blockId = treeStore.createNewTree()->blockId(); + auto loaded = treeStore.load(blockId); EXPECT_NE(none, loaded); } TEST_F(DataTreeStoreTest, NewTreeIsLeafOnly) { auto tree = treeStore.createNewTree(); - EXPECT_IS_LEAF_NODE(tree->key()); + EXPECT_IS_LEAF_NODE(tree->blockId()); } TEST_F(DataTreeStoreTest, TreeIsNotLoadableAfterRemove_DeleteByTree) { - Key key = treeStore.createNewTree()->key(); - auto tree = treeStore.load(key); + BlockId blockId = treeStore.createNewTree()->blockId(); + auto tree = treeStore.load(blockId); EXPECT_NE(none, tree); treeStore.remove(std::move(*tree)); - EXPECT_EQ(none, treeStore.load(key)); + EXPECT_EQ(none, treeStore.load(blockId)); } TEST_F(DataTreeStoreTest, TreeIsNotLoadableAfterRemove_DeleteByKey) { - Key key = treeStore.createNewTree()->key(); - treeStore.remove(key); - EXPECT_EQ(none, treeStore.load(key)); + BlockId blockId = treeStore.createNewTree()->blockId(); + treeStore.remove(blockId); + EXPECT_EQ(none, treeStore.load(blockId)); } TEST_F(DataTreeStoreTest, RemovingTreeRemovesAllNodesOfTheTree_DeleteByTree) { - auto tree1_key = CreateThreeLevelMinData()->key(); - auto tree2_key = treeStore.createNewTree()->key(); + auto tree1_blockId = CreateThreeLevelMinData()->blockId(); + auto tree2_blockId = treeStore.createNewTree()->blockId(); - auto tree1 = treeStore.load(tree1_key).value(); + auto tree1 = treeStore.load(tree1_blockId).value(); treeStore.remove(std::move(tree1)); //Check that the only remaining node is tree2 EXPECT_EQ(1u, nodeStore->numNodes()); - EXPECT_NE(none, treeStore.load(tree2_key)); + EXPECT_NE(none, treeStore.load(tree2_blockId)); } TEST_F(DataTreeStoreTest, RemovingTreeRemovesAllNodesOfTheTree_DeleteByKey) { - auto tree1_key = CreateThreeLevelMinData()->key(); - auto tree2_key = treeStore.createNewTree()->key(); + auto tree1_blockId = CreateThreeLevelMinData()->blockId(); + auto tree2_blockId = treeStore.createNewTree()->blockId(); - treeStore.remove(tree1_key); + treeStore.remove(tree1_blockId); //Check that the only remaining node is tree2 EXPECT_EQ(1u, nodeStore->numNodes()); - EXPECT_NE(none, treeStore.load(tree2_key)); + EXPECT_NE(none, treeStore.load(tree2_blockId)); } diff --git a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_NumStoredBytes.cpp b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_NumStoredBytes.cpp index 17c12a6d..5b8a6b87 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_NumStoredBytes.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_NumStoredBytes.cpp @@ -10,7 +10,7 @@ using blobstore::onblocks::datanodestore::DataInnerNode; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataNodeLayout; using blobstore::onblocks::datatreestore::DataTree; -using blockstore::Key; +using blockstore::BlockId; class DataTreeTest_NumStoredBytes: public DataTreeTest { public: @@ -27,49 +27,49 @@ INSTANTIATE_TEST_CASE_P(HalfFullLastLeaf, DataTreeTest_NumStoredBytes_P, Values( INSTANTIATE_TEST_CASE_P(FullLastLeaf, DataTreeTest_NumStoredBytes_P, Values((uint32_t)DataNodeLayout(DataTreeTest_NumStoredBytes::BLOCKSIZE_BYTES).maxBytesPerLeaf())); TEST_P(DataTreeTest_NumStoredBytes_P, SingleLeaf) { - Key key = CreateLeafWithSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateLeafWithSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, TwoLeafTree) { - Key key = CreateTwoLeafWithSecondLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateTwoLeafWithSecondLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, FullTwolevelTree) { - Key key = CreateFullTwoLevelWithLastLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateFullTwoLevelWithLastLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*(nodeStore->layout().maxChildrenPerInnerNode()-1) + GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, ThreeLevelTreeWithOneChild) { - Key key = CreateThreeLevelWithOneChildAndLastLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateThreeLevelWithOneChildAndLastLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, ThreeLevelTreeWithTwoChildren) { - Key key = CreateThreeLevelWithTwoChildrenAndLastLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateThreeLevelWithTwoChildrenAndLastLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, ThreeLevelTreeWithThreeChildren) { - Key key = CreateThreeLevelWithThreeChildrenAndLastLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateThreeLevelWithThreeChildrenAndLastLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(2*nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, FullThreeLevelTree) { - Key key = CreateFullThreeLevelWithLastLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateFullThreeLevelWithLastLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode()*(nodeStore->layout().maxChildrenPerInnerNode()-1) + nodeStore->layout().maxBytesPerLeaf()*(nodeStore->layout().maxChildrenPerInnerNode()-1) + GetParam(), tree->numStoredBytes()); } TEST_P(DataTreeTest_NumStoredBytes_P, FourLevelMinDataTree) { - Key key = CreateFourLevelMinDataWithLastLeafSize(GetParam())->key(); - auto tree = treeStore.load(key).value(); + BlockId blockId = CreateFourLevelMinDataWithLastLeafSize(GetParam())->blockId(); + auto tree = treeStore.load(blockId).value(); EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode()*nodeStore->layout().maxChildrenPerInnerNode() + GetParam(), tree->numStoredBytes()); } diff --git a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_Performance.cpp b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_Performance.cpp index 718f18e5..b229f13b 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_Performance.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_Performance.cpp @@ -8,7 +8,7 @@ using blobstore::onblocks::datanodestore::DataInnerNode; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datatreestore::DataTree; using blobstore::onblocks::datatreestore::LeafHandle; -using blockstore::Key; +using blockstore::BlockId; using blockstore::testfake::FakeBlockStore; using cpputils::Data; using cpputils::make_unique_ref; @@ -24,8 +24,8 @@ public: }; TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Twolevel_DeleteByTree) { - auto key = CreateFullTwoLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullTwoLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); treeStore.remove(std::move(tree)); @@ -38,10 +38,10 @@ TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Twolevel_DeleteByTree) } TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Twolevel_DeleteByKey) { - auto key = CreateFullTwoLevel()->key(); + auto blockId = CreateFullTwoLevel()->blockId(); blockStore->resetCounters(); - treeStore.remove(key); + treeStore.remove(blockId); EXPECT_EQ(1u, blockStore->loadedBlocks().size()); EXPECT_EQ(0u, blockStore->createdBlocks()); @@ -51,8 +51,8 @@ TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Twolevel_DeleteByKey) } TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Threelevel_DeleteByTree) { - auto key = CreateFullThreeLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullThreeLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); treeStore.remove(std::move(tree)); @@ -65,10 +65,10 @@ TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Threelevel_DeleteByTre } TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Threelevel_DeleteByKey) { - auto key = CreateFullThreeLevel()->key(); + auto blockId = CreateFullThreeLevel()->blockId(); blockStore->resetCounters(); - treeStore.remove(key); + treeStore.remove(blockId); EXPECT_EQ(1u + maxChildrenPerInnerNode, blockStore->loadedBlocks().size()); EXPECT_EQ(0u, blockStore->createdBlocks()); @@ -78,8 +78,8 @@ TEST_F(DataTreeTest_Performance, DeletingDoesntLoadLeaves_Threelevel_DeleteByKey } TEST_F(DataTreeTest_Performance, TraverseLeaves_Twolevel_All) { - auto key = CreateFullTwoLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullTwoLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 0, maxChildrenPerInnerNode); @@ -92,8 +92,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_Twolevel_All) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_Twolevel_Some) { - auto key = CreateFullTwoLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullTwoLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 3, 5); @@ -106,8 +106,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_Twolevel_Some) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_All) { - auto key = CreateFullThreeLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullThreeLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 0, maxChildrenPerInnerNode * maxChildrenPerInnerNode); @@ -120,8 +120,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_All) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_InOneInner) { - auto key = CreateFullThreeLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullThreeLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 3, 5); @@ -134,8 +134,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_InOneInner) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_InTwoInner) { - auto key = CreateFullThreeLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullThreeLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 3, 3 + maxChildrenPerInnerNode); @@ -148,8 +148,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_InTwoInner) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_WholeInner) { - auto key = CreateFullThreeLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullThreeLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), maxChildrenPerInnerNode, 2*maxChildrenPerInnerNode); @@ -162,8 +162,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_Threelevel_WholeInner) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingInside) { - auto key = CreateInner({CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 1, 4); @@ -176,8 +176,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingInside) { } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingOutside_TwoLevel) { - auto key = CreateInner({CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 4, 5); @@ -190,8 +190,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingOutside_TwoL } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingOutside_ThreeLevel) { - auto key = CreateInner({CreateFullTwoLevel(), CreateFullTwoLevel()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateFullTwoLevel(), CreateFullTwoLevel()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 2*maxChildrenPerInnerNode+1, 2*maxChildrenPerInnerNode+2); @@ -204,8 +204,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingOutside_Thre } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingAtBeginOfChild) { - auto key = CreateInner({CreateFullTwoLevel(), CreateFullTwoLevel()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateFullTwoLevel(), CreateFullTwoLevel()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), maxChildrenPerInnerNode, 3*maxChildrenPerInnerNode); @@ -218,8 +218,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTree_StartingAtBeginOfChi } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInOldDepth) { - auto key = CreateInner({CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 4, maxChildrenPerInnerNode+2); @@ -232,8 +232,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInOldDe } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInOldDepth_ResizeLastLeaf) { - auto key = CreateInner({CreateLeaf(), CreateLeafWithSize(5)})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeafWithSize(5)})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), 4, maxChildrenPerInnerNode+2); @@ -246,8 +246,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInOldDe } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInNewDepth) { - auto key = CreateInner({CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), maxChildrenPerInnerNode, maxChildrenPerInnerNode+2); @@ -260,8 +260,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInNewDe } TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInNewDepth_ResizeLastLeaf) { - auto key = CreateInner({CreateLeaf(), CreateLeafWithSize(5)})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeafWithSize(5)})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); Traverse(tree.get(), maxChildrenPerInnerNode, maxChildrenPerInnerNode+2); @@ -274,8 +274,8 @@ TEST_F(DataTreeTest_Performance, TraverseLeaves_GrowingTreeDepth_StartingInNewDe } TEST_F(DataTreeTest_Performance, ResizeNumBytes_ZeroToZero) { - auto key = CreateLeafWithSize(0)->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateLeafWithSize(0)->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(0); @@ -288,8 +288,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_ZeroToZero) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowOneLeaf) { - auto key = CreateLeafWithSize(0)->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateLeafWithSize(0)->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(5); @@ -302,8 +302,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowOneLeaf) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_ShrinkOneLeaf) { - auto key = CreateLeafWithSize(5)->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateLeafWithSize(5)->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(2); @@ -316,8 +316,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_ShrinkOneLeaf) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_ShrinkOneLeafToZero) { - auto key = CreateLeafWithSize(5)->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateLeafWithSize(5)->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(0); @@ -330,8 +330,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_ShrinkOneLeafToZero) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowOneLeafInLargerTree) { - auto key = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf(), CreateLeafWithSize(5)})})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf(), CreateLeafWithSize(5)})})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf*(maxChildrenPerInnerNode+1)+6); // Grow by one byte @@ -344,8 +344,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowOneLeafInLargerTree) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowByOneLeaf) { - auto key = CreateInner({CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf*2+1); // Grow by one byte @@ -358,8 +358,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowByOneLeaf) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowByOneLeaf_GrowLastLeaf) { - auto key = CreateInner({CreateLeaf(), CreateLeafWithSize(5)})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeafWithSize(5)})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf*2+1); // Grow by one byte @@ -372,8 +372,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_GrowByOneLeaf_GrowLastLeaf) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_ShrinkByOneLeaf) { - auto key = CreateInner({CreateLeaf(), CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(2*maxBytesPerLeaf-1); @@ -386,8 +386,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_ShrinkByOneLeaf) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_IncreaseTreeDepth_0to1) { - auto key = CreateLeaf()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateLeaf()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf+1); @@ -400,8 +400,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_IncreaseTreeDepth_0to1) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_IncreaseTreeDepth_1to2) { - auto key = CreateFullTwoLevel()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateFullTwoLevel()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf*maxChildrenPerInnerNode+1); @@ -414,8 +414,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_IncreaseTreeDepth_1to2) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_IncreaseTreeDepth_0to2) { - auto key = CreateLeaf()->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateLeaf()->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf*maxChildrenPerInnerNode+1); @@ -428,8 +428,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_IncreaseTreeDepth_0to2) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_DecreaseTreeDepth_1to0) { - auto key = CreateInner({CreateLeaf(), CreateLeaf()})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateLeaf(), CreateLeaf()})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf); @@ -442,8 +442,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_DecreaseTreeDepth_1to0) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_DecreaseTreeDepth_2to1) { - auto key = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf()})})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf()})})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf*maxChildrenPerInnerNode); @@ -456,8 +456,8 @@ TEST_F(DataTreeTest_Performance, ResizeNumBytes_DecreaseTreeDepth_2to1) { } TEST_F(DataTreeTest_Performance, ResizeNumBytes_DecreaseTreeDepth_2to0) { - auto key = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf()})})->key(); - auto tree = treeStore.load(key).value(); + auto blockId = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf()})})->blockId(); + auto tree = treeStore.load(blockId).value(); blockStore->resetCounters(); tree->resizeNumBytes(maxBytesPerLeaf); diff --git a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeByTraversing.cpp b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeByTraversing.cpp index 98e8d04b..604f2162 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeByTraversing.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeByTraversing.cpp @@ -21,7 +21,7 @@ using blobstore::onblocks::datanodestore::DataNodeLayout; using blobstore::onblocks::datatreestore::DataTree; using blobstore::onblocks::datatreestore::LeafHandle; using blobstore::onblocks::utils::ceilDivision; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using boost::none; @@ -32,9 +32,9 @@ public: static constexpr DataNodeLayout LAYOUT = DataNodeLayout(BLOCKSIZE_BYTES); unique_ref CreateTree(unique_ref root) { - Key key = root->key(); + BlockId blockId = root->blockId(); cpputils::destruct(std::move(root)); - return treeStore.load(key).value(); + return treeStore.load(blockId).value(); } unique_ref CreateLeafTreeWithSize(uint32_t size) { @@ -65,23 +65,23 @@ public: return CreateTree(CreateFourLevelMinDataWithLastLeafSize(size)); } - void EXPECT_IS_LEFTMAXDATA_TREE(const Key &key) { - auto root = nodeStore->load(key).value(); + void EXPECT_IS_LEFTMAXDATA_TREE(const BlockId &blockId) { + auto root = nodeStore->load(blockId).value(); DataInnerNode *inner = dynamic_cast(root.get()); if (inner != nullptr) { for (uint32_t i = 0; i < inner->numChildren()-1; ++i) { - EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->key()); + EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->blockId()); } - EXPECT_IS_LEFTMAXDATA_TREE(inner->LastChild()->key()); + EXPECT_IS_LEFTMAXDATA_TREE(inner->LastChild()->blockId()); } } - void EXPECT_IS_MAXDATA_TREE(const Key &key) { - auto root = nodeStore->load(key).value(); + void EXPECT_IS_MAXDATA_TREE(const BlockId &blockId) { + auto root = nodeStore->load(blockId).value(); DataInnerNode *inner = dynamic_cast(root.get()); if (inner != nullptr) { for (uint32_t i = 0; i < inner->numChildren(); ++i) { - EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->key()); + EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->blockId()); } } else { DataLeafNode *leaf = dynamic_cast(root.get()); @@ -104,8 +104,8 @@ public: ZEROES.FillWithZeroes(); } - void GrowTree(const Key &key) { - auto tree = treeStore.load(key); + void GrowTree(const BlockId &blockId) { + auto tree = treeStore.load(blockId); GrowTree(tree.get().get()); } @@ -115,14 +115,14 @@ public: tree->flush(); } - unique_ref LastLeaf(const Key &key) { - auto root = nodeStore->load(key).value(); + unique_ref LastLeaf(const BlockId &blockId) { + auto root = nodeStore->load(blockId).value(); auto leaf = dynamic_pointer_move(root); if (leaf != none) { return std::move(*leaf); } auto inner = dynamic_pointer_move(root).value(); - return LastLeaf(inner->LastChild()->key()); + return LastLeaf(inner->LastChild()->blockId()); } uint32_t oldLastLeafSize; @@ -176,7 +176,7 @@ INSTANTIATE_TEST_CASE_P(DataTreeTest_ResizeByTraversing_P, DataTreeTest_ResizeBy TEST_P(DataTreeTest_ResizeByTraversing_P, StructureIsValid) { GrowTree(tree.get()); - EXPECT_IS_LEFTMAXDATA_TREE(tree->key()); + EXPECT_IS_LEFTMAXDATA_TREE(tree->blockId()); } TEST_P(DataTreeTest_ResizeByTraversing_P, NumLeavesIsCorrect_FromCache) { @@ -197,26 +197,26 @@ TEST_P(DataTreeTest_ResizeByTraversing_P, NumLeavesIsCorrect) { TEST_P(DataTreeTest_ResizeByTraversing_P, DepthFlagsAreCorrect) { GrowTree(tree.get()); uint32_t depth = ceil(log(newNumberOfLeaves)/log(DataTreeTest_ResizeByTraversing::LAYOUT.maxChildrenPerInnerNode())); - CHECK_DEPTH(depth, tree->key()); + CHECK_DEPTH(depth, tree->blockId()); } TEST_P(DataTreeTest_ResizeByTraversing_P, KeyDoesntChange) { - Key key = tree->key(); + BlockId blockId = tree->blockId(); tree->flush(); GrowTree(tree.get()); - EXPECT_EQ(key, tree->key()); + EXPECT_EQ(blockId, tree->blockId()); } TEST_P(DataTreeTest_ResizeByTraversing_P, DataStaysIntact) { uint32_t oldNumberOfLeaves = std::max(UINT64_C(1), ceilDivision(tree->numStoredBytes(), (uint64_t)nodeStore->layout().maxBytesPerLeaf())); TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged); - Key key = tree->key(); + BlockId blockId = tree->blockId(); cpputils::destruct(std::move(tree)); - data.FillInto(nodeStore->load(key).get().get()); + data.FillInto(nodeStore->load(blockId).get().get()); - GrowTree(key); + GrowTree(blockId); - data.EXPECT_DATA_CORRECT(nodeStore->load(key).get().get(), oldNumberOfLeaves, oldLastLeafSize); + data.EXPECT_DATA_CORRECT(nodeStore->load(blockId).get().get(), oldNumberOfLeaves, oldLastLeafSize); } TEST_P(DataTreeTest_ResizeByTraversing_P, AllLeavesAreTraversed) { diff --git a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeNumBytes.cpp b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeNumBytes.cpp index d3f86c0d..9a06e121 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeNumBytes.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_ResizeNumBytes.cpp @@ -20,7 +20,7 @@ using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataNodeLayout; using blobstore::onblocks::datatreestore::DataTree; using blobstore::onblocks::utils::ceilDivision; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using boost::none; @@ -31,9 +31,9 @@ public: static constexpr DataNodeLayout LAYOUT = DataNodeLayout(BLOCKSIZE_BYTES); unique_ref CreateTree(unique_ref root) { - Key key = root->key(); + BlockId blockId = root->blockId(); cpputils::destruct(std::move(root)); - return treeStore.load(key).value(); + return treeStore.load(blockId).value(); } unique_ref CreateLeafTreeWithSize(uint32_t size) { @@ -64,23 +64,23 @@ public: return CreateTree(CreateFourLevelMinDataWithLastLeafSize(size)); } - void EXPECT_IS_LEFTMAXDATA_TREE(const Key &key) { - auto root = nodeStore->load(key).value(); + void EXPECT_IS_LEFTMAXDATA_TREE(const BlockId &blockId) { + auto root = nodeStore->load(blockId).value(); DataInnerNode *inner = dynamic_cast(root.get()); if (inner != nullptr) { for (uint32_t i = 0; i < inner->numChildren()-1; ++i) { - EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->key()); + EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->blockId()); } - EXPECT_IS_LEFTMAXDATA_TREE(inner->LastChild()->key()); + EXPECT_IS_LEFTMAXDATA_TREE(inner->LastChild()->blockId()); } } - void EXPECT_IS_MAXDATA_TREE(const Key &key) { - auto root = nodeStore->load(key).value(); + void EXPECT_IS_MAXDATA_TREE(const BlockId &blockId) { + auto root = nodeStore->load(blockId).value(); DataInnerNode *inner = dynamic_cast(root.get()); if (inner != nullptr) { for (uint32_t i = 0; i < inner->numChildren(); ++i) { - EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->key()); + EXPECT_IS_MAXDATA_TREE(inner->getChild(i)->blockId()); } } else { DataLeafNode *leaf = dynamic_cast(root.get()); @@ -103,18 +103,18 @@ public: ZEROES.FillWithZeroes(); } - void ResizeTree(const Key &key, uint64_t size) { - treeStore.load(key).get()->resizeNumBytes(size); + void ResizeTree(const BlockId &blockId, uint64_t size) { + treeStore.load(blockId).get()->resizeNumBytes(size); } - unique_ref LastLeaf(const Key &key) { - auto root = nodeStore->load(key).value(); + unique_ref LastLeaf(const BlockId &blockId) { + auto root = nodeStore->load(blockId).value(); auto leaf = dynamic_pointer_move(root); if (leaf != none) { return std::move(*leaf); } auto inner = dynamic_pointer_move(root).value(); - return LastLeaf(inner->LastChild()->key()); + return LastLeaf(inner->LastChild()->blockId()); } uint32_t oldLastLeafSize; @@ -165,7 +165,7 @@ INSTANTIATE_TEST_CASE_P(DataTreeTest_ResizeNumBytes_P, DataTreeTest_ResizeNumByt TEST_P(DataTreeTest_ResizeNumBytes_P, StructureIsValid) { tree->resizeNumBytes(newSize); tree->flush(); - EXPECT_IS_LEFTMAXDATA_TREE(tree->key()); + EXPECT_IS_LEFTMAXDATA_TREE(tree->blockId()); } TEST_P(DataTreeTest_ResizeNumBytes_P, NumBytesIsCorrect) { @@ -197,29 +197,29 @@ TEST_P(DataTreeTest_ResizeNumBytes_P, DepthFlagsAreCorrect) { tree->resizeNumBytes(newSize); tree->flush(); uint32_t depth = ceil(log(newNumberOfLeaves)/log(DataTreeTest_ResizeNumBytes::LAYOUT.maxChildrenPerInnerNode()) - 0.00000000001); // The subtraction takes care of double inaccuracies if newNumberOfLeaves == maxChildrenPerInnerNode - CHECK_DEPTH(depth, tree->key()); + CHECK_DEPTH(depth, tree->blockId()); } TEST_P(DataTreeTest_ResizeNumBytes_P, KeyDoesntChange) { - Key key = tree->key(); + BlockId blockId = tree->blockId(); tree->flush(); tree->resizeNumBytes(newSize); - EXPECT_EQ(key, tree->key()); + EXPECT_EQ(blockId, tree->blockId()); } TEST_P(DataTreeTest_ResizeNumBytes_P, DataStaysIntact) { uint32_t oldNumberOfLeaves = std::max(UINT64_C(1), ceilDivision(tree->numStoredBytes(), (uint64_t)nodeStore->layout().maxBytesPerLeaf())); TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged); - Key key = tree->key(); + BlockId blockId = tree->blockId(); cpputils::destruct(std::move(tree)); - data.FillInto(nodeStore->load(key).get().get()); + data.FillInto(nodeStore->load(blockId).get().get()); - ResizeTree(key, newSize); + ResizeTree(blockId, newSize); if (oldNumberOfLeaves < newNumberOfLeaves || (oldNumberOfLeaves == newNumberOfLeaves && oldLastLeafSize < newLastLeafSize)) { - data.EXPECT_DATA_CORRECT(nodeStore->load(key).get().get(), oldNumberOfLeaves, oldLastLeafSize); + data.EXPECT_DATA_CORRECT(nodeStore->load(blockId).get().get(), oldNumberOfLeaves, oldLastLeafSize); } else { - data.EXPECT_DATA_CORRECT(nodeStore->load(key).get().get(), newNumberOfLeaves, newLastLeafSize); + data.EXPECT_DATA_CORRECT(nodeStore->load(blockId).get().get(), newNumberOfLeaves, newLastLeafSize); } } @@ -241,18 +241,18 @@ TEST_P(DataTreeTest_ResizeNumBytes_P, UnneededBlocksGetDeletedWhenShrinking) { TEST_F(DataTreeTest_ResizeNumBytes, ResizeToZero_NumBytesIsCorrect) { auto tree = CreateThreeLevelTreeWithThreeChildrenAndLastLeafSize(10u); tree->resizeNumBytes(0); - Key key = tree->key(); + BlockId blockId = tree->blockId(); cpputils::destruct(std::move(tree)); - auto leaf = LoadLeafNode(key); + auto leaf = LoadLeafNode(blockId); EXPECT_EQ(0u, leaf->numBytes()); } -TEST_F(DataTreeTest_ResizeNumBytes, ResizeToZero_KeyDoesntChange) { +TEST_F(DataTreeTest_ResizeNumBytes, ResizeToZero_blockIdDoesntChange) { auto tree = CreateThreeLevelTreeWithThreeChildrenAndLastLeafSize(10u); - Key key = tree->key(); + BlockId blockId = tree->blockId(); tree->resizeNumBytes(0); tree->flush(); - EXPECT_EQ(key, tree->key()); + EXPECT_EQ(blockId, tree->blockId()); } TEST_F(DataTreeTest_ResizeNumBytes, ResizeToZero_UnneededBlocksGetDeletedWhenShrinking) { diff --git a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_TraverseLeaves.cpp b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_TraverseLeaves.cpp index d725090f..8425a5e3 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_TraverseLeaves.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/DataTreeTest_TraverseLeaves.cpp @@ -10,7 +10,7 @@ using blobstore::onblocks::datanodestore::DataInnerNode; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datatreestore::DataTree; using blobstore::onblocks::datatreestore::LeafHandle; -using blockstore::Key; +using blockstore::BlockId; using cpputils::unique_ref; using cpputils::Data; @@ -23,8 +23,8 @@ public: MOCK_METHOD1(calledCreateLeaf, shared_ptr(uint32_t)); }; -MATCHER_P(KeyEq, expected, "node key equals") { - return arg->key() == expected; +MATCHER_P(KeyEq, expected, "node blockId equals") { + return arg->blockId() == expected; } class DataTreeTest_TraverseLeaves: public DataTreeTest { @@ -56,13 +56,13 @@ public: })); } - void EXPECT_TRAVERSE_LEAF(const Key &key, bool isRightBorderLeaf, uint32_t leafIndex) { - EXPECT_CALL(traversor, calledExistingLeaf(KeyEq(key), isRightBorderLeaf, leafIndex)).Times(1); + void EXPECT_TRAVERSE_LEAF(const BlockId &blockId, bool isRightBorderLeaf, uint32_t leafIndex) { + EXPECT_CALL(traversor, calledExistingLeaf(KeyEq(blockId), isRightBorderLeaf, leafIndex)).Times(1); } void EXPECT_TRAVERSE_ALL_CHILDREN_OF(const DataInnerNode &node, bool isRightBorderNode, uint32_t firstLeafIndex) { for (unsigned int i = 0; i < node.numChildren(); ++i) { - EXPECT_TRAVERSE_LEAF(node.getChild(i)->key(), isRightBorderNode && i == node.numChildren()-1, firstLeafIndex+i); + EXPECT_TRAVERSE_LEAF(node.getChild(i)->blockId(), isRightBorderNode && i == node.numChildren()-1, firstLeafIndex+i); } } @@ -73,7 +73,7 @@ public: void TraverseLeaves(DataNode *root, uint32_t beginIndex, uint32_t endIndex) { root->flush(); - auto tree = treeStore.load(root->key()).value(); + auto tree = treeStore.load(root->blockId()).value(); tree->traverseLeaves(beginIndex, endIndex, [this] (uint32_t nodeIndex, bool isRightBorderNode,LeafHandle leaf) { traversor.calledExistingLeaf(leaf.node(), isRightBorderNode, nodeIndex); }, [this] (uint32_t nodeIndex) -> Data { @@ -86,7 +86,7 @@ public: TEST_F(DataTreeTest_TraverseLeaves, TraverseSingleLeafTree) { auto root = CreateLeaf(); - EXPECT_TRAVERSE_LEAF(root->key(), true, 0); + EXPECT_TRAVERSE_LEAF(root->blockId(), true, 0); TraverseLeaves(root.get(), 0, 1); } @@ -107,21 +107,21 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseNothingInSingleLeafTree2) { TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstLeafOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - EXPECT_TRAVERSE_LEAF(root->getChild(0)->key(), false, 0); + EXPECT_TRAVERSE_LEAF(root->getChild(0)->blockId(), false, 0); TraverseLeaves(root.get(), 0, 1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddleLeafOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - EXPECT_TRAVERSE_LEAF(root->getChild(5)->key(), false, 5); + EXPECT_TRAVERSE_LEAF(root->getChild(5)->blockId(), false, 5); TraverseLeaves(root.get(), 5, 6); } TEST_F(DataTreeTest_TraverseLeaves, TraverseLastLeafOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - EXPECT_TRAVERSE_LEAF(root->getChild(nodeStore->layout().maxChildrenPerInnerNode()-1)->key(), true, nodeStore->layout().maxChildrenPerInnerNode()-1); + EXPECT_TRAVERSE_LEAF(root->getChild(nodeStore->layout().maxChildrenPerInnerNode()-1)->blockId(), true, nodeStore->layout().maxChildrenPerInnerNode()-1); TraverseLeaves(root.get(), nodeStore->layout().maxChildrenPerInnerNode()-1, nodeStore->layout().maxChildrenPerInnerNode()); } @@ -142,21 +142,21 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseNothingInFullTwolevelTree2) { TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstLeafOfThreeLevelMinDataTree) { auto root = CreateThreeLevelMinData(); - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->key())->getChild(0)->key(), false, 0); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->blockId())->getChild(0)->blockId(), false, 0); TraverseLeaves(root.get(), 0, 1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddleLeafOfThreeLevelMinDataTree) { auto root = CreateThreeLevelMinData(); - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->key())->getChild(5)->key(), false, 5); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->blockId())->getChild(5)->blockId(), false, 5); TraverseLeaves(root.get(), 5, 6); } TEST_F(DataTreeTest_TraverseLeaves, TraverseLastLeafOfThreeLevelMinDataTree) { auto root = CreateThreeLevelMinData(); - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(), true, nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->blockId())->getChild(0)->blockId(), true, nodeStore->layout().maxChildrenPerInnerNode()); TraverseLeaves(root.get(), nodeStore->layout().maxChildrenPerInnerNode(), nodeStore->layout().maxChildrenPerInnerNode()+1); } @@ -170,15 +170,15 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfFullTwolevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(0)->key()), false, 0); - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(), true, nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(0)->blockId()), false, 0); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->blockId())->getChild(0)->blockId(), true, nodeStore->layout().maxChildrenPerInnerNode()); TraverseLeaves(root.get(), 0, nodeStore->layout().maxChildrenPerInnerNode()+1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstChildOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(0)->key()), false, 0); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(0)->blockId()), false, 0); TraverseLeaves(root.get(), 0, nodeStore->layout().maxChildrenPerInnerNode()); } @@ -186,7 +186,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstChildOfThreelevelMinDataTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); for (unsigned int i = 0; i < 5; ++i) { - EXPECT_TRAVERSE_LEAF(root->getChild(i)->key(), false, i); + EXPECT_TRAVERSE_LEAF(root->getChild(i)->blockId(), false, i); } TraverseLeaves(root.get(), 0, 5); @@ -195,7 +195,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfFullTwolevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseInnerPartOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); for (unsigned int i = 5; i < 10; ++i) { - EXPECT_TRAVERSE_LEAF(root->getChild(i)->key(), false, i); + EXPECT_TRAVERSE_LEAF(root->getChild(i)->blockId(), false, i); } TraverseLeaves(root.get(), 5, 10); @@ -204,7 +204,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseInnerPartOfFullTwolevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseLastPartOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); for (unsigned int i = 5; i < nodeStore->layout().maxChildrenPerInnerNode(); ++i) { - EXPECT_TRAVERSE_LEAF(root->getChild(i)->key(), i==nodeStore->layout().maxChildrenPerInnerNode()-1, i); + EXPECT_TRAVERSE_LEAF(root->getChild(i)->blockId(), i==nodeStore->layout().maxChildrenPerInnerNode()-1, i); } TraverseLeaves(root.get(), 5, nodeStore->layout().maxChildrenPerInnerNode()); @@ -212,9 +212,9 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseLastPartOfFullTwolevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto node = LoadInnerNode(root->getChild(0)->key()); + auto node = LoadInnerNode(root->getChild(0)->blockId()); for (unsigned int i = 0; i < 5; ++i) { - EXPECT_TRAVERSE_LEAF(node->getChild(i)->key(), false, i); + EXPECT_TRAVERSE_LEAF(node->getChild(i)->blockId(), false, i); } TraverseLeaves(root.get(), 0, 5); @@ -222,9 +222,9 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfThreelevelMinDataTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseInnerPartOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto node = LoadInnerNode(root->getChild(0)->key()); + auto node = LoadInnerNode(root->getChild(0)->blockId()); for (unsigned int i = 5; i < 10; ++i) { - EXPECT_TRAVERSE_LEAF(node->getChild(i)->key(), false, i); + EXPECT_TRAVERSE_LEAF(node->getChild(i)->blockId(), false, i); } TraverseLeaves(root.get(), 5, 10); @@ -232,18 +232,18 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseInnerPartOfThreelevelMinDataTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseLastPartOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto node = LoadInnerNode(root->getChild(0)->key()); + auto node = LoadInnerNode(root->getChild(0)->blockId()); for (unsigned int i = 5; i < nodeStore->layout().maxChildrenPerInnerNode(); ++i) { - EXPECT_TRAVERSE_LEAF(node->getChild(i)->key(), false, i); + EXPECT_TRAVERSE_LEAF(node->getChild(i)->blockId(), false, i); } - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(), true, nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->blockId())->getChild(0)->blockId(), true, nodeStore->layout().maxChildrenPerInnerNode()); TraverseLeaves(root.get(), 5, nodeStore->layout().maxChildrenPerInnerNode()+1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstLeafOfThreelevelTree) { auto root = CreateThreeLevel(); - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->key())->getChild(0)->key(), false, 0); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->blockId())->getChild(0)->blockId(), false, 0); TraverseLeaves(root.get(), 0, 1); } @@ -251,7 +251,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstLeafOfThreelevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseLastLeafOfThreelevelTree) { auto root = CreateThreeLevel(); uint32_t numLeaves = nodeStore->layout().maxChildrenPerInnerNode() * 5 + 3; - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->LastChild()->key())->LastChild()->key(), true, numLeaves-1); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->LastChild()->blockId())->LastChild()->blockId(), true, numLeaves-1); TraverseLeaves(root.get(), numLeaves-1, numLeaves); } @@ -259,7 +259,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseLastLeafOfThreelevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddleLeafOfThreelevelTree) { auto root = CreateThreeLevel(); uint32_t wantedLeafIndex = nodeStore->layout().maxChildrenPerInnerNode() * 2 + 5; - EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(2)->key())->getChild(5)->key(), false, wantedLeafIndex); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(2)->blockId())->getChild(5)->blockId(), false, wantedLeafIndex); TraverseLeaves(root.get(), wantedLeafIndex, wantedLeafIndex+1); } @@ -268,12 +268,12 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfThreelevelTree) { auto root = CreateThreeLevel(); //Traverse all leaves in the first two children of the root for(unsigned int i = 0; i < 2; ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->key()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->blockId()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse some of the leaves in the third child of the root - auto child = LoadInnerNode(root->getChild(2)->key()); + auto child = LoadInnerNode(root->getChild(2)->blockId()); for(unsigned int i = 0; i < 5; ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), false, 2 * nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), false, 2 * nodeStore->layout().maxChildrenPerInnerNode() + i); } TraverseLeaves(root.get(), 0, 2 * nodeStore->layout().maxChildrenPerInnerNode() + 5); @@ -282,18 +282,18 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfThreelevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddlePartOfThreelevelTree_OnlyFullChildren) { auto root = CreateThreeLevel(); //Traverse some of the leaves in the second child of the root - auto child = LoadInnerNode(root->getChild(1)->key()); + auto child = LoadInnerNode(root->getChild(1)->blockId()); for(unsigned int i = 5; i < nodeStore->layout().maxChildrenPerInnerNode(); ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), false, nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), false, nodeStore->layout().maxChildrenPerInnerNode() + i); } //Traverse all leaves in the third and fourth child of the root for(unsigned int i = 2; i < 4; ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->key()),false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->blockId()),false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse some of the leaves in the fifth child of the root - child = LoadInnerNode(root->getChild(4)->key()); + child = LoadInnerNode(root->getChild(4)->blockId()); for(unsigned int i = 0; i < 5; ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), false, 4 * nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), false, 4 * nodeStore->layout().maxChildrenPerInnerNode() + i); } TraverseLeaves(root.get(), nodeStore->layout().maxChildrenPerInnerNode() + 5, 4 * nodeStore->layout().maxChildrenPerInnerNode() + 5); @@ -302,18 +302,18 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddlePartOfThreelevelTree_OnlyFullC TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddlePartOfThreelevelTree_AlsoLastNonfullChild) { auto root = CreateThreeLevel(); //Traverse some of the leaves in the second child of the root - auto child = LoadInnerNode(root->getChild(1)->key()); + auto child = LoadInnerNode(root->getChild(1)->blockId()); for(unsigned int i = 5; i < nodeStore->layout().maxChildrenPerInnerNode(); ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), false, nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), false, nodeStore->layout().maxChildrenPerInnerNode() + i); } //Traverse all leaves in the third, fourth and fifth child of the root for(unsigned int i = 2; i < 5; ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->key()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->blockId()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse some of the leaves in the sixth child of the root - child = LoadInnerNode(root->getChild(5)->key()); + child = LoadInnerNode(root->getChild(5)->blockId()); for(unsigned int i = 0; i < 2; ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), false, 5 * nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), false, 5 * nodeStore->layout().maxChildrenPerInnerNode() + i); } TraverseLeaves(root.get(), nodeStore->layout().maxChildrenPerInnerNode() + 5, 5 * nodeStore->layout().maxChildrenPerInnerNode() + 2); @@ -322,18 +322,18 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddlePartOfThreelevelTree_AlsoLastN TEST_F(DataTreeTest_TraverseLeaves, TraverseLastPartOfThreelevelTree) { auto root = CreateThreeLevel(); //Traverse some of the leaves in the second child of the root - auto child = LoadInnerNode(root->getChild(1)->key()); + auto child = LoadInnerNode(root->getChild(1)->blockId()); for(unsigned int i = 5; i < nodeStore->layout().maxChildrenPerInnerNode(); ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), false, nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), false, nodeStore->layout().maxChildrenPerInnerNode() + i); } //Traverse all leaves in the third, fourth and fifth child of the root for(unsigned int i = 2; i < 5; ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->key()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->blockId()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse all of the leaves in the sixth child of the root - child = LoadInnerNode(root->getChild(5)->key()); + child = LoadInnerNode(root->getChild(5)->blockId()); for(unsigned int i = 0; i < child->numChildren(); ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), i == child->numChildren()-1, 5 * nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), i == child->numChildren()-1, 5 * nodeStore->layout().maxChildrenPerInnerNode() + i); } TraverseLeaves(root.get(), nodeStore->layout().maxChildrenPerInnerNode() + 5, 5 * nodeStore->layout().maxChildrenPerInnerNode() + child->numChildren()); @@ -343,12 +343,12 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfThreelevelTree) { auto root = CreateThreeLevel(); //Traverse all leaves in the third, fourth and fifth child of the root for(unsigned int i = 0; i < 5; ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->key()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(i)->blockId()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse all of the leaves in the sixth child of the root - auto child = LoadInnerNode(root->getChild(5)->key()); + auto child = LoadInnerNode(root->getChild(5)->blockId()); for(unsigned int i = 0; i < child->numChildren(); ++i) { - EXPECT_TRAVERSE_LEAF(child->getChild(i)->key(), i==child->numChildren()-1, 5 * nodeStore->layout().maxChildrenPerInnerNode() + i); + EXPECT_TRAVERSE_LEAF(child->getChild(i)->blockId(), i==child->numChildren()-1, 5 * nodeStore->layout().maxChildrenPerInnerNode() + i); } TraverseLeaves(root.get(), 0, 5 * nodeStore->layout().maxChildrenPerInnerNode() + child->numChildren()); @@ -357,19 +357,19 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfThreelevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfFourLevelTree) { auto root = CreateFourLevel(); //Traverse all leaves of the full threelevel tree in the first child - auto firstChild = LoadInnerNode(root->getChild(0)->key()); + auto firstChild = LoadInnerNode(root->getChild(0)->blockId()); for(unsigned int i = 0; i < firstChild->numChildren(); ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(firstChild->getChild(i)->key()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(firstChild->getChild(i)->blockId()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse all leaves of the full threelevel tree in the second child - auto secondChild = LoadInnerNode(root->getChild(1)->key()); + auto secondChild = LoadInnerNode(root->getChild(1)->blockId()); for(unsigned int i = 0; i < secondChild->numChildren(); ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(secondChild->getChild(i)->key()), false, (nodeStore->layout().maxChildrenPerInnerNode() + i) * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(secondChild->getChild(i)->blockId()), false, (nodeStore->layout().maxChildrenPerInnerNode() + i) * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse all leaves of the non-full threelevel tree in the third child - auto thirdChild = LoadInnerNode(root->getChild(2)->key()); - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(thirdChild->getChild(0)->key()), false, 2 * nodeStore->layout().maxChildrenPerInnerNode() * nodeStore->layout().maxChildrenPerInnerNode()); - EXPECT_TRAVERSE_LEAF(LoadInnerNode(thirdChild->getChild(1)->key())->getChild(0)->key(), true, 2 * nodeStore->layout().maxChildrenPerInnerNode() * nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxChildrenPerInnerNode()); + auto thirdChild = LoadInnerNode(root->getChild(2)->blockId()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(thirdChild->getChild(0)->blockId()), false, 2 * nodeStore->layout().maxChildrenPerInnerNode() * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(thirdChild->getChild(1)->blockId())->getChild(0)->blockId(), true, 2 * nodeStore->layout().maxChildrenPerInnerNode() * nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxChildrenPerInnerNode()); TraverseLeaves(root.get(), 0, 2*nodeStore->layout().maxChildrenPerInnerNode()*nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxChildrenPerInnerNode() + 1); } @@ -377,24 +377,24 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfFourLevelTree) { TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddlePartOfFourLevelTree) { auto root = CreateFourLevel(); //Traverse some leaves of the full threelevel tree in the first child - auto firstChild = LoadInnerNode(root->getChild(0)->key()); - auto secondChildOfFirstChild = LoadInnerNode(firstChild->getChild(1)->key()); + auto firstChild = LoadInnerNode(root->getChild(0)->blockId()); + auto secondChildOfFirstChild = LoadInnerNode(firstChild->getChild(1)->blockId()); for(unsigned int i = 5; i < secondChildOfFirstChild->numChildren(); ++i) { - EXPECT_TRAVERSE_LEAF(secondChildOfFirstChild->getChild(i)->key(), false, nodeStore->layout().maxChildrenPerInnerNode()+i); + EXPECT_TRAVERSE_LEAF(secondChildOfFirstChild->getChild(i)->blockId(), false, nodeStore->layout().maxChildrenPerInnerNode()+i); } for(unsigned int i = 2; i < firstChild->numChildren(); ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(firstChild->getChild(i)->key()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(firstChild->getChild(i)->blockId()), false, i * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse all leaves of the full threelevel tree in the second child - auto secondChild = LoadInnerNode(root->getChild(1)->key()); + auto secondChild = LoadInnerNode(root->getChild(1)->blockId()); for(unsigned int i = 0; i < secondChild->numChildren(); ++i) { - EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(secondChild->getChild(i)->key()), false, (nodeStore->layout().maxChildrenPerInnerNode() + i) * nodeStore->layout().maxChildrenPerInnerNode()); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(secondChild->getChild(i)->blockId()), false, (nodeStore->layout().maxChildrenPerInnerNode() + i) * nodeStore->layout().maxChildrenPerInnerNode()); } //Traverse some leaves of the non-full threelevel tree in the third child - auto thirdChild = LoadInnerNode(root->getChild(2)->key()); - auto firstChildOfThirdChild = LoadInnerNode(thirdChild->getChild(0)->key()); + auto thirdChild = LoadInnerNode(root->getChild(2)->blockId()); + auto firstChildOfThirdChild = LoadInnerNode(thirdChild->getChild(0)->blockId()); for(unsigned int i = 0; i < firstChildOfThirdChild->numChildren()-1; ++i) { - EXPECT_TRAVERSE_LEAF(firstChildOfThirdChild->getChild(i)->key(), false, 2 * nodeStore->layout().maxChildrenPerInnerNode()*nodeStore->layout().maxChildrenPerInnerNode()+i); + EXPECT_TRAVERSE_LEAF(firstChildOfThirdChild->getChild(i)->blockId(), false, 2 * nodeStore->layout().maxChildrenPerInnerNode()*nodeStore->layout().maxChildrenPerInnerNode()+i); } TraverseLeaves(root.get(), nodeStore->layout().maxChildrenPerInnerNode()+5, 2*nodeStore->layout().maxChildrenPerInnerNode()*nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxChildrenPerInnerNode() -1); @@ -403,7 +403,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddlePartOfFourLevelTree) { TEST_F(DataTreeTest_TraverseLeaves, LastLeafIsAlreadyResizedInCallback) { auto root = CreateLeaf(); root->flush(); - auto tree = treeStore.load(root->key()).value(); + auto tree = treeStore.load(root->blockId()).value(); tree->traverseLeaves(0, 2, [this] (uint32_t leafIndex, bool /*isRightBorderNode*/, LeafHandle leaf) { if (leafIndex == 0) { EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf(), leaf.node()->numBytes()); @@ -418,7 +418,7 @@ TEST_F(DataTreeTest_TraverseLeaves, LastLeafIsAlreadyResizedInCallback) { TEST_F(DataTreeTest_TraverseLeaves, LastLeafIsAlreadyResizedInCallback_TwoLevel) { auto root = CreateFullTwoLevelWithLastLeafSize(5); root->flush(); - auto tree = treeStore.load(root->key()).value(); + auto tree = treeStore.load(root->blockId()).value(); tree->traverseLeaves(0, nodeStore->layout().maxChildrenPerInnerNode()+1, [this] (uint32_t /*leafIndex*/, bool /*isRightBorderNode*/, LeafHandle leaf) { EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf(), leaf.node()->numBytes()); }, [] (uint32_t /*nodeIndex*/) -> Data { @@ -428,7 +428,7 @@ TEST_F(DataTreeTest_TraverseLeaves, LastLeafIsAlreadyResizedInCallback_TwoLevel) TEST_F(DataTreeTest_TraverseLeaves, ResizeFromOneLeafToMultipleLeaves) { auto root = CreateLeaf(); - EXPECT_TRAVERSE_LEAF(root->key(), false, 0); + EXPECT_TRAVERSE_LEAF(root->blockId(), false, 0); //EXPECT_CALL(traversor, calledExistingLeaf(_, false, 0)).Times(1); for (uint32_t i = 1; i < 10; ++i) { EXPECT_CREATE_LEAF(i); diff --git a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp b/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp index d2bf827a..8be22415 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp @@ -15,43 +15,43 @@ using blobstore::onblocks::datanodestore::DataNodeStore; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataInnerNode; using blockstore::testfake::FakeBlockStore; -using blockstore::Key; +using blockstore::BlockId; using cpputils::Data; using namespace blobstore::onblocks::datatreestore::algorithms; class GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest: public DataTreeTest { public: struct TestData { - Key rootNode; - Key expectedResult; + BlockId rootNode; + BlockId expectedResult; }; void check(const TestData &testData) { auto root = nodeStore->load(testData.rootNode).value(); auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get()); - EXPECT_EQ(testData.expectedResult, result->key()); + EXPECT_EQ(testData.expectedResult, result->blockId()); } TestData CreateTwoRightBorderNodes() { auto node = CreateInner({CreateLeaf()}); - return TestData{node->key(), node->key()}; + return TestData{node->blockId(), node->blockId()}; } TestData CreateThreeRightBorderNodes() { auto node = CreateInner({CreateLeaf()}); auto root = CreateInner({node.get()}); - return TestData{root->key(), node->key()}; + return TestData{root->blockId(), node->blockId()}; } TestData CreateThreeRightBorderNodes_LastFull() { auto root = CreateInner({CreateFullTwoLevel()}); - return TestData{root->key(), root->key()}; + return TestData{root->blockId(), root->blockId()}; } TestData CreateLargerTree() { auto node = CreateInner({CreateLeaf(), CreateLeaf()}); auto root = CreateInner({CreateFullTwoLevel().get(), node.get()}); - return TestData{root->key(), node->key()}; + return TestData{root->blockId(), node->blockId()}; } }; diff --git a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp b/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp index 1c2261a3..a4b931df 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp @@ -15,65 +15,65 @@ using blobstore::onblocks::datanodestore::DataNodeStore; using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataInnerNode; using blockstore::testfake::FakeBlockStore; -using blockstore::Key; +using blockstore::BlockId; using namespace blobstore::onblocks::datatreestore::algorithms; class GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest: public DataTreeTest { public: struct TestData { - Key rootNode; - Key expectedResult; + BlockId rootNode; + BlockId expectedResult; }; void check(const TestData &testData) { auto root = nodeStore->load(testData.rootNode).value(); auto result = GetLowestRightBorderNodeWithMoreThanOneChildOrNull(nodeStore, root.get()); - EXPECT_EQ(testData.expectedResult, result->key()); + EXPECT_EQ(testData.expectedResult, result->blockId()); } - Key CreateLeafOnlyTree() { - return CreateLeaf()->key(); + BlockId CreateLeafOnlyTree() { + return CreateLeaf()->blockId(); } - Key CreateTwoRightBorderNodes() { - return CreateInner({CreateLeaf()})->key(); + BlockId CreateTwoRightBorderNodes() { + return CreateInner({CreateLeaf()})->blockId(); } - Key CreateThreeRightBorderNodes() { - return CreateInner({CreateInner({CreateLeaf()})})->key(); + BlockId CreateThreeRightBorderNodes() { + return CreateInner({CreateInner({CreateLeaf()})})->blockId(); } TestData CreateThreeRightBorderNodes_LastFull() { auto node = CreateFullTwoLevel(); auto root = CreateInner({node.get()}); - return TestData{root->key(), node->key()}; + return TestData{root->blockId(), node->blockId()}; } TestData CreateLargerTree() { auto node = CreateInner({CreateLeaf(), CreateLeaf()}); auto root = CreateInner({CreateFullTwoLevel().get(), node.get()}); - return TestData{root->key(), node->key()}; + return TestData{root->blockId(), node->blockId()}; } TestData CreateThreeLevelTreeWithRightBorderSingleNodeChain() { auto root = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf()})}); - return TestData{root->key(), root->key()}; + return TestData{root->blockId(), root->blockId()}; } TestData CreateThreeLevelTree() { auto node = CreateInner({CreateLeaf(), CreateLeaf()}); auto root = CreateInner({CreateFullTwoLevel().get(), node.get()}); - return TestData{root->key(), node->key()}; + return TestData{root->blockId(), node->blockId()}; } TestData CreateFullTwoLevelTree() { auto node = CreateFullTwoLevel(); - return TestData{node->key(), node->key()}; + return TestData{node->blockId(), node->blockId()}; } TestData CreateFullThreeLevelTree() { auto root = CreateFullThreeLevel(); - return TestData{root->key(), root->LastChild()->key()}; + return TestData{root->blockId(), root->LastChild()->blockId()}; } }; diff --git a/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp b/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp index 0d014b57..82d69965 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp +++ b/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp @@ -10,7 +10,7 @@ using blobstore::onblocks::datanodestore::DataInnerNode; using blobstore::onblocks::datanodestore::DataLeafNode; using blobstore::onblocks::datatreestore::DataTree; using blockstore::mock::MockBlockStore; -using blockstore::Key; +using blockstore::BlockId; using cpputils::unique_ref; using cpputils::make_unique_ref; using std::initializer_list; @@ -45,19 +45,19 @@ unique_ref DataTreeTest::CreateInner(initializer_list DataTreeTest::CreateInner(vector children) { ASSERT(children.size() >= 1, "An inner node must have at least one child"); - vector childrenKeys; + vector childrenKeys; childrenKeys.reserve(children.size()); for (const DataNode *child : children) { ASSERT(child->depth() == (*children.begin())->depth(), "Children with different depth"); - childrenKeys.push_back(child->key()); + childrenKeys.push_back(child->blockId()); } auto node = nodeStore->createNewInnerNode((*children.begin())->depth()+1, childrenKeys); return node; } unique_ref DataTreeTest::CreateLeafOnlyTree() { - auto key = CreateLeaf()->key(); - return treeStore.load(key).value(); + auto blockId = CreateLeaf()->blockId(); + return treeStore.load(blockId).value(); } void DataTreeTest::FillNode(DataInnerNode *node) { @@ -98,15 +98,15 @@ unique_ref DataTreeTest::CreateFullThreeLevel() { return root; } -unique_ref DataTreeTest::LoadInnerNode(const Key &key) { - auto node = nodeStore->load(key).value(); +unique_ref DataTreeTest::LoadInnerNode(const BlockId &blockId) { + auto node = nodeStore->load(blockId).value(); auto casted = dynamic_pointer_move(node); EXPECT_NE(none, casted) << "Is not an inner node"; return std::move(*casted); } -unique_ref DataTreeTest::LoadLeafNode(const Key &key) { - auto node = nodeStore->load(key).value(); +unique_ref DataTreeTest::LoadLeafNode(const BlockId &blockId) { + auto node = nodeStore->load(blockId).value(); auto casted = dynamic_pointer_move(node); EXPECT_NE(none, casted) << "Is not a leaf node"; return std::move(*casted); @@ -117,8 +117,8 @@ unique_ref DataTreeTest::CreateTwoLeaf() { } unique_ref DataTreeTest::CreateTwoLeafTree() { - auto key = CreateTwoLeaf()->key(); - return treeStore.load(key).value(); + auto blockId = CreateTwoLeaf()->blockId(); + return treeStore.load(blockId).value(); } unique_ref DataTreeTest::CreateLeafWithSize(uint32_t size) { @@ -137,9 +137,9 @@ unique_ref DataTreeTest::CreateTwoLeafWithSecondLeafSize(uint32_t unique_ref DataTreeTest::CreateFullTwoLevelWithLastLeafSize(uint32_t size) { auto root = CreateFullTwoLevel(); for (uint32_t i = 0; i < root->numChildren()-1; ++i) { - LoadLeafNode(root->getChild(i)->key())->resize(nodeStore->layout().maxBytesPerLeaf()); + LoadLeafNode(root->getChild(i)->blockId())->resize(nodeStore->layout().maxBytesPerLeaf()); } - LoadLeafNode(root->LastChild()->key())->resize(size); + LoadLeafNode(root->LastChild()->blockId())->resize(size); return root; } @@ -176,12 +176,12 @@ unique_ref DataTreeTest::CreateThreeLevelWithThreeChildrenAndLast unique_ref DataTreeTest::CreateFullThreeLevelWithLastLeafSize(uint32_t size) { auto root = CreateFullThreeLevel(); for (uint32_t i = 0; i < root->numChildren(); ++i) { - auto node = LoadInnerNode(root->getChild(i)->key()); + auto node = LoadInnerNode(root->getChild(i)->blockId()); for (uint32_t j = 0; j < node->numChildren(); ++j) { - LoadLeafNode(node->getChild(j)->key())->resize(nodeStore->layout().maxBytesPerLeaf()); + LoadLeafNode(node->getChild(j)->blockId())->resize(nodeStore->layout().maxBytesPerLeaf()); } } - LoadLeafNode(LoadInnerNode(root->LastChild()->key())->LastChild()->key())->resize(size); + LoadLeafNode(LoadInnerNode(root->LastChild()->blockId())->LastChild()->blockId())->resize(size); return root; } @@ -192,50 +192,50 @@ unique_ref DataTreeTest::CreateFourLevelMinDataWithLastLeafSize(u }); } -void DataTreeTest::EXPECT_IS_LEAF_NODE(const Key &key) { - auto node = LoadLeafNode(key); +void DataTreeTest::EXPECT_IS_LEAF_NODE(const BlockId &blockId) { + auto node = LoadLeafNode(blockId); EXPECT_NE(nullptr, node.get()); } -void DataTreeTest::EXPECT_IS_INNER_NODE(const Key &key) { - auto node = LoadInnerNode(key); +void DataTreeTest::EXPECT_IS_INNER_NODE(const BlockId &blockId) { + auto node = LoadInnerNode(blockId); EXPECT_NE(nullptr, node.get()); } -void DataTreeTest::EXPECT_IS_TWONODE_CHAIN(const Key &key) { - auto node = LoadInnerNode(key); +void DataTreeTest::EXPECT_IS_TWONODE_CHAIN(const BlockId &blockId) { + auto node = LoadInnerNode(blockId); EXPECT_EQ(1u, node->numChildren()); - EXPECT_IS_LEAF_NODE(node->getChild(0)->key()); + EXPECT_IS_LEAF_NODE(node->getChild(0)->blockId()); } -void DataTreeTest::EXPECT_IS_FULL_TWOLEVEL_TREE(const Key &key) { - auto node = LoadInnerNode(key); +void DataTreeTest::EXPECT_IS_FULL_TWOLEVEL_TREE(const BlockId &blockId) { + auto node = LoadInnerNode(blockId); EXPECT_EQ(nodeStore->layout().maxChildrenPerInnerNode(), node->numChildren()); for (unsigned int i = 0; i < node->numChildren(); ++i) { - EXPECT_IS_LEAF_NODE(node->getChild(i)->key()); + EXPECT_IS_LEAF_NODE(node->getChild(i)->blockId()); } } -void DataTreeTest::EXPECT_IS_FULL_THREELEVEL_TREE(const Key &key) { - auto root = LoadInnerNode(key); +void DataTreeTest::EXPECT_IS_FULL_THREELEVEL_TREE(const BlockId &blockId) { + auto root = LoadInnerNode(blockId); EXPECT_EQ(nodeStore->layout().maxChildrenPerInnerNode(), root->numChildren()); for (unsigned int i = 0; i < root->numChildren(); ++i) { - auto node = LoadInnerNode(root->getChild(i)->key()); + auto node = LoadInnerNode(root->getChild(i)->blockId()); EXPECT_EQ(nodeStore->layout().maxChildrenPerInnerNode(), node->numChildren()); for (unsigned int j = 0; j < node->numChildren(); ++j) { - EXPECT_IS_LEAF_NODE(node->getChild(j)->key()); + EXPECT_IS_LEAF_NODE(node->getChild(j)->blockId()); } } } -void DataTreeTest::CHECK_DEPTH(int depth, const Key &key) { +void DataTreeTest::CHECK_DEPTH(int depth, const BlockId &blockId) { if (depth == 0) { - EXPECT_IS_LEAF_NODE(key); + EXPECT_IS_LEAF_NODE(blockId); } else { - auto node = LoadInnerNode(key); + auto node = LoadInnerNode(blockId); EXPECT_EQ(depth, node->depth()); for (uint32_t i = 0; i < node->numChildren(); ++i) { - CHECK_DEPTH(depth-1, node->getChild(i)->key()); + CHECK_DEPTH(depth-1, node->getChild(i)->blockId()); } } } diff --git a/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.h b/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.h index 17133cbb..74ad0e77 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.h +++ b/test/blobstore/implementations/onblocks/datatreestore/testutils/DataTreeTest.h @@ -34,8 +34,8 @@ public: cpputils::unique_ref CreateThreeLevelMinData(); cpputils::unique_ref CreateFourLevelMinData(); - cpputils::unique_ref LoadInnerNode(const blockstore::Key &key); - cpputils::unique_ref LoadLeafNode(const blockstore::Key &key); + cpputils::unique_ref LoadInnerNode(const blockstore::BlockId &blockId); + cpputils::unique_ref LoadLeafNode(const blockstore::BlockId &blockId); cpputils::unique_ref CreateLeafWithSize(uint32_t size); cpputils::unique_ref CreateTwoLeafWithSecondLeafSize(uint32_t size); @@ -52,13 +52,13 @@ public: blobstore::onblocks::datanodestore::DataNodeStore *nodeStore; blobstore::onblocks::datatreestore::DataTreeStore treeStore; - void EXPECT_IS_LEAF_NODE(const blockstore::Key &key); - void EXPECT_IS_INNER_NODE(const blockstore::Key &key); - void EXPECT_IS_TWONODE_CHAIN(const blockstore::Key &key); - void EXPECT_IS_FULL_TWOLEVEL_TREE(const blockstore::Key &key); - void EXPECT_IS_FULL_THREELEVEL_TREE(const blockstore::Key &key); + void EXPECT_IS_LEAF_NODE(const blockstore::BlockId &blockId); + void EXPECT_IS_INNER_NODE(const blockstore::BlockId &blockId); + void EXPECT_IS_TWONODE_CHAIN(const blockstore::BlockId &blockId); + void EXPECT_IS_FULL_TWOLEVEL_TREE(const blockstore::BlockId &blockId); + void EXPECT_IS_FULL_THREELEVEL_TREE(const blockstore::BlockId &blockId); - void CHECK_DEPTH(int depth, const blockstore::Key &key); + void CHECK_DEPTH(int depth, const blockstore::BlockId &blockId); private: DISALLOW_COPY_AND_ASSIGN(DataTreeTest); diff --git a/test/blobstore/implementations/onblocks/datatreestore/testutils/TwoLevelDataFixture.h b/test/blobstore/implementations/onblocks/datatreestore/testutils/TwoLevelDataFixture.h index c79599e0..a27497e5 100644 --- a/test/blobstore/implementations/onblocks/datatreestore/testutils/TwoLevelDataFixture.h +++ b/test/blobstore/implementations/onblocks/datatreestore/testutils/TwoLevelDataFixture.h @@ -51,7 +51,7 @@ private: auto inner = dynamic_cast(node); int leafIndex = firstLeafIndex; for (uint32_t i = 0; i < inner->numChildren(); ++i) { - auto child = _dataNodeStore->load(inner->getChild(i)->key()).value(); + auto child = _dataNodeStore->load(inner->getChild(i)->blockId()).value(); leafIndex = ForEachLeaf(child.get(), leafIndex, endLeafIndex, action); } return leafIndex; diff --git a/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.h b/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.h index 3cf277df..d521602d 100644 --- a/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.h +++ b/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.h @@ -14,8 +14,8 @@ public: cpputils::unique_ref blobStore; - cpputils::unique_ref loadBlob(const blockstore::Key &key) { - auto loaded = blobStore->load(key); + cpputils::unique_ref loadBlob(const blockstore::BlockId &blockId) { + auto loaded = blobStore->load(blockId); EXPECT_TRUE((bool)loaded); return std::move(*loaded); } diff --git a/test/blockstore/implementations/caching/CachingBlockStore2Test_Specific.cpp b/test/blockstore/implementations/caching/CachingBlockStore2Test_Specific.cpp index c4bf3561..ab10c17e 100644 --- a/test/blockstore/implementations/caching/CachingBlockStore2Test_Specific.cpp +++ b/test/blockstore/implementations/caching/CachingBlockStore2Test_Specific.cpp @@ -27,18 +27,18 @@ TEST_F(CachingBlockStore2Test, PhysicalBlockSize_zerophysical) { } TEST_F(CachingBlockStore2Test, PhysicalBlockSize_zerovirtual) { - auto key = blockStore.create(Data(0)); + auto blockId = blockStore.create(Data(0)); blockStore.flush(); - auto base = baseBlockStore->load(key).value(); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(base.size())); } TEST_F(CachingBlockStore2Test, PhysicalBlockSize_negativeboundaries) { // This tests that a potential if/else in blockSizeFromPhysicalBlockSize that catches negative values has the // correct boundary set. We test the highest value that is negative and the smallest value that is positive. - auto key = blockStore.create(Data(0)); + auto blockId = blockStore.create(Data(0)); blockStore.flush(); - auto physicalSizeForVirtualSizeZero = baseBlockStore->load(key).value().size(); + auto physicalSizeForVirtualSizeZero = baseBlockStore->load(blockId).value().size(); if (physicalSizeForVirtualSizeZero > 0) { EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero - 1)); } @@ -47,9 +47,9 @@ TEST_F(CachingBlockStore2Test, PhysicalBlockSize_negativeboundaries) { } TEST_F(CachingBlockStore2Test, PhysicalBlockSize_positive) { - auto key = blockStore.create(Data(10*1024u)); + auto blockId = blockStore.create(Data(10*1024u)); blockStore.flush(); - auto base = baseBlockStore->load(key).value(); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(10*1024u, blockStore.blockSizeFromPhysicalBlockSize(base.size())); } diff --git a/test/blockstore/implementations/encrypted/EncryptedBlockStoreTest_Specific.cpp b/test/blockstore/implementations/encrypted/EncryptedBlockStoreTest_Specific.cpp index 25beeb99..6bddf695 100644 --- a/test/blockstore/implementations/encrypted/EncryptedBlockStoreTest_Specific.cpp +++ b/test/blockstore/implementations/encrypted/EncryptedBlockStoreTest_Specific.cpp @@ -31,29 +31,29 @@ public: unique_ref> blockStore; Data data; - blockstore::Key CreateBlockDirectlyWithFixtureAndReturnKey() { + blockstore::BlockId CreateBlockDirectlyWithFixtureAndReturnKey() { return CreateBlockReturnKey(data); } - blockstore::Key CreateBlockReturnKey(const Data &initData) { + blockstore::BlockId CreateBlockReturnKey(const Data &initData) { return blockStore->create(initData.copy()); } - blockstore::Key CreateBlockWriteFixtureToItAndReturnKey() { - auto key = blockStore->create(Data(data.size())); - blockStore->store(key, data); - return key; + blockstore::BlockId CreateBlockWriteFixtureToItAndReturnKey() { + auto blockId = blockStore->create(Data(data.size())); + blockStore->store(blockId, data); + return blockId; } - void ModifyBaseBlock(const blockstore::Key &key) { - auto block = baseBlockStore->load(key).value(); + void ModifyBaseBlock(const blockstore::BlockId &blockId) { + auto block = baseBlockStore->load(blockId).value(); byte* middle_byte = ((CryptoPP::byte*)block.data()) + 10; *middle_byte = *middle_byte + 1; - baseBlockStore->store(key, block); + baseBlockStore->store(blockId, block); } - blockstore::Key CopyBaseBlock(const blockstore::Key &key) { - auto source = baseBlockStore->load(key).value(); + blockstore::BlockId CopyBaseBlock(const blockstore::BlockId &blockId) { + auto source = baseBlockStore->load(blockId).value(); return baseBlockStore->create(std::move(source)); } @@ -62,46 +62,46 @@ private: }; TEST_F(EncryptedBlockStoreTest, LoadingWithSameKeyWorks_WriteOnCreate) { - auto key = CreateBlockDirectlyWithFixtureAndReturnKey(); - auto loaded = blockStore->load(key); + auto blockId = CreateBlockDirectlyWithFixtureAndReturnKey(); + auto loaded = blockStore->load(blockId); EXPECT_NE(boost::none, loaded); EXPECT_EQ(data.size(), loaded->size()); EXPECT_EQ(0, std::memcmp(data.data(), loaded->data(), data.size())); } TEST_F(EncryptedBlockStoreTest, LoadingWithSameKeyWorks_WriteSeparately) { - auto key = CreateBlockWriteFixtureToItAndReturnKey(); - auto loaded = blockStore->load(key); + auto blockId = CreateBlockWriteFixtureToItAndReturnKey(); + auto loaded = blockStore->load(blockId); EXPECT_NE(boost::none, loaded); EXPECT_EQ(data.size(), loaded->size()); EXPECT_EQ(0, std::memcmp(data.data(), loaded->data(), data.size())); } TEST_F(EncryptedBlockStoreTest, LoadingWithDifferentKeyDoesntWork_WriteOnCreate) { - auto key = CreateBlockDirectlyWithFixtureAndReturnKey(); + auto blockId = CreateBlockDirectlyWithFixtureAndReturnKey(); blockStore->__setKey(FakeAuthenticatedCipher::Key2()); - auto loaded = blockStore->load(key); + auto loaded = blockStore->load(blockId); EXPECT_EQ(boost::none, loaded); } TEST_F(EncryptedBlockStoreTest, LoadingWithDifferentKeyDoesntWork_WriteSeparately) { - auto key = CreateBlockWriteFixtureToItAndReturnKey(); + auto blockId = CreateBlockWriteFixtureToItAndReturnKey(); blockStore->__setKey(FakeAuthenticatedCipher::Key2()); - auto loaded = blockStore->load(key); + auto loaded = blockStore->load(blockId); EXPECT_EQ(boost::none, loaded); } TEST_F(EncryptedBlockStoreTest, LoadingModifiedBlockFails_WriteOnCreate) { - auto key = CreateBlockDirectlyWithFixtureAndReturnKey(); - ModifyBaseBlock(key); - auto loaded = blockStore->load(key); + auto blockId = CreateBlockDirectlyWithFixtureAndReturnKey(); + ModifyBaseBlock(blockId); + auto loaded = blockStore->load(blockId); EXPECT_EQ(boost::none, loaded); } TEST_F(EncryptedBlockStoreTest, LoadingModifiedBlockFails_WriteSeparately) { - auto key = CreateBlockWriteFixtureToItAndReturnKey(); - ModifyBaseBlock(key); - auto loaded = blockStore->load(key); + auto blockId = CreateBlockWriteFixtureToItAndReturnKey(); + ModifyBaseBlock(blockId); + auto loaded = blockStore->load(blockId); EXPECT_EQ(boost::none, loaded); } @@ -110,8 +110,8 @@ TEST_F(EncryptedBlockStoreTest, PhysicalBlockSize_zerophysical) { } TEST_F(EncryptedBlockStoreTest, PhysicalBlockSize_zerovirtual) { - auto key = CreateBlockReturnKey(Data(0)); - auto base = baseBlockStore->load(key).value(); + auto blockId = CreateBlockReturnKey(Data(0)); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(0u, blockStore->blockSizeFromPhysicalBlockSize(base.size())); } @@ -127,7 +127,7 @@ TEST_F(EncryptedBlockStoreTest, PhysicalBlockSize_negativeboundaries) { } TEST_F(EncryptedBlockStoreTest, PhysicalBlockSize_positive) { - auto key = CreateBlockReturnKey(Data(10*1024)); - auto base = baseBlockStore->load(key).value(); + auto blockId = CreateBlockReturnKey(Data(10*1024)); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(10*1024u, blockStore->blockSizeFromPhysicalBlockSize(base.size())); } diff --git a/test/blockstore/implementations/integrity/IntegrityBlockStoreTest_Specific.cpp b/test/blockstore/implementations/integrity/IntegrityBlockStoreTest_Specific.cpp index ee44753b..2fa919fe 100644 --- a/test/blockstore/implementations/integrity/IntegrityBlockStoreTest_Specific.cpp +++ b/test/blockstore/implementations/integrity/IntegrityBlockStoreTest_Specific.cpp @@ -48,61 +48,61 @@ public: return std::make_pair(baseBlockStore, std::move(blockStore)); } - blockstore::Key CreateBlockReturnKey() { + blockstore::BlockId CreateBlockReturnKey() { return CreateBlockReturnKey(data); } - blockstore::Key CreateBlockReturnKey(const Data &initData) { + blockstore::BlockId CreateBlockReturnKey(const Data &initData) { return blockStore->create(initData.copy()); } - Data loadBaseBlock(const blockstore::Key &key) { - return baseBlockStore->load(key).value(); + Data loadBaseBlock(const blockstore::BlockId &blockId) { + return baseBlockStore->load(blockId).value(); } - Data loadBlock(const blockstore::Key &key) { - return blockStore->load(key).value(); + Data loadBlock(const blockstore::BlockId &blockId) { + return blockStore->load(blockId).value(); } - void modifyBlock(const blockstore::Key &key) { - auto block = blockStore->load(key).value(); + void modifyBlock(const blockstore::BlockId &blockId) { + auto block = blockStore->load(blockId).value(); byte* first_byte = (byte*)block.data(); *first_byte = *first_byte + 1; - blockStore->store(key, block); + blockStore->store(blockId, block); } - void rollbackBaseBlock(const blockstore::Key &key, const Data &data) { - baseBlockStore->store(key, data); + void rollbackBaseBlock(const blockstore::BlockId &blockId, const Data &data) { + baseBlockStore->store(blockId, data); } - void decreaseVersionNumber(const blockstore::Key &key) { - auto baseBlock = baseBlockStore->load(key).value(); + void decreaseVersionNumber(const blockstore::BlockId &blockId) { + auto baseBlock = baseBlockStore->load(blockId).value(); uint64_t* version = (uint64_t*)((uint8_t*)baseBlock.data()+IntegrityBlockStore2::VERSION_HEADER_OFFSET); ASSERT(*version > 1, "Can't decrease the lowest allowed version number"); *version -= 1; - baseBlockStore->store(key, baseBlock); + baseBlockStore->store(blockId, baseBlock); } - void increaseVersionNumber(const blockstore::Key &key) { - auto baseBlock = baseBlockStore->load(key).value(); + void increaseVersionNumber(const blockstore::BlockId &blockId) { + auto baseBlock = baseBlockStore->load(blockId).value(); uint64_t* version = (uint64_t*)((uint8_t*)baseBlock.data()+IntegrityBlockStore2::VERSION_HEADER_OFFSET); *version += 1; - baseBlockStore->store(key, baseBlock); + baseBlockStore->store(blockId, baseBlock); } - void changeClientId(const blockstore::Key &key) { - auto baseBlock = baseBlockStore->load(key).value(); + void changeClientId(const blockstore::BlockId &blockId) { + auto baseBlock = baseBlockStore->load(blockId).value(); uint32_t* clientId = (uint32_t*)((uint8_t*)baseBlock.data()+IntegrityBlockStore2::CLIENTID_HEADER_OFFSET); *clientId += 1; - baseBlockStore->store(key, baseBlock); + baseBlockStore->store(blockId, baseBlock); } - void deleteBlock(const blockstore::Key &key) { - blockStore->remove(key); + void deleteBlock(const blockstore::BlockId &blockId) { + blockStore->remove(blockId); } - void insertBaseBlock(const blockstore::Key &key, Data data) { - EXPECT_TRUE(baseBlockStore->tryCreate(key, std::move(data))); + void insertBaseBlock(const blockstore::BlockId &blockId, Data data) { + EXPECT_TRUE(baseBlockStore->tryCreate(blockId, std::move(data))); } private: @@ -113,76 +113,76 @@ constexpr uint32_t IntegrityBlockStoreTest::myClientId; // Test that a decreasing version number is not allowed TEST_F(IntegrityBlockStoreTest, RollbackPrevention_DoesntAllowDecreasingVersionNumberForSameClient_1) { - auto key = CreateBlockReturnKey(); - Data oldBaseBlock = loadBaseBlock(key); - modifyBlock(key); - rollbackBaseBlock(key, oldBaseBlock); + auto blockId = CreateBlockReturnKey(); + Data oldBaseBlock = loadBaseBlock(blockId); + modifyBlock(blockId); + rollbackBaseBlock(blockId, oldBaseBlock); EXPECT_THROW( - blockStore->load(key), + blockStore->load(blockId), IntegrityViolationError ); } TEST_F(IntegrityBlockStoreTest, RollbackPrevention_DoesntAllowDecreasingVersionNumberForSameClient_2) { - auto key = CreateBlockReturnKey(); + auto blockId = CreateBlockReturnKey(); // Increase the version number - modifyBlock(key); + modifyBlock(blockId); // Decrease the version number again - decreaseVersionNumber(key); + decreaseVersionNumber(blockId); EXPECT_THROW( - blockStore->load(key), + blockStore->load(blockId), IntegrityViolationError ); } // Test that a different client doesn't need to have a higher version number (i.e. version numbers are per client). TEST_F(IntegrityBlockStoreTest, RollbackPrevention_DoesAllowDecreasingVersionNumberForDifferentClient) { - auto key = CreateBlockReturnKey(); + auto blockId = CreateBlockReturnKey(); // Increase the version number - modifyBlock(key); + modifyBlock(blockId); // Fake a modification by a different client with lower version numbers - changeClientId(key); - decreaseVersionNumber(key); - EXPECT_NE(boost::none, blockStore->load(key)); + changeClientId(blockId); + decreaseVersionNumber(blockId); + EXPECT_NE(boost::none, blockStore->load(blockId)); } // Test that it doesn't allow a rollback to the "newest" block of a client, when this block was superseded by a version of a different client TEST_F(IntegrityBlockStoreTest, RollbackPrevention_DoesntAllowSameVersionNumberForOldClient) { - auto key = CreateBlockReturnKey(); + auto blockId = CreateBlockReturnKey(); // Increase the version number - modifyBlock(key); - Data oldBaseBlock = loadBaseBlock(key); + modifyBlock(blockId); + Data oldBaseBlock = loadBaseBlock(blockId); // Fake a modification by a different client with lower version numbers - changeClientId(key); - loadBlock(key); // make the block store know about this other client's modification + changeClientId(blockId); + loadBlock(blockId); // make the block store know about this other client's modification // Rollback to old client - rollbackBaseBlock(key, oldBaseBlock); + rollbackBaseBlock(blockId, oldBaseBlock); EXPECT_THROW( - blockStore->load(key), + blockStore->load(blockId), IntegrityViolationError ); } // Test that deleted blocks cannot be re-introduced TEST_F(IntegrityBlockStoreTest, RollbackPrevention_DoesntAllowReintroducingDeletedBlocks) { - auto key = CreateBlockReturnKey(); - Data oldBaseBlock = loadBaseBlock(key); - deleteBlock(key); - insertBaseBlock(key, std::move(oldBaseBlock)); + auto blockId = CreateBlockReturnKey(); + Data oldBaseBlock = loadBaseBlock(blockId); + deleteBlock(blockId); + insertBaseBlock(blockId, std::move(oldBaseBlock)); EXPECT_THROW( - blockStore->load(key), + blockStore->load(blockId), IntegrityViolationError ); } // This can happen if a client synchronization is delayed. Another client might have won the conflict and pushed a new version for the deleted block. TEST_F(IntegrityBlockStoreTest, RollbackPrevention_AllowsReintroducingDeletedBlocksWithNewVersionNumber) { - auto key = CreateBlockReturnKey(); - Data oldBaseBlock = loadBaseBlock(key); - deleteBlock(key); - insertBaseBlock(key, std::move(oldBaseBlock)); - increaseVersionNumber(key); - EXPECT_NE(boost::none, blockStore->load(key)); + auto blockId = CreateBlockReturnKey(); + Data oldBaseBlock = loadBaseBlock(blockId); + deleteBlock(blockId); + insertBaseBlock(blockId, std::move(oldBaseBlock)); + increaseVersionNumber(blockId); + EXPECT_NE(boost::none, blockStore->load(blockId)); } // Check that in a multi-client scenario, missing blocks are not integrity errors, because another client might have deleted them. @@ -190,9 +190,9 @@ TEST_F(IntegrityBlockStoreTest, DeletionPrevention_AllowsDeletingBlocksWhenDeact InMemoryBlockStore2 *baseBlockStore; unique_ptr blockStore; std::tie(baseBlockStore, blockStore) = makeBlockStoreWithoutDeletionPrevention(); - auto key = blockStore->create(Data(0)); - baseBlockStore->remove(key); - EXPECT_EQ(boost::none, blockStore->load(key)); + auto blockId = blockStore->create(Data(0)); + baseBlockStore->remove(blockId); + EXPECT_EQ(boost::none, blockStore->load(blockId)); } // Check that in a single-client scenario, missing blocks are integrity errors. @@ -200,10 +200,10 @@ TEST_F(IntegrityBlockStoreTest, DeletionPrevention_DoesntAllowDeletingBlocksWhen InMemoryBlockStore2 *baseBlockStore; unique_ptr blockStore; std::tie(baseBlockStore, blockStore) = makeBlockStoreWithDeletionPrevention(); - auto key = blockStore->create(Data(0)); - baseBlockStore->remove(key); + auto blockId = blockStore->create(Data(0)); + baseBlockStore->remove(blockId); EXPECT_THROW( - blockStore->load(key), + blockStore->load(blockId), IntegrityViolationError ); } @@ -213,10 +213,10 @@ TEST_F(IntegrityBlockStoreTest, DeletionPrevention_InForEachBlock_AllowsDeleting InMemoryBlockStore2 *baseBlockStore; unique_ptr blockStore; std::tie(baseBlockStore, blockStore) = makeBlockStoreWithoutDeletionPrevention(); - auto key = blockStore->create(Data(0)); - baseBlockStore->remove(key); + auto blockId = blockStore->create(Data(0)); + baseBlockStore->remove(blockId); int count = 0; - blockStore->forEachBlock([&count] (const blockstore::Key &) { + blockStore->forEachBlock([&count] (const blockstore::BlockId &) { ++count; }); EXPECT_EQ(0, count); @@ -227,18 +227,18 @@ TEST_F(IntegrityBlockStoreTest, DeletionPrevention_InForEachBlock_DoesntAllowDel InMemoryBlockStore2 *baseBlockStore; unique_ptr blockStore; std::tie(baseBlockStore, blockStore) = makeBlockStoreWithDeletionPrevention(); - auto key = blockStore->create(Data(0)); - baseBlockStore->remove(key); + auto blockId = blockStore->create(Data(0)); + baseBlockStore->remove(blockId); EXPECT_THROW( - blockStore->forEachBlock([] (const blockstore::Key &) {}), + blockStore->forEachBlock([] (const blockstore::BlockId &) {}), IntegrityViolationError ); } TEST_F(IntegrityBlockStoreTest, LoadingWithDifferentBlockIdFails) { - auto key = CreateBlockReturnKey(); - blockstore::Key key2 = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - baseBlockStore->store(key2, baseBlockStore->load(key).value()); + auto blockId = CreateBlockReturnKey(); + blockstore::BlockId key2 = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + baseBlockStore->store(key2, baseBlockStore->load(blockId).value()); EXPECT_THROW( blockStore->load(key2), IntegrityViolationError @@ -256,8 +256,8 @@ TEST_F(IntegrityBlockStoreTest, PhysicalBlockSize_zerophysical) { } TEST_F(IntegrityBlockStoreTest, PhysicalBlockSize_zerovirtual) { - auto key = CreateBlockReturnKey(Data(0)); - auto base = baseBlockStore->load(key).value(); + auto blockId = CreateBlockReturnKey(Data(0)); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(0u, blockStore->blockSizeFromPhysicalBlockSize(base.size())); } @@ -273,7 +273,7 @@ TEST_F(IntegrityBlockStoreTest, PhysicalBlockSize_negativeboundaries) { } TEST_F(IntegrityBlockStoreTest, PhysicalBlockSize_positive) { - auto key = CreateBlockReturnKey(Data(10*1024)); - auto base = baseBlockStore->load(key).value(); + auto blockId = CreateBlockReturnKey(Data(10*1024)); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(10*1024u, blockStore->blockSizeFromPhysicalBlockSize(base.size())); } diff --git a/test/blockstore/implementations/integrity/KnownBlockVersionsTest.cpp b/test/blockstore/implementations/integrity/KnownBlockVersionsTest.cpp index 33ab0370..fd693cbb 100644 --- a/test/blockstore/implementations/integrity/KnownBlockVersionsTest.cpp +++ b/test/blockstore/implementations/integrity/KnownBlockVersionsTest.cpp @@ -3,7 +3,7 @@ #include using blockstore::integrity::KnownBlockVersions; -using blockstore::Key; +using blockstore::BlockId; using cpputils::TempFile; using std::unordered_set; @@ -11,8 +11,8 @@ class KnownBlockVersionsTest : public ::testing::Test { public: KnownBlockVersionsTest() :stateFile(false), testobj(stateFile.path(), myClientId) {} - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - blockstore::Key key2 = blockstore::Key::FromString("C772972491BB4932A1389EE14BC7090A"); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + blockstore::BlockId blockId2 = blockstore::BlockId::FromString("C772972491BB4932A1389EE14BC7090A"); static constexpr uint32_t myClientId = 0x12345678; static constexpr uint32_t clientId = 0x23456789; static constexpr uint32_t clientId2 = 0x34567890; @@ -20,47 +20,47 @@ public: TempFile stateFile; KnownBlockVersions testobj; - void setVersion(KnownBlockVersions *testobj, uint32_t clientId, const blockstore::Key &key, uint64_t version) { - if (!testobj->checkAndUpdateVersion(clientId, key, version)) { + void setVersion(KnownBlockVersions *testobj, uint32_t clientId, const blockstore::BlockId &blockId, uint64_t version) { + if (!testobj->checkAndUpdateVersion(clientId, blockId, version)) { throw std::runtime_error("Couldn't increase version"); } } - void EXPECT_VERSION_IS(uint64_t version, KnownBlockVersions *testobj, blockstore::Key &key, uint32_t clientId) { - EXPECT_FALSE(testobj->checkAndUpdateVersion(clientId, key, version-1)); - EXPECT_TRUE(testobj->checkAndUpdateVersion(clientId, key, version+1)); + void EXPECT_VERSION_IS(uint64_t version, KnownBlockVersions *testobj, blockstore::BlockId &blockId, uint32_t clientId) { + EXPECT_FALSE(testobj->checkAndUpdateVersion(clientId, blockId, version-1)); + EXPECT_TRUE(testobj->checkAndUpdateVersion(clientId, blockId, version+1)); } }; TEST_F(KnownBlockVersionsTest, setandget) { - setVersion(&testobj, clientId, key, 5); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, setandget_isPerClientId) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key, 3); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(3u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId, 3); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(3u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, setandget_isPerBlock) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId, key2, 3); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(3u, testobj.getBlockVersion(clientId, key2)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId, blockId2, 3); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(3u, testobj.getBlockVersion(clientId, blockId2)); } TEST_F(KnownBlockVersionsTest, setandget_allowsIncreasing) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId, key, 6); - EXPECT_EQ(6u, testobj.getBlockVersion(clientId, key)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId, blockId, 6); + EXPECT_EQ(6u, testobj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, setandget_doesntAllowDecreasing) { - setVersion(&testobj, clientId, key, 5); + setVersion(&testobj, clientId, blockId, 5); EXPECT_ANY_THROW( - setVersion(&testobj, clientId, key, 4); + setVersion(&testobj, clientId, blockId, 4); ); } @@ -69,245 +69,245 @@ TEST_F(KnownBlockVersionsTest, myClientId_isConsistent) { } TEST_F(KnownBlockVersionsTest, incrementVersion_newentry) { - auto version = testobj.incrementVersion(key); + auto version = testobj.incrementVersion(blockId); EXPECT_EQ(1u, version); - EXPECT_EQ(1u, testobj.getBlockVersion(testobj.myClientId(), key)); + EXPECT_EQ(1u, testobj.getBlockVersion(testobj.myClientId(), blockId)); } TEST_F(KnownBlockVersionsTest, incrementVersion_oldentry) { - setVersion(&testobj, testobj.myClientId(), key, 5); - auto version = testobj.incrementVersion(key); + setVersion(&testobj, testobj.myClientId(), blockId, 5); + auto version = testobj.incrementVersion(blockId); EXPECT_EQ(6u, version); - EXPECT_EQ(6u, testobj.getBlockVersion(testobj.myClientId(), key)); + EXPECT_EQ(6u, testobj.getBlockVersion(testobj.myClientId(), blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_newentry) { - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 5)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_sameClientSameVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 5)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_sameClientLowerVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 4)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 4)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_sameClientNewerVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 6)); - EXPECT_EQ(6u, testobj.getBlockVersion(clientId, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 6)); + EXPECT_EQ(6u, testobj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_differentClientSameVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 5)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 5)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_differentClientLowerVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 3)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(3u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 3)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(3u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_differentClientHigherVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientLowerVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 3)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 3)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientSameVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 5)); // Don't allow rollback to old client's newest block, if it was superseded by another client - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); // Don't allow rollback to old client's newest block, if it was superseded by another client + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientHigherVersion) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 6)); - EXPECT_EQ(6u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 6)); + EXPECT_EQ(6u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientLowerVersion_oldClientIsSelf) { - setVersion(&testobj, testobj.myClientId(), key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_FALSE(testobj.checkAndUpdateVersion(testobj.myClientId(), key, 3)); - EXPECT_EQ(5u, testobj.getBlockVersion(testobj.myClientId(), key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, testobj.myClientId(), blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_FALSE(testobj.checkAndUpdateVersion(testobj.myClientId(), blockId, 3)); + EXPECT_EQ(5u, testobj.getBlockVersion(testobj.myClientId(), blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientSameVersion_oldClientIsSelf) { - setVersion(&testobj, testobj.myClientId(), key, 5); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_FALSE(testobj.checkAndUpdateVersion(testobj.myClientId(), key, 5)); // Don't allow rollback to old client's newest block, if it was superseded by another client - EXPECT_EQ(5u, testobj.getBlockVersion(testobj.myClientId(), key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, testobj.myClientId(), blockId, 5); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_FALSE(testobj.checkAndUpdateVersion(testobj.myClientId(), blockId, 5)); // Don't allow rollback to old client's newest block, if it was superseded by another client + EXPECT_EQ(5u, testobj.getBlockVersion(testobj.myClientId(), blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientHigherVersion_oldClientIsSelf) { - setVersion(&testobj, testobj.myClientId(), key, 4); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 7)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(testobj.myClientId(), key, 6)); - EXPECT_EQ(6u, testobj.getBlockVersion(testobj.myClientId(), key)); - EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, key)); + setVersion(&testobj, testobj.myClientId(), blockId, 4); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 7)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(testobj.myClientId(), blockId, 6)); + EXPECT_EQ(6u, testobj.getBlockVersion(testobj.myClientId(), blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(clientId2, blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientLowerVersion_newClientIsSelf) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, testobj.myClientId(), key, 7); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 3)); - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(testobj.myClientId(), key)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, testobj.myClientId(), blockId, 7); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 3)); + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(testobj.myClientId(), blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientSameVersion_newClientIsSelf) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, testobj.myClientId(), key, 7); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 5)); // Don't allow rollback to old client's newest block, if it was superseded by another client - EXPECT_EQ(5u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(testobj.myClientId(), key)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, testobj.myClientId(), blockId, 7); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); // Don't allow rollback to old client's newest block, if it was superseded by another client + EXPECT_EQ(5u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(testobj.myClientId(), blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdateVersion_oldentry_oldClientHigherVersion_newClientIsSelf) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, testobj.myClientId(), key, 7); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 6)); - EXPECT_EQ(6u, testobj.getBlockVersion(clientId, key)); - EXPECT_EQ(7u, testobj.getBlockVersion(testobj.myClientId(), key)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, testobj.myClientId(), blockId, 7); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 6)); + EXPECT_EQ(6u, testobj.getBlockVersion(clientId, blockId)); + EXPECT_EQ(7u, testobj.getBlockVersion(testobj.myClientId(), blockId)); } TEST_F(KnownBlockVersionsTest, checkAndUpdate_twoEntriesDontInfluenceEachOther_differentKeys) { // Setup - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 100)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key2, 100)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 150)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId2, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 150)); // Checks - EXPECT_VERSION_IS(150, &testobj, key, clientId); - EXPECT_VERSION_IS(100, &testobj, key2, clientId); + EXPECT_VERSION_IS(150, &testobj, blockId, clientId); + EXPECT_VERSION_IS(100, &testobj, blockId2, clientId); } TEST_F(KnownBlockVersionsTest, checkAndUpdate_twoEntriesDontInfluenceEachOther_differentClientIds) { // Setup - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 100)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 100)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 150)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 150)); - EXPECT_VERSION_IS(150, &testobj, key, clientId); - EXPECT_VERSION_IS(100, &testobj, key, clientId2); + EXPECT_VERSION_IS(150, &testobj, blockId, clientId); + EXPECT_VERSION_IS(100, &testobj, blockId, clientId2); } TEST_F(KnownBlockVersionsTest, checkAndUpdate_allowsRollbackToSameClientWithSameVersionNumber) { - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 100)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 100)); } TEST_F(KnownBlockVersionsTest, checkAndUpdate_doesntAllowRollbackToOldClientWithSameVersionNumber) { - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, key, 100)); - EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, key, 10)); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId, blockId, 100)); + EXPECT_TRUE(testobj.checkAndUpdateVersion(clientId2, blockId, 10)); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 100)); } TEST_F(KnownBlockVersionsTest, saveAndLoad_empty) { TempFile stateFile(false); KnownBlockVersions(stateFile.path(), myClientId); - EXPECT_TRUE(KnownBlockVersions(stateFile.path(), myClientId).checkAndUpdateVersion(clientId, key, 1)); + EXPECT_TRUE(KnownBlockVersions(stateFile.path(), myClientId).checkAndUpdateVersion(clientId, blockId, 1)); } TEST_F(KnownBlockVersionsTest, saveAndLoad_oneentry) { TempFile stateFile(false); - EXPECT_TRUE(KnownBlockVersions(stateFile.path(), myClientId).checkAndUpdateVersion(clientId, key, 100)); + EXPECT_TRUE(KnownBlockVersions(stateFile.path(), myClientId).checkAndUpdateVersion(clientId, blockId, 100)); KnownBlockVersions obj(stateFile.path(), myClientId); - EXPECT_EQ(100u, obj.getBlockVersion(clientId, key)); + EXPECT_EQ(100u, obj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, saveAndLoad_threeentries) { TempFile stateFile(false); { KnownBlockVersions obj(stateFile.path(), myClientId); - EXPECT_TRUE(obj.checkAndUpdateVersion(obj.myClientId(), key, 100)); - EXPECT_TRUE(obj.checkAndUpdateVersion(obj.myClientId(), key2, 50)); - EXPECT_TRUE(obj.checkAndUpdateVersion(clientId, key, 150)); + EXPECT_TRUE(obj.checkAndUpdateVersion(obj.myClientId(), blockId, 100)); + EXPECT_TRUE(obj.checkAndUpdateVersion(obj.myClientId(), blockId2, 50)); + EXPECT_TRUE(obj.checkAndUpdateVersion(clientId, blockId, 150)); } KnownBlockVersions obj(stateFile.path(), myClientId); - EXPECT_EQ(100u, obj.getBlockVersion(obj.myClientId(), key)); - EXPECT_EQ(50u, obj.getBlockVersion(obj.myClientId(), key2)); - EXPECT_EQ(150u, obj.getBlockVersion(clientId, key)); + EXPECT_EQ(100u, obj.getBlockVersion(obj.myClientId(), blockId)); + EXPECT_EQ(50u, obj.getBlockVersion(obj.myClientId(), blockId2)); + EXPECT_EQ(150u, obj.getBlockVersion(clientId, blockId)); } TEST_F(KnownBlockVersionsTest, saveAndLoad_lastUpdateClientIdIsStored) { { KnownBlockVersions obj(stateFile.path(), myClientId); - EXPECT_TRUE(obj.checkAndUpdateVersion(clientId, key, 100)); - EXPECT_TRUE(obj.checkAndUpdateVersion(clientId2, key, 10)); + EXPECT_TRUE(obj.checkAndUpdateVersion(clientId, blockId, 100)); + EXPECT_TRUE(obj.checkAndUpdateVersion(clientId2, blockId, 10)); } KnownBlockVersions obj(stateFile.path(), myClientId); - EXPECT_FALSE(obj.checkAndUpdateVersion(clientId, key, 100)); - EXPECT_TRUE(obj.checkAndUpdateVersion(clientId2, key, 10)); - EXPECT_TRUE(obj.checkAndUpdateVersion(clientId, key, 101)); + EXPECT_FALSE(obj.checkAndUpdateVersion(clientId, blockId, 100)); + EXPECT_TRUE(obj.checkAndUpdateVersion(clientId2, blockId, 10)); + EXPECT_TRUE(obj.checkAndUpdateVersion(clientId, blockId, 101)); } TEST_F(KnownBlockVersionsTest, markAsDeleted_doesntAllowReIntroducing_sameClientId) { - setVersion(&testobj, clientId, key, 5); - testobj.markBlockAsDeleted(key); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 5)); + setVersion(&testobj, clientId, blockId, 5); + testobj.markBlockAsDeleted(blockId); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); } TEST_F(KnownBlockVersionsTest, markAsDeleted_doesntAllowReIntroducing_oldClientId) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key, 5); - testobj.markBlockAsDeleted(key); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 5)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId, 5); + testobj.markBlockAsDeleted(blockId); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); } TEST_F(KnownBlockVersionsTest, markAsDeleted_checkAndUpdateDoesntDestroyState) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key, 5); - testobj.markBlockAsDeleted(key); - EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, key, 5)); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId, 5); + testobj.markBlockAsDeleted(blockId); + EXPECT_FALSE(testobj.checkAndUpdateVersion(clientId, blockId, 5)); // Check block is still deleted - EXPECT_FALSE(testobj.blockShouldExist(key)); + EXPECT_FALSE(testobj.blockShouldExist(blockId)); } TEST_F(KnownBlockVersionsTest, blockShouldExist_unknownBlock) { - EXPECT_FALSE(testobj.blockShouldExist(key)); + EXPECT_FALSE(testobj.blockShouldExist(blockId)); } TEST_F(KnownBlockVersionsTest, blockShouldExist_knownBlock) { - setVersion(&testobj, clientId, key, 5); - EXPECT_TRUE(testobj.blockShouldExist(key)); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_TRUE(testobj.blockShouldExist(blockId)); } TEST_F(KnownBlockVersionsTest, blockShouldExist_deletedBlock) { - setVersion(&testobj, clientId, key, 5); - testobj.markBlockAsDeleted(key); - EXPECT_FALSE(testobj.blockShouldExist(key)); + setVersion(&testobj, clientId, blockId, 5); + testobj.markBlockAsDeleted(blockId); + EXPECT_FALSE(testobj.blockShouldExist(blockId)); } TEST_F(KnownBlockVersionsTest, path) { @@ -316,37 +316,37 @@ TEST_F(KnownBlockVersionsTest, path) { } TEST_F(KnownBlockVersionsTest, existingBlocks_empty) { - EXPECT_EQ(unordered_set({}), testobj.existingBlocks()); + EXPECT_EQ(unordered_set({}), testobj.existingBlocks()); } TEST_F(KnownBlockVersionsTest, existingBlocks_oneentry) { - setVersion(&testobj, clientId, key, 5); - EXPECT_EQ(unordered_set({key}), testobj.existingBlocks()); + setVersion(&testobj, clientId, blockId, 5); + EXPECT_EQ(unordered_set({blockId}), testobj.existingBlocks()); } TEST_F(KnownBlockVersionsTest, existingBlocks_twoentries) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key2, 5); - EXPECT_EQ(unordered_set({key, key2}), testobj.existingBlocks()); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId2, 5); + EXPECT_EQ(unordered_set({blockId, blockId2}), testobj.existingBlocks()); } TEST_F(KnownBlockVersionsTest, existingBlocks_twoentries_sameKey) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key, 5); - EXPECT_EQ(unordered_set({key}), testobj.existingBlocks()); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId, 5); + EXPECT_EQ(unordered_set({blockId}), testobj.existingBlocks()); } TEST_F(KnownBlockVersionsTest, existingBlocks_deletedEntry) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key2, 5); - testobj.markBlockAsDeleted(key2); - EXPECT_EQ(unordered_set({key}), testobj.existingBlocks()); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId2, 5); + testobj.markBlockAsDeleted(blockId2); + EXPECT_EQ(unordered_set({blockId}), testobj.existingBlocks()); } TEST_F(KnownBlockVersionsTest, existingBlocks_deletedEntries) { - setVersion(&testobj, clientId, key, 5); - setVersion(&testobj, clientId2, key2, 5); - testobj.markBlockAsDeleted(key); - testobj.markBlockAsDeleted(key2); - EXPECT_EQ(unordered_set({}), testobj.existingBlocks()); + setVersion(&testobj, clientId, blockId, 5); + setVersion(&testobj, clientId2, blockId2, 5); + testobj.markBlockAsDeleted(blockId); + testobj.markBlockAsDeleted(blockId2); + EXPECT_EQ(unordered_set({}), testobj.existingBlocks()); } diff --git a/test/blockstore/implementations/ondisk/OnDiskBlockStoreTest_Specific.cpp b/test/blockstore/implementations/ondisk/OnDiskBlockStoreTest_Specific.cpp index 4ecfe09c..eac53467 100644 --- a/test/blockstore/implementations/ondisk/OnDiskBlockStoreTest_Specific.cpp +++ b/test/blockstore/implementations/ondisk/OnDiskBlockStoreTest_Specific.cpp @@ -7,7 +7,7 @@ using ::testing::Test; using cpputils::TempDir; using cpputils::Data; using std::ifstream; -using blockstore::Key; +using blockstore::BlockId; using namespace blockstore::ondisk; @@ -20,12 +20,12 @@ public: TempDir baseDir; OnDiskBlockStore2 blockStore; - blockstore::Key CreateBlockReturnKey(const Data &initData) { + blockstore::BlockId CreateBlockReturnKey(const Data &initData) { return blockStore.create(initData.copy()); } - uint64_t getPhysicalBlockSize(const Key &key) { - ifstream stream((baseDir.path() / key.ToString().substr(0,3) / key.ToString().substr(3)).c_str()); + uint64_t getPhysicalBlockSize(const BlockId &blockId) { + ifstream stream((baseDir.path() / blockId.ToString().substr(0,3) / blockId.ToString().substr(3)).c_str()); stream.seekg(0, stream.end); return stream.tellg(); } @@ -36,8 +36,8 @@ TEST_F(OnDiskBlockStoreTest, PhysicalBlockSize_zerophysical) { } TEST_F(OnDiskBlockStoreTest, PhysicalBlockSize_zerovirtual) { - auto key = CreateBlockReturnKey(Data(0)); - auto baseSize = getPhysicalBlockSize(key); + auto blockId = CreateBlockReturnKey(Data(0)); + auto baseSize = getPhysicalBlockSize(blockId); EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(baseSize)); } @@ -53,14 +53,14 @@ TEST_F(OnDiskBlockStoreTest, PhysicalBlockSize_negativeboundaries) { } TEST_F(OnDiskBlockStoreTest, PhysicalBlockSize_positive) { - auto key = CreateBlockReturnKey(Data(10*1024)); - auto baseSize = getPhysicalBlockSize(key); + auto blockId = CreateBlockReturnKey(Data(10*1024)); + auto baseSize = getPhysicalBlockSize(blockId); EXPECT_EQ(10*1024u, blockStore.blockSizeFromPhysicalBlockSize(baseSize)); } TEST_F(OnDiskBlockStoreTest, NumBlocksIsCorrectAfterAddingTwoBlocksWithSameKeyPrefix) { - const Key key1 = Key::FromString("4CE72ECDD20877A12ADBF4E3927C0A13"); - const Key key2 = Key::FromString("4CE72ECDD20877A12ADBF4E3927C0A14"); + const BlockId key1 = BlockId::FromString("4CE72ECDD20877A12ADBF4E3927C0A13"); + const BlockId key2 = BlockId::FromString("4CE72ECDD20877A12ADBF4E3927C0A14"); EXPECT_TRUE(blockStore.tryCreate(key1, cpputils::Data(0))); EXPECT_TRUE(blockStore.tryCreate(key2, cpputils::Data(0))); EXPECT_EQ(2u, blockStore.numBlocks()); diff --git a/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockCreateTest.cpp b/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockCreateTest.cpp index 42ada196..fd3f53f5 100644 --- a/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockCreateTest.cpp +++ b/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockCreateTest.cpp @@ -24,26 +24,26 @@ public: OnDiskBlockCreateTest() // Don't create the temp file yet (therefore pass false to the TempFile constructor) : dir(), - key(Key::FromString("1491BB4932A389EE14BC7090AC772972")), - file(dir.path() / key.ToString().substr(0,3) / key.ToString().substr(3), false) { + key(BlockId::FromString("1491BB4932A389EE14BC7090AC772972")), + file(dir.path() / blockId.ToString().substr(0,3) / blockId.ToString().substr(3), false) { } TempDir dir; - Key key; + BlockId key; TempFile file; }; TEST_F(OnDiskBlockCreateTest, CreatingBlockCreatesFile) { EXPECT_FALSE(bf::exists(file.path())); - auto block = OnDiskBlock::CreateOnDisk(dir.path(), key, Data(0)); + auto block = OnDiskBlock::CreateOnDisk(dir.path(), blockId, Data(0)); EXPECT_TRUE(bf::exists(file.path())); EXPECT_TRUE(bf::is_regular_file(file.path())); } TEST_F(OnDiskBlockCreateTest, CreatingExistingBlockReturnsNull) { - auto block1 = OnDiskBlock::CreateOnDisk(dir.path(), key, Data(0)); - auto block2 = OnDiskBlock::CreateOnDisk(dir.path(), key, Data(0)); + auto block1 = OnDiskBlock::CreateOnDisk(dir.path(), blockId, Data(0)); + auto block2 = OnDiskBlock::CreateOnDisk(dir.path(), blockId, Data(0)); EXPECT_TRUE((bool)block1); EXPECT_FALSE((bool)block2); } @@ -54,7 +54,7 @@ public: Data ZEROES; OnDiskBlockCreateSizeTest(): - block(OnDiskBlock::CreateOnDisk(dir.path(), key, Data(GetParam()).FillWithZeroes()).value()), + block(OnDiskBlock::CreateOnDisk(dir.path(), blockId, Data(GetParam()).FillWithZeroes()).value()), ZEROES(block->size()) { ZEROES.FillWithZeroes(); diff --git a/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp b/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp index 45e44184..0bab7f82 100644 --- a/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp +++ b/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp @@ -26,25 +26,25 @@ public: OnDiskBlockFlushTest() // Don't create the temp file yet (therefore pass false to the TempFile constructor) : dir(), - key(Key::FromString("1491BB4932A389EE14BC7090AC772972")), - file(dir.path() / key.ToString().substr(0,3) / key.ToString().substr(3), false), + key(BlockId::FromString("1491BB4932A389EE14BC7090AC772972")), + file(dir.path() / blockId.ToString().substr(0,3) / blockId.ToString().substr(3), false), randomData(DataFixture::generate(GetParam())) { } TempDir dir; - Key key; + BlockId key; TempFile file; Data randomData; unique_ref CreateBlockAndLoadItFromDisk() { { - OnDiskBlock::CreateOnDisk(dir.path(), key, randomData.copy()).value(); + OnDiskBlock::CreateOnDisk(dir.path(), blockId, randomData.copy()).value(); } - return OnDiskBlock::LoadFromDisk(dir.path(), key).value(); + return OnDiskBlock::LoadFromDisk(dir.path(), blockId).value(); } unique_ref CreateBlock() { - return OnDiskBlock::CreateOnDisk(dir.path(), key, randomData.copy()).value(); + return OnDiskBlock::CreateOnDisk(dir.path(), blockId, randomData.copy()).value(); } void WriteDataToBlock(const unique_ref &block) { diff --git a/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp b/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp index 22d758e9..200a666b 100644 --- a/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp +++ b/test/blockstore/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp @@ -31,24 +31,24 @@ class OnDiskBlockLoadTest: public Test, public WithParamInterface { public: OnDiskBlockLoadTest(): dir(), - key(Key::FromString("1491BB4932A389EE14BC7090AC772972")), - file(dir.path() / key.ToString(), false) { + key(BlockId::FromString("1491BB4932A389EE14BC7090AC772972")), + file(dir.path() / blockId.ToString(), false) { } TempDir dir; - Key key; + BlockId key; TempFile file; void CreateBlockWithSize(size_t size) { Data data(size); - OnDiskBlock::CreateOnDisk(dir.path(), key, std::move(data)); + OnDiskBlock::CreateOnDisk(dir.path(), blockId, std::move(data)); } void StoreData(Data data) { - OnDiskBlock::CreateOnDisk(dir.path(), key, std::move(data)); + OnDiskBlock::CreateOnDisk(dir.path(), blockId, std::move(data)); } unique_ref LoadBlock() { - return OnDiskBlock::LoadFromDisk(dir.path(), key).value(); + return OnDiskBlock::LoadFromDisk(dir.path(), blockId).value(); } void EXPECT_BLOCK_DATA_EQ(const Data &expected, const OnDiskBlock &actual) { @@ -76,7 +76,7 @@ TEST_P(OnDiskBlockLoadTest, LoadedDataIsCorrect) { } TEST_F(OnDiskBlockLoadTest, LoadNotExistingBlock) { - Key key2 = Key::FromString("272EE5517627CFA147A971A8E6E747E0"); + BlockId key2 = BlockId::FromString("272EE5517627CFA147A971A8E6E747E0"); EXPECT_EQ(boost::none, OnDiskBlock::LoadFromDisk(dir.path(), key2)); } */ \ No newline at end of file diff --git a/test/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreTest_Specific.cpp b/test/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreTest_Specific.cpp index 065c109c..59670fb6 100644 --- a/test/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreTest_Specific.cpp +++ b/test/blockstore/implementations/parallelaccess/ParallelAccessBlockStoreTest_Specific.cpp @@ -21,8 +21,8 @@ public: FakeBlockStore *baseBlockStore; ParallelAccessBlockStore blockStore; - blockstore::Key CreateBlockReturnKey(const Data &initData) { - return blockStore.create(initData)->key(); + blockstore::BlockId CreateBlockReturnKey(const Data &initData) { + return blockStore.create(initData)->blockId(); } }; @@ -31,8 +31,8 @@ TEST_F(ParallelAccessBlockStoreTest, PhysicalBlockSize_zerophysical) { } TEST_F(ParallelAccessBlockStoreTest, PhysicalBlockSize_zerovirtual) { - auto key = CreateBlockReturnKey(Data(0)); - auto base = baseBlockStore->load(key).value(); + auto blockId = CreateBlockReturnKey(Data(0)); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(base->size())); } @@ -48,7 +48,7 @@ TEST_F(ParallelAccessBlockStoreTest, PhysicalBlockSize_negativeboundaries) { } TEST_F(ParallelAccessBlockStoreTest, PhysicalBlockSize_positive) { - auto key = CreateBlockReturnKey(Data(10*1024)); - auto base = baseBlockStore->load(key).value(); + auto blockId = CreateBlockReturnKey(Data(10*1024)); + auto base = baseBlockStore->load(blockId).value(); EXPECT_EQ(10*1024u, blockStore.blockSizeFromPhysicalBlockSize(base->size())); } diff --git a/test/blockstore/interface/helpers/BlockStoreWithRandomKeysTest.cpp b/test/blockstore/interface/helpers/BlockStoreWithRandomKeysTest.cpp index 9235d800..33b77e98 100644 --- a/test/blockstore/interface/helpers/BlockStoreWithRandomKeysTest.cpp +++ b/test/blockstore/interface/helpers/BlockStoreWithRandomKeysTest.cpp @@ -20,45 +20,45 @@ using namespace blockstore; class BlockStoreWithRandomKeysMock: public BlockStoreWithRandomKeys { public: - optional> tryCreate(const Key &key, Data data) { - return cpputils::nullcheck(std::unique_ptr(do_create(key, data))); + optional> tryCreate(const BlockId &blockId, Data data) { + return cpputils::nullcheck(std::unique_ptr(do_create(blockId, data))); } - MOCK_METHOD2(do_create, Block*(const Key &, const Data &data)); - unique_ref overwrite(const Key &key, Data data) { - return cpputils::nullcheck(std::unique_ptr(do_overwrite(key, data))).value(); + MOCK_METHOD2(do_create, Block*(const BlockId &, const Data &data)); + unique_ref overwrite(const BlockId &blockId, Data data) { + return cpputils::nullcheck(std::unique_ptr(do_overwrite(blockId, data))).value(); } - MOCK_METHOD2(do_overwrite, Block*(const Key &, const Data &data)); - optional> load(const Key &key) { - return cpputils::nullcheck(std::unique_ptr(do_load(key))); + MOCK_METHOD2(do_overwrite, Block*(const BlockId &, const Data &data)); + optional> load(const BlockId &blockId) { + return cpputils::nullcheck(std::unique_ptr(do_load(blockId))); } - MOCK_METHOD1(do_load, Block*(const Key &)); + MOCK_METHOD1(do_load, Block*(const BlockId &)); void remove(unique_ref block) {UNUSED(block);} - MOCK_METHOD1(remove, void(const Key &)); + MOCK_METHOD1(remove, void(const BlockId &)); MOCK_CONST_METHOD0(numBlocks, uint64_t()); MOCK_CONST_METHOD0(estimateNumFreeBytes, uint64_t()); MOCK_CONST_METHOD1(blockSizeFromPhysicalBlockSize, uint64_t(uint64_t)); - MOCK_CONST_METHOD1(forEachBlock, void(std::function)); + MOCK_CONST_METHOD1(forEachBlock, void(std::function)); }; class BlockMock: public Block { public: - BlockMock(): Block(Key::Random()) {} + BlockMock(): Block(BlockId::Random()) {} MOCK_CONST_METHOD0(data, const void*()); MOCK_METHOD3(write, void(const void*, uint64_t, uint64_t)); MOCK_METHOD0(flush, void()); MOCK_CONST_METHOD0(size, size_t()); MOCK_METHOD1(resize, void(size_t)); - MOCK_CONST_METHOD0(key, const Key&()); + MOCK_CONST_METHOD0(blockId, const BlockId&()); }; class BlockStoreWithRandomKeysTest: public Test { public: BlockStoreWithRandomKeysTest() :blockStoreMock(), blockStore(blockStoreMock), - key(Key::FromString("1491BB4932A389EE14BC7090AC772972")) {} + blockId(BlockId::FromString("1491BB4932A389EE14BC7090AC772972")) {} BlockStoreWithRandomKeysMock blockStoreMock; BlockStore &blockStore; - const blockstore::Key key; + const blockstore::BlockId blockId; Data createDataWithSize(size_t size) { Data fixture(DataFixture::generate(size)); @@ -87,8 +87,8 @@ TEST_F(BlockStoreWithRandomKeysTest, DataIsPassedThrough1024) { } TEST_F(BlockStoreWithRandomKeysTest, KeyHasCorrectSize) { - EXPECT_CALL(blockStoreMock, do_create(_, _)).WillOnce(Invoke([](const Key &key, const Data &) { - EXPECT_EQ(Key::STRING_LENGTH, key.ToString().size()); + EXPECT_CALL(blockStoreMock, do_create(_, _)).WillOnce(Invoke([](const BlockId &blockId, const Data &) { + EXPECT_EQ(BlockId::STRING_LENGTH, blockId.ToString().size()); return new BlockMock; })); @@ -96,14 +96,14 @@ TEST_F(BlockStoreWithRandomKeysTest, KeyHasCorrectSize) { } TEST_F(BlockStoreWithRandomKeysTest, TwoBlocksGetDifferentKeys) { - Key first_key = key; + BlockId first_blockId = blockId; EXPECT_CALL(blockStoreMock, do_create(_, _)) - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - first_key = key; + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + first_blockId = blockId; return new BlockMock; })) - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - EXPECT_NE(first_key, key); + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + EXPECT_NE(first_blockId, blockId); return new BlockMock; })); @@ -113,16 +113,16 @@ TEST_F(BlockStoreWithRandomKeysTest, TwoBlocksGetDifferentKeys) { } TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExists) { - Key first_key = key; + BlockId first_blockId = blockId; Data data = createDataWithSize(1024); EXPECT_CALL(blockStoreMock, do_create(_, Eq(ByRef(data)))) - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - first_key = key; + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + first_blockId = blockId; return nullptr; })) //TODO Check that this test case fails when the second do_create call gets different data - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - EXPECT_NE(first_key, key); + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + EXPECT_NE(first_blockId, blockId); return new BlockMock; })); @@ -130,20 +130,20 @@ TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExists) { } TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExistsTwoTimes) { - Key first_key = key; + BlockId first_blockId = blockId; Data data = createDataWithSize(1024); EXPECT_CALL(blockStoreMock, do_create(_, Eq(ByRef(data)))) - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - first_key = key; + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + first_blockId = blockId; return nullptr; })) //TODO Check that this test case fails when the second/third do_create calls get different data - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - first_key = key; + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + first_blockId = blockId; return nullptr; })) - .WillOnce(Invoke([&first_key](const Key &key, const Data &) { - EXPECT_NE(first_key, key); + .WillOnce(Invoke([&first_blockId](const BlockId &blockId, const Data &) { + EXPECT_NE(first_blockId, blockId); return new BlockMock; })); diff --git a/test/blockstore/testutils/BlockStore2Test.h b/test/blockstore/testutils/BlockStore2Test.h index b6366010..a0aad969 100644 --- a/test/blockstore/testutils/BlockStore2Test.h +++ b/test/blockstore/testutils/BlockStore2Test.h @@ -56,231 +56,231 @@ public: TYPED_TEST_CASE_P(BlockStore2Test); TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCallingTryCreateOnExistingBlock_thenFails) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); - EXPECT_FALSE(this->blockStore->tryCreate(key, cpputils::Data(1024))); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); + EXPECT_FALSE(this->blockStore->tryCreate(blockId, cpputils::Data(1024))); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds) { - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(1024))); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(1024))); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds) { this->blockStore->create(cpputils::Data(512)); - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(1024))); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(1024))); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadExistingBlock_thenSucceeds) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); - EXPECT_NE(boost::none, this->blockStore->load(key)); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); + EXPECT_NE(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenLoadNonexistingBlock_thenFails) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_EQ(boost::none, this->blockStore->load(key)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_EQ(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadNonexistingBlock_thenFails) { this->blockStore->create(cpputils::Data(512)); - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_EQ(boost::none, this->blockStore->load(key)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_EQ(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringExistingBlock_thenSucceeds) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); - this->blockStore->store(key, cpputils::Data(1024)); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); + this->blockStore->store(blockId, cpputils::Data(1024)); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - this->blockStore->store(key, cpputils::Data(1024)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + this->blockStore->store(blockId, cpputils::Data(1024)); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds) { this->blockStore->create(cpputils::Data(512)); - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - this->blockStore->store(key, cpputils::Data(1024)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + this->blockStore->store(blockId, cpputils::Data(1024)); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingTwoBlocks_thenTheyGetDifferentKeys) { - blockstore::Key key1 = this->blockStore->create(cpputils::Data(1024)); - blockstore::Key key2 = this->blockStore->create(cpputils::Data(1024)); - EXPECT_NE(key1, key2); + blockstore::BlockId blockId1 = this->blockStore->create(cpputils::Data(1024)); + blockstore::BlockId blockId2 = this->blockStore->create(cpputils::Data(1024)); + EXPECT_NE(blockId1, blockId2); } TYPED_TEST_P(BlockStore2Test, givenOtherwiseEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); - EXPECT_NE(boost::none, this->blockStore->load(key)); - EXPECT_TRUE(this->blockStore->remove(key)); - EXPECT_EQ(boost::none, this->blockStore->load(key)); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); + EXPECT_NE(boost::none, this->blockStore->load(blockId)); + EXPECT_TRUE(this->blockStore->remove(blockId)); + EXPECT_EQ(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); this->blockStore->create(cpputils::Data(512)); - EXPECT_NE(boost::none, this->blockStore->load(key)); - EXPECT_TRUE(this->blockStore->remove(key)); - EXPECT_EQ(boost::none, this->blockStore->load(key)); + EXPECT_NE(boost::none, this->blockStore->load(blockId)); + EXPECT_TRUE(this->blockStore->remove(blockId)); + EXPECT_EQ(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, givenOtherwiseEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); - EXPECT_TRUE(this->blockStore->remove(key)); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); + EXPECT_TRUE(this->blockStore->remove(blockId)); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds) { - blockstore::Key key = this->blockStore->create(cpputils::Data(1024)); + blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024)); this->blockStore->create(cpputils::Data(512)); - EXPECT_EQ(true, this->blockStore->remove(key)); + EXPECT_EQ(true, this->blockStore->remove(blockId)); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenRemovingNonexistingBlock_thenFails) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - auto result = this->blockStore->remove(key); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + auto result = this->blockStore->remove(blockId); EXPECT_EQ(false, result); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingNonexistingBlock_thenFails) { - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973"); - blockstore::Key differentKey = blockstore::Key::FromString("290AC2C7097274A389EE14B91B72B493"); - ASSERT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(1024))); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973"); + blockstore::BlockId differentKey = blockstore::BlockId::FromString("290AC2C7097274A389EE14B91B72B493"); + ASSERT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(1024))); EXPECT_EQ(false, this->blockStore->remove(differentKey)); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) { - auto key = this->blockStore->create(cpputils::Data(0)); - auto loaded = this->blockStore->load(key).value(); + auto blockId = this->blockStore->create(cpputils::Data(0)); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) { this->blockStore->create(cpputils::Data(512)); - auto key = this->blockStore->create(cpputils::Data(0)); - auto loaded = this->blockStore->load(key).value(); + auto blockId = this->blockStore->create(cpputils::Data(0)); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) { cpputils::Data data = cpputils::DataFixture::generate(1024); - auto key = this->blockStore->create(data.copy()); - auto loaded = this->blockStore->load(key).value(); + auto blockId = this->blockStore->create(data.copy()); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(loaded, data); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) { this->blockStore->create(cpputils::Data(512)); cpputils::Data data = cpputils::DataFixture::generate(1024); - auto key = this->blockStore->create(data.copy()); - auto loaded = this->blockStore->load(key).value(); + auto blockId = this->blockStore->create(data.copy()); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(loaded, data); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) { - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973"); - ASSERT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(0))); - auto loaded = this->blockStore->load(key).value(); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973"); + ASSERT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(0))); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) { - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973"); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973"); this->blockStore->create(cpputils::Data(512)); - ASSERT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(0))); - auto loaded = this->blockStore->load(key).value(); + ASSERT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(0))); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) { - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973"); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973"); cpputils::Data data = cpputils::DataFixture::generate(1024); - ASSERT_TRUE(this->blockStore->tryCreate(key, data.copy())); - auto loaded = this->blockStore->load(key).value(); + ASSERT_TRUE(this->blockStore->tryCreate(blockId, data.copy())); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(loaded, data); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) { - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973"); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973"); this->blockStore->create(cpputils::Data(512)); cpputils::Data data = cpputils::DataFixture::generate(1024); - ASSERT_TRUE(this->blockStore->tryCreate(key, data.copy())); - auto loaded = this->blockStore->load(key).value(); + ASSERT_TRUE(this->blockStore->tryCreate(blockId, data.copy())); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(loaded, data); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingNonExistingEmptyBlock_thenCorrectBlockLoads) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - this->blockStore->store(key, cpputils::Data(0)); - auto loaded = this->blockStore->load(key).value(); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + this->blockStore->store(blockId, cpputils::Data(0)); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingNonExistingEmptyBlock_thenCorrectBlockLoads) { this->blockStore->create(cpputils::Data(512)); - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - this->blockStore->store(key, cpputils::Data(0)); - auto loaded = this->blockStore->load(key).value(); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + this->blockStore->store(blockId, cpputils::Data(0)); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); cpputils::Data data = cpputils::DataFixture::generate(1024); - this->blockStore->store(key, data.copy()); - auto loaded = this->blockStore->load(key).value(); + this->blockStore->store(blockId, data.copy()); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(data, loaded); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads) { this->blockStore->create(cpputils::Data(512)); - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); cpputils::Data data = cpputils::DataFixture::generate(1024); - this->blockStore->store(key, data.copy()); - auto loaded = this->blockStore->load(key).value(); + this->blockStore->store(blockId, data.copy()); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(data, loaded); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads) { - auto key = this->blockStore->create(cpputils::Data(512)); - this->blockStore->store(key, cpputils::Data(0)); - auto loaded = this->blockStore->load(key).value(); + auto blockId = this->blockStore->create(cpputils::Data(512)); + this->blockStore->store(blockId, cpputils::Data(0)); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads) { this->blockStore->create(cpputils::Data(512)); - auto key = this->blockStore->create(cpputils::Data(512)); - this->blockStore->store(key, cpputils::Data(0)); - auto loaded = this->blockStore->load(key).value(); + auto blockId = this->blockStore->create(cpputils::Data(512)); + this->blockStore->store(blockId, cpputils::Data(0)); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(0u, loaded.size()); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads) { - auto key = this->blockStore->create(cpputils::Data(512)); + auto blockId = this->blockStore->create(cpputils::Data(512)); cpputils::Data data = cpputils::DataFixture::generate(1024); - this->blockStore->store(key, data.copy()); - auto loaded = this->blockStore->load(key).value(); + this->blockStore->store(blockId, data.copy()); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(data, loaded); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads) { this->blockStore->create(cpputils::Data(512)); - auto key = this->blockStore->create(cpputils::Data(512)); + auto blockId = this->blockStore->create(cpputils::Data(512)); cpputils::Data data = cpputils::DataFixture::generate(1024); - this->blockStore->store(key, data.copy()); - auto loaded = this->blockStore->load(key).value(); + this->blockStore->store(blockId, data.copy()); + auto loaded = this->blockStore->load(blockId).value(); EXPECT_EQ(data, loaded); } TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenLoadingNonExistingBlock_thenFails) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_EQ(boost::none, this->blockStore->load(key)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_EQ(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadingNonExistingBlock_thenFails) { this->blockStore->create(cpputils::Data(512)); - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); - EXPECT_EQ(boost::none, this->blockStore->load(key)); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); + EXPECT_EQ(boost::none, this->blockStore->load(blockId)); } TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectOnEmptyBlockstore) { @@ -296,8 +296,8 @@ TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterCreatingOneBlock) { TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterRemovingTheLastBlock) { auto blockStore = this->fixture.createBlockStore(); - blockstore::Key key = blockStore->create(cpputils::Data(1)); - EXPECT_TRUE(blockStore->remove(key)); + blockstore::BlockId blockId = blockStore->create(cpputils::Data(1)); + EXPECT_TRUE(blockStore->remove(blockId)); EXPECT_EQ(0u, blockStore->numBlocks()); } @@ -310,23 +310,23 @@ TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterCreatingTwoBlocks) { TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterRemovingABlock) { auto blockStore = this->fixture.createBlockStore(); - blockstore::Key key = blockStore->create(cpputils::Data(1)); + blockstore::BlockId blockId = blockStore->create(cpputils::Data(1)); blockStore->create(cpputils::Data(1)); - EXPECT_TRUE(blockStore->remove(key)); + EXPECT_TRUE(blockStore->remove(blockId)); EXPECT_EQ(1u, blockStore->numBlocks()); } TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterStoringANewBlock) { - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); auto blockStore = this->fixture.createBlockStore(); - blockStore->store(key, cpputils::Data(1)); + blockStore->store(blockId, cpputils::Data(1)); EXPECT_EQ(1u, blockStore->numBlocks()); } TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterStoringAnExistingBlock) { auto blockStore = this->fixture.createBlockStore(); - blockstore::Key key = blockStore->create(cpputils::Data(1)); - blockStore->store(key, cpputils::Data(1)); + blockstore::BlockId blockId = blockStore->create(cpputils::Data(1)); + blockStore->store(blockId, cpputils::Data(1)); EXPECT_EQ(1u, blockStore->numBlocks()); } @@ -339,35 +339,35 @@ TYPED_TEST_P(BlockStore2Test, ForEachBlock_zeroblocks) { TYPED_TEST_P(BlockStore2Test, ForEachBlock_oneblock) { auto blockStore = this->fixture.createBlockStore(); - auto key = blockStore->create(cpputils::Data(1)); + auto blockId = blockStore->create(cpputils::Data(1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({key}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({blockId}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStore2Test, ForEachBlock_twoblocks) { auto blockStore = this->fixture.createBlockStore(); - auto key1 = blockStore->create(cpputils::Data(1)); - auto key2 = blockStore->create(cpputils::Data(1)); + auto blockId1 = blockStore->create(cpputils::Data(1)); + auto blockId2 = blockStore->create(cpputils::Data(1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({key1, key2}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({blockId1, blockId2}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStore2Test, ForEachBlock_threeblocks) { auto blockStore = this->fixture.createBlockStore(); - auto key1 = blockStore->create(cpputils::Data(1)); - auto key2 = blockStore->create(cpputils::Data(1)); - auto key3 = blockStore->create(cpputils::Data(1)); + auto blockId1 = blockStore->create(cpputils::Data(1)); + auto blockId2 = blockStore->create(cpputils::Data(1)); + auto blockId3 = blockStore->create(cpputils::Data(1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({key1, key2, key3}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({blockId1, blockId2, blockId3}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStore2Test, ForEachBlock_doesntListRemovedBlocks_oneblock) { auto blockStore = this->fixture.createBlockStore(); - auto key1 = blockStore->create(cpputils::Data(1)); - EXPECT_TRUE(blockStore->remove(key1)); + auto blockId1 = blockStore->create(cpputils::Data(1)); + EXPECT_TRUE(blockStore->remove(blockId1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); this->EXPECT_UNORDERED_EQ({}, mockForEachBlockCallback.called_with); @@ -375,12 +375,12 @@ TYPED_TEST_P(BlockStore2Test, ForEachBlock_doesntListRemovedBlocks_oneblock) { TYPED_TEST_P(BlockStore2Test, ForEachBlock_doesntListRemovedBlocks_twoblocks) { auto blockStore = this->fixture.createBlockStore(); - auto key1 = blockStore->create(cpputils::Data(1)); - auto key2 = blockStore->create(cpputils::Data(1)); - EXPECT_TRUE(blockStore->remove(key1)); + auto blockId1 = blockStore->create(cpputils::Data(1)); + auto blockId2 = blockStore->create(cpputils::Data(1)); + EXPECT_TRUE(blockStore->remove(blockId1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({key2}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({blockId2}, mockForEachBlockCallback.called_with); } REGISTER_TYPED_TEST_CASE_P(BlockStore2Test, diff --git a/test/blockstore/testutils/BlockStoreTest.h b/test/blockstore/testutils/BlockStoreTest.h index 29e509ec..1d54a42c 100644 --- a/test/blockstore/testutils/BlockStoreTest.h +++ b/test/blockstore/testutils/BlockStoreTest.h @@ -10,13 +10,13 @@ class MockForEachBlockCallback final { public: - std::function callback() { - return [this] (const blockstore::Key &key) { - called_with.push_back(key); + std::function callback() { + return [this] (const blockstore::BlockId &blockId) { + called_with.push_back(blockId); }; } - std::vector called_with; + std::vector called_with; }; class BlockStoreTestFixture { @@ -44,9 +44,9 @@ public: EXPECT_EQ(0, std::memcmp(fixture.data(), block->data(), fixture.size())); // Store and reload block and check data is still correct - auto key = block->key(); + auto blockId = block->blockId(); cpputils::destruct(std::move(block)); - block = blockStore->load(key).value(); + block = blockStore->load(blockId).value(); EXPECT_EQ(0, std::memcmp(fixture.data(), block->data(), fixture.size())); } @@ -71,27 +71,27 @@ public: TYPED_TEST_CASE_P(BlockStoreTest); -TYPED_TEST_P(BlockStoreTest, TwoCreatedBlocksHaveDifferentKeys) { +TYPED_TEST_P(BlockStoreTest, TwoCreatedBlocksHaveDifferentBlockIds) { auto blockStore = this->fixture.createBlockStore(); auto block1 = blockStore->create(cpputils::Data(1024)); auto block2 = blockStore->create(cpputils::Data(1024)); - EXPECT_NE(block1->key(), block2->key()); + EXPECT_NE(block1->blockId(), block2->blockId()); } TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting_DeleteByBlock) { auto blockStore = this->fixture.createBlockStore(); - auto blockkey = blockStore->create(cpputils::Data(1024))->key(); - auto block = blockStore->load(blockkey); + auto blockId = blockStore->create(cpputils::Data(1024))->blockId(); + auto block = blockStore->load(blockId); EXPECT_NE(boost::none, block); blockStore->remove(std::move(*block)); - EXPECT_EQ(boost::none, blockStore->load(blockkey)); + EXPECT_EQ(boost::none, blockStore->load(blockId)); } -TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting_DeleteByKey) { +TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting_DeleteByBlockId) { auto blockStore = this->fixture.createBlockStore(); - auto blockkey = blockStore->create(cpputils::Data(1024))->key(); - blockStore->remove(blockkey); - EXPECT_EQ(boost::none, blockStore->load(blockkey)); + auto blockId = blockStore->create(cpputils::Data(1024))->blockId(); + blockStore->remove(blockId); + EXPECT_EQ(boost::none, blockStore->load(blockId)); } TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectOnEmptyBlockstore) { @@ -118,10 +118,10 @@ TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteB EXPECT_EQ(0u, blockStore->numBlocks()); } -TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByKey) { +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlockId) { auto blockStore = this->fixture.createBlockStore(); - auto key = blockStore->create(cpputils::Data(1))->key(); - blockStore->remove(key); + auto blockId = blockStore->create(cpputils::Data(1))->blockId(); + blockStore->remove(blockId); EXPECT_EQ(0u, blockStore->numBlocks()); } @@ -161,11 +161,11 @@ TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlock EXPECT_EQ(1u, blockStore->numBlocks()); } -TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock_DeleteByKey) { +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlockId) { auto blockStore = this->fixture.createBlockStore(); - auto key = blockStore->create(cpputils::Data(1))->key(); + auto blockId = blockStore->create(cpputils::Data(1))->blockId(); blockStore->create(cpputils::Data(1)); - blockStore->remove(key); + blockStore->remove(blockId); EXPECT_EQ(1u, blockStore->numBlocks()); } @@ -189,7 +189,7 @@ TYPED_TEST_P(BlockStoreTest, ForEachBlock_oneblock) { auto block = blockStore->create(cpputils::Data(1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({block->key()}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({block->blockId()}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStoreTest, ForEachBlock_twoblocks) { @@ -198,7 +198,7 @@ TYPED_TEST_P(BlockStoreTest, ForEachBlock_twoblocks) { auto block2 = blockStore->create(cpputils::Data(1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({block1->key(), block2->key()}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({block1->blockId(), block2->blockId()}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStoreTest, ForEachBlock_threeblocks) { @@ -208,7 +208,7 @@ TYPED_TEST_P(BlockStoreTest, ForEachBlock_threeblocks) { auto block3 = blockStore->create(cpputils::Data(1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({block1->key(), block2->key(), block3->key()}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({block1->blockId(), block2->blockId(), block3->blockId()}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStoreTest, ForEachBlock_doesntListRemovedBlocks_oneblock) { @@ -227,7 +227,7 @@ TYPED_TEST_P(BlockStoreTest, ForEachBlock_doesntListRemovedBlocks_twoblocks) { blockStore->remove(std::move(block1)); MockForEachBlockCallback mockForEachBlockCallback; blockStore->forEachBlock(mockForEachBlockCallback.callback()); - this->EXPECT_UNORDERED_EQ({block2->key()}, mockForEachBlockCallback.called_with); + this->EXPECT_UNORDERED_EQ({block2->blockId()}, mockForEachBlockCallback.called_with); } TYPED_TEST_P(BlockStoreTest, Resize_Larger_FromZero) { @@ -302,20 +302,20 @@ REGISTER_TYPED_TEST_CASE_P(BlockStoreTest, AfterCreate_FlushesWhenDestructed, AfterLoad_FlushesWhenDestructed, LoadNonExistingBlock, - TwoCreatedBlocksHaveDifferentKeys, + TwoCreatedBlocksHaveDifferentBlockIds, BlockIsNotLoadableAfterDeleting_DeleteByBlock, - BlockIsNotLoadableAfterDeleting_DeleteByKey, + BlockIsNotLoadableAfterDeleting_DeleteByBlockId, NumBlocksIsCorrectOnEmptyBlockstore, NumBlocksIsCorrectAfterAddingOneBlock, NumBlocksIsCorrectAfterAddingOneBlock_AfterClosingBlock, NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlock, - NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByKey, + NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlockId, NumBlocksIsCorrectAfterAddingTwoBlocks, NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingFirstBlock, NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingSecondBlock, NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingBothBlocks, NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlock, - NumBlocksIsCorrectAfterRemovingABlock_DeleteByKey, + NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlockId, WriteAndReadImmediately, WriteAndReadAfterLoading, WriteTwiceAndRead, diff --git a/test/blockstore/testutils/BlockStoreTest_Data.h b/test/blockstore/testutils/BlockStoreTest_Data.h index 3804faea..6be3c920 100644 --- a/test/blockstore/testutils/BlockStoreTest_Data.h +++ b/test/blockstore/testutils/BlockStoreTest_Data.h @@ -28,9 +28,9 @@ public: } void TestWriteAndReadAfterLoading() { - blockstore::Key key = CreateBlockWriteToItAndReturnKey(foregroundData); + blockstore::BlockId blockId = CreateBlockWriteToItAndReturnKey(foregroundData); - auto loaded_block = blockStore->load(key).value(); + auto loaded_block = blockStore->load(blockId).value(); EXPECT_DATA_READS_AS(foregroundData, *loaded_block, testData.offset, testData.count); EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(*loaded_block, testData.offset, testData.count); } @@ -44,61 +44,61 @@ public: } void TestOverwriteSameSizeAndReadImmediately() { - auto key = blockStore->create(cpputils::Data(testData.blocksize))->key(); - auto block = blockStore->overwrite(key, backgroundData.copy()); + auto blockId = blockStore->create(cpputils::Data(testData.blocksize))->blockId(); + auto block = blockStore->overwrite(blockId, backgroundData.copy()); EXPECT_EQ(testData.blocksize, block->size()); EXPECT_DATA_READS_AS(backgroundData, *block, 0, testData.blocksize); } void TestOverwriteSameSizeAndReadAfterLoading() { - auto key = blockStore->create(cpputils::Data(testData.blocksize))->key(); - blockStore->overwrite(key, backgroundData.copy()); - auto block = blockStore->load(key).value(); + auto blockId = blockStore->create(cpputils::Data(testData.blocksize))->blockId(); + blockStore->overwrite(blockId, backgroundData.copy()); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(testData.blocksize, block->size()); EXPECT_DATA_READS_AS(backgroundData, *block, 0, testData.blocksize); } void TestOverwriteSmallerSizeAndReadImmediately() { - auto key = blockStore->create(cpputils::Data(testData.blocksize))->key(); - auto block = blockStore->overwrite(key, foregroundData.copy()); + auto blockId = blockStore->create(cpputils::Data(testData.blocksize))->blockId(); + auto block = blockStore->overwrite(blockId, foregroundData.copy()); EXPECT_EQ(testData.count, block->size()); EXPECT_DATA_READS_AS(foregroundData, *block, 0, testData.count); } void TestOverwriteSmallerSizeAndReadAfterLoading() { - auto key = blockStore->create(cpputils::Data(testData.blocksize))->key(); - blockStore->overwrite(key, foregroundData.copy()); - auto block = blockStore->load(key).value(); + auto blockId = blockStore->create(cpputils::Data(testData.blocksize))->blockId(); + blockStore->overwrite(blockId, foregroundData.copy()); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(testData.count, block->size()); EXPECT_DATA_READS_AS(foregroundData, *block, 0, testData.count); } void TestOverwriteLargerSizeAndReadImmediately() { - auto key = blockStore->create(cpputils::Data(testData.count))->key(); - auto block = blockStore->overwrite(key, backgroundData.copy()); + auto blockId = blockStore->create(cpputils::Data(testData.count))->blockId(); + auto block = blockStore->overwrite(blockId, backgroundData.copy()); EXPECT_EQ(testData.blocksize, block->size()); EXPECT_DATA_READS_AS(backgroundData, *block, 0, testData.blocksize); } void TestOverwriteLargerSizeAndReadAfterLoading() { - auto key = blockStore->create(cpputils::Data(testData.count))->key(); - blockStore->overwrite(key, backgroundData.copy()); - auto block = blockStore->load(key).value(); + auto blockId = blockStore->create(cpputils::Data(testData.count))->blockId(); + blockStore->overwrite(blockId, backgroundData.copy()); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(testData.blocksize, block->size()); EXPECT_DATA_READS_AS(backgroundData, *block, 0, testData.blocksize); } void TestOverwriteNonexistingAndReadImmediately() { - auto key = blockStore->createKey(); - auto block = blockStore->overwrite(key, backgroundData.copy()); + auto blockId = blockStore->createBlockId(); + auto block = blockStore->overwrite(blockId, backgroundData.copy()); EXPECT_EQ(testData.blocksize, block->size()); EXPECT_DATA_READS_AS(backgroundData, *block, 0, testData.blocksize); } void TestOverwriteNonexistingAndReadAfterLoading() { - auto key = blockStore->createKey(); - blockStore->overwrite(key, backgroundData.copy()); - auto block = blockStore->load(key).value(); + auto blockId = blockStore->createBlockId(); + blockStore->overwrite(blockId, backgroundData.copy()); + auto block = blockStore->load(blockId).value(); EXPECT_EQ(testData.blocksize, block->size()); EXPECT_DATA_READS_AS(backgroundData, *block, 0, testData.blocksize); } @@ -109,11 +109,11 @@ private: cpputils::Data foregroundData; cpputils::Data backgroundData; - blockstore::Key CreateBlockWriteToItAndReturnKey(const cpputils::Data &to_write) { + blockstore::BlockId CreateBlockWriteToItAndReturnKey(const cpputils::Data &to_write) { auto newblock = blockStore->create(cpputils::Data(testData.blocksize).FillWithZeroes()); newblock->write(to_write.data(), testData.offset, testData.count); - return newblock->key(); + return newblock->blockId(); } void EXPECT_DATA_READS_AS(const cpputils::Data &expected, const blockstore::Block &block, off_t offset, size_t count) { diff --git a/test/blockstore/testutils/BlockStoreTest_Size.h b/test/blockstore/testutils/BlockStoreTest_Size.h index 85effa79..4ddf3eb8 100644 --- a/test/blockstore/testutils/BlockStoreTest_Size.h +++ b/test/blockstore/testutils/BlockStoreTest_Size.h @@ -17,8 +17,8 @@ public: } void TestLoadingUnchangedBlockHasCorrectSize() { - blockstore::Key key = CreateBlock()->key(); - auto loaded_block = blockStore->load(key).value(); + blockstore::BlockId blockId = CreateBlock()->blockId(); + auto loaded_block = blockStore->load(blockId).value(); EXPECT_EQ(size, loaded_block->size()); } @@ -30,8 +30,8 @@ public: void TestLoadingUnchangedBlockData() { cpputils::Data data = cpputils::DataFixture::generate(size); - blockstore::Key key = blockStore->create(data)->key(); - auto loaded_block = blockStore->load(key).value(); + blockstore::BlockId blockId = blockStore->create(data)->blockId(); + auto loaded_block = blockStore->load(blockId).value(); EXPECT_EQ(0, std::memcmp(data.data(), loaded_block->data(), size)); } @@ -69,34 +69,34 @@ public: void TestAfterCreate_FlushesWhenDestructed() { cpputils::Data randomData = cpputils::DataFixture::generate(size); - blockstore::Key key = blockstore::Key::Null(); + blockstore::BlockId blockId = blockstore::BlockId::Null(); { auto block = blockStore->create(cpputils::Data(size)); - key = block->key(); + blockId = block->blockId(); WriteDataToBlock(block.get(), randomData); } - auto loaded_block = blockStore->load(key).value(); + auto loaded_block = blockStore->load(blockId).value(); EXPECT_BLOCK_DATA_CORRECT(*loaded_block, randomData); } void TestAfterLoad_FlushesWhenDestructed() { cpputils::Data randomData = cpputils::DataFixture::generate(size); - blockstore::Key key = blockstore::Key::Null(); + blockstore::BlockId blockId = blockstore::BlockId::Null(); { - key = CreateBlock()->key(); - auto block = blockStore->load(key).value(); + blockId = CreateBlock()->blockId(); + auto block = blockStore->load(blockId).value(); WriteDataToBlock(block.get(), randomData); } - auto loaded_block = blockStore->load(key).value(); + auto loaded_block = blockStore->load(blockId).value(); EXPECT_BLOCK_DATA_CORRECT(*loaded_block, randomData); } void TestLoadNonExistingBlock() { - EXPECT_EQ(boost::none, blockStore->load(key)); + EXPECT_EQ(boost::none, blockStore->load(blockId)); } private: - const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); + const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); cpputils::unique_ref blockStore; size_t size; @@ -107,23 +107,23 @@ private: } cpputils::unique_ref StoreDataToBlockAndLoadIt(const cpputils::Data &data) { - blockstore::Key key = StoreDataToBlockAndGetKey(data); - return blockStore->load(key).value(); + blockstore::BlockId blockId = StoreDataToBlockAndGetKey(data); + return blockStore->load(blockId).value(); } - blockstore::Key StoreDataToBlockAndGetKey(const cpputils::Data &data) { - return blockStore->create(data)->key(); + blockstore::BlockId StoreDataToBlockAndGetKey(const cpputils::Data &data) { + return blockStore->create(data)->blockId(); } cpputils::unique_ref StoreDataToBlockAndLoadItDirectlyAfterFlushing(const cpputils::Data &data) { auto block = blockStore->create(data); block->flush(); - return blockStore->load(block->key()).value(); + return blockStore->load(block->blockId()).value(); } cpputils::unique_ref CreateBlockAndLoadIt() { - blockstore::Key key = CreateBlock()->key(); - return blockStore->load(key).value(); + blockstore::BlockId blockId = CreateBlock()->blockId(); + return blockStore->load(blockId).value(); } cpputils::unique_ref CreateBlock() { diff --git a/test/blockstore/testutils/BlockStoreWithRandomKeysTest.h b/test/blockstore/testutils/BlockStoreWithRandomKeysTest.h index 46d1879b..f08fcad3 100644 --- a/test/blockstore/testutils/BlockStoreWithRandomKeysTest.h +++ b/test/blockstore/testutils/BlockStoreWithRandomKeysTest.h @@ -22,7 +22,7 @@ public: "Given test fixture for instantiating the (type parameterized) BlockStoreWithRandomKeysTest must inherit from BlockStoreWithRandomKeysTestFixture" ); - blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); + blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972"); const std::vector SIZES = {0, 1, 1024, 4096, 10*1024*1024}; @@ -33,45 +33,45 @@ TYPED_TEST_CASE_P(BlockStoreWithRandomKeysTest); TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndSameSize) { auto blockStore = this->fixture.createBlockStore(); - auto block = blockStore->tryCreate(this->key, cpputils::Data(1024)); + auto block = blockStore->tryCreate(this->blockId, cpputils::Data(1024)); (*block)->flush(); //TODO Ideally, flush shouldn't be necessary here. - auto block2 = blockStore->tryCreate(this->key, cpputils::Data(1024)); + auto block2 = blockStore->tryCreate(this->blockId, cpputils::Data(1024)); EXPECT_NE(boost::none, block); EXPECT_EQ(boost::none, block2); } TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndDifferentSize) { auto blockStore = this->fixture.createBlockStore(); - auto block = blockStore->tryCreate(this->key, cpputils::Data(1024)); + auto block = blockStore->tryCreate(this->blockId, cpputils::Data(1024)); (*block)->flush(); //TODO Ideally, flush shouldn't be necessary here. - auto block2 = blockStore->tryCreate(this->key, cpputils::Data(4096)); + auto block2 = blockStore->tryCreate(this->blockId, cpputils::Data(4096)); EXPECT_NE(boost::none, block); EXPECT_EQ(boost::none, block2); } TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndFirstNullSize) { auto blockStore = this->fixture.createBlockStore(); - auto block = blockStore->tryCreate(this->key, cpputils::Data(0)); + auto block = blockStore->tryCreate(this->blockId, cpputils::Data(0)); (*block)->flush(); //TODO Ideally, flush shouldn't be necessary here. - auto block2 = blockStore->tryCreate(this->key, cpputils::Data(1024)); + auto block2 = blockStore->tryCreate(this->blockId, cpputils::Data(1024)); EXPECT_NE(boost::none, block); EXPECT_EQ(boost::none, block2); } TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndSecondNullSize) { auto blockStore = this->fixture.createBlockStore(); - auto block = blockStore->tryCreate(this->key, cpputils::Data(1024)); + auto block = blockStore->tryCreate(this->blockId, cpputils::Data(1024)); (*block)->flush(); //TODO Ideally, flush shouldn't be necessary here. - auto block2 = blockStore->tryCreate(this->key, cpputils::Data(0)); + auto block2 = blockStore->tryCreate(this->blockId, cpputils::Data(0)); EXPECT_NE(boost::none, block); EXPECT_EQ(boost::none, block2); } TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndBothNullSize) { auto blockStore = this->fixture.createBlockStore(); - auto block = blockStore->tryCreate(this->key, cpputils::Data(0)); + auto block = blockStore->tryCreate(this->blockId, cpputils::Data(0)); (*block)->flush(); //TODO Ideally, flush shouldn't be necessary here. - auto block2 = blockStore->tryCreate(this->key, cpputils::Data(0)); + auto block2 = blockStore->tryCreate(this->blockId, cpputils::Data(0)); EXPECT_NE(boost::none, block); EXPECT_EQ(boost::none, block2); } diff --git a/test/cryfs/config/CryCipherTest.cpp b/test/cryfs/config/CryCipherTest.cpp index 3652bdf9..d336f793 100644 --- a/test/cryfs/config/CryCipherTest.cpp +++ b/test/cryfs/config/CryCipherTest.cpp @@ -43,32 +43,32 @@ public: template void _EXPECT_ENCRYPTS_WITH_ACTUAL_BLOCKSTORE_DECRYPTS_CORRECTLY_WITH_EXPECTED_BLOCKSTORE(const CryCipher &actualCipher, const std::string &encKey, Data dataFixture) { - blockstore::Key key = blockstore::Key::Random(); - Data encrypted = _encryptUsingEncryptedBlockStoreWithCipher(actualCipher, encKey, key, dataFixture.copy()); - Data decrypted = _decryptUsingEncryptedBlockStoreWithCipher(encKey, key, std::move(encrypted)); + blockstore::BlockId blockId = blockstore::BlockId::Random(); + Data encrypted = _encryptUsingEncryptedBlockStoreWithCipher(actualCipher, encKey, blockId, dataFixture.copy()); + Data decrypted = _decryptUsingEncryptedBlockStoreWithCipher(encKey, blockId, std::move(encrypted)); EXPECT_EQ(dataFixture, decrypted); } - Data _encryptUsingEncryptedBlockStoreWithCipher(const CryCipher &cipher, const std::string &encKey, const blockstore::Key &key, Data data) { + Data _encryptUsingEncryptedBlockStoreWithCipher(const CryCipher &cipher, const std::string &encKey, const blockstore::BlockId &blockId, Data data) { unique_ref _baseStore = make_unique_ref(); InMemoryBlockStore2 *baseStore = _baseStore.get(); unique_ref encryptedStore = cipher.createEncryptedBlockstore(std::move(_baseStore), encKey); - bool created = encryptedStore->tryCreate(key, std::move(data)); + bool created = encryptedStore->tryCreate(blockId, std::move(data)); EXPECT_TRUE(created); - return _loadBlock(baseStore, key); + return _loadBlock(baseStore, blockId); } template - Data _decryptUsingEncryptedBlockStoreWithCipher(const std::string &encKey, const blockstore::Key &key, Data data) { + Data _decryptUsingEncryptedBlockStoreWithCipher(const std::string &encKey, const blockstore::BlockId &blockId, Data data) { unique_ref baseStore = make_unique_ref(); - bool created = baseStore->tryCreate(key, std::move(data)); + bool created = baseStore->tryCreate(blockId, std::move(data)); EXPECT_TRUE(created); EncryptedBlockStore2 encryptedStore(std::move(baseStore), Cipher::EncryptionKey::FromString(encKey)); - return _loadBlock(&encryptedStore, key); + return _loadBlock(&encryptedStore, blockId); } - Data _loadBlock(BlockStore2 *store, const blockstore::Key &key) { - return store->load(key).value(); + Data _loadBlock(BlockStore2 *store, const blockstore::BlockId &blockId) { + return store->load(blockId).value(); } };