From ea3a7f3dab3bd1fe744f775819d64dd7642c85ce Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 22 Feb 2016 12:37:16 +0100 Subject: [PATCH] removed cap constraints --- arangod/Aql/Collection.cpp | 5 - arangod/CMakeLists.txt | 1 - arangod/Cluster/ClusterInfo.cpp | 15 -- arangod/Indexes/CapConstraint.cpp | 183 ---------------------- arangod/Indexes/CapConstraint.h | 116 -------------- arangod/Indexes/Index.cpp | 24 --- arangod/Indexes/Index.h | 5 +- arangod/Makefile.files | 1 - arangod/V8Server/v8-vocindex.cpp | 75 +-------- arangod/VocBase/document-collection.cpp | 200 +----------------------- arangod/VocBase/document-collection.h | 19 --- 11 files changed, 6 insertions(+), 638 deletions(-) delete mode 100644 arangod/Indexes/CapConstraint.cpp delete mode 100644 arangod/Indexes/CapConstraint.h diff --git a/arangod/Aql/Collection.cpp b/arangod/Aql/Collection.cpp index faab751ad4..203c4bf3fe 100644 --- a/arangod/Aql/Collection.cpp +++ b/arangod/Aql/Collection.cpp @@ -383,11 +383,6 @@ void Collection::fillIndexesLocal() const { indexes.reserve(n); for (size_t i = 0; i < n; ++i) { - if (allIndexes[i]->type() == arangodb::Index::TRI_IDX_TYPE_CAP_CONSTRAINT) { - // ignore this type of index - continue; - } - auto idx = std::make_unique(allIndexes[i]); indexes.emplace_back(idx.get()); idx.release(); diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index b25e6bf08f..406f219bb5 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -159,7 +159,6 @@ add_executable( HttpServer/HttpsCommTask.cpp HttpServer/HttpsServer.cpp HttpServer/PathHandler.cpp - Indexes/CapConstraint.cpp Indexes/EdgeIndex.cpp Indexes/FulltextIndex.cpp Indexes/GeoIndex2.cpp diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 3a95c7dbf0..026dbf9672 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -1649,21 +1649,6 @@ int ClusterInfo::ensureIndexCoordinator( return setErrormsg(TRI_ERROR_NO_ERROR, errorMsg); } } - - if (type.copyString() == "cap") { - // special handling for cap constraints - if (hasSameIndexType) { - // there can only be one cap constraint - return setErrormsg(TRI_ERROR_ARANGO_CAP_CONSTRAINT_ALREADY_DEFINED, - errorMsg); - } - - if (numberOfShards > 1) { - // there must be at most one shard if there should be a cap - // constraint - return setErrormsg(TRI_ERROR_CLUSTER_UNSUPPORTED, errorMsg); - } - } } // no existing index found. diff --git a/arangod/Indexes/CapConstraint.cpp b/arangod/Indexes/CapConstraint.cpp deleted file mode 100644 index 27a417f4ef..0000000000 --- a/arangod/Indexes/CapConstraint.cpp +++ /dev/null @@ -1,183 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// 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 Dr. Frank Celler -//////////////////////////////////////////////////////////////////////////////// - -#include "CapConstraint.h" -#include "Basics/Logger.h" -#include "Utils/transactions.h" -#include "VocBase/document-collection.h" -#include "VocBase/transaction.h" - -using namespace arangodb; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief minimum size -//////////////////////////////////////////////////////////////////////////////// - -int64_t const CapConstraint::MinSize = 16384; - -CapConstraint::CapConstraint(TRI_idx_iid_t iid, - TRI_document_collection_t* collection, - size_t count, int64_t size) - : Index(iid, collection, - std::vector>(), false, - false), - _count(count), - _size(static_cast(size)) {} - -CapConstraint::~CapConstraint() {} - -size_t CapConstraint::memory() const { return 0; } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief return a VelocyPack representation of the index -//////////////////////////////////////////////////////////////////////////////// - -void CapConstraint::toVelocyPack(VPackBuilder& builder, - bool withFigures) const { - Index::toVelocyPack(builder, withFigures); - builder.add("size", VPackValue(_count)); - builder.add("byteSize", VPackValue(_size)); - builder.add("unique", VPackValue(false)); -} - -int CapConstraint::insert(arangodb::Transaction*, TRI_doc_mptr_t const* doc, - bool) { - if (_size > 0) { - // there is a size restriction - auto marker = static_cast( - doc->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME - - // check if the document would be too big - if (static_cast(marker->_size) > _size) { - return TRI_ERROR_ARANGO_DOCUMENT_TOO_LARGE; - } - } - - return TRI_ERROR_NO_ERROR; -} - -int CapConstraint::remove(arangodb::Transaction*, TRI_doc_mptr_t const*, bool) { - return TRI_ERROR_NO_ERROR; -} - -int CapConstraint::postInsert(arangodb::Transaction* trx, - TRI_transaction_collection_t* trxCollection, - TRI_doc_mptr_t const*) { - TRI_ASSERT(_count > 0 || _size > 0); - - return apply(trx, trxCollection->_collection->_collection, trxCollection); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief initialize the cap constraint -//////////////////////////////////////////////////////////////////////////////// - -int CapConstraint::initialize(arangodb::Transaction* trx) { - TRI_ASSERT(_count > 0 || _size > 0); - - TRI_headers_t* headers = _collection->_headersPtr; // ONLY IN INDEX (CAP) - int64_t currentCount = static_cast(headers->count()); - int64_t currentSize = headers->size(); - - if ((_count > 0 && currentCount <= _count) && - (_size > 0 && currentSize <= _size)) { - // nothing to do - return TRI_ERROR_NO_ERROR; - } else { - TRI_vocbase_t* vocbase = _collection->_vocbase; - TRI_voc_cid_t cid = _collection->_info.id(); - - arangodb::SingleCollectionWriteTransaction trx( - new arangodb::StandaloneTransactionContext(), vocbase, cid); - trx.addHint(TRI_TRANSACTION_HINT_LOCK_NEVER, false); - trx.addHint(TRI_TRANSACTION_HINT_NO_BEGIN_MARKER, false); - trx.addHint(TRI_TRANSACTION_HINT_NO_ABORT_MARKER, false); - trx.addHint( - TRI_TRANSACTION_HINT_SINGLE_OPERATION, - false); // this is actually not true, but necessary to create trx id 0 - - int res = trx.begin(); - - if (res != TRI_ERROR_NO_ERROR) { - return res; - } - - TRI_transaction_collection_t* trxCollection = trx.trxCollection(); - res = apply(&trx, _collection, trxCollection); - - res = trx.finish(res); - - return res; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief apply the cap constraint for the collection -//////////////////////////////////////////////////////////////////////////////// - -int CapConstraint::apply(arangodb::Transaction* trx, - TRI_document_collection_t* document, - TRI_transaction_collection_t* trxCollection) { - TRI_headers_t* headers = - document->_headersPtr; // PROTECTED by trx in trxCollection - int64_t currentCount = static_cast(headers->count()); - int64_t currentSize = headers->size(); - - int res = TRI_ERROR_NO_ERROR; - - // delete while at least one of the constraints is still violated - while ((_count > 0 && currentCount > _count) || - (_size > 0 && currentSize > _size)) { - TRI_doc_mptr_t* oldest = headers->front(); - - if (oldest != nullptr) { - TRI_ASSERT(oldest->getDataPtr() != - nullptr); // ONLY IN INDEX, PROTECTED by RUNTIME - size_t oldSize = ((TRI_df_marker_t*)(oldest->getDataPtr())) - ->_size; // ONLY IN INDEX, PROTECTED by RUNTIME - - TRI_ASSERT(oldSize > 0); - - if (trxCollection != nullptr) { - res = TRI_DeleteDocumentDocumentCollection(trx, trxCollection, nullptr, - oldest); - - if (res != TRI_ERROR_NO_ERROR) { - LOG(WARN) << "cannot cap collection: " << TRI_errno_string(res); - break; - } - } else { - headers->unlink(oldest); - } - - currentCount--; - currentSize -= (int64_t)oldSize; - } else { - // we should not get here - LOG(WARN) << "logic error in " << __FUNCTION__; - break; - } - } - - return res; -} diff --git a/arangod/Indexes/CapConstraint.h b/arangod/Indexes/CapConstraint.h deleted file mode 100644 index 2b0b341954..0000000000 --- a/arangod/Indexes/CapConstraint.h +++ /dev/null @@ -1,116 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// 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 Dr. Frank Celler -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ARANGOD_INDEXES_CAP_CONSTRAINT_H -#define ARANGOD_INDEXES_CAP_CONSTRAINT_H 1 - -#include "Basics/Common.h" -#include "Indexes/Index.h" -#include "VocBase/vocbase.h" -#include "VocBase/voc-types.h" - -namespace arangodb { - -class CapConstraint final : public Index { - public: - CapConstraint() = delete; - - CapConstraint(TRI_idx_iid_t, struct TRI_document_collection_t*, size_t, - int64_t); - - ~CapConstraint(); - - public: - ////////////////////////////////////////////////////////////////////////////// - /// @brief maximum number of documents in the collection - ////////////////////////////////////////////////////////////////////////////// - - int64_t count() const { return _count; } - - ////////////////////////////////////////////////////////////////////////////// - /// @brief maximum size of documents in the collection - ////////////////////////////////////////////////////////////////////////////// - - int64_t size() const { return _size; } - - IndexType type() const override final { - return Index::TRI_IDX_TYPE_CAP_CONSTRAINT; - } - - bool isSorted() const override final { return false; } - - bool hasSelectivityEstimate() const override final { return false; } - - bool dumpFields() const override final { return false; } - - size_t memory() const override final; - - void toVelocyPack(VPackBuilder&, bool) const override final; - // Uses default toVelocyPackFigures - - int insert(arangodb::Transaction*, struct TRI_doc_mptr_t const*, - bool) override final; - - int remove(arangodb::Transaction*, struct TRI_doc_mptr_t const*, - bool) override final; - - int postInsert(arangodb::Transaction*, struct TRI_transaction_collection_s*, - struct TRI_doc_mptr_t const*) override final; - - ////////////////////////////////////////////////////////////////////////////// - /// @brief initialize the cap constraint - ////////////////////////////////////////////////////////////////////////////// - - int initialize(arangodb::Transaction*); - - private: - ////////////////////////////////////////////////////////////////////////////// - /// @brief apply the cap constraint for the collection - ////////////////////////////////////////////////////////////////////////////// - - int apply(arangodb::Transaction*, TRI_document_collection_t*, - struct TRI_transaction_collection_s*); - - private: - ////////////////////////////////////////////////////////////////////////////// - /// @brief maximum number of documents in the collection - ////////////////////////////////////////////////////////////////////////////// - - int64_t const _count; - - ////////////////////////////////////////////////////////////////////////////// - /// @brief maximum size of documents in the collection - ////////////////////////////////////////////////////////////////////////////// - - int64_t const _size; - - public: - ////////////////////////////////////////////////////////////////////////////// - /// @brief minimum size - ////////////////////////////////////////////////////////////////////////////// - - static int64_t const MinSize; -}; -} - -#endif diff --git a/arangod/Indexes/Index.cpp b/arangod/Indexes/Index.cpp index 688c4a25f5..8a2deb4d1e 100644 --- a/arangod/Indexes/Index.cpp +++ b/arangod/Indexes/Index.cpp @@ -115,9 +115,6 @@ Index::IndexType Index::type(char const* type) { if (::strcmp(type, "fulltext") == 0) { return TRI_IDX_TYPE_FULLTEXT_INDEX; } - if (::strcmp(type, "cap") == 0) { - return TRI_IDX_TYPE_CAP_CONSTRAINT; - } if (::strcmp(type, "geo1") == 0) { return TRI_IDX_TYPE_GEO1_INDEX; } @@ -144,14 +141,10 @@ char const* Index::typeName(Index::IndexType type) { return "skiplist"; case TRI_IDX_TYPE_FULLTEXT_INDEX: return "fulltext"; - case TRI_IDX_TYPE_CAP_CONSTRAINT: - return "cap"; case TRI_IDX_TYPE_GEO1_INDEX: return "geo1"; case TRI_IDX_TYPE_GEO2_INDEX: return "geo2"; - case TRI_IDX_TYPE_PRIORITY_QUEUE_INDEX: - case TRI_IDX_TYPE_BITARRAY_INDEX: case TRI_IDX_TYPE_UNKNOWN: { } } @@ -285,23 +278,6 @@ bool Index::Compare(VPackSlice const& lhs, VPackSlice const& rhs) { return false; } } - } else if (type == IndexType::TRI_IDX_TYPE_CAP_CONSTRAINT) { - // size, byteSize - value = lhs.get("size"); - if (value.isNumber()) { - if (arangodb::basics::VelocyPackHelper::compare(value, rhs.get("size"), - false) != 0) { - return false; - } - } - - value = lhs.get("byteSize"); - if (value.isNumber()) { - if (arangodb::basics::VelocyPackHelper::compare( - value, rhs.get("byteSize"), false) != 0) { - return false; - } - } } // other index types: fields must be identical if present diff --git a/arangod/Indexes/Index.h b/arangod/Indexes/Index.h index 5f38ed5d51..4734ae91a8 100644 --- a/arangod/Indexes/Index.h +++ b/arangod/Indexes/Index.h @@ -158,10 +158,7 @@ class Index { TRI_IDX_TYPE_HASH_INDEX, TRI_IDX_TYPE_EDGE_INDEX, TRI_IDX_TYPE_FULLTEXT_INDEX, - TRI_IDX_TYPE_PRIORITY_QUEUE_INDEX, // DEPRECATED and not functional anymore - TRI_IDX_TYPE_SKIPLIST_INDEX, - TRI_IDX_TYPE_BITARRAY_INDEX, // DEPRECATED and not functional anymore - TRI_IDX_TYPE_CAP_CONSTRAINT + TRI_IDX_TYPE_SKIPLIST_INDEX }; public: diff --git a/arangod/Makefile.files b/arangod/Makefile.files index 99b173eb32..d54b13367e 100644 --- a/arangod/Makefile.files +++ b/arangod/Makefile.files @@ -114,7 +114,6 @@ arangod_libarangod_a_SOURCES = \ arangod/HttpServer/HttpsCommTask.cpp \ arangod/HttpServer/HttpsServer.cpp \ arangod/HttpServer/PathHandler.cpp \ - arangod/Indexes/CapConstraint.cpp \ arangod/Indexes/EdgeIndex.cpp \ arangod/Indexes/FulltextIndex.cpp \ arangod/Indexes/GeoIndex2.cpp \ diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 99fca4aaf1..489a6051f4 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -24,7 +24,6 @@ #include "v8-vocindex.h" #include "Basics/conversions.h" #include "FulltextIndex/fulltext-index.h" -#include "Indexes/CapConstraint.h" #include "Indexes/EdgeIndex.h" #include "Indexes/FulltextIndex.h" #include "Indexes/GeoIndex2.h" @@ -313,46 +312,6 @@ static int EnhanceJsonIndexFulltext(v8::Isolate* isolate, return res; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief enhances the json of a cap constraint -//////////////////////////////////////////////////////////////////////////////// - -static int EnhanceJsonIndexCap(v8::Isolate* isolate, - v8::Handle const obj, - VPackBuilder& builder) { - // handle "size" attribute - size_t count = 0; - if (obj->Has(TRI_V8_ASCII_STRING("size")) && - obj->Get(TRI_V8_ASCII_STRING("size"))->IsNumber()) { - int64_t value = TRI_ObjectToInt64(obj->Get(TRI_V8_ASCII_STRING("size"))); - - if (value < 0 || value > INT64_MAX) { - return TRI_ERROR_BAD_PARAMETER; - } - count = (size_t)value; - } - - // handle "byteSize" attribute - int64_t byteSize = 0; - if (obj->Has(TRI_V8_ASCII_STRING("byteSize")) && - obj->Get(TRI_V8_ASCII_STRING("byteSize"))->IsNumber()) { - byteSize = TRI_ObjectToInt64(obj->Get(TRI_V8_ASCII_STRING("byteSize"))); - } - - if (count == 0 && byteSize <= 0) { - return TRI_ERROR_BAD_PARAMETER; - } - - if (byteSize < 0 || - (byteSize > 0 && byteSize < arangodb::CapConstraint::MinSize)) { - return TRI_ERROR_BAD_PARAMETER; - } - - builder.add("size", VPackValue(count)); - builder.add("byteSize", VPackValue(byteSize)); - return TRI_ERROR_NO_ERROR; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief enhances the json of an index //////////////////////////////////////////////////////////////////////////////// @@ -425,15 +384,13 @@ static int EnhanceIndexJson(v8::FunctionCallbackInfo const& args, builder.add("type", VPackValue(idxType)); switch (type) { - case arangodb::Index::TRI_IDX_TYPE_UNKNOWN: - case arangodb::Index::TRI_IDX_TYPE_PRIORITY_QUEUE_INDEX: { + case arangodb::Index::TRI_IDX_TYPE_UNKNOWN: { res = TRI_ERROR_BAD_PARAMETER; break; } case arangodb::Index::TRI_IDX_TYPE_PRIMARY_INDEX: - case arangodb::Index::TRI_IDX_TYPE_EDGE_INDEX: - case arangodb::Index::TRI_IDX_TYPE_BITARRAY_INDEX: { + case arangodb::Index::TRI_IDX_TYPE_EDGE_INDEX: { break; } @@ -456,10 +413,6 @@ static int EnhanceIndexJson(v8::FunctionCallbackInfo const& args, case arangodb::Index::TRI_IDX_TYPE_FULLTEXT_INDEX: res = EnhanceJsonIndexFulltext(isolate, obj, builder, create); break; - - case arangodb::Index::TRI_IDX_TYPE_CAP_CONSTRAINT: - res = EnhanceJsonIndexCap(isolate, obj, builder); - break; } } catch (...) { // TODO Check for different type of Errors @@ -624,9 +577,7 @@ static void EnsureIndexLocal(v8::FunctionCallbackInfo const& args, switch (type) { case arangodb::Index::TRI_IDX_TYPE_UNKNOWN: case arangodb::Index::TRI_IDX_TYPE_PRIMARY_INDEX: - case arangodb::Index::TRI_IDX_TYPE_EDGE_INDEX: - case arangodb::Index::TRI_IDX_TYPE_PRIORITY_QUEUE_INDEX: - case arangodb::Index::TRI_IDX_TYPE_BITARRAY_INDEX: { + case arangodb::Index::TRI_IDX_TYPE_EDGE_INDEX: { // these indexes cannot be created directly TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); } @@ -728,26 +679,6 @@ static void EnsureIndexLocal(v8::FunctionCallbackInfo const& args, } break; } - - case arangodb::Index::TRI_IDX_TYPE_CAP_CONSTRAINT: { - size_t size = arangodb::basics::VelocyPackHelper::getNumericValue( - slice, "size", 0); - - int64_t byteSize = - arangodb::basics::VelocyPackHelper::getNumericValue( - slice, "byteSize", 0); - ; - - if (create) { - idx = static_cast( - TRI_EnsureCapConstraintDocumentCollection(&trx, document, iid, size, - byteSize, created)); - } else { - idx = static_cast( - TRI_LookupCapConstraintDocumentCollection(document)); - } - break; - } } if (idx == nullptr && create) { diff --git a/arangod/VocBase/document-collection.cpp b/arangod/VocBase/document-collection.cpp index 233dc923cb..59fcfc0e4d 100644 --- a/arangod/VocBase/document-collection.cpp +++ b/arangod/VocBase/document-collection.cpp @@ -33,7 +33,6 @@ #include "Basics/ThreadPool.h" #include "Cluster/ServerState.h" #include "FulltextIndex/fulltext-index.h" -#include "Indexes/CapConstraint.h" #include "Indexes/EdgeIndex.h" #include "Indexes/FulltextIndex.h" #include "Indexes/GeoIndex2.h" @@ -75,7 +74,6 @@ TRI_document_collection_t::TRI_document_collection_t() _nextCompactionStartIndex(0), _lastCompactionStatus(nullptr), _useSecondaryIndexes(true), - _capConstraint(nullptr), _ditches(this), _headersPtr(nullptr), _keyGenerator(nullptr), @@ -531,10 +529,7 @@ TRI_doc_collection_info_t* TRI_document_collection_t::figures() { void TRI_document_collection_t::addIndex(arangodb::Index* idx) { _indexes.emplace_back(idx); - if (idx->type() == arangodb::Index::TRI_IDX_TYPE_CAP_CONSTRAINT) { - // register cap constraint - _capConstraint = static_cast(idx); - } else if (idx->type() == arangodb::Index::TRI_IDX_TYPE_FULLTEXT_INDEX) { + if (idx->type() == arangodb::Index::TRI_IDX_TYPE_FULLTEXT_INDEX) { ++_cleanupIndexes; } } @@ -558,10 +553,7 @@ arangodb::Index* TRI_document_collection_t::removeIndex(TRI_idx_iid_t iid) { // found! _indexes.erase(_indexes.begin() + i); - if (idx->type() == arangodb::Index::TRI_IDX_TYPE_CAP_CONSTRAINT) { - // unregister cap constraint - _capConstraint = nullptr; - } else if (idx->type() == arangodb::Index::TRI_IDX_TYPE_FULLTEXT_INDEX) { + if (idx->type() == arangodb::Index::TRI_IDX_TYPE_FULLTEXT_INDEX) { --_cleanupIndexes; } @@ -605,20 +597,6 @@ arangodb::EdgeIndex* TRI_document_collection_t::edgeIndex() { return nullptr; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief return the cap constraint index, if it exists -//////////////////////////////////////////////////////////////////////////////// - -arangodb::CapConstraint* TRI_document_collection_t::capConstraint() { - for (auto const& idx : _indexes) { - if (idx->type() == arangodb::Index::TRI_IDX_TYPE_CAP_CONSTRAINT) { - return static_cast(idx); - } - } - - return nullptr; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief get an index by id //////////////////////////////////////////////////////////////////////////////// @@ -655,11 +633,6 @@ int TRI_AddOperationTransaction(TRI_transaction_t*, static int FillIndex(arangodb::Transaction*, TRI_document_collection_t*, arangodb::Index*); -static int CapConstraintFromVelocyPack(arangodb::Transaction*, - TRI_document_collection_t*, - VPackSlice const&, TRI_idx_iid_t, - arangodb::Index**); - static int GeoIndexFromVelocyPack(arangodb::Transaction*, TRI_document_collection_t*, VPackSlice const&, TRI_idx_iid_t, arangodb::Index**); @@ -2558,13 +2531,6 @@ int TRI_FromVelocyPackIndexDocumentCollection( TRI_UpdateTickServer(iid); - // ........................................................................... - // CAP CONSTRAINT - // ........................................................................... - if (typeStr == "cap") { - return CapConstraintFromVelocyPack(trx, document, slice, iid, idx); - } - // ........................................................................... // GEO INDEX (list or attribute) // ........................................................................... @@ -3687,168 +3653,6 @@ static int PidNamesByAttributeNames( return TRI_ERROR_NO_ERROR; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief adds a cap constraint to a collection -//////////////////////////////////////////////////////////////////////////////// - -static arangodb::Index* CreateCapConstraintDocumentCollection( - arangodb::Transaction* trx, TRI_document_collection_t* document, - size_t count, int64_t size, TRI_idx_iid_t iid, bool& created) { - created = false; - - // check if we already know a cap constraint - auto existing = document->capConstraint(); - - if (existing != nullptr) { - if (static_cast(existing->count()) == count && - existing->size() == size) { - return static_cast(existing); - } - - TRI_set_errno(TRI_ERROR_ARANGO_CAP_CONSTRAINT_ALREADY_DEFINED); - return nullptr; - } - - if (iid == 0) { - iid = arangodb::Index::generateId(); - } - - // create a new index - auto cc = new arangodb::CapConstraint(iid, document, count, size); - std::unique_ptr capConstraint(cc); - - cc->initialize(trx); - arangodb::Index* idx = static_cast(capConstraint.get()); - - // initializes the index with all existing documents - int res = FillIndex(trx, document, idx); - - if (res != TRI_ERROR_NO_ERROR) { - TRI_set_errno(res); - - return nullptr; - } - - // and store index - try { - document->addIndex(idx); - capConstraint.release(); - } catch (...) { - TRI_set_errno(res); - - return nullptr; - } - - created = true; - - return idx; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief restores an index -//////////////////////////////////////////////////////////////////////////////// - -static int CapConstraintFromVelocyPack(arangodb::Transaction* trx, - TRI_document_collection_t* document, - VPackSlice const& definition, - TRI_idx_iid_t iid, - arangodb::Index** dst) { - if (dst != nullptr) { - *dst = nullptr; - } - - VPackSlice val1 = definition.get("size"); - VPackSlice val2 = definition.get("byteSize"); - - if (!val1.isNumber() && !val2.isNumber()) { - LOG(ERR) << "ignoring cap constraint " << iid << ", 'size' and 'byteSize' missing"; - - return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); - } - - size_t count = 0; - if (val1.isNumber()) { - if (val1.isDouble()) { - double tmp = val1.getDouble(); - if (tmp > 0.0) { - count = static_cast(tmp); - } - } else { - count = val1.getNumericValue(); - } - } - - int64_t size = 0; - if (val2.isNumber()) { - if (val2.isDouble()) { - double tmp = val2.getDouble(); - if (tmp > arangodb::CapConstraint::MinSize) { - size = static_cast(tmp); - } - } else { - int64_t tmp = val2.getNumericValue(); - if (tmp > arangodb::CapConstraint::MinSize) { - size = static_cast(tmp); - } - } - } - - if (count == 0 && size == 0) { - LOG(ERR) << "ignoring cap constraint " << iid << ", 'size' must be at least 1, or 'byteSize' must be at least " << arangodb::CapConstraint::MinSize; - - return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); - } - - bool created; - auto idx = CreateCapConstraintDocumentCollection(trx, document, count, size, - iid, created); - - if (dst != nullptr) { - *dst = idx; - } - - return idx == nullptr ? TRI_errno() : TRI_ERROR_NO_ERROR; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief looks up a cap constraint -//////////////////////////////////////////////////////////////////////////////// - -arangodb::Index* TRI_LookupCapConstraintDocumentCollection( - TRI_document_collection_t* document) { - return static_cast(document->capConstraint()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief ensures that a cap constraint exists -//////////////////////////////////////////////////////////////////////////////// - -arangodb::Index* TRI_EnsureCapConstraintDocumentCollection( - arangodb::Transaction* trx, TRI_document_collection_t* document, - TRI_idx_iid_t iid, size_t count, int64_t size, bool& created) { - READ_LOCKER(readLocker, document->_vocbase->_inventoryLock); - - WRITE_LOCKER(writeLocker, document->_lock); - - auto idx = CreateCapConstraintDocumentCollection(trx, document, count, size, - iid, created); - - if (idx != nullptr) { - if (created) { - arangodb::aql::QueryCache::instance()->invalidate( - document->_vocbase, document->_info.namec_str()); - int res = TRI_SaveIndex(document, idx, true); - - if (res != TRI_ERROR_NO_ERROR) { - delete idx; - idx = nullptr; - } - } - } - - return idx; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief adds a geo index to a collection //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h index 7d77b1c7a7..0dabe05542 100644 --- a/arangod/VocBase/document-collection.h +++ b/arangod/VocBase/document-collection.h @@ -42,7 +42,6 @@ class TRI_headers_t; class VocShaper; namespace arangodb { -class CapConstraint; class EdgeIndex; class ExampleMatcher; class Index; @@ -293,9 +292,6 @@ struct TRI_document_collection_t : public TRI_collection_t { arangodb::Index* lookupIndex(TRI_idx_iid_t) const; arangodb::PrimaryIndex* primaryIndex(); arangodb::EdgeIndex* edgeIndex(); - arangodb::CapConstraint* capConstraint(); - - arangodb::CapConstraint* _capConstraint; arangodb::Ditches* ditches() { return &_ditches; } @@ -827,21 +823,6 @@ TRI_IndexesDocumentCollection(TRI_document_collection_t*, bool); bool TRI_DropIndexDocumentCollection(TRI_document_collection_t*, TRI_idx_iid_t, bool); -//////////////////////////////////////////////////////////////////////////////// -/// @brief looks up a cap constraint -//////////////////////////////////////////////////////////////////////////////// - -arangodb::Index* TRI_LookupCapConstraintDocumentCollection( - TRI_document_collection_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief ensures that a cap constraint exists -//////////////////////////////////////////////////////////////////////////////// - -arangodb::Index* TRI_EnsureCapConstraintDocumentCollection( - arangodb::Transaction*, TRI_document_collection_t*, TRI_idx_iid_t, size_t, - int64_t, bool&); - //////////////////////////////////////////////////////////////////////////////// /// @brief finds a geo index, list style ///