@@ -1220,14 +1220,55 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
1220
1220
std::vector<TRI_voc_tick_t> ids;
1221
1221
velocypack::Slice databases = result[0 ].get (std::vector<std::string>(
1222
1222
{AgencyCommHelper::path (), " Plan" , " Databases" }));
1223
-
1224
1223
if (!databases.isObject ()) {
1225
1224
return false ;
1226
1225
}
1227
1226
1227
+ for (VPackObjectIterator::ObjectPair options : VPackObjectIterator (databases)) {
1228
+ try {
1229
+ ids.push_back (std::stoul (options.value .get (" id" ).copyString ()));
1230
+ } catch (std::invalid_argument& e) {
1231
+ LOG_TOPIC (" a9233" , ERR, Logger::CLUSTER)
1232
+ << " Number conversion for planned database id for " << options.key .stringView () << " failed: " << e.what ();
1233
+ } catch (std::out_of_range const & e) {
1234
+ LOG_TOPIC (" a9243" , ERR, Logger::CLUSTER)
1235
+ << " Number conversion for planned database id for " << options.key .stringView () << " failed: " << e.what ();
1236
+ } catch (std::bad_alloc const &) {
1237
+ LOG_TOPIC (" a9234" , FATAL, Logger::CLUSTER)
1238
+ << " Failed to allocate memory to enumerate planned databases from agency" ;
1239
+ FATAL_ERROR_EXIT ();
1240
+ } catch (std::exception const & e) {
1241
+ LOG_TOPIC (" a9235" , FATAL, Logger::CLUSTER)
1242
+ << " Failed to read planned databases " << options.key .stringView () << " from agency: " << e.what ();
1243
+ }
1244
+ }
1245
+
1246
+ // get the list of databases that we know about locally
1247
+ std::vector<TRI_voc_tick_t> localIds = databaseFeature.getDatabaseIds (false );
1248
+ for (auto id : localIds) {
1249
+ auto r = std::find (ids.begin (), ids.end (), id);
1250
+
1251
+ if (r == ids.end ()) {
1252
+ // local database not found in the plan...
1253
+ std::string dbName = " n/a" ;
1254
+ TRI_vocbase_t* db = databaseFeature.useDatabase (id);
1255
+ TRI_ASSERT (db);
1256
+ if (db) {
1257
+ try {
1258
+ dbName = db->name ();
1259
+ } catch (...) {
1260
+ db->release ();
1261
+ throw ;
1262
+ }
1263
+ db->release ();
1264
+ }
1265
+ Result res = databaseFeature.dropDatabase (id, true );
1266
+ events::DropDatabase (dbName, res, ExecContext::current ());
1267
+ }
1268
+ }
1269
+
1228
1270
// loop over all database names we got and create a local database
1229
1271
// instance if not yet present:
1230
-
1231
1272
for (VPackObjectIterator::ObjectPair options : VPackObjectIterator (databases)) {
1232
1273
if (!options.value .isObject ()) {
1233
1274
continue ;
@@ -1243,9 +1284,6 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
1243
1284
TRI_ASSERT (false );
1244
1285
}
1245
1286
1246
- // known plan IDs
1247
- ids.push_back (info.getId ());
1248
-
1249
1287
auto dbName = info.getName ();
1250
1288
TRI_vocbase_t* vocbase = databaseFeature.useDatabase (dbName);
1251
1289
if (vocbase == nullptr ) {
@@ -1273,24 +1311,6 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
1273
1311
}
1274
1312
}
1275
1313
1276
- // get the list of databases that we know about locally
1277
- std::vector<TRI_voc_tick_t> localIds = databaseFeature.getDatabaseIds (false );
1278
-
1279
- for (auto id : localIds) {
1280
- auto r = std::find (ids.begin (), ids.end (), id);
1281
-
1282
- if (r == ids.end ()) {
1283
- // local database not found in the plan...
1284
- TRI_vocbase_t* db = databaseFeature.useDatabase (id);
1285
- TRI_ASSERT (db);
1286
- std::string dbName = db ? db->name () : " n/a" ;
1287
- if (db) {
1288
- db->release ();
1289
- }
1290
- Result res = databaseFeature.dropDatabase (id, true );
1291
- events::DropDatabase (dbName, res, ExecContext::current ());
1292
- }
1293
- }
1294
1314
1295
1315
} else {
1296
1316
return false ;
0 commit comments