1
0
Fork 0

Removed TRI_json_t from Index Constructors and replaced it by VelocyPack. SingleServerTests pass. Some clister tests fail

This commit is contained in:
Michael Hackstein 2016-01-20 16:19:24 +01:00
parent 77b12f872f
commit 1178d42004
14 changed files with 77 additions and 94 deletions

View File

@ -37,6 +37,8 @@
#include "VocBase/transaction.h" #include "VocBase/transaction.h"
#include "VocBase/vocbase.h" #include "VocBase/vocbase.h"
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
using namespace triagens::aql; using namespace triagens::aql;
@ -251,26 +253,27 @@ void Collection::fillIndexesCoordinator() const {
} }
TRI_json_t const* json = (*collectionInfo).getIndexes(); TRI_json_t const* json = (*collectionInfo).getIndexes();
auto indexBuilder = triagens::basics::JsonHelper::toVelocyPack(json);
VPackSlice const slice = indexBuilder->slice();
if (TRI_IsArrayJson(json)) { if (slice.isArray()) {
size_t const n = TRI_LengthArrayJson(json); size_t const n = static_cast<size_t>(slice.length());
indexes.reserve(n); indexes.reserve(n);
for (size_t i = 0; i < n; ++i) { for (auto const& v : VPackArrayIterator(slice)) {
TRI_json_t const* v = TRI_LookupArrayJson(json, i);
if (!TRI_IsObjectJson(v)) { if (!v.isObject()) {
continue; continue;
} }
VPackSlice const type = v.get("type");
TRI_json_t const* type = TRI_LookupObjectJson(v, "type"); if (!type.isString()) {
if (!TRI_IsStringJson(type)) {
// no "type" attribute. this is invalid // no "type" attribute. this is invalid
continue; continue;
} }
std::string typeString = type.copyString();
if (strcmp(type->_value._string.data, "cap") == 0) { if (typeString == "cap") {
// ignore cap constraints // ignore cap constraints
continue; continue;
} }
@ -312,43 +315,43 @@ void Collection::fillIndexesDBServer() const {
name.c_str(), vocbase->_name); name.c_str(), vocbase->_name);
} }
TRI_json_t const* json = (*collectionInfo).getIndexes(); std::shared_ptr<VPackBuilder> indexBuilder =
if (!TRI_IsArrayJson(json)) { triagens::basics::JsonHelper::toVelocyPack(
(*collectionInfo).getIndexes());
VPackSlice const slice = indexBuilder->slice();
if (!slice.isArray()) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"unexpected indexes definition format"); "unexpected indexes definition format");
} }
size_t const n = TRI_LengthArrayJson(json); size_t const n = static_cast<size_t>(slice.length());
indexes.reserve(n); indexes.reserve(n);
// register indexes // register indexes
for (size_t i = 0; i < n; ++i) { for (auto const& v : VPackArrayIterator(slice)) {
TRI_json_t const* v = TRI_LookupArrayJson(json, i); if (v.isObject()) {
if (TRI_IsObjectJson(v)) {
// lookup index id // 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 // no "id" attribute. this is invalid
continue; 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 // no "type" attribute. this is invalid
continue; continue;
} }
if (strcmp(type->_value._string.data, "cap") == 0) { if (type.copyString() == "cap") {
// ignore cap constraints // ignore cap constraints
continue; continue;
} }
// use numeric index id // use numeric index id
uint64_t iid = triagens::basics::StringUtils::uint64( uint64_t iid = triagens::basics::StringUtils::uint64(id.copyString());
id->_value._string.data, id->_value._string.length - 1);
triagens::arango::Index* data = nullptr; triagens::arango::Index* data = nullptr;
auto const& allIndexes = document->allIndexes(); auto const& allIndexes = document->allIndexes();

View File

@ -28,10 +28,14 @@
#include "Basics/Exceptions.h" #include "Basics/Exceptions.h"
#include "Basics/json.h" #include "Basics/json.h"
#include "Basics/JsonHelper.h" #include "Basics/JsonHelper.h"
#include "Basics/VelocyPackHelper.h"
#include "Indexes/Index.h" #include "Indexes/Index.h"
#include "Indexes/IndexIterator.h" #include "Indexes/IndexIterator.h"
#include <iosfwd> #include <iosfwd>
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens { namespace triagens {
namespace aql { namespace aql {
class Ast; 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( : id(triagens::basics::StringUtils::uint64(
triagens::basics::JsonHelper::checkAndGetStringValue(json, "id"))), triagens::basics::VelocyPackHelper::checkAndGetStringValue(slice,
"id"))),
type(triagens::arango::Index::type( type(triagens::arango::Index::type(
triagens::basics::JsonHelper::checkAndGetStringValue(json, "type") triagens::basics::VelocyPackHelper::checkAndGetStringValue(slice,
"type")
.c_str())), .c_str())),
unique(triagens::basics::JsonHelper::getBooleanValue(json, "unique", unique(triagens::basics::VelocyPackHelper::getBooleanValue(
false)), slice, "unique", false)),
sparse(triagens::basics::JsonHelper::getBooleanValue(json, "sparse", sparse(triagens::basics::VelocyPackHelper::getBooleanValue(
false)), slice, "sparse", false)),
ownsInternals(false), ownsInternals(false),
fields(), fields(),
internals(nullptr) { internals(nullptr) {
TRI_json_t const* f = TRI_LookupObjectJson(json, "fields"); VPackSlice const f = slice.get("fields");
if (TRI_IsArrayJson(f)) { if (f.isArray()) {
size_t const n = TRI_LengthArrayJson(f); size_t const n = static_cast<size_t>(f.length());
fields.reserve(n); fields.reserve(n);
for (size_t i = 0; i < n; ++i) { for (auto const& name : VPackArrayIterator(f)) {
auto* name = static_cast<TRI_json_t const*>(
TRI_AtVector(&f->_value._objects, i));
if (TRI_IsStringJson(name)) { if (name.isString()) {
std::vector<triagens::basics::AttributeName> parsedAttributes; std::vector<triagens::basics::AttributeName> parsedAttributes;
TRI_ParseAttributeString(std::string(name->_value._string.data, TRI_ParseAttributeString(name.copyString(), parsedAttributes);
name->_value._string.length - 1),
parsedAttributes);
fields.emplace_back(parsedAttributes); fields.emplace_back(parsedAttributes);
} }
} }

View File

@ -455,8 +455,8 @@ EdgeIndex::EdgeIndex(TRI_idx_iid_t iid, TRI_document_collection_t* collection)
/// this is used in the cluster coordinator case /// this is used in the cluster coordinator case
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
EdgeIndex::EdgeIndex(TRI_json_t const* json) EdgeIndex::EdgeIndex(VPackSlice const& slice)
: Index(json), _edgesFrom(nullptr), _edgesTo(nullptr), _numBuckets(1) {} : Index(slice), _edgesFrom(nullptr), _edgesTo(nullptr), _numBuckets(1) {}
EdgeIndex::~EdgeIndex() { EdgeIndex::~EdgeIndex() {
delete _edgesTo; delete _edgesTo;

View File

@ -32,9 +32,6 @@
#include "VocBase/vocbase.h" #include "VocBase/vocbase.h"
#include "VocBase/voc-types.h" #include "VocBase/voc-types.h"
struct TRI_json_t;
namespace triagens { namespace triagens {
namespace aql { namespace aql {
class SortCondition; class SortCondition;
@ -87,7 +84,7 @@ class EdgeIndex final : public Index {
EdgeIndex(TRI_idx_iid_t, struct TRI_document_collection_t*); EdgeIndex(TRI_idx_iid_t, struct TRI_document_collection_t*);
explicit EdgeIndex(struct TRI_json_t const*); explicit EdgeIndex(VPackSlice const&);
~EdgeIndex(); ~EdgeIndex();

View File

@ -291,8 +291,8 @@ HashIndex::HashIndex(
/// this is used in the cluster coordinator case /// this is used in the cluster coordinator case
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
HashIndex::HashIndex(TRI_json_t const* json) HashIndex::HashIndex(VPackSlice const& slice)
: PathBasedIndex(json, false), _uniqueArray(nullptr) {} : PathBasedIndex(slice, false), _uniqueArray(nullptr) {}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief destroys the index /// @brief destroys the index

View File

@ -35,8 +35,6 @@
#include "VocBase/document-collection.h" #include "VocBase/document-collection.h"
#include "VocBase/VocShaper.h" #include "VocBase/VocShaper.h"
struct TRI_json_t;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief hash index query parameter /// @brief hash index query parameter
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -103,7 +101,7 @@ class HashIndex final : public PathBasedIndex {
std::vector<std::vector<triagens::basics::AttributeName>> const&, std::vector<std::vector<triagens::basics::AttributeName>> const&,
bool, bool); bool, bool);
explicit HashIndex(struct TRI_json_t const*); explicit HashIndex(VPackSlice const&);
~HashIndex(); ~HashIndex();

View File

@ -41,8 +41,6 @@
using namespace triagens::arango; using namespace triagens::arango;
Index::Index( Index::Index(
TRI_idx_iid_t iid, TRI_document_collection_t* collection, TRI_idx_iid_t iid, TRI_document_collection_t* collection,
std::vector<std::vector<triagens::basics::AttributeName>> const& fields, std::vector<std::vector<triagens::basics::AttributeName>> const& fields,
@ -62,52 +60,45 @@ Index::Index(
/// this is used in the cluster coordinator case /// 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( : _iid(triagens::basics::StringUtils::uint64(
triagens::basics::JsonHelper::checkAndGetStringValue(json, "id"))), triagens::basics::VelocyPackHelper::checkAndGetStringValue(slice,
"id"))),
_collection(nullptr), _collection(nullptr),
_fields(), _fields(),
_unique( _unique(triagens::basics::VelocyPackHelper::getBooleanValue(
triagens::basics::JsonHelper::getBooleanValue(json, "unique", false)), slice, "unique", false)),
_sparse( _sparse(triagens::basics::VelocyPackHelper::getBooleanValue(
triagens::basics::JsonHelper::getBooleanValue(json, "sparse", false)), slice, "sparse", false)),
_selectivityEstimate(0.0) { _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, THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"invalid index description"); "invalid index description");
} }
size_t const n = TRI_LengthArrayJson(fields); size_t const n = static_cast<size_t>(fields.length());
_fields.reserve(n); _fields.reserve(n);
for (size_t i = 0; i < n; ++i) { for (auto const& name : VPackArrayIterator(fields)) {
auto name = static_cast<TRI_json_t const*>( if (!name.isString()) {
TRI_AtVector(&fields->_value._objects, i));
if (!TRI_IsStringJson(name)) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"invalid index description"); "invalid index description");
} }
std::vector<triagens::basics::AttributeName> parsedAttributes; std::vector<triagens::basics::AttributeName> parsedAttributes;
TRI_ParseAttributeString( TRI_ParseAttributeString(name.copyString(), parsedAttributes);
std::string(name->_value._string.data, name->_value._string.length - 1),
parsedAttributes);
_fields.emplace_back(parsedAttributes); _fields.emplace_back(parsedAttributes);
} }
TRI_json_t const* se = TRI_LookupObjectJson(json, "selectivityEstimate"); _selectivityEstimate =
triagens::basics::VelocyPackHelper::getNumericValue<double>(
if (TRI_IsNumberJson(se)) { slice, "selectivityEstimate", 0.0);
_selectivityEstimate = json->_value._number;
}
} }
Index::~Index() {} Index::~Index() {}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief return the index type based on a type name /// @brief return the index type based on a type name
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -698,4 +689,3 @@ std::ostream& operator<<(std::ostream& stream,
return stream; return stream;
} }

View File

@ -39,7 +39,6 @@
struct TRI_doc_mptr_t; struct TRI_doc_mptr_t;
struct TRI_document_collection_t; struct TRI_document_collection_t;
struct TRI_json_t;
struct TRI_shaped_json_s; struct TRI_shaped_json_s;
struct TRI_transaction_collection_s; struct TRI_transaction_collection_s;
@ -140,7 +139,7 @@ class Index {
std::vector<std::vector<triagens::basics::AttributeName>> const&, std::vector<std::vector<triagens::basics::AttributeName>> const&,
bool unique, bool sparse); bool unique, bool sparse);
explicit Index(struct TRI_json_t const*); explicit Index(VPackSlice const&);
virtual ~Index(); virtual ~Index();

View File

@ -75,8 +75,8 @@ PathBasedIndex::PathBasedIndex(
/// this is used in the cluster coordinator case /// this is used in the cluster coordinator case
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
PathBasedIndex::PathBasedIndex(TRI_json_t const* json, bool allowPartialIndex) PathBasedIndex::PathBasedIndex(VPackSlice const& slice, bool allowPartialIndex)
: Index(json), : Index(slice),
_shaper(nullptr), _shaper(nullptr),
_paths(), _paths(),
_useExpansion(false), _useExpansion(false),

View File

@ -31,7 +31,6 @@
#include "VocBase/voc-types.h" #include "VocBase/voc-types.h"
#include "VocBase/document-collection.h" #include "VocBase/document-collection.h"
struct TRI_json_t;
class VocShaper; class VocShaper;
@ -75,7 +74,7 @@ class PathBasedIndex : public Index {
std::vector<std::vector<triagens::basics::AttributeName>> const&, std::vector<std::vector<triagens::basics::AttributeName>> const&,
bool unique, bool sparse, bool allowPartialIndex); bool unique, bool sparse, bool allowPartialIndex);
explicit PathBasedIndex(struct TRI_json_t const*, bool); explicit PathBasedIndex(VPackSlice const&, bool);
~PathBasedIndex(); ~PathBasedIndex();

View File

@ -114,8 +114,8 @@ PrimaryIndex::PrimaryIndex(TRI_document_collection_t* collection)
/// this is used in the cluster coordinator case /// this is used in the cluster coordinator case
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
PrimaryIndex::PrimaryIndex(TRI_json_t const* json) PrimaryIndex::PrimaryIndex(VPackSlice const& slice)
: Index(json), _primaryIndex(nullptr) {} : Index(slice), _primaryIndex(nullptr) {}
PrimaryIndex::~PrimaryIndex() { delete _primaryIndex; } PrimaryIndex::~PrimaryIndex() { delete _primaryIndex; }

View File

@ -31,9 +31,6 @@
#include "VocBase/vocbase.h" #include "VocBase/vocbase.h"
#include "VocBase/voc-types.h" #include "VocBase/voc-types.h"
struct TRI_json_t;
namespace triagens { namespace triagens {
namespace aql { namespace aql {
class SortCondition; class SortCondition;
@ -72,7 +69,7 @@ class PrimaryIndex final : public Index {
explicit PrimaryIndex(struct TRI_document_collection_t*); explicit PrimaryIndex(struct TRI_document_collection_t*);
explicit PrimaryIndex(struct TRI_json_t const*); explicit PrimaryIndex(VPackSlice const&);
~PrimaryIndex(); ~PrimaryIndex();

View File

@ -754,8 +754,8 @@ SkiplistIndex::SkiplistIndex(
/// this is used in the cluster coordinator case /// this is used in the cluster coordinator case
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
SkiplistIndex::SkiplistIndex(TRI_json_t const* json) SkiplistIndex::SkiplistIndex(VPackSlice const& slice)
: PathBasedIndex(json, true), : PathBasedIndex(slice, true),
CmpElmElm(this), CmpElmElm(this),
CmpKeyElm(this), CmpKeyElm(this),
_skiplistIndex(nullptr) {} _skiplistIndex(nullptr) {}

View File

@ -34,8 +34,6 @@
#include "VocBase/vocbase.h" #include "VocBase/vocbase.h"
#include "VocBase/voc-types.h" #include "VocBase/voc-types.h"
struct TRI_json_t;
typedef struct { typedef struct {
TRI_shaped_json_t* _fields; // list of shaped json objects which the TRI_shaped_json_t* _fields; // list of shaped json objects which the
// collection should know about // collection should know about
@ -207,7 +205,7 @@ class SkiplistIndex final : public PathBasedIndex {
std::vector<std::vector<triagens::basics::AttributeName>> const&, bool, std::vector<std::vector<triagens::basics::AttributeName>> const&, bool,
bool); bool);
explicit SkiplistIndex(struct TRI_json_t const*); explicit SkiplistIndex(VPackSlice const&);
~SkiplistIndex(); ~SkiplistIndex();