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/vocbase.h"
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
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<size_t>(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<VPackBuilder> 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<size_t>(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();

View File

@ -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 <iosfwd>
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
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<size_t>(f.length());
fields.reserve(n);
for (size_t i = 0; i < n; ++i) {
auto* name = static_cast<TRI_json_t const*>(
TRI_AtVector(&f->_value._objects, i));
for (auto const& name : VPackArrayIterator(f)) {
if (TRI_IsStringJson(name)) {
if (name.isString()) {
std::vector<triagens::basics::AttributeName> parsedAttributes;
TRI_ParseAttributeString(std::string(name->_value._string.data,
name->_value._string.length - 1),
parsedAttributes);
TRI_ParseAttributeString(name.copyString(), 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
////////////////////////////////////////////////////////////////////////////////
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;

View File

@ -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();

View File

@ -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

View File

@ -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<std::vector<triagens::basics::AttributeName>> const&,
bool, bool);
explicit HashIndex(struct TRI_json_t const*);
explicit HashIndex(VPackSlice const&);
~HashIndex();

View File

@ -41,8 +41,6 @@
using namespace triagens::arango;
Index::Index(
TRI_idx_iid_t iid, TRI_document_collection_t* collection,
std::vector<std::vector<triagens::basics::AttributeName>> 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<size_t>(fields.length());
_fields.reserve(n);
for (size_t i = 0; i < n; ++i) {
auto name = static_cast<TRI_json_t const*>(
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<triagens::basics::AttributeName> 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<double>(
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;
}

View File

@ -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<std::vector<triagens::basics::AttributeName>> const&,
bool unique, bool sparse);
explicit Index(struct TRI_json_t const*);
explicit Index(VPackSlice const&);
virtual ~Index();

View File

@ -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),

View File

@ -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<std::vector<triagens::basics::AttributeName>> const&,
bool unique, bool sparse, bool allowPartialIndex);
explicit PathBasedIndex(struct TRI_json_t const*, bool);
explicit PathBasedIndex(VPackSlice const&, bool);
~PathBasedIndex();

View File

@ -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; }

View File

@ -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();

View File

@ -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) {}

View File

@ -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<std::vector<triagens::basics::AttributeName>> const&, bool,
bool);
explicit SkiplistIndex(struct TRI_json_t const*);
explicit SkiplistIndex(VPackSlice const&);
~SkiplistIndex();