@@ -31,8 +31,7 @@ using namespace arangodb::consensus;
31
31
AddFollower::AddFollower (Node const & snapshot, AgentInterface* agent,
32
32
std::string const & jobId, std::string const & creator,
33
33
std::string const & database,
34
- std::string const & collection,
35
- std::string const & shard)
34
+ std::string const & collection, std::string const & shard)
36
35
: Job(NOTFOUND, snapshot, agent, jobId, creator),
37
36
_database(database),
38
37
_collection(collection),
@@ -59,15 +58,14 @@ AddFollower::AddFollower(Node const& snapshot, AgentInterface* agent,
59
58
60
59
AddFollower::~AddFollower () {}
61
60
62
- void AddFollower::run () {
63
- runHelper (" " , _shard);
64
- }
61
+ void AddFollower::run () { runHelper (" " , _shard); }
65
62
66
63
bool AddFollower::create (std::shared_ptr<VPackBuilder> envelope) {
67
- LOG_TOPIC (INFO, Logger::SUPERVISION) << " Todo: AddFollower(s) "
68
- << " to shard " << _shard << " in collection " << _collection;
64
+ LOG_TOPIC (INFO, Logger::SUPERVISION)
65
+ << " Todo: AddFollower(s) "
66
+ << " to shard " << _shard << " in collection " << _collection;
69
67
70
- bool selfCreate = (envelope == nullptr ); // Do we create ourselves?
68
+ bool selfCreate = (envelope == nullptr ); // Do we create ourselves?
71
69
72
70
if (selfCreate) {
73
71
_jb = std::make_shared<Builder>();
@@ -85,7 +83,8 @@ bool AddFollower::create(std::shared_ptr<VPackBuilder> envelope) {
85
83
std::string path = toDoPrefix + _jobId;
86
84
87
85
_jb->add (VPackValue (path));
88
- { VPackObjectBuilder guard (_jb.get ());
86
+ {
87
+ VPackObjectBuilder guard (_jb.get ());
89
88
_jb->add (" creator" , VPackValue (_creator));
90
89
_jb->add (" type" , VPackValue (" addFollower" ));
91
90
_jb->add (" database" , VPackValue (_database));
@@ -131,7 +130,7 @@ bool AddFollower::start() {
131
130
" collection must not have 'distributeShardsLike' attribute" );
132
131
return false ;
133
132
}
134
-
133
+
135
134
// Look at Plan:
136
135
std::string planPath =
137
136
planColPrefix + _database + " /" + _collection + " /shards/" + _shard;
@@ -151,17 +150,18 @@ bool AddFollower::start() {
151
150
152
151
// Check that the shard is not locked:
153
152
if (_snapshot.has (blockedShardsPrefix + _shard)) {
154
- LOG_TOPIC (DEBUG, Logger::SUPERVISION) << " shard " << _shard
155
- << " is currently locked, not starting AddFollower job " << _jobId;
153
+ LOG_TOPIC (DEBUG, Logger::SUPERVISION)
154
+ << " shard " << _shard
155
+ << " is currently locked, not starting AddFollower job " << _jobId;
156
156
return false ;
157
157
}
158
158
159
159
// Now find some new servers to add:
160
160
auto available = Job::availableServers (_snapshot);
161
161
// Remove those already in Plan:
162
162
for (VPackSlice server : VPackArrayIterator (planned)) {
163
- available.erase (std::remove (available.begin (), available.end (),
164
- server. copyString ()), available.end ());
163
+ available.erase (std::remove (available.begin (), available.end (), server. copyString ()),
164
+ available.end ());
165
165
}
166
166
// Remove those that are not in state "GOOD":
167
167
auto it = available.begin ();
@@ -175,9 +175,9 @@ bool AddFollower::start() {
175
175
176
176
// Check that we have enough:
177
177
if (available.size () < desiredReplFactor - actualReplFactor) {
178
- LOG_TOPIC (DEBUG, Logger::SUPERVISION) << " shard " << _shard
179
- << " does not have enough candidates to add followers, waiting, jobId= "
180
- << _jobId;
178
+ LOG_TOPIC (DEBUG, Logger::SUPERVISION)
179
+ << " shard " << _shard
180
+ << " does not have enough candidates to add followers, waiting, jobId= " << _jobId;
181
181
return false ;
182
182
}
183
183
@@ -194,14 +194,15 @@ bool AddFollower::start() {
194
194
}
195
195
196
196
// Now we can act, simply add all in chosen to all plans for all shards:
197
- std::vector<Job::shard_t > shardsLikeMe
198
- = clones (_snapshot, _database, _collection, _shard);
197
+ std::vector<Job::shard_t > shardsLikeMe =
198
+ clones (_snapshot, _database, _collection, _shard);
199
199
200
200
// Copy todo to finished:
201
201
Builder todo, trx;
202
202
203
203
// Get todo entry
204
- { VPackArrayBuilder guard (&todo);
204
+ {
205
+ VPackArrayBuilder guard (&todo);
205
206
// When create() was done with the current snapshot, then the job object
206
207
// will not be in the snapshot under ToDo, but in this case we find it
207
208
// in _jb:
@@ -211,8 +212,8 @@ bool AddFollower::start() {
211
212
} catch (std::exception const &) {
212
213
// Just in case, this is never going to happen, since we will only
213
214
// call the start() method if the job is already in ToDo.
214
- LOG_TOPIC (INFO, Logger::SUPERVISION)
215
- << " Failed to get key " + toDoPrefix + _jobId + " from agency snapshot" ;
215
+ LOG_TOPIC (INFO, Logger::SUPERVISION) << " Failed to get key " + toDoPrefix + _jobId +
216
+ " from agency snapshot" ;
216
217
return false ;
217
218
}
218
219
} else {
@@ -221,60 +222,64 @@ bool AddFollower::start() {
221
222
} catch (std::exception const & e) {
222
223
// Just in case, this is never going to happen, since when _jb is
223
224
// set, then the current job is stored under ToDo.
224
- LOG_TOPIC (WARN, Logger::SUPERVISION) << e. what () << " : "
225
- << __FILE__ << " :" << __LINE__;
225
+ LOG_TOPIC (WARN, Logger::SUPERVISION)
226
+ << e. what () << " : " << __FILE__ << " :" << __LINE__;
226
227
return false ;
227
228
}
228
229
}
229
230
}
230
-
231
+
231
232
// Enter pending, remove todo, block toserver
232
- { VPackArrayBuilder listOfTransactions (&trx);
233
+ {
234
+ VPackArrayBuilder listOfTransactions (&trx);
233
235
234
- { VPackObjectBuilder objectForMutation (&trx);
236
+ {
237
+ VPackObjectBuilder objectForMutation (&trx);
235
238
236
239
addPutJobIntoSomewhere (trx, " Finished" , todo.slice ()[0 ]);
237
240
addRemoveJobFromSomewhere (trx, " ToDo" , _jobId);
238
241
239
242
// --- Plan changes
240
243
doForAllShards (_snapshot, _database, shardsLikeMe,
241
- [&trx, &chosen](Slice plan, Slice current, std::string& planPath) {
242
- trx.add (VPackValue (planPath));
243
- { VPackArrayBuilder serverList (&trx);
244
- for (auto const & srv : VPackArrayIterator (plan)) {
245
- trx.add (srv);
246
- }
247
- for (auto const & srv : chosen) {
248
- trx.add (VPackValue (srv));
249
- }
250
- }
251
- });
244
+ [&trx, &chosen](Slice plan, Slice current, std::string& planPath) {
245
+ trx.add (VPackValue (planPath));
246
+ {
247
+ VPackArrayBuilder serverList (&trx);
248
+ for (auto const & srv : VPackArrayIterator (plan)) {
249
+ trx.add (srv);
250
+ }
251
+ for (auto const & srv : chosen) {
252
+ trx.add (VPackValue (srv));
253
+ }
254
+ }
255
+ });
252
256
253
257
addIncreasePlanVersion (trx);
254
258
} // mutation part of transaction done
255
259
// Preconditions
256
- { VPackObjectBuilder precondition (&trx);
260
+ {
261
+ VPackObjectBuilder precondition (&trx);
257
262
// --- Check that Planned servers are still as we expect
258
263
addPreconditionUnchanged (trx, planPath, planned);
259
264
addPreconditionShardNotBlocked (trx, _shard);
260
265
for (auto const & srv : chosen) {
261
266
addPreconditionServerGood (trx, srv);
262
267
}
263
- } // precondition done
264
- } // array for transaction done
265
-
268
+ } // precondition done
269
+ } // array for transaction done
270
+
266
271
// Transact to agency
267
272
write_ret_t res = singleWriteTransaction (_agent, trx);
268
273
269
274
if (res.accepted && res.indices .size () == 1 && res.indices [0 ]) {
270
275
_status = FINISHED;
271
- LOG_TOPIC (INFO, Logger::SUPERVISION)
272
- << " Pending: Addfollower(s) to shard " << _shard << " in collection "
273
- << _collection;
276
+ LOG_TOPIC (INFO, Logger::SUPERVISION) << " Pending: Addfollower(s) to shard " << _shard
277
+ << " in collection " << _collection;
274
278
return true ;
275
279
}
276
280
277
- LOG_TOPIC (INFO, Logger::SUPERVISION) << " Start precondition failed for AddFollower " + _jobId;
281
+ LOG_TOPIC (INFO, Logger::SUPERVISION)
282
+ << " Start precondition failed for AddFollower " + _jobId;
278
283
return false ;
279
284
}
280
285
@@ -283,20 +288,19 @@ JOB_STATUS AddFollower::status() {
283
288
return _status;
284
289
}
285
290
286
- TRI_ASSERT (false ); // PENDING is not an option for this job, since it
287
- // travels directly from ToDo to Finished or Failed
291
+ TRI_ASSERT (false ); // PENDING is not an option for this job, since it
292
+ // travels directly from ToDo to Finished or Failed
288
293
return _status;
289
294
}
290
295
291
296
arangodb::Result AddFollower::abort () {
292
-
293
297
// We can assume that the job is in ToDo or not there:
294
298
if (_status == NOTFOUND || _status == FINISHED || _status == FAILED) {
295
299
return Result (TRI_ERROR_SUPERVISION_GENERAL_FAILURE,
296
300
" Failed aborting addFollower job beyond pending stage" );
297
301
}
298
302
299
- Result result;
303
+ Result result;
300
304
// Can now only be TODO or PENDING
301
305
if (_status == TODO) {
302
306
finish (" " , " " , false , " job aborted" );
@@ -305,6 +309,4 @@ arangodb::Result AddFollower::abort() {
305
309
306
310
TRI_ASSERT (false ); // cannot happen, since job moves directly to FINISHED
307
311
return result;
308
-
309
312
}
310
-
0 commit comments