From 9754d38df3d6d93d5f942f850c2d52d9f068755c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Gra=CC=88tzer?= Date: Thu, 30 Mar 2017 16:00:27 +0200 Subject: [PATCH] Added hash-, skip list, persistent indexes --- arangod/RocksDBEngine/RocksDBEdgeIndex.cpp | 4 +- arangod/RocksDBEngine/RocksDBEdgeIndex.h | 2 +- arangod/RocksDBEngine/RocksDBHashIndex.h | 48 ++++++++++++++++++ arangod/RocksDBEngine/RocksDBIndexFactory.cpp | 21 +++++--- arangod/RocksDBEngine/RocksDBPathBasedIndex.h | 9 +++- .../RocksDBEngine/RocksDBPersistentIndex.h | 49 +++++++++++++++++++ arangod/RocksDBEngine/RocksDBSkiplistIndex.h | 48 ++++++++++++++++++ arangod/RocksDBEngine/RocksDBVPackIndex.h | 17 ++----- 8 files changed, 172 insertions(+), 26 deletions(-) create mode 100644 arangod/RocksDBEngine/RocksDBHashIndex.h create mode 100644 arangod/RocksDBEngine/RocksDBPersistentIndex.h create mode 100644 arangod/RocksDBEngine/RocksDBSkiplistIndex.h diff --git a/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp b/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp index 19bb895456..28e36906a5 100644 --- a/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp @@ -41,7 +41,6 @@ #include "RocksDBEngine/RocksDBToken.h" #include "RocksDBEngine/RocksDBTransactionState.h" #include "RocksDBEngine/RocksDBTypes.h" -#include "RocksDBEngine/RocksDBCommon.h" #include #include @@ -80,7 +79,6 @@ RocksDBEdgeIndexIterator::~RocksDBEdgeIndexIterator() { } bool RocksDBEdgeIndexIterator::next(TokenCallback const& cb, size_t limit) { - if (limit == 0 || !_iterator.valid()) { // No limit no data, or we are actually done. The last call should have // returned false @@ -114,7 +112,7 @@ bool RocksDBEdgeIndexIterator::next(TokenCallback const& cb, size_t limit) { // aquire the document token through the primary index RocksDBToken token; - Result res = rocksColl->lookupDocumentToken( _trx, edgeKey, token); + Result res = rocksColl->lookupDocumentToken(_trx, edgeKey, token); if (res.ok()) { cb(token); if (--limit == 0) { diff --git a/arangod/RocksDBEngine/RocksDBEdgeIndex.h b/arangod/RocksDBEngine/RocksDBEdgeIndex.h index e78e276f16..0e2bbed968 100644 --- a/arangod/RocksDBEngine/RocksDBEdgeIndex.h +++ b/arangod/RocksDBEngine/RocksDBEdgeIndex.h @@ -108,7 +108,7 @@ class RocksDBEdgeIndex final : public RocksDBIndex { arangodb::basics::LocalTaskQueue* queue = nullptr) override; int unload() override; - + int drop() override; int sizeHint(transaction::Methods*, size_t) override; diff --git a/arangod/RocksDBEngine/RocksDBHashIndex.h b/arangod/RocksDBEngine/RocksDBHashIndex.h new file mode 100644 index 0000000000..13c842c41b --- /dev/null +++ b/arangod/RocksDBEngine/RocksDBHashIndex.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Simon Grätzer +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGOD_ROCKSDB_ROCKSDB_HASH_INDEX_H +#define ARANGOD_ROCKSDB_ROCKSDB_HASH_INDEX_H 1 + +#include "RocksDBEngine/RocksDBVPackIndex.h" + +namespace arangodb { + +class RocksDBHashIndex final : public RocksDBVPackIndex { + public: + RocksDBHashIndex() = delete; + + RocksDBHashIndex(TRI_idx_iid_t iid, LogicalCollection* coll, + arangodb::velocypack::Slice const& info) + : RocksDBVPackIndex(iid, coll, info) {} + + public: + IndexType type() const override { return Index::TRI_IDX_TYPE_HASH_INDEX; } + + char const* typeName() const override { return "rocksdb-hash"; } + + bool isSorted() const override { return false; } +}; +} + +#endif diff --git a/arangod/RocksDBEngine/RocksDBIndexFactory.cpp b/arangod/RocksDBEngine/RocksDBIndexFactory.cpp index efa72d9e16..6afb892cd4 100644 --- a/arangod/RocksDBEngine/RocksDBIndexFactory.cpp +++ b/arangod/RocksDBEngine/RocksDBIndexFactory.cpp @@ -29,6 +29,9 @@ #include "RocksDBEngine/RocksDBEdgeIndex.h" #include "RocksDBEngine/RocksDBEngine.h" #include "RocksDBEngine/RocksDBPrimaryIndex.h" +#include "RocksDBEngine/RocksDBPersistentIndex.h" +#include "RocksDBEngine/RocksDBHashIndex.h" +#include "RocksDBEngine/RocksDBSkiplistIndex.h" #include "StorageEngine/EngineSelectorFeature.h" #include "VocBase/ticks.h" #include "VocBase/voc-types.h" @@ -357,13 +360,19 @@ std::shared_ptr RocksDBIndexFactory::prepareIndexFromSlice( new arangodb::RocksDBEdgeIndex(iid, col, StaticStrings::FromString)); break; } + //case arangodb::Index::TRI_IDX_TYPE_GEO1_INDEX: + //case arangodb::Index::TRI_IDX_TYPE_GEO2_INDEX: case arangodb::Index::TRI_IDX_TYPE_HASH_INDEX: { - LOG_TOPIC(WARN, Logger::FIXME) << "Hash Index not implemented"; - // // TODO: fix this wrong index type. only used temporarily because we - // don't have other indexes - // newIdx.reset(new arangodb::RocksDBEdgeIndex(db, iid, col, - // StaticStrings::FromString)); - // break; + newIdx.reset(new arangodb::RocksDBHashIndex(iid, col, info)); + break; + } + case arangodb::Index::TRI_IDX_TYPE_SKIPLIST_INDEX: { + newIdx.reset(new arangodb::RocksDBSkiplistIndex(iid, col, info)); + break; + } + case arangodb::Index::TRI_IDX_TYPE_PERSISTENT_INDEX: { + newIdx.reset(new arangodb::RocksDBPersistentIndex(iid, col, info)); + break; } case arangodb::Index::TRI_IDX_TYPE_UNKNOWN: diff --git a/arangod/RocksDBEngine/RocksDBPathBasedIndex.h b/arangod/RocksDBEngine/RocksDBPathBasedIndex.h index e1288ca672..d8e1eaa7fb 100644 --- a/arangod/RocksDBEngine/RocksDBPathBasedIndex.h +++ b/arangod/RocksDBEngine/RocksDBPathBasedIndex.h @@ -18,7 +18,7 @@ /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// -/// @author Jan Steemann +/// @author Simon Grätzer //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_MMFILES_PATH_BASED_INDEX_H @@ -47,9 +47,14 @@ class RocksDBPathBasedIndex : public RocksDBIndex { arangodb::velocypack::Slice const&, size_t baseSize, bool allowPartialIndex); - ~RocksDBPathBasedIndex(); + virtual ~RocksDBPathBasedIndex(); public: + + bool allowExpansion() const override { return true; } + + bool canBeDropped() const override { return true; } + /// @brief return the attribute paths std::vector> const& paths() const { return _paths; } diff --git a/arangod/RocksDBEngine/RocksDBPersistentIndex.h b/arangod/RocksDBEngine/RocksDBPersistentIndex.h new file mode 100644 index 0000000000..9106f7db9e --- /dev/null +++ b/arangod/RocksDBEngine/RocksDBPersistentIndex.h @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Simon Grätzer +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGOD_ROCKSDB_ROCKSDB_PERSISTENT_INDEX_H +#define ARANGOD_ROCKSDB_ROCKSDB_PERSISTENT_INDEX_H 1 + +#include "RocksDBEngine/RocksDBVPackIndex.h" +namespace arangodb { + +class RocksDBPersistentIndex final : public RocksDBVPackIndex { + public: + RocksDBPersistentIndex() = delete; + + RocksDBPersistentIndex(TRI_idx_iid_t iid, LogicalCollection* coll, + arangodb::velocypack::Slice const& info) + : RocksDBVPackIndex(iid, coll, info) {} + + public: + IndexType type() const override { + return Index::TRI_IDX_TYPE_PERSISTENT_INDEX; + } + + char const* typeName() const override { return "rocksdb-persistent"; } + + bool isSorted() const override { return true; } +}; +} + +#endif diff --git a/arangod/RocksDBEngine/RocksDBSkiplistIndex.h b/arangod/RocksDBEngine/RocksDBSkiplistIndex.h new file mode 100644 index 0000000000..1b7f53e888 --- /dev/null +++ b/arangod/RocksDBEngine/RocksDBSkiplistIndex.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Simon Grätzer +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGOD_ROCKSDB_ROCKSDB_SKIPLIST_INDEX_H +#define ARANGOD_ROCKSDB_ROCKSDB_SKIPLIST_INDEX_H 1 + +#include "RocksDBEngine/RocksDBVPackIndex.h" + +namespace arangodb { + +class RocksDBSkiplistIndex final : public RocksDBVPackIndex { + public: + RocksDBSkiplistIndex() = delete; + + RocksDBSkiplistIndex(TRI_idx_iid_t iid, LogicalCollection* coll, + arangodb::velocypack::Slice const& info) + : RocksDBVPackIndex(iid, coll, info) {} + + public: + IndexType type() const override { return Index::TRI_IDX_TYPE_SKIPLIST_INDEX; } + + char const* typeName() const override { return "rocksdb-skiplist"; } + + bool isSorted() const override { return true; } +}; +} + +#endif diff --git a/arangod/RocksDBEngine/RocksDBVPackIndex.h b/arangod/RocksDBEngine/RocksDBVPackIndex.h index d1e0f9e311..ff70ce3dcc 100644 --- a/arangod/RocksDBEngine/RocksDBVPackIndex.h +++ b/arangod/RocksDBEngine/RocksDBVPackIndex.h @@ -93,7 +93,7 @@ class RocksDBVPackIndexIterator final : public IndexIterator { RocksDBKeyBounds _bounds; }; -class RocksDBVPackIndex final : public RocksDBPathBasedIndex { +class RocksDBVPackIndex : public RocksDBPathBasedIndex { friend class RocksDBVPackIndexIterator; public: @@ -102,21 +102,10 @@ class RocksDBVPackIndex final : public RocksDBPathBasedIndex { RocksDBVPackIndex(TRI_idx_iid_t, LogicalCollection*, arangodb::velocypack::Slice const&); - ~RocksDBVPackIndex(); + virtual ~RocksDBVPackIndex(); public: - IndexType type() const override { - return Index::TRI_IDX_TYPE_PERSISTENT_INDEX; - } - - char const* typeName() const override { return "rocksdb-unique-index"; } - - bool allowExpansion() const override { return true; } - - bool canBeDropped() const override { return true; } - - bool isSorted() const override { return true; } - + bool hasSelectivityEstimate() const override { return _unique && true; } double selectivityEstimate(