10000 Feature/arangosearch link version by gnusi · Pull Request #14717 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/arangosearch link version #14717

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 18 commits into from
Sep 2, 2021
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
gnusi committed Aug 31, 2021
commit 4462900990ab8a75cf834e43ce04dddb63dffdb8
100 changes: 50 additions & 50 deletions arangod/ClusterEngine/ClusterIndexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,53 +44,55 @@

namespace {

struct DefaultIndexFactory : public arangodb::IndexTypeFactory {
using namespace arangodb;

struct DefaultIndexFactory : public IndexTypeFactory {
std::string const _type;

explicit DefaultIndexFactory(arangodb::application_features::ApplicationServer& server,
explicit DefaultIndexFactory(application_features::ApplicationServer& server,
std::string const& type)
: IndexTypeFactory(server), _type(type) {}

bool equal(arangodb::velocypack::Slice const& lhs,
arangodb::velocypack::Slice const& rhs,
bool equal(velocypack::Slice lhs,
velocypack::Slice rhs,
std::string const& dbname) const override {
auto& clusterEngine =
_server.getFeature<arangodb::EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
_server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
auto* engine = clusterEngine.actualEngine();

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

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

std::shared_ptr<arangodb::Index> instantiate(arangodb::LogicalCollection& collection,
arangodb::velocypack::Slice const& definition,
arangodb::IndexId id,
bool /* isClusterConstructor */) const override {
std::shared_ptr<Index> instantiate(LogicalCollection& collection,
velocypack::Slice definition,
IndexId id,
bool /* isClusterConstructor */) const override {
auto& clusterEngine =
_server.getFeature<arangodb::EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
_server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
auto ct = clusterEngine.engineType();

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

virtual arangodb::Result normalize(
arangodb::velocypack::Builder& normalized,
arangodb::velocypack::Slice definition,
virtual Result normalize(
velocypack::Builder& normalized,
velocypack::Slice definition,
bool isCreation,
TRI_vocbase_t const& vocbase) const override {
auto& clusterEngine =
_server.getFeature<arangodb::EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
_server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
auto* engine = clusterEngine.actualEngine();

if (!engine) {
return arangodb::Result(
return Result(
TRI_ERROR_INTERNAL,
"cannot find storage engine while normalizing index");
}
Expand All @@ -101,50 +103,48 @@ struct DefaultIndexFactory : public arangodb::IndexTypeFactory {
};

struct EdgeIndexFactory : public DefaultIndexFactory {
explicit EdgeIndexFactory(arangodb::application_features::ApplicationServer& server,
explicit EdgeIndexFactory(application_features::ApplicationServer& server,
std::string const& type)
: DefaultIndexFactory(server, type) {}

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

auto& clusterEngine =
_server.getFeature<arangodb::EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
auto& clusterEngine = _server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
auto ct = clusterEngine.engineType();

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

struct PrimaryIndexFactory : public DefaultIndexFactory {
explicit PrimaryIndexFactory(arangodb::application_features::ApplicationServer& server,
explicit PrimaryIndexFactory(application_features::ApplicationServer& server,
std::string const& type)
: DefaultIndexFactory(server, type) {}

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

auto& clusterEngine =
_server.getFeature<arangodb::EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
auto& clusterEngine = _server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
auto ct = clusterEngine.engineType();

return std::make_shared<arangodb::ClusterIndex>(arangodb::IndexId::primary(), collection,
ct, arangodb::Index::TRI_IDX_TYPE_PRIMARY_INDEX,
definition);
return std::make_shared<ClusterIndex>(
IndexId::primary(), collection, ct,
Index::TRI_IDX_TYPE_PRIMARY_INDEX, definition);
}
};

Expand Down Expand Up @@ -180,7 +180,7 @@ ClusterIndexFactory::ClusterIndexFactory(application_features::ApplicationServer
/// @brief index name aliases (e.g. "persistent" => "hash", "skiplist" =>
/// "hash") used to display storage engine capabilities
std::unordered_map<std::string, std::string> ClusterIndexFactory::indexAliases() const {
auto& ce = _server.getFeature<EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
auto& ce = _server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
auto* ae = ce.actualEngine();
if (!ae) {
THROW_ARANGO_EXCEPTION_MESSAGE(
Expand All @@ -194,7 +194,7 @@ Result ClusterIndexFactory::enhanceIndexDefinition(
velocypack::Builder& normalized,
bool isCreation,
TRI_vocbase_t const& vocbase) const {
auto& ce = _server.getFeature<EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
auto& ce = _server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();

auto* ae = ce.actualEngine();

Expand All @@ -206,8 +206,8 @@ Result ClusterIndexFactory::enhanceIndexDefinition(
definition, normalized, isCreation, vocbase);
}

void ClusterIndexFactory::fillSystemIndexes(arangodb::LogicalCollection& col,
std::vector<std::shared_ptr<arangodb::Index>>& systemIndexes) const {
void ClusterIndexFactory::fillSystemIndexes(LogicalCollection& col,
std::vector<std::shared_ptr<Index>>& systemIndexes) const {
// create primary index
VPackBuilder input;
input.openObject();
Expand All @@ -222,10 +222,10 @@ void ClusterIndexFactory::fillSystemIndexes(arangodb::LogicalCollection& col,
input.close();

// get the storage engine type
auto& ce = _server.getFeature<EngineSelectorFeature>().engine<arangodb::ClusterEngine>();
auto& ce = _server.getFeature<EngineSelectorFeature>().engine<ClusterEngine>();
ClusterEngineType ct = ce.engineType();

systemIndexes.emplace_back(std::make_shared<arangodb::ClusterIndex>(
systemIndexes.emplace_back(std::make_shared<ClusterIndex>(
IndexId::primary(), col, ct, Index::TRI_IDX_TYPE_PRIMARY_INDEX, input.slice()));

// create edges indexes
Expand All @@ -249,7 +249,7 @@ void ClusterIndexFactory::fillSystemIndexes(arangodb::LogicalCollection& col,
input.add(StaticStrings::IndexUnique, VPackValue(false));
input.add(StaticStrings::IndexSparse, VPackValue(false));
input.close();
systemIndexes.emplace_back(std::make_shared<arangodb::ClusterIndex>(
systemIndexes.emplace_back(std::make_shared<ClusterIndex>(
IndexId::edgeFrom(), col, ct, Index::TRI_IDX_TYPE_EDGE_INDEX, input.slice()));

// second edge index
Expand All @@ -267,15 +267,15 @@ void ClusterIndexFactory::fillSystemIndexes(arangodb::LogicalCollection& col,
input.add(StaticStrings::IndexUnique, VPackValue(false));
input.add(StaticStrings::IndexSparse, VPackValue(false));
input.close();
systemIndexes.emplace_back(std::make_shared<arangodb::ClusterIndex>(
systemIndexes.emplace_back(std::make_shared<ClusterIndex>(
IndexId::edgeTo(), col, ct, Index::TRI_IDX_TYPE_EDGE_INDEX, input.slice()));
}
}
}

void ClusterIndexFactory::prepareIndexes(
LogicalCollection& col, arangodb::velocypack::Slice const& indexesSlice,
std::vector<std::shared_ptr<arangodb::Index>>& indexes) const {
LogicalCollection& col, velocypack::Slice indexesSlice,
std::vector<std::shared_ptr<Index>>& indexes) const {
TRI_ASSERT(indexesSlice.isArray());

for (VPackSlice v : VPackArrayIterator(indexesSlice)) {
Expand All @@ -294,7 +294,7 @@ void ClusterIndexFactory::prepareIndexes(
TRI_ASSERT(idx != nullptr);
indexes.emplace_back(std::move(idx));
} catch (std::exception const& ex) {
LOG_TOPIC("7ed52", ERR, arangodb::Logger::ENGINES)
LOG_TOPIC("7ed52", ERR, Logger::ENGINES)
<< "error creating index from definition '" << v.toString() << "': " << ex.what();

}
Expand Down
8 changes: 4 additions & 4 deletions arangod/ClusterEngine/ClusterIndexFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class ClusterIndexFactory final : public IndexFactory {
/// used to display storage engine capabilities
std::unordered_map<std::string, std::string> indexAliases() const override;

void fillSystemIndexes(arangodb::LogicalCollection& col,
std::vector<std::shared_ptr<arangodb::Index>>& systemIndexes) const override;
void fillSystemIndexes(LogicalCollection& col,
std::vector<std::shared_ptr<Index>>& systemIndexes) const override;

/// @brief create indexes from a list of index definitions
void prepareIndexes(LogicalCollection& col, arangodb::velocypack::Slice const& indexesSlice,
std::vector<std::shared_ptr<arangodb::Index>>& indexes) const override;
void prepareIndexes(LogicalCollection& col, velocypack::Slice indexesSlice,
std::vector<std::shared_ptr<Index>>& indexes) const override;
};

} // namespace arangodb
Expand Down
65 changes: 34 additions & 31 deletions arangod/IResearch/IResearchLinkCoordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@

namespace {

arangodb::ClusterEngineType getEngineType(arangodb::application_features::ApplicationServer& server) {
using namespace arangodb;

ClusterEngineType getEngineType(application_features::ApplicationServer& server) {
#ifdef ARANGODB_USE_GOOGLE_TESTS
// during the unit tests there is a mock storage engine which cannot be casted
// to a ClusterEngine at all. the only sensible way to find out the engine type is
// to try a dynamic_cast here and assume the MockEngine if the cast goes wrong
auto& engine = server.getFeature<arangodb::EngineSelectorFeature>().engine();
auto cast = dynamic_cast<arangodb::ClusterEngine*>(&engine);
auto& engine = server.getFeature<EngineSelectorFeature>().engine();
auto cast = dynamic_cast<ClusterEngine*>(&engine);
if (cast != nullptr) {
return cast->engineType();
}
return arangodb::ClusterEngineType::MockEngine;
return ClusterEngineType::MockEngine;
#else
return server.getFeature<arangodb::EngineSelectorFeature>()
.engine<arangodb::ClusterEngine>()
Expand All @@ -77,32 +79,30 @@ IResearchLinkCoordinator::IResearchLinkCoordinator(IndexId id, LogicalCollection
_sparse = true; // always sparse
}

void IResearchLinkCoordinator::toVelocyPack( // generate definition
arangodb::velocypack::Builder& builder, // destination buffer
std::underlying_type<arangodb::Index::Serialize>::type flags // definition flags
) const {
void IResearchLinkCoordinator::toVelocyPack(
velocypack::Builder& builder,
std::underlying_type<Index::Serialize>::type flags) const {
if (builder.isOpenObject()) {
THROW_ARANGO_EXCEPTION(arangodb::Result( // result
TRI_ERROR_BAD_PARAMETER, // code
THROW_ARANGO_EXCEPTION(Result(
TRI_ERROR_BAD_PARAMETER,
std::string("failed to generate link definition for arangosearch view "
"Cluster link '") +
std::to_string(arangodb::Index::id().id()) + "'"));
std::to_string(Index::id().id()) + "'"));
}

auto forPersistence = // definition for persistence
arangodb::Index::hasFlag(flags, arangodb::Index::Serialize::Internals);
auto forPersistence = Index::hasFlag(flags, Index::Serialize::Internals);

builder.openObject();

if (!properties(builder, forPersistence).ok()) {
THROW_ARANGO_EXCEPTION(arangodb::Result( // result
TRI_ERROR_INTERNAL, // code
THROW_ARANGO_EXCEPTION(Result(
TRI_ERROR_INTERNAL,
std::string("failed to generate link definition for arangosearch view "
"Cluster link '") +
std::to_string(arangodb::Index::id().id()) + "'"));
std::to_string(Index::id().id()) + "'"));
}

if (arangodb::Index::hasFlag(flags, arangodb::Index::Serialize::Figures)) {
if (Index::hasFlag(flags, Index::Serialize::Figures)) {
builder.add("figures", VPackValue(VPackValueType::Object));
toVelocyPackFigures(builder);
builder.close();
Expand All @@ -111,20 +111,20 @@ void IResearchLinkCoordinator::toVelocyPack( // generate definition
builder.close();
}

IResearchLinkCoordinator::IndexFactory::IndexFactory(arangodb::application_features::ApplicationServer& server)
IResearchLinkCoordinator::IndexFactory::IndexFactory(application_features::ApplicationServer& server)
: IndexTypeFactory(server) {}

bool IResearchLinkCoordinator::IndexFactory::equal(arangodb::velocypack::Slice const& lhs,
arangodb::velocypack::Slice const& rhs,
bool IResearchLinkCoordinator::IndexFactory::equal(velocypack::Slice lhs,
velocypack::Slice rhs,
std::string const& dbname) const {
return arangodb::iresearch::IResearchLinkHelper::equal(_server, lhs, rhs, dbname);
return IResearchLinkHelper::equal(_server, lhs, rhs, dbname);
}

std::shared_ptr<arangodb::Index> IResearchLinkCoordinator::IndexFactory::instantiate(
arangodb::LogicalCollection& collection, arangodb::velocypack::Slice const& definition,
IndexId id, bool isClusterConstructor) const {
auto link = std::shared_ptr<arangodb::iresearch::IResearchLinkCoordinator>(
new arangodb::iresearch::IResearchLinkCoordinator(id, collection));
std::shared_ptr<Index> IResearchLinkCoordinator::IndexFactory::instantiate(
LogicalCollection& collection, VPackSlice definition,
IndexId id, bool /*isClusterConstructor*/) const {
auto link = std::shared_ptr<IResearchLinkCoordinator>(
new IResearchLinkCoordinator(id, collection));
auto res = link->init(definition);

if (!res.ok()) {
Expand All @@ -134,13 +134,16 @@ std::shared_ptr<arangodb::Index> IResea 7CD5 rchLinkCoordinator::IndexFactory::instant
return link;
}

arangodb::Result IResearchLinkCoordinator::IndexFactory::normalize(
arangodb::velocypack::Builder& normalized,
arangodb::velocypack::Slice definition,
Result IResearchLinkCoordinator::IndexFactory::normalize(
velocypack::Builder& normalized,
velocypack::Slice definition,
bool isCreation,
TRI_vocbase_t const& vocbase) const {
return arangodb::iresearch::IResearchLinkHelper::normalize(
normalized, definition, isCreation, vocbase);
// no attribute set in a definition -> old version
constexpr LinkVersion defaultVersion = LinkVersion::MIN;

return IResearchLinkHelper::normalize(
normalized, definition, isCreation, vocbase, defaultVersion);
}

std::shared_ptr<IResearchLinkCoordinator::IndexFactory> IResearchLinkCoordinator::createFactory(
Expand Down
Loading
0