diff --git a/arangod/RocksDBEngine/CMakeLists.txt b/arangod/RocksDBEngine/CMakeLists.txt index 36a37c8f0c..7a39fb4622 100644 --- a/arangod/RocksDBEngine/CMakeLists.txt +++ b/arangod/RocksDBEngine/CMakeLists.txt @@ -9,6 +9,7 @@ set(ROCKSDB_SOURCES RocksDBEngine/RocksDBEngine.cpp RocksDBEngine/RocksDBIndex.cpp RocksDBEngine/RocksDBIndexFactory.cpp + RocksDBEngine/RocksDBHashIndex.cpp RocksDBEngine/RocksDBKey.cpp RocksDBEngine/RocksDBKeyBounds.cpp RocksDBEngine/RocksDBPrimaryIndex.cpp diff --git a/arangod/RocksDBEngine/RocksDBCollection.cpp b/arangod/RocksDBEngine/RocksDBCollection.cpp index de23d1c6f7..bf1ff8ea7e 100644 --- a/arangod/RocksDBEngine/RocksDBCollection.cpp +++ b/arangod/RocksDBEngine/RocksDBCollection.cpp @@ -123,7 +123,8 @@ void RocksDBCollection::getPropertiesVPackCoordinator( /// @brief closes an open collection int RocksDBCollection::close() { - THROW_ARANGO_NOT_YET_IMPLEMENTED(); + // TODO + //THROW_ARANGO_NOT_YET_IMPLEMENTED(); return TRI_ERROR_NO_ERROR; } diff --git a/arangod/RocksDBEngine/RocksDBEngine.cpp b/arangod/RocksDBEngine/RocksDBEngine.cpp index 646d1ca7dd..89472c5ec0 100644 --- a/arangod/RocksDBEngine/RocksDBEngine.cpp +++ b/arangod/RocksDBEngine/RocksDBEngine.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/arangod/RocksDBEngine/RocksDBHashIndex.cpp b/arangod/RocksDBEngine/RocksDBHashIndex.cpp new file mode 100644 index 0000000000..724dc22833 --- /dev/null +++ b/arangod/RocksDBEngine/RocksDBHashIndex.cpp @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2014-2017 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 +//////////////////////////////////////////////////////////////////////////////// + +#include "RocksDBHashIndex.h" +#include +#include +#include "Basics/VelocyPackHelper.h" + +using namespace arangodb; + +/// @brief Test if this index matches the definition +/// different to the Index::matchesDefinition because the ordering can +/// be arbitrary +bool RocksDBHashIndex::matchesDefinition(VPackSlice const& info) const { + TRI_ASSERT(info.isObject()); +#ifdef ARANGODB_ENABLE_MAINTAINER_MODE + VPackSlice typeSlice = info.get("type"); + TRI_ASSERT(typeSlice.isString()); + StringRef typeStr(typeSlice); + TRI_ASSERT(typeStr == oldtypeName()); +#endif + auto value = info.get("id"); + if (!value.isNone()) { + // We already have an id. + if (!value.isString()) { + // Invalid ID + return false; + } + // Short circuit. If id is correct the index is identical. + StringRef idRef(value); + return idRef == std::to_string(_iid); + } + + value = info.get("fields"); + if (!value.isArray()) { + return false; + } + + size_t const n = static_cast(value.length()); + if (n != _fields.size()) { + return false; + } + if (_unique != arangodb::basics::VelocyPackHelper::getBooleanValue( + info, "unique", false)) { + return false; + } + if (_sparse != arangodb::basics::VelocyPackHelper::getBooleanValue( + info, "sparse", false)) { + return false; + } + + // This check does not take ordering of attributes into account. + std::vector translate; + for (auto const& f : VPackArrayIterator(value)) { + bool found = false; + if (!f.isString()) { + // Invalid field definition! + return false; + } + translate.clear(); + arangodb::StringRef in(f); + TRI_ParseAttributeString(in, translate, true); + + for (size_t i = 0; i < n; ++i) { + if (arangodb::basics::AttributeName::isIdentical(_fields[i], translate, + false)) { + found = true; + break; + } + } + if (!found) { + return false; + } + } + return true; +} diff --git a/arangod/RocksDBEngine/RocksDBHashIndex.h b/arangod/RocksDBEngine/RocksDBHashIndex.h index 13c842c41b..aeb0f52e5a 100644 --- a/arangod/RocksDBEngine/RocksDBHashIndex.h +++ b/arangod/RocksDBEngine/RocksDBHashIndex.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,6 +41,8 @@ class RocksDBHashIndex final : public RocksDBVPackIndex { char const* typeName() const override { return "rocksdb-hash"; } + bool matchesDefinition(VPackSlice const& info) const override; + bool isSorted() const override { return false; } }; } diff --git a/arangod/RocksDBEngine/RocksDBIndex.cpp b/arangod/RocksDBEngine/RocksDBIndex.cpp index dd9c3923fb..1e46f7298e 100644 --- a/arangod/RocksDBEngine/RocksDBIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBIndex.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/arangod/RocksDBEngine/RocksDBIndexFactory.cpp b/arangod/RocksDBEngine/RocksDBIndexFactory.cpp index 6afb892cd4..a3debdfdf3 100644 --- a/arangod/RocksDBEngine/RocksDBIndexFactory.cpp +++ b/arangod/RocksDBEngine/RocksDBIndexFactory.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); @@ -147,6 +147,20 @@ static int EnhanceJsonIndexSkiplist(VPackSlice const definition, return res; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief enhances the json of a persistent index +//////////////////////////////////////////////////////////////////////////////// + +static int EnhanceJsonIndexPersistent(VPackSlice const definition, + VPackBuilder& builder, bool create) { + int res = ProcessIndexFields(definition, builder, 0, create); + if (res == TRI_ERROR_NO_ERROR) { + ProcessIndexSparseFlag(definition, builder, create); + ProcessIndexUniqueFlag(definition, builder); + } + return res; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief process the geojson flag and add it to the json //////////////////////////////////////////////////////////////////////////////// @@ -280,6 +294,10 @@ int RocksDBIndexFactory::enhanceIndexDefinition(VPackSlice const definition, case Index::TRI_IDX_TYPE_SKIPLIST_INDEX: res = EnhanceJsonIndexSkiplist(definition, enhanced, create); break; + + case Index::TRI_IDX_TYPE_PERSISTENT_INDEX: + res = EnhanceJsonIndexPersistent(definition, enhanced, create); + break; case Index::TRI_IDX_TYPE_UNKNOWN: default: { diff --git a/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp b/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp index 9c2ef14796..6dab4a641c 100644 --- a/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/arangod/RocksDBEngine/RocksDBTransactionCollection.cpp b/arangod/RocksDBEngine/RocksDBTransactionCollection.cpp index 5effde8072..62c12a8f06 100644 --- a/arangod/RocksDBEngine/RocksDBTransactionCollection.cpp +++ b/arangod/RocksDBEngine/RocksDBTransactionCollection.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/js/common/tests/shell/shell-hash-index-noncluster.js b/js/common/tests/shell/shell-hash-index-noncluster-mmfiles.js similarity index 100% rename from js/common/tests/shell/shell-hash-index-noncluster.js rename to js/common/tests/shell/shell-hash-index-noncluster-mmfiles.js