@@ -32,7 +32,34 @@ AddFollower::AddFollower(Node const& snapshot, Agent* agent,
32
32
std::string const & prefix, std::string const & database,
33
33
std::string const & collection,
34
34
std::string const & shard,
35
- std::string const & newFollower)
35
+ std::initializer_list<std::string> const & newFollower)
36
+ : Job(snapshot, agent, jobId, creator, prefix),
37
+ _database(database),
38
+ _collection(collection),
39
+ _shard(shard),
40
+ _newFollower(newFollower) {
41
+ try {
42
+ JOB_STATUS js = status ();
43
+
44
+ if (js == TODO) {
45
+ start ();
46
+ } else if (js == NOTFOUND) {
47
+ if (create ()) {
48
+ start ();
49
+ }
50
+ }
51
+ } catch (std::exception const & e) {
52
+ LOG_TOPIC (WARN, Logger::AGENCY) << e.what () << __FILE__ << __LINE__;
53
+ finish (" Shards/" + _shard, false , e.what ());
54
+ }
55
+ }
56
+
57
+ AddFollower::AddFollower (Node const & snapshot, Agent* agent,
58
+ std::string const & jobId, std::string const & creator,
59
+ std::string const & prefix, std::string const & database,
60
+ std::string const & collection,
61
+ std::string const & shard,
62
+ std::vector<std::string> const & newFollower)
36
63
: Job(snapshot, agent, jobId, creator, prefix),
37
64
_database(database),
38
65
_collection(collection),
@@ -109,7 +136,13 @@ bool AddFollower::create() {
109
136
_jb->add (" database" , VPackValue (_database));
110
137
_jb->add (" collection" , VPackValue (_collection));
111
138
_jb->add (" shard" , VPackValue (_shard));
112
- _jb->add (" newFollower" , VPackValue (_newFollower));
139
+ _jb->add (VPackValue (" newFollower" ));
140
+ {
141
+ VPackArrayBuilder b (_jb.get ());
142
+ for (auto const & i : _newFollower) {
143
+ _jb->add (VPackValue (i));
144
+ }
145
+ }
113
146
_jb->add (" jobId" , VPackValue (_jobId));
114
147
_jb->add (" timeCreated" , VPackValue (now));
115
148
@@ -142,15 +175,15 @@ bool AddFollower::start() {
142
175
143
176
for (auto const & srv : VPackArrayIterator (current)) {
144
177
TRI_ASSERT (srv.isString ());
145
- if (srv.copyString () == _newFollower) {
178
+ if (srv.copyString () == _newFollower. front () ) {
146
179
finish (" Shards/" + _shard, false ,
147
180
" newFollower must not be already holding the shard." );
148
181
return false ;
149
182
}
150
183
}
151
184
for (auto const & srv : VPackArrayIterator (planned)) {
152
185
TRI_ASSERT (srv.isString ());
153
- if (srv.copyString () == _newFollower) {
186
+ if (srv.copyString () == _newFollower. front () ) {
154
187
finish (" Shards/" + _shard, false ,
155
188
" newFollower must not be planned for shard already." );
156
189
return false ;
@@ -206,7 +239,9 @@ bool AddFollower::start() {
206
239
for (auto const & srv : VPackArrayIterator (planned)) {
207
240
pending.add (srv);
208
241
}
209
- pending.add (VPackValue (_newFollower));
242
+ for (auto const & i : _newFollower) {
243
+ pending.add (VPackValue (i));
244
+ }
210
245
pending.close ();
211
246
212
247
// --- Increment Plan/Version
@@ -237,7 +272,7 @@ bool AddFollower::start() {
237
272
238
273
if (res.accepted && res.indices .size () == 1 && res.indices [0 ]) {
239
274
LOG_TOPIC (INFO, Logger::AGENCY)
240
- << " Pending: Addfollower " + _newFollower + " to shard " + _shard;
275
+ << " Pending: Addfollower " << _newFollower << " to shard " << _shard;
241
276
return true ;
242
277
}
243
278
@@ -253,8 +288,12 @@ JOB_STATUS AddFollower::status() {
253
288
try {
254
289
_database = _snapshot (pos[status] + _jobId + " /database" ).getString ();
255
290
_collection = _snapshot (pos[status] + _jobId + " /collection" ).getString ();
256
- _newFollower =
257
- _snapshot (pos[status] + _jobId + " /newFollower" ).getString ();
291
+ for (auto const & i :
292
+ VPackArrayIterator (
293
+ _snapshot (pos[status] + _jobId + " /newFollower" ).getArray ())) {
294
+ _newFollower.push_back (i.copyString ());
295
+ }
296
+ _snapshot (pos[status] + _jobId + " /newFollower" ).getArray ();
258
297
_shard = _snapshot (pos[status] + _jobId + " /shard" ).getString ();
259
298
} catch (std::exception const & e) {
260
299
std::stringstream err;
@@ -271,7 +310,7 @@ JOB_STATUS AddFollower::status() {
271
310
272
311
Slice current = _snapshot (curPath).slice ();
273
312
for (auto const & srv : VPackArrayIterator (current)) {
274
- if (srv.copyString () == _newFollower) {
313
+ if (srv.copyString () == _newFollower. front () ) {
275
314
if (finish (" Shards/" + _shard)) {
276
315
return FINISHED;
277
316
}
0 commit comments