10000 issue 505.1: move index json comparison into index-type-specific impl… · surajpatel11/arangodb@e16be8f · GitHub
[go: up one dir, main page]

Skip to content

Commit e16be8f

Browse files
vasiliy-arangodbAndrey Abramov
authored and
Andrey Abramov
committed
issue 505.1: move index json comparison into index-type-specific implementations to address issue with incorrect definition comparison (arangodb#7430)
* issue 505: move index json comparison into index-type-specific implementations to address issue with incorrect definition comparison * remove commented-out code * fix typo * backport: add additional logging and fix typo
1 parent 6ba81d7 commit e16be8f

26 files changed

+1598
-1022
lines changed

arangod/ClusterEngine/ClusterIndexFactory.cpp

Lines changed: 186 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -38,90 +38,199 @@
3838
#include <velocypack/Slice.h>
3939
#include <velocypack/velocypack-aliases.h>
4040

41-
namespace arangodb {
41+
namespace {
4242

43-
ClusterIndexFactory::ClusterIndexFactory() {
44-
emplaceFactory(
45-
"edge",
46-
[](
47-
LogicalCollection& collection,
48-
velocypack::Slice const& definition,
49-
TRI_idx_iid_t id,
50-
bool isClusterConstructor
51-
)->std::shared_ptr<Index> {
52-
if (!isClusterConstructor) {
53-
// this indexes cannot be created directly
54-
THROW_ARANGO_EXCEPTION_MESSAGE(
55-
TRI_ERROR_INTERNAL, "cannot create edge index"
56-
);
57-
}
58-
59-
auto* ce = static_cast<ClusterEngine*>(EngineSelectorFeature::ENGINE);
60-
auto ct = ce->engineType();
61-
62-
return std::make_shared<ClusterIndex>(
63-
id, collection, ct, Index::TRI_IDX_TYPE_EDGE_INDEX, definition
43+
struct DefaultIndexFactory: public arangodb::IndexTypeFactory {
44+
std::string const _type;
45+
46+
DefaultIndexFactory(std::string const& type): _type(type) {}
47+
48+
virtual bool equal(
49+
arangodb::velocypack::Slice const& lhs,
50+
arangodb::velocypack::Slice const& rhs
51+
) const override {
52+
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
53+
arangodb::EngineSelectorFeature::ENGINE
54+
);
55+
56+
if (!clusterEngine) {
57+
THROW_ARANGO_EXCEPTION(arangodb::Result(
58+
TRI_ERROR_INTERNAL,
59+
"cannot find cluster engine while normalizing index"
60+
));
61+
}
62+
63+
auto* engine = clusterEngine->actualEngine();
64+
65+
if (!engine) {
66+
THROW_ARANGO_EXCEPTION(arangodb::Result(
67+
TRI_ERROR_INTERNAL,
68+
"cannot find storage engine while normalizing index"
69+
));
70+
}
71+
72+
return engine->indexFactory().factory(_type).equal(lhs, rhs);
73+
}
74+
75+
virtual arangodb::Result instantiate(
76+
std::shared_ptr<arangodb::Index>& index,
77+
arangodb::LogicalCollection& collection,
78+
arangodb::velocypack::Slice const& definition,
79+
TRI_idx_iid_t id,
80+
bool //isClusterConstructor
81+
) const override {
82+
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
83+
arangodb::EngineSelectorFeature::ENGINE
84+
);
85+
86+
if (!clusterEngine) {
87+
return arangodb::Result(
88+
TRI_ERROR_INTERNAL,
89+
"cannot find cluster engine while creating index"
6490
);
6591
}
66-
);
67-
68-
emplaceFactory(
69-
"primary",
70-
[](
71-
LogicalCollection& collection,
72-
velocypack::Slice const& definition,
73-
TRI_idx_iid_t id,
74-
bool isClusterConstructor
75-
)->std::shared_ptr<Index> {
76-
if (!isClusterConstructor) {
77-
// this indexes cannot be created directly
78-
THROW_ARANGO_EXCEPTION_MESSAGE(
79-
TRI_ERROR_INTERNAL, "cannot create primary index"
80-
);
81-
}
82-
83-
auto* ce = static_cast<ClusterEngine*>(EngineSelectorFeature::ENGINE);
84-
auto ct = ce->engineType();
85-
86-
return std::make_shared<ClusterIndex>(
87-
0, collection, ct, Index::TRI_IDX_TYPE_PRIMARY_INDEX, definition
92+
93+
auto ct = clusterEngine->engineType();
94+
95+
index = std::make_shared<arangodb::ClusterIndex>(
96+
id, collection, ct, arangodb::Index::type(_type), definition
97+
);
98+
99+
return arangodb::Result();
100+
}
101+
102+
virtual arangodb::Result normalize(
103+
arangodb::velocypack::Builder& normalized,
104+
arangodb::velocypack::Slice definition,
105+
bool isCreation
106+
) const override {
107+
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
108+
arangodb::EngineSelectorFeature::ENGINE
109+
);
110+
111+
if (!clusterEngine) {
112+
return arangodb::Result(
113+
TRI_ERROR_INTERNAL,
114+
"cannot find cluster engine while normalizing index"
115+
);
116+
}
117+
118+
auto* engine = clusterEngine->actualEngine();
119+
120+
if (!engine) {
121+
return arangodb::Result(
122+
TRI_ERROR_INTERNAL,
123+
"cannot find storage engine while normalizing index"
88124
);
89125
}
90-
);
91-
92-
// both engines support all types right now
93-
static const std::vector<std::string> supported = {
94-
"fulltext",
95-
"geo",
96-
"geo1",
97-
"geo2",
98-
"hash",
99-
"persistent",
100-
"skiplist"
101-
};
102-
103-
for (auto& typeStr: supported) {
104-
auto type = Index::type(typeStr);
105-
106-
emplaceFactory(
107-
typeStr,
108-
[type](
109-
LogicalCollection& collection,
110-
velocypack::Slice const& definition,
111-
TRI_idx_iid_t id,
112-
bool isClusterConstructor
113-
)->std::shared_ptr<Index> {
114-
auto* ce = static_cast<ClusterEngine*>(EngineSelectorFeature::ENGINE);
115-
auto ct = ce->engineType();
116-
117-
return std::make_shared<ClusterIndex>(
118-
id, collection, ct, type, definition
119-
);
120-
}
126+
127+
return engine->indexFactory().factory(_type).normalize(
128+
normalized, definition, isCreation
121129
);
122130
}
131+
};
132+
133+
struct EdgeIndexFactory: public DefaultIndexFactory {
134+
EdgeIndexFactory(std::string const& type): DefaultIndexFactory(type) {}
135+
136+
virtual arangodb::Result instantiate(
137+
std::shared_ptr<arangodb::Index>& index,
138+
arangodb::LogicalCollection& collection,
139+
arangodb::velocypack::Slice const& definition,
140+
TRI_idx_iid_t id,
141+
bool isClusterConstructor
142+
) const override {
143+
if (!isClusterConstructor) {
144+
// this indexes cannot be created directly
145+
return arangodb::Result(TRI_ERROR_INTERNAL, "cannot create edge index");
146+
}
147+
148+
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
149+
arangodb::EngineSelectorFeature::ENGINE
150+
);
151+
152+
if (!clusterEngine) {
153+
return arangodb::Result(
154+
TRI_ERROR_INTERNAL,
155+
"cannot find storage engine while creating index"
156+
);
157+
}
158+
159+
auto ct = clusterEngine->engineType();
160+
161+
index = std::make_shared<arangodb::ClusterIndex>(
162+
id, collection, ct, arangodb::Index::TRI_IDX_TYPE_EDGE_INDEX, definition
163+
);
164+
165+
return arangodb::Result();
166+
}
167+
};
168+
169+
struct PrimaryIndexFactory: public DefaultIndexFactory {
170+
PrimaryIndexFactory(std::string const& type): DefaultIndexFactory(type) {}
171+
172+
virtual arangodb::Result instantiate(
173+
std::shared_ptr<arangodb::Index>& index,
174+
arangodb::LogicalCollection& collection,
175+
arangodb::velocypack::Slice const& definition,
176+
TRI_idx_iid_t id,
177+
bool isClusterConstructor
178+
) const override {
179+
if (!isClusterConstructor) {
180+
// this indexes cannot be created directly
181+
return arangodb::Result(
182+
TRI_ERROR_INTERNAL,
183+
"cannot create primary index"
184+
);
185+
}
186+
187+
auto* clusterEngine = static_cast<arangodb::ClusterEngine*>(
188+
arangodb::EngineSelectorFeature::ENGINE
189+
);
190+
191+
if (!clusterEngine) {
192+
return arangodb::Result(
193+
TRI_ERROR_INTERNAL,
194+
"cannot find storage engine while creating index"
195+
);
196+
}
197+
198+
auto ct = clusterEngine->engineType();
199+
200+
index = std::make_shared<arangodb::ClusterIndex>(
201+
0, collection, ct, arangodb::Index::TRI_IDX_TYPE_PRIMARY_INDEX, definition
202+
);
203+
204+
return arangodb::Result();
205+
}
206+
};
207+
123208
}
124-
209+
210+
namespace arangodb {
211+
212+
ClusterIndexFactory::ClusterIndexFactory() {
213+
static const EdgeIndexFactory edgeIndexFactory("edge");
214+
static const DefaultIndexFactory fulltextIndexFactory("fulltext");
215+
static const DefaultIndexFactory geoIndexFactory("geo");
216+
static const DefaultIndexFactory geo1IndexFactory("geo1");
217+
static const DefaultIndexFactory geo2IndexFactory("geo2");
218+
static const DefaultIndexFactory hashIndexFactory("hash");
219+
static const DefaultIndexFactory persistentIndexFactory("persistent");
220+
static const PrimaryIndexFactory primaryIndexFactory("primary");
221+
static const DefaultIndexFactory skiplistIndexFactory("skiplist");
222+
223+
emplace(edgeIndexFactory._type, edgeIndexFactory);
224+
emplace(fulltextIndexFactory._type, fulltextIndexFactory);
225+
emplace(geoIndexFactory._type, geoIndexFactory);
226+
emplace(geo1IndexFactory._type, geo1IndexFactory);
227+
emplace(geo2IndexFactory._type, geo2IndexFactory);
228+
emplace(hashIndexFactory._type, hashIndexFactory);
229+
emplace(persistentIndexFactory._type, persistentIndexFactory);
230+
emplace(primaryIndexFactory._type, primaryIndexFactory);
231+
emplace(skiplistIndexFactory._type, skiplistIndexFactory);
232+
}
233+
125234
Result ClusterIndexFactory::enhanceIndexDefinition(VPackSlice const definition,
126235
VPackBuilder& normalized,
127236
bool isCreation,
@@ -239,4 +348,4 @@ void ClusterIndexFactory::prepareIndexes(
239348

240349
// -----------------------------------------------------------------------------
241350
// --SECTION-- END-OF-FILE
242-
// -----------------------------------------------------------------------------
351+
// -----------------------------------------------------------------------------

arangod/IResearch/IResearchFeature.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ void registerFilters(arangodb::aql::AqlFunctionFeature& functions) {
197197
}
198198

199199
void registerIndexFactory() {
200-
static const std::map<std::string, arangodb::IndexFactory::IndexTypeFactory> factories = {
201-
{ "ClusterEngine", arangodb::iresearch::IResearchLinkCoordinator::make },
202-
{ "MMFilesEngine", arangodb::iresearch::IResearchMMFilesLink::make },
203-
{ "RocksDBEngine", arangodb::iresearch::IResearchRocksDBLink::make }
200+
static const std::map<std::string, arangodb::IndexTypeFactory const*> factories = {
201+
{ "ClusterEngine", &arangodb::iresearch::IResearchLinkCoordinator::factory() },
202+
{ "MMFilesEngine", &arangodb::iresearch::IResearchMMFilesLink::factory() },
203+
{ "RocksDBEngine", &arangodb::iresearch::IResearchRocksDBLink::factory() }
204204
};
205205
auto const& indexType = arangodb::iresearch::DATA_SOURCE_TYPE.name();
206206

@@ -220,25 +220,14 @@ void registerIndexFactory() {
220220
// ok to const-cast since this should only be called on startup
221221
auto& indexFactory =
222222
const_cast<arangodb::IndexFactory&>(engine->indexFactory());
223-
auto res = indexFactory.emplaceFactory(indexType, entry.second);
223+
auto res = indexFactory.emplace(indexType, *(entry.second));
224224

225225
if (!res.ok()) {
226226
THROW_ARANGO_EXCEPTION_MESSAGE(
227227
res.errorNumber(),
228228
std::string("failure registering IResearch link factory with index factory from feature '") + entry.first + "': " + res.errorMessage()
229229
);
230230
}
231-
232-
res = indexFactory.emplaceNormalizer(
233-
indexType, arangodb::iresearch::IResearchLinkHelper::normalize
234-
);
235-
236-
if (!res.ok()) {
237-
THROW_ARANGO_EXCEPTION_MESSAGE(
238-
res.errorNumber(),
239-
std::string("failure registering IResearch link normalizer with index factory from feature '") + entry.first + "': " + res.errorMessage()
240-
);
241-
}
242231
}
243232
}
244233

0 commit comments

Comments
 (0)
0