@@ -1220,14 +1220,55 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
12201220 std::vector<TRI_voc_tick_t> ids;
12211221 velocypack::Slice databases = result[0 ].get (std::vector<std::string>(
12221222 {AgencyCommHelper::path (), " Plan" , " Databases" }));
1223-
12241223 if (!databases.isObject ()) {
12251224 return false ;
12261225 }
12271226
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+
12281270 // loop over all database names we got and create a local database
12291271 // instance if not yet present:
1230-
12311272 for (VPackObjectIterator::ObjectPair options : VPackObjectIterator (databases)) {
12321273 if (!options.value .isObject ()) {
12331274 continue ;
@@ -1243,9 +1284,6 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
12431284 TRI_ASSERT (false );
12441285 }
12451286
1246- // known plan IDs
1247- ids.push_back (info.getId ());
1248-
12491287 auto dbName = info.getName ();
12501288 TRI_vocbase_t* vocbase = databaseFeature.useDatabase (dbName);
12511289 if (vocbase == nullptr ) {
@@ -1273,24 +1311,6 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
12731311 }
12741312 }
12751313
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- }
12941314
12951315 } else {
12961316 return false ;
0 commit comments