27
27
28
28
#include " Basics/Common.h"
29
29
#include " Basics/JsonHelper.h"
30
+ #include " Basics/VelocyPackHelper.h"
30
31
#include " Basics/Mutex.h"
31
32
#include " Basics/ReadWriteLock.h"
32
33
#include " Cluster/AgencyComm.h"
35
36
#include " VocBase/vocbase.h"
36
37
37
38
#include < velocypack/Slice.h>
39
+ #include < velocypack/Iterator.h>
40
+ #include < velocypack/velocypack-aliases.h>
38
41
39
42
struct TRI_json_t ;
40
43
@@ -55,7 +58,7 @@ class CollectionInfo {
55
58
public:
56
59
CollectionInfo ();
57
60
58
- explicit CollectionInfo (struct TRI_json_t * );
61
+ CollectionInfo (std::shared_ptr<VPackBuilder>, VPackSlice );
59
62
60
63
CollectionInfo (CollectionInfo const &);
61
64
@@ -72,70 +75,65 @@ class CollectionInfo {
72
75
// ////////////////////////////////////////////////////////////////////////////
73
76
74
77
int replicationFactor () const {
75
- TRI_json_t* const node
76
- = arangodb::basics::JsonHelper::getObjectElement (_json,
77
- " replicationFactor" );
78
-
79
- if (TRI_IsNumberJson (node)) {
80
- return (int ) (node->_value ._number );
81
- }
82
- return 1 ;
78
+ return arangodb::basics::VelocyPackHelper::getNumericValue<TRI_voc_size_t>(
79
+ _slice, " replicationFactor" , 1 );
83
80
}
84
81
85
82
// ////////////////////////////////////////////////////////////////////////////
86
83
// / @brief returns the replication quorum
87
84
// ////////////////////////////////////////////////////////////////////////////
88
85
89
86
int replicationQuorum () const {
90
- TRI_json_t* const node
91
- = arangodb::basics::JsonHelper::getObjectElement (_json,
92
- " replicationQuorum" );
93
-
94
- if (TRI_IsNumberJson (node)) {
95
- return (int ) (node->_value ._number );
96
- }
97
- return 1 ;
87
+ return arangodb::basics::VelocyPackHelper::getNumericValue<TRI_voc_size_t>(
88
+ _slice, " replicationQuorum" , 1 );
98
89
}
99
90
100
91
// ////////////////////////////////////////////////////////////////////////////
101
92
// / @brief checks whether there is no info contained
102
93
// ////////////////////////////////////////////////////////////////////////////
103
94
104
95
bool empty () const {
105
- return ( nullptr == _json); // || (id() == 0 );
96
+ return _slice. isNone ( );
106
97
}
107
98
108
99
// ////////////////////////////////////////////////////////////////////////////
109
100
// / @brief returns the collection id
110
101
// ////////////////////////////////////////////////////////////////////////////
111
102
112
103
TRI_voc_cid_t id () const {
113
- return arangodb::basics::JsonHelper::stringUInt64 (_json, " id" );
104
+ if (!_slice.isObject ()) {
105
+ return 0 ;
106
+ }
107
+ VPackSlice idSlice = _slice.get (" id" );
108
+ if (idSlice.isString ()) {
109
+ return arangodb::basics::VelocyPackHelper::stringUInt64 (idSlice);
110
+ }
111
+ return 0 ;
114
112
}
115
113
116
114
// ////////////////////////////////////////////////////////////////////////////
117
115
// / @brief returns the collection id as a string
118
116
// ////////////////////////////////////////////////////////////////////////////
119
117
120
118
std::string id_as_string () const {
121
- return arangodb::basics::JsonHelper ::getStringValue (_json , " id" , " " );
119
+ return arangodb::basics::VelocyPackHelper ::getStringValue (_slice , " id" , " " );
122
120
}
123
121
124
122
// ////////////////////////////////////////////////////////////////////////////
125
123
// / @brief returns the collection name
126
124
// ////////////////////////////////////////////////////////////////////////////
127
125
128
126
std::string name () const {
129
- return arangodb::basics::JsonHelper ::getStringValue (_json , " name" , " " );
127
+ return arangodb::basics::VelocyPackHelper ::getStringValue (_slice , " name" , " " );
130
128
}
131
129
132
130
// ////////////////////////////////////////////////////////////////////////////
133
131
// / @brief returns the collection type
134
132
// ////////////////////////////////////////////////////////////////////////////
135
133
136
134
TRI_col_type_e type () const {
137
- return (TRI_col_type_e)arangodb::basics::JsonHelper ::getNumericValue<int >(
138
- _json , " type" , (int )TRI_COL_TYPE_UNKNOWN);
135
+ return (TRI_col_type_e)arangodb::basics::VelocyPackHelper ::getNumericValue<int >(
136
+ _slice , " type" , (int )TRI_COL_TYPE_UNKNOWN);
139
137
}
140
138
141
139
// ////////////////////////////////////////////////////////////////////////////
@@ -144,8 +142,8 @@ class CollectionInfo {
144
142
145
143
TRI_vocbase_col_status_e status () const {
146
144
return (TRI_vocbase_col_status_e)
147
- arangodb::basics::JsonHelper ::getNumericValue<int >(
148
- _json , " status" , (int )TRI_VOC_COL_STATUS_CORRUPTED);
145
+ arangodb::basics::VelocyPackHelper ::getNumericValue<int >(
146
+ _slice , " status" , (int )TRI_VOC_COL_STATUS_CORRUPTED);
149
147
}
150
148
151
149
// ////////////////////////////////////////////////////////////////////////////
@@ -161,7 +159,7 @@ class CollectionInfo {
161
159
// ////////////////////////////////////////////////////////////////////////////
162
160
163
161
bool deleted () const {
164
- return arangodb::basics::JsonHelper ::getBooleanValue (_json , " deleted" ,
162
+ return arangodb::basics::VelocyPackHelper ::getBooleanValue (_slice , " deleted" ,
165
163
false );
166
164
}
167
165
@@ -170,7 +168,7 @@ class CollectionInfo {
170
168
// ////////////////////////////////////////////////////////////////////////////
171
169
172
170
bool doCompact () const {
173
- return arangodb::basics::JsonHelper ::getBooleanValue (_json , " doCompact" ,
171
+ return arangodb::basics::VelocyPackHelper ::getBooleanValue (_slice , " doCompact" ,
174
172
false );
175
173
}
176
174
@@ -179,7 +177,7 @@ class CollectionInfo {
179
177
// ////////////////////////////////////////////////////////////////////////////
180
178
181
179
bool isSystem () const {
182
- return arangodb::basics::JsonHelper ::getBooleanValue (_json , " isSystem" ,
180
+ return arangodb::basics::VelocyPackHelper ::getBooleanValue (_slice , " isSystem" ,
183
181
false );
184
182
}
185
183
@@ -188,45 +186,41 @@ class CollectionInfo {
188
186
// ////////////////////////////////////////////////////////////////////////////
189
187
190
188
bool isVolatile () const {
191
- return arangodb::basics::JsonHelper ::getBooleanValue (_json , " isVolatile" ,
189
+ return arangodb::basics::VelocyPackHelper ::getBooleanValue (_slice , " isVolatile" ,
192
190
false );
193
191
}
194
192
195
193
// ////////////////////////////////////////////////////////////////////////////
196
194
// / @brief returns the indexes
197
195
// ////////////////////////////////////////////////////////////////////////////
198
196
199
- TRI_json_t const * getIndexes () const {
200
- return arangodb::basics::JsonHelper::getObjectElement (_json, " indexes" );
197
+ VPackSlice const getIndexes () const {
198
+ if (_slice.isNone ()) {
199
+ return VPackSlice ();
200
+ }
201
+ return _slice.get (" indexes" );
201
202
}
202
203
203
204
// ////////////////////////////////////////////////////////////////////////////
204
205
// / @brief returns a copy of the key options
205
- // / the caller is responsible for freeing it
206
206
// ////////////////////////////////////////////////////////////////////////////
207
207
208
- TRI_json_t* keyOptions () const {
209
- TRI_json_t const * keyOptions =
210
- arangodb::basics::JsonHelper::getObjectElement (_json, " keyOptions" );
211
-
212
- if (keyOptions != nullptr ) {
213
- return TRI_CopyJson (TRI_UNKNOWN_MEM_ZONE, keyOptions);
208
+ VPackSlice const keyOptions () const {
209
+ if (_slice.isNone ()) {
210
+ return VPackSlice ();
214
211
}
215
-
216
- return nullptr ;
212
+ return _slice.get (" keyOptions" );
217
213
}
218
214
219
215
// ////////////////////////////////////////////////////////////////////////////
220
216
// / @brief whether or not a collection allows user-defined keys
221
217
// ////////////////////////////////////////////////////////////////////////////
222
218
223
219
bool allowUserKeys () const {
224
- TRI_json_t const * keyOptions =
225
- arangodb::basics::JsonHelper::getObjectElement (_json, " keyOptions" );
226
-
227
- if (keyOptions != nullptr ) {
228
- return arangodb::basics::JsonHelper::getBooleanValue (
229
- keyOptions, " allowUserKeys" , true );
220
+ VPackSlice keyOptionsSlice = keyOptions ();
221
+ if (!keyOptionsSlice.isNone ()) {
222
+ return arangodb::basics::VelocyPackHelper::getBooleanValue (
223
+ keyOptionsSlice, " allowUserKeys" , true );
230
224
}
231
225
232
226
return true ; // the default value
@@ -237,7 +231,7 @@ class CollectionInfo {
237
231
// ////////////////////////////////////////////////////////////////////////////
238
232
239
233
bool waitForSync () const {
240
- return arangodb::basics::JsonHelper ::getBooleanValue (_json , " waitForSync" ,
234
+ return arangodb::basics::VelocyPackHelper ::getBooleanValue (_slice , " waitForSync" ,
241
235
false );
242
236
}
243
237
@@ -246,43 +240,56 @@ class CollectionInfo {
246
240
// ////////////////////////////////////////////////////////////////////////////
247
241
248
242
TRI_voc_size_t journalSize () const {
249
- return arangodb::basics::JsonHelper ::getNumericValue<TRI_voc_size_t>(
250
- _json , " journalSize" , 0 );
243
+ return arangodb::basics::VelocyPackHelper ::getNumericValue<TRI_voc_size_t>(
244
+ _slice , " journalSize" , 0 );
251
245
}
252
246
253
247
// ////////////////////////////////////////////////////////////////////////////
254
248
// / @brief returns the number of buckets for indexes
255
249
// ////////////////////////////////////////////////////////////////////////////
256
250
257
251
uint32_t indexBuckets () const {
258
- return arangodb::basics::JsonHelper ::getNumericValue<uint32_t >(
259
- _json , " indexBuckets" , 1 );
252
+ return arangodb::basics::VelocyPackHelper ::getNumericValue<uint32_t >(
253
+ _slice , " indexBuckets" , 1 );
260
254
}
261
255
262
256
// ////////////////////////////////////////////////////////////////////////////
263
257
// / @brief returns the shard keys
264
258
// ////////////////////////////////////////////////////////////////////////////
265
259
266
260
std::vector<std::string> shardKeys () const {
267
- TRI_json_t* const node =
268
- arangodb::basics::JsonHelper::getObjectElement (_json, " shardKeys" );
269
- return arangodb::basics::JsonHelper::stringArray (node);
261
+ std::vector<std::string> shardKeys;
262
+
263
+ if (_slice.isNone ()) {
264
+ return shardKeys;
265
+ }
266
+ auto shardKeysSlice = _slice.get (" shardKeys" );
267
+ if (shardKeysSlice.isArray ()) {
268
+ for (auto const & shardKey: VPackArrayIterator (shardKeysSlice)) {
269
+ shardKeys.push_back (shardKey.copyString ());
270
+ }
271
+ }
272
+
273
+ return shardKeys;
270
274
}
271
275
272
276
// ////////////////////////////////////////////////////////////////////////////
273
277
// / @brief returns true if the default shard key is used
274
278
// ////////////////////////////////////////////////////////////////////////////
275
279
276
280
bool usesDefaultShardKeys () const {
277
- TRI_json_t* const node =
278
- arangodb::basics::JsonHelper::getObjectElement (_json, " shardKeys" );
279
- if (TRI_LengthArrayJson (node) != 1 ) {
281
+ if (_slice.isNone ()) {
282
+ return false ;
283
+ }
284
+ auto shardKeysSlice = _slice.get (" shardKeys" );
285
+ if (!shardKeysSlice.isArray () || shardKeysSlice.length () != 1 ) {
280
286
return false ;
281
287
}
282
- TRI_json_t* firstKey = TRI_LookupArrayJson (node, 0 );
283
- TRI_ASSERT (TRI_IsStringJson (firstKey));
288
+
289
+ auto firstElement = shardKeysSlice.get (0 );
290
+ TRI_ASSERT (firstElement.isString ());
284
291
std::string shardKey =
285
- arangodb::basics::JsonHelper ::getStringValue (firstKey , " " );
292
+ arangodb::basics::VelocyPackHelper ::getStringValue (firstElement , " " );
286
293
return shardKey == TRI_VOC_ATTRIBUTE_KEY;
287
294
}
288
295
@@ -302,22 +309,18 @@ class CollectionInfo {
302
309
return res;
303
310
}
304
311
res.reset (new ShardMap ());
305
- TRI_json_t* const node =
306
- arangodb::basics::JsonHelper::getObjectElement (_json, " shards" );
307
- if (node != nullptr && TRI_IsObjectJson (node)) {
308
- size_t len = TRI_LengthVector (&node->_value ._objects );
309
- for (size_t i = 0 ; i < len; i += 2 ) {
310
- auto key =
311
- static_cast <TRI_json_t*>(TRI_AtVector (&node->_value ._objects , i));
312
- auto value = static_cast <TRI_json_t*>(
313
- TRI_AtVector (&node->_value ._objects , i + 1 ));
314
- if (TRI_IsStringJson (key) && TRI_IsArrayJson (value)) {
315
- ShardID shard = arangodb::basics::JsonHelper::getStringValue (key, " " );
316
- std::vector<ServerID> servers =
317
- arangodb::basics::JsonHelper::stringArray (value);
318
- if (shard != " " ) {
319
- (*res).insert (make_pair (shard, servers));
312
+
313
+ auto shardsSlice = _slice.get (" shards" );
314
+ if (shardsSlice.isObject ()) {
315
+ for (auto const & shardSlice: VPackObjectIterator (shardsSlice)) {
316
+ if (shardSlice.key .isString () && shardSlice.value .isArray ()) {
317
+ ShardID shard = shardSlice.key .copyString ();
318
+
319
+ std::vector<ServerID> servers;
320
+ for (auto const & serverSlice: VPackArrayIterator (shardSlice.value )) {
321
+ servers.push_back (serverSlice.copyString ());
320
322
}
323
+ (*res).insert (make_pair (shardSlice.key .copyString (), servers));
321
324
}
322
325
}
323
326
}
@@ -333,11 +336,13 @@ class CollectionInfo {
333
336
// ////////////////////////////////////////////////////////////////////////////
334
337
335
338
int numberOfShards () const {
336
- TRI_json_t* const node =
337
- arangodb::basics::JsonHelper::getObjectElement (_json, " shards" );
339
+ if (_slice.isNone ()) {
340
+ return 0 ;
341
+ }
342
+ auto shardsSlice = _slice.get (" shards" );
338
343
339
- if (TRI_IsObjectJson (node )) {
340
- return ( int )( TRI_LengthVector (&node-> _value . _objects ) / 2 );
344
+ if (shardsSlice. isObject ( )) {
345
+ return shardsSlice. length ( );
341
346
}
342
347
return 0 ;
343
348
}
@@ -346,10 +351,16 @@ class CollectionInfo {
346
351
// / @brief returns the json
347
352
// ////////////////////////////////////////////////////////////////////////////
348
353
349
- TRI_json_t const * getJson () const { return _json; }
354
+ std::shared_ptr<VPackBuilder> const getVPack () const { return _vpack; }
355
+
356
+ // ////////////////////////////////////////////////////////////////////////////
357
+ // / @brief returns the slice
358
+ // ////////////////////////////////////////////////////////////////////////////
359
+ VPackSlice const getSlice () const { return _slice; }
350
360
351
361
private:
352
- TRI_json_t* _json;
362
+ std::shared_ptr<VPackBuilder> _vpack;
363
+ VPackSlice _slice;
353
364
354
365
// Only to protect the cache:
355
366
mutable Mutex _mutex;
@@ -583,13 +594,6 @@ class ClusterInfo {
583
594
584
595
std::vector<DatabaseID> listDatabases (bool = false );
585
596
586
- // ////////////////////////////////////////////////////////////////////////////
587
- // / @brief (re-)load the information about planned collections from the agency
588
- // / Usually one does not have to call this directly.
589
- // ////////////////////////////////////////////////////////////////////////////
590
-
591
- void loadPlannedCollections ();
592
-
593
597
// ////////////////////////////////////////////////////////////////////////////
594
598
// / @brief (re-)load the information about our plan
595
599
// / Usually one does not have to call this directly.
@@ -933,7 +937,6 @@ class ClusterInfo {
933
937
934
938
// The Plan state:
935
939
AllCollections _plannedCollections; // from Plan/Collections/
936
- ProtectionData _plannedCollectionsProt;
937
940
std::unordered_map<CollectionID,
938
941
std::shared_ptr<std::vector<std::string>>>
939
942
_shards; // from Plan/Collections/
0 commit comments