38
38
#include < velocypack/Slice.h>
39
39
#include < velocypack/velocypack-aliases.h>
40
40
41
- namespace arangodb {
41
+ namespace {
42
42
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"
64
90
);
65
91
}
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"
88
124
);
89
125
}
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
121
129
);
122
130
}
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
+
123
208
}
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
+
125
234
Result ClusterIndexFactory::enhanceIndexDefinition (VPackSlice const definition,
126
235
VPackBuilder& normalized,
127
236
bool isCreation,
@@ -239,4 +348,4 @@ void ClusterIndexFactory::prepareIndexes(
239
348
240
349
// -----------------------------------------------------------------------------
241
350
// --SECTION-- END-OF-FILE
242
- // -----------------------------------------------------------------------------
351
+ // -----------------------------------------------------------------------------
0 commit comments