From 1178d420046fc193082127b5fac67b095abe8564 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Wed, 20 Jan 2016 16:19:24 +0100 Subject: [PATCH] Removed TRI_json_t from Index Constructors and replaced it by VelocyPack. SingleServerTests pass. Some clister tests fail --- arangod/Aql/Collection.cpp | 49 ++++++++++++++++-------------- arangod/Aql/Index.h | 36 +++++++++++----------- arangod/Indexes/EdgeIndex.cpp | 4 +-- arangod/Indexes/EdgeIndex.h | 5 +-- arangod/Indexes/HashIndex.cpp | 4 +-- arangod/Indexes/HashIndex.h | 4 +-- arangod/Indexes/Index.cpp | 42 ++++++++++--------------- arangod/Indexes/Index.h | 3 +- arangod/Indexes/PathBasedIndex.cpp | 4 +-- arangod/Indexes/PathBasedIndex.h | 3 +- arangod/Indexes/PrimaryIndex.cpp | 4 +-- arangod/Indexes/PrimaryIndex.h | 5 +-- arangod/Indexes/SkiplistIndex.cpp | 4 +-- arangod/Indexes/SkiplistIndex.h | 4 +-- 14 files changed, 77 insertions(+), 94 deletions(-) diff --git a/arangod/Aql/Collection.cpp b/arangod/Aql/Collection.cpp index 33450d94cb..73f12e4e38 100644 --- a/arangod/Aql/Collection.cpp +++ b/arangod/Aql/Collection.cpp @@ -37,6 +37,8 @@ #include "VocBase/transaction.h" #include "VocBase/vocbase.h" +#include +#include using namespace triagens::aql; @@ -251,26 +253,27 @@ void Collection::fillIndexesCoordinator() const { } TRI_json_t const* json = (*collectionInfo).getIndexes(); + auto indexBuilder = triagens::basics::JsonHelper::toVelocyPack(json); + VPackSlice const slice = indexBuilder->slice(); - if (TRI_IsArrayJson(json)) { - size_t const n = TRI_LengthArrayJson(json); + if (slice.isArray()) { + size_t const n = static_cast(slice.length()); indexes.reserve(n); - for (size_t i = 0; i < n; ++i) { - TRI_json_t const* v = TRI_LookupArrayJson(json, i); + for (auto const& v : VPackArrayIterator(slice)) { - if (!TRI_IsObjectJson(v)) { + if (!v.isObject()) { continue; } + VPackSlice const type = v.get("type"); - TRI_json_t const* type = TRI_LookupObjectJson(v, "type"); - - if (!TRI_IsStringJson(type)) { + if (!type.isString()) { // no "type" attribute. this is invalid continue; } + std::string typeString = type.copyString(); - if (strcmp(type->_value._string.data, "cap") == 0) { + if (typeString == "cap") { // ignore cap constraints continue; } @@ -312,43 +315,43 @@ void Collection::fillIndexesDBServer() const { name.c_str(), vocbase->_name); } - TRI_json_t const* json = (*collectionInfo).getIndexes(); - if (!TRI_IsArrayJson(json)) { + std::shared_ptr indexBuilder = + triagens::basics::JsonHelper::toVelocyPack( + (*collectionInfo).getIndexes()); + VPackSlice const slice = indexBuilder->slice(); + if (!slice.isArray()) { THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "unexpected indexes definition format"); } - size_t const n = TRI_LengthArrayJson(json); + size_t const n = static_cast(slice.length()); indexes.reserve(n); // register indexes - for (size_t i = 0; i < n; ++i) { - TRI_json_t const* v = TRI_LookupArrayJson(json, i); - - if (TRI_IsObjectJson(v)) { + for (auto const& v : VPackArrayIterator(slice)) { + if (v.isObject()) { // lookup index id - TRI_json_t const* id = TRI_LookupObjectJson(v, "id"); + VPackSlice const id = v.get("id"); - if (!TRI_IsStringJson(id)) { + if (!id.isString()) { // no "id" attribute. this is invalid continue; } - TRI_json_t const* type = TRI_LookupObjectJson(v, "type"); + VPackSlice const type = v.get("type"); - if (!TRI_IsStringJson(type)) { + if (!type.isString()) { // no "type" attribute. this is invalid continue; } - if (strcmp(type->_value._string.data, "cap") == 0) { + if (type.copyString() == "cap") { // ignore cap constraints continue; } // use numeric index id - uint64_t iid = triagens::basics::StringUtils::uint64( - id->_value._string.data, id->_value._string.length - 1); + uint64_t iid = triagens::basics::StringUtils::uint64(id.copyString()); triagens::arango::Index* data = nullptr; auto const& allIndexes = document->allIndexes(); diff --git a/arangod/Aql/Index.h b/arangod/Aql/Index.h index 584cc1ce4d..4bd6c14407 100644 --- a/arangod/Aql/Index.h +++ b/arangod/Aql/Index.h @@ -28,10 +28,14 @@ #include "Basics/Exceptions.h" #include "Basics/json.h" #include "Basics/JsonHelper.h" +#include "Basics/VelocyPackHelper.h" #include "Indexes/Index.h" #include "Indexes/IndexIterator.h" #include +#include +#include + namespace triagens { namespace aql { class Ast; @@ -64,34 +68,32 @@ struct Index { } } - explicit Index(TRI_json_t const* json) + explicit Index(VPackSlice const& slice) : id(triagens::basics::StringUtils::uint64( - triagens::basics::JsonHelper::checkAndGetStringValue(json, "id"))), + triagens::basics::VelocyPackHelper::checkAndGetStringValue(slice, + "id"))), type(triagens::arango::Index::type( - triagens::basics::JsonHelper::checkAndGetStringValue(json, "type") + triagens::basics::VelocyPackHelper::checkAndGetStringValue(slice, + "type") .c_str())), - unique(triagens::basics::JsonHelper::getBooleanValue(json, "unique", - false)), - sparse(triagens::basics::JsonHelper::getBooleanValue(json, "sparse", - false)), + unique(triagens::basics::VelocyPackHelper::getBooleanValue( + slice, "unique", false)), + sparse(triagens::basics::VelocyPackHelper::getBooleanValue( + slice, "sparse", false)), ownsInternals(false), fields(), internals(nullptr) { - TRI_json_t const* f = TRI_LookupObjectJson(json, "fields"); + VPackSlice const f = slice.get("fields"); - if (TRI_IsArrayJson(f)) { - size_t const n = TRI_LengthArrayJson(f); + if (f.isArray()) { + size_t const n = static_cast(f.length()); fields.reserve(n); - for (size_t i = 0; i < n; ++i) { - auto* name = static_cast( - TRI_AtVector(&f->_value._objects, i)); + for (auto const& name : VPackArrayIterator(f)) { - if (TRI_IsStringJson(name)) { + if (name.isString()) { std::vector parsedAttributes; - TRI_ParseAttributeString(std::string(name->_value._string.data, - name->_value._string.length - 1), - parsedAttributes); + TRI_ParseAttributeString(name.copyString(), parsedAttributes); fields.emplace_back(parsedAttributes); } } diff --git a/arangod/Indexes/EdgeIndex.cpp b/arangod/Indexes/EdgeIndex.cpp index 77a4ccf44d..7447605fc9 100644 --- a/arangod/Indexes/EdgeIndex.cpp +++ b/arangod/Indexes/EdgeIndex.cpp @@ -455,8 +455,8 @@ EdgeIndex::EdgeIndex(TRI_idx_iid_t iid, TRI_document_collection_t* collection) /// this is used in the cluster coordinator case //////////////////////////////////////////////////////////////////////////////// -EdgeIndex::EdgeIndex(TRI_json_t const* json) - : Index(json), _edgesFrom(nullptr), _edgesTo(nullptr), _numBuckets(1) {} +EdgeIndex::EdgeIndex(VPackSlice const& slice) + : Index(slice), _edgesFrom(nullptr), _edgesTo(nullptr), _numBuckets(1) {} EdgeIndex::~EdgeIndex() { delete _edgesTo; diff --git a/arangod/Indexes/EdgeIndex.h b/arangod/Indexes/EdgeIndex.h index 0d60368e68..8acb4d51a5 100644 --- a/arangod/Indexes/EdgeIndex.h +++ b/arangod/Indexes/EdgeIndex.h @@ -32,9 +32,6 @@ #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" -struct TRI_json_t; - - namespace triagens { namespace aql { class SortCondition; @@ -87,7 +84,7 @@ class EdgeIndex final : public Index { EdgeIndex(TRI_idx_iid_t, struct TRI_document_collection_t*); - explicit EdgeIndex(struct TRI_json_t const*); + explicit EdgeIndex(VPackSlice const&); ~EdgeIndex(); diff --git a/arangod/Indexes/HashIndex.cpp b/arangod/Indexes/HashIndex.cpp index e0f9be071d..cbd90c8201 100644 --- a/arangod/Indexes/HashIndex.cpp +++ b/arangod/Indexes/HashIndex.cpp @@ -291,8 +291,8 @@ HashIndex::HashIndex( /// this is used in the cluster coordinator case //////////////////////////////////////////////////////////////////////////////// -HashIndex::HashIndex(TRI_json_t const* json) - : PathBasedIndex(json, false), _uniqueArray(nullptr) {} +HashIndex::HashIndex(VPackSlice const& slice) + : PathBasedIndex(slice, false), _uniqueArray(nullptr) {} //////////////////////////////////////////////////////////////////////////////// /// @brief destroys the index diff --git a/arangod/Indexes/HashIndex.h b/arangod/Indexes/HashIndex.h index f83286d299..e58188b8b2 100644 --- a/arangod/Indexes/HashIndex.h +++ b/arangod/Indexes/HashIndex.h @@ -35,8 +35,6 @@ #include "VocBase/document-collection.h" #include "VocBase/VocShaper.h" -struct TRI_json_t; - //////////////////////////////////////////////////////////////////////////////// /// @brief hash index query parameter //////////////////////////////////////////////////////////////////////////////// @@ -103,7 +101,7 @@ class HashIndex final : public PathBasedIndex { std::vector> const&, bool, bool); - explicit HashIndex(struct TRI_json_t const*); + explicit HashIndex(VPackSlice const&); ~HashIndex(); diff --git a/arangod/Indexes/Index.cpp b/arangod/Indexes/Index.cpp index bc42434152..1dc1b7e0b0 100644 --- a/arangod/Indexes/Index.cpp +++ b/arangod/Indexes/Index.cpp @@ -41,8 +41,6 @@ using namespace triagens::arango; - - Index::Index( TRI_idx_iid_t iid, TRI_document_collection_t* collection, std::vector> const& fields, @@ -62,52 +60,45 @@ Index::Index( /// this is used in the cluster coordinator case //////////////////////////////////////////////////////////////////////////////// -Index::Index(TRI_json_t const* json) +Index::Index(VPackSlice const& slice) : _iid(triagens::basics::StringUtils::uint64( - triagens::basics::JsonHelper::checkAndGetStringValue(json, "id"))), + triagens::basics::VelocyPackHelper::checkAndGetStringValue(slice, + "id"))), _collection(nullptr), _fields(), - _unique( - triagens::basics::JsonHelper::getBooleanValue(json, "unique", false)), - _sparse( - triagens::basics::JsonHelper::getBooleanValue(json, "sparse", false)), + _unique(triagens::basics::VelocyPackHelper::getBooleanValue( + slice, "unique", false)), + _sparse(triagens::basics::VelocyPackHelper::getBooleanValue( + slice, "sparse", false)), _selectivityEstimate(0.0) { - TRI_json_t const* fields = TRI_LookupObjectJson(json, "fields"); + VPackSlice const fields = slice.get("fields"); - if (!TRI_IsArrayJson(fields)) { + if (!fields.isArray()) { THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "invalid index description"); } - size_t const n = TRI_LengthArrayJson(fields); + size_t const n = static_cast(fields.length()); _fields.reserve(n); - for (size_t i = 0; i < n; ++i) { - auto name = static_cast( - TRI_AtVector(&fields->_value._objects, i)); - - if (!TRI_IsStringJson(name)) { + for (auto const& name : VPackArrayIterator(fields)) { + if (!name.isString()) { THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "invalid index description"); } std::vector parsedAttributes; - TRI_ParseAttributeString( - std::string(name->_value._string.data, name->_value._string.length - 1), - parsedAttributes); + TRI_ParseAttributeString(name.copyString(), parsedAttributes); _fields.emplace_back(parsedAttributes); } - TRI_json_t const* se = TRI_LookupObjectJson(json, "selectivityEstimate"); - - if (TRI_IsNumberJson(se)) { - _selectivityEstimate = json->_value._number; - } + _selectivityEstimate = + triagens::basics::VelocyPackHelper::getNumericValue( + slice, "selectivityEstimate", 0.0); } Index::~Index() {} - //////////////////////////////////////////////////////////////////////////////// /// @brief return the index type based on a type name //////////////////////////////////////////////////////////////////////////////// @@ -698,4 +689,3 @@ std::ostream& operator<<(std::ostream& stream, return stream; } - diff --git a/arangod/Indexes/Index.h b/arangod/Indexes/Index.h index e2764d66ed..a5f7c763bd 100644 --- a/arangod/Indexes/Index.h +++ b/arangod/Indexes/Index.h @@ -39,7 +39,6 @@ struct TRI_doc_mptr_t; struct TRI_document_collection_t; -struct TRI_json_t; struct TRI_shaped_json_s; struct TRI_transaction_collection_s; @@ -140,7 +139,7 @@ class Index { std::vector> const&, bool unique, bool sparse); - explicit Index(struct TRI_json_t const*); + explicit Index(VPackSlice const&); virtual ~Index(); diff --git a/arangod/Indexes/PathBasedIndex.cpp b/arangod/Indexes/PathBasedIndex.cpp index 3c85a93e5a..ce45ea4f7b 100644 --- a/arangod/Indexes/PathBasedIndex.cpp +++ b/arangod/Indexes/PathBasedIndex.cpp @@ -75,8 +75,8 @@ PathBasedIndex::PathBasedIndex( /// this is used in the cluster coordinator case //////////////////////////////////////////////////////////////////////////////// -PathBasedIndex::PathBasedIndex(TRI_json_t const* json, bool allowPartialIndex) - : Index(json), +PathBasedIndex::PathBasedIndex(VPackSlice const& slice, bool allowPartialIndex) + : Index(slice), _shaper(nullptr), _paths(), _useExpansion(false), diff --git a/arangod/Indexes/PathBasedIndex.h b/arangod/Indexes/PathBasedIndex.h index 00b896c878..467063744c 100644 --- a/arangod/Indexes/PathBasedIndex.h +++ b/arangod/Indexes/PathBasedIndex.h @@ -31,7 +31,6 @@ #include "VocBase/voc-types.h" #include "VocBase/document-collection.h" -struct TRI_json_t; class VocShaper; @@ -75,7 +74,7 @@ class PathBasedIndex : public Index { std::vector> const&, bool unique, bool sparse, bool allowPartialIndex); - explicit PathBasedIndex(struct TRI_json_t const*, bool); + explicit PathBasedIndex(VPackSlice const&, bool); ~PathBasedIndex(); diff --git a/arangod/Indexes/PrimaryIndex.cpp b/arangod/Indexes/PrimaryIndex.cpp index 01f38ec084..d68301d5b1 100644 --- a/arangod/Indexes/PrimaryIndex.cpp +++ b/arangod/Indexes/PrimaryIndex.cpp @@ -114,8 +114,8 @@ PrimaryIndex::PrimaryIndex(TRI_document_collection_t* collection) /// this is used in the cluster coordinator case //////////////////////////////////////////////////////////////////////////////// -PrimaryIndex::PrimaryIndex(TRI_json_t const* json) - : Index(json), _primaryIndex(nullptr) {} +PrimaryIndex::PrimaryIndex(VPackSlice const& slice) + : Index(slice), _primaryIndex(nullptr) {} PrimaryIndex::~PrimaryIndex() { delete _primaryIndex; } diff --git a/arangod/Indexes/PrimaryIndex.h b/arangod/Indexes/PrimaryIndex.h index 57bebbdeee..299ffb5063 100644 --- a/arangod/Indexes/PrimaryIndex.h +++ b/arangod/Indexes/PrimaryIndex.h @@ -31,9 +31,6 @@ #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" -struct TRI_json_t; - - namespace triagens { namespace aql { class SortCondition; @@ -72,7 +69,7 @@ class PrimaryIndex final : public Index { explicit PrimaryIndex(struct TRI_document_collection_t*); - explicit PrimaryIndex(struct TRI_json_t const*); + explicit PrimaryIndex(VPackSlice const&); ~PrimaryIndex(); diff --git a/arangod/Indexes/SkiplistIndex.cpp b/arangod/Indexes/SkiplistIndex.cpp index deee99d523..8bbf7dc2e4 100644 --- a/arangod/Indexes/SkiplistIndex.cpp +++ b/arangod/Indexes/SkiplistIndex.cpp @@ -754,8 +754,8 @@ SkiplistIndex::SkiplistIndex( /// this is used in the cluster coordinator case //////////////////////////////////////////////////////////////////////////////// -SkiplistIndex::SkiplistIndex(TRI_json_t const* json) - : PathBasedIndex(json, true), +SkiplistIndex::SkiplistIndex(VPackSlice const& slice) + : PathBasedIndex(slice, true), CmpElmElm(this), CmpKeyElm(this), _skiplistIndex(nullptr) {} diff --git a/arangod/Indexes/SkiplistIndex.h b/arangod/Indexes/SkiplistIndex.h index c6fecd1f08..6d2c4691c4 100644 --- a/arangod/Indexes/SkiplistIndex.h +++ b/arangod/Indexes/SkiplistIndex.h @@ -34,8 +34,6 @@ #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" -struct TRI_json_t; - typedef struct { TRI_shaped_json_t* _fields; // list of shaped json objects which the // collection should know about @@ -207,7 +205,7 @@ class SkiplistIndex final : public PathBasedIndex { std::vector> const&, bool, bool); - explicit SkiplistIndex(struct TRI_json_t const*); + explicit SkiplistIndex(VPackSlice const&); ~SkiplistIndex();