8000 issue 505.1: move index json comparison into index-type-specific implementations to address issue with incorrect definition comparison by vasiliy-arangodb · Pull Request #7430 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

issue 505.1: move index json comparison into index-type-specific implementations to address issue with incorrect definition comparison #7430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
issue 505: move index json comparison into index-type-specific implem…
…entations to address issue with incorrect definition comparison
  • Loading branch information
vasiliy-arangodb committed Nov 22, 2018
commit 13c96217449b399a6c3c83e47e4fc20a6e0d7861
263 changes: 186 additions & 77 deletions arangod/ClusterEngine/ClusterIndexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,90 +38,199 @@
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>

namespace arangodb {
namespace {

ClusterIndexFactory::ClusterIndexFactory() {
emplaceFactory(
"edge",
[](
LogicalCollection& collection,
velocypack::Slice const& definition,
TRI_idx_iid_t id,
bool isClusterConstructor
)->std::shared_ptr<Index> {
if (!isClusterConstructor) {
// this indexes cannot be created directly
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL, "cannot create edge index"
);
}

auto* ce = static_cast<ClusterEngine*>(EngineSelectorFeature::ENGINE);
auto ct = ce->engineType();

return std::make_shared<ClusterIndex>(
id, collection, ct, Index::TRI_IDX_TYPE_EDGE_INDEX, definition
struct DefaultIndexFactory: public arangodb::IndexTypeFactory {
std::string const _type;

DefaultIndexFactory(std::string const& type): _type(type) {}

virtual bool equal(
arangodb::velocypack::Slice const& lhs,
arangodb::velocypack::Slice const& rhs
) const override {
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
arangodb::EngineSelectorFeature::ENGINE
);

if (!clusterEngine) {
THROW_ARANGO_EXCEPTION(arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find cluster engine while normalizing index"
));
}

auto* engine = clusterEngine->actualEngine();

if (!engine) {
THROW_ARANGO_EXCEPTION(arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find storage engine while normalizing index"
));
}

return engine->indexFactory().factory(_type).equal(lhs, rhs);
}

virtual arangodb::Result instantiate(
std::shared_ptr<arangodb::Index>& index,
arangodb::LogicalCollection& collection,
arangodb::velocypack::Slice const& definition,
TRI_idx_iid_t id,
bool //isClusterConstructor
) const override {
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
arangodb::EngineSelectorFeature::ENGINE
);

if (!clusterEngine) {
return arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find cluster engine while creating index"
);
}
);

emplaceFactory(
"primary",
[](
LogicalCollection& collection,
velocypack::Slice const& definition,
TRI_idx_iid_t id,
bool isClusterConstructor
)->std::shared_ptr<Index> {
if (!isClusterConstructor) {
// this indexes cannot be created directly
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL, "cannot create primary index"
);
}

auto* ce = static_cast<ClusterEngine*>(EngineSelectorFeature::ENGINE);
auto ct = ce->engineType();

return std::make_shared<ClusterIndex>(
0, collection, ct, Index::TRI_IDX_TYPE_PRIMARY_INDEX, definition

auto ct = clusterEngine->engineType();

index = std::make_shared<arangodb::ClusterIndex>(
id, collection, ct, arangodb::Index::type(_type), definition
);

return arangodb::Result();
}

virtual arangodb::Result normalize(
arangodb::velocypack::Builder& normalized,
arangodb::velocypack::Slice definition,
bool isCreation
) const override {
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
arangodb::EngineSelectorFeature::ENGINE
);

if (!clusterEngine) {
return arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find cluster engine while normalizing index"
);
}

auto* engine = clusterEngine->actualEngine();

if (!engine) {
return arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find storage engine while normalizing index"
);
}
);

// both engines support all types right now
static const std::vector<std::string> supported = {
"fulltext",
"geo",
"geo1",
"geo2",
"hash",
"persistent",
"skiplist"
};

for (auto& typeStr: supported) {
auto type = Index::type(typeStr);

emplaceFactory(
typeStr,
[type](
LogicalCollection& collection,
velocypack::Slice const& definition,
TRI_idx_iid_t id,
bool isClusterConstructor
)->std::shared_ptr<Index> {
auto* ce = static_cast<ClusterEngine*>(EngineSelectorFeature::ENGINE);
auto ct = ce->engineType();

return std::make_shared<ClusterIndex>(
id, collection, ct, type, definition
);
}

return engine->indexFactory().factory(_type).normalize(
normalized, definition, isCreation
);
}
};

struct EdgeIndexFactory: public DefaultIndexFactory {
EdgeIndexFactory(std::string const& type): DefaultIndexFactory(type) {}

virtual arangodb::Result instantiate(
std::shared_ptr<arangodb::Index>& index,
arangodb::LogicalCollection& collection,
arangodb::velocypack::Slice const& definition,
TRI_idx_iid_t id,
bool isClusterConstructor
) const override {
if (!isClusterConstructor) {
// this indexes cannot be created directly
return arangodb::Result(TRI_ERROR_INTERNAL, "cannot create edge index");
}

auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
arangodb::EngineSelectorFeature::ENGINE
);

if (!clusterEngine) {
return arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find storage engine while creating index"
);
}

auto ct = clusterEngine->engineType();

index = std::make_shared<arangodb::ClusterIndex>(
id, collection, ct, arangodb::Index::TRI_IDX_TYPE_EDGE_INDEX, definition
);

return arangodb::Result();
}
};

struct PrimaryIndexFactory: public DefaultIndexFactory {
PrimaryIndexFactory(std::string const& type): DefaultIndexFactory(type) {}

virtual arangodb::Result instantiate(
std::shared_ptr<arangodb::Index>& index,
arangodb::LogicalCollection& collection,
arangodb::velocypack::Slice const& definition,
TRI_idx_iid_t id,
bool isClusterConstructor
) const override {
if (!isClusterConstructor) {
// this indexes cannot be created directly
return arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot create primary index"
);
}

auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
arangodb::EngineSelectorFeature::ENGINE
);

if (!clusterEngine) {
return arangodb::Result(
TRI_ERROR_INTERNAL,
"cannot find storage engine while creating index"
);
}

auto ct = clusterEngine->engineType();

index = std::make_shared<arangodb::ClusterIndex>(
0, collection, ct, arangodb::Index::TRI_IDX_TYPE_PRIMARY_INDEX, definition
);

return arangodb::Result();
}
};

}


namespace arangodb {

ClusterIndexFactory::ClusterIndexFactory() {
static const EdgeIndexFactory edgeIndexFactory("edge");
static const DefaultIndexFactory fulltextIndexFactory("fulltext");
static const DefaultIndexFactory geoIndexFactory("geo");
static const DefaultIndexFactory geo1IndexFactory("geo1");
static const DefaultIndexFactory geo2IndexFactory("geo2");
static const DefaultIndexFactory hashIndexFactory("hash");
static const DefaultIndexFactory persistentIndexFactory("persistent");
static const PrimaryIndexFactory primaryIndexFactory("primary");
static const DefaultIndexFactory skiplistIndexFactory("skiplist");

emplace(edgeIndexFactory._type, edgeIndexFactory);
emplace(fulltextIndexFactory._type, fulltextIndexFactory);
emplace(geoIndexFactory._type, geoIndexFactory);
emplace(geo1IndexFactory._type, geo1IndexFactory);
emplace(geo2IndexFactory._type, geo2IndexFactory);
emplace(hashIndexFactory._type, hashIndexFactory);
emplace(persistentIndexFactory._type, persistentIndexFactory);
emplace(primaryIndexFactory._type, primaryIndexFactory);
emplace(skiplistIndexFactory._type, skiplistIndexFactory);
}

Result ClusterIndexFactory::enhanceIndexDefinition(VPackSlice const definition,
VPackBuilder& normalized,
bool isCreation,
Expand Down Expand Up @@ -239,4 +348,4 @@ void ClusterIndexFactory::prepareIndexes(

// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
15 changes: 8 additions & 7 deletions arangod/IResearch/IResearchFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ void 8000 registerFilters(arangodb::aql::AqlFunctionFeature& functions) {
}

void registerIndexFactory() {
static const std::map<std::string, arangodb::IndexFactory::IndexTypeFactory> factories = {
{ "ClusterEngine", arangodb::iresearch::IResearchLinkCoordinator::make },
{ "MMFilesEngine", arangodb::iresearch::IResearchMMFilesLink::make },
{ "RocksDBEngine", arangodb::iresearch::IResearchRocksDBLink::make }
static const std::map<std::string, arangodb::IndexTypeFactory const*> factories = {
{ "ClusterEngine", &arangodb::iresearch::IResearchLinkCoordinator::factory() },
{ "MMFilesEngine", &arangodb::iresearch::IResearchMMFilesLink::factory() },
{ "RocksDBEngine", &arangodb::iresearch::IResearchRocksDBLink::factory() }
};
auto const& indexType = arangodb::iresearch::DATA_SOURCE_TYPE.name();

Expand All @@ -255,15 +255,15 @@ void registerIndexFactory() {
// ok to const-cast since this should only be called on startup
auto& indexFactory =
const_cast<arangodb::IndexFactory&>(engine->indexFactory());
auto res = indexFactory.emplaceFactory(indexType, entry.second);
auto res = indexFactory.emplace(indexType, *(entry.second));

if (!res.ok()) {
THROW_ARANGO_EXCEPTION_MESSAGE(
res.errorNumber(),
std::string("failure registering IResearch link factory with index factory from feature '") + entry.first + "': " + res.errorMessage()
);
}

/*
res = indexFactory.emplaceNormalizer(
indexType, arangodb::iresearch::IResearchLinkHelper::normalize
);
Expand All @@ -274,6 +274,7 @@ void registerIndexFactory() {
std::string("failure registering IResearch link normalizer with index factory from feature '") + entry.first + "': " + res.errorMessage()
);
}
*/
}
}

Expand Down Expand Up @@ -845,4 +846,4 @@ NS_END // arangodb

// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
Loading
0