1
0
Fork 0

moved dropDatabaseCoordinator() into DatabaseFeature

This commit is contained in:
jsteemann 2016-07-25 14:04:55 +02:00
parent de6d7182c8
commit b288d3e4dd
5 changed files with 45 additions and 54 deletions

View File

@ -550,7 +550,8 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
if (r == ids.end()) {
// local database not found in the plan...
TRI_DropByIdCoordinatorDatabaseServer(_server, id, false);
DatabaseFeature* databaseFeature = application_features::ApplicationServer::getFeature<DatabaseFeature>("Database");
databaseFeature->dropDatabaseCoordinator(id, false);
}
}

View File

@ -581,6 +581,48 @@ int DatabaseFeature::createDatabase(TRI_voc_tick_t id, std::string const& name,
return res;
}
/// @brief drop coordinator database
int DatabaseFeature::dropDatabaseCoordinator(TRI_voc_tick_t id, bool force) {
int res = TRI_ERROR_ARANGO_DATABASE_NOT_FOUND;
MUTEX_LOCKER(mutexLocker, _databasesMutex);
auto oldLists = _databasesLists.load();
decltype(oldLists) newLists = nullptr;
TRI_vocbase_t* vocbase = nullptr;
try {
newLists = new DatabasesLists(*oldLists);
for (auto it = newLists->_coordinatorDatabases.begin();
it != newLists->_coordinatorDatabases.end(); it++) {
vocbase = it->second;
if (vocbase->_id == id &&
(force || std::string(vocbase->_name) != TRI_VOC_SYSTEM_DATABASE)) {
newLists->_droppedDatabases.emplace(vocbase);
newLists->_coordinatorDatabases.erase(it);
break;
}
vocbase = nullptr;
}
} catch (...) {
delete newLists;
return TRI_ERROR_OUT_OF_MEMORY;
}
if (vocbase != nullptr) {
_databasesLists = newLists;
_databasesProtector.scan();
delete oldLists;
if (TRI_DropVocBase(vocbase)) {
LOG(INFO) << "dropping coordinator database '" << vocbase->_name << "'";
res = TRI_ERROR_NO_ERROR;
}
} else {
delete newLists;
}
return res;
}
/// @brief drop database
int DatabaseFeature::dropDatabase(std::string const& name, bool writeMarker, bool waitForDeletion, bool removeAppsDirectory) {
if (name == TRI_VOC_SYSTEM_DATABASE) {

View File

@ -79,6 +79,7 @@ class DatabaseFeature final : public application_features::ApplicationFeature {
public:
int createDatabaseCoordinator(TRI_voc_tick_t id, std::string const& name, TRI_vocbase_t*& result);
int createDatabase(TRI_voc_tick_t id, std::string const& name, bool writeMarker, TRI_vocbase_t*& result);
int dropDatabaseCoordinator(TRI_voc_tick_t id, bool force);
int dropDatabase(std::string const& name, bool writeMarker, bool waitForDeletion, bool removeAppsDirectory);
int dropDatabase(TRI_voc_tick_t id, bool writeMarker, bool waitForDeletion, bool removeAppsDirectory);

View File

@ -198,53 +198,6 @@ std::vector<TRI_voc_tick_t> TRI_GetIdsCoordinatorDatabaseServer(
return v;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an existing coordinator database
////////////////////////////////////////////////////////////////////////////////
int TRI_DropByIdCoordinatorDatabaseServer(TRI_server_t* server,
TRI_voc_tick_t id, bool force) {
int res = TRI_ERROR_ARANGO_DATABASE_NOT_FOUND;
MUTEX_LOCKER(mutexLocker, server->_databasesMutex);
auto oldLists = server->_databasesLists.load();
decltype(oldLists) newLists = nullptr;
TRI_vocbase_t* vocbase = nullptr;
try {
newLists = new DatabasesLists(*oldLists);
for (auto it = newLists->_coordinatorDatabases.begin();
it != newLists->_coordinatorDatabases.end(); it++) {
vocbase = it->second;
if (vocbase->_id == id &&
(force ||
!TRI_EqualString(vocbase->_name, TRI_VOC_SYSTEM_DATABASE))) {
newLists->_droppedDatabases.emplace(vocbase);
newLists->_coordinatorDatabases.erase(it);
break;
}
vocbase = nullptr;
}
} catch (...) {
delete newLists;
return TRI_ERROR_OUT_OF_MEMORY;
}
if (vocbase != nullptr) {
server->_databasesLists = newLists;
server->_databasesProtector.scan();
delete oldLists;
if (TRI_DropVocBase(vocbase)) {
LOG(INFO) << "dropping coordinator database '" << vocbase->_name << "'";
res = TRI_ERROR_NO_ERROR;
}
} else {
delete newLists;
}
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get a coordinator database by its id
/// this will increase the reference-counter for the database

View File

@ -76,12 +76,6 @@ int TRI_InitDatabasesServer(TRI_server_t*);
std::vector<TRI_voc_tick_t> TRI_GetIdsCoordinatorDatabaseServer(TRI_server_t*,
bool includeSystem = false);
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an existing coordinator database
////////////////////////////////////////////////////////////////////////////////
int TRI_DropByIdCoordinatorDatabaseServer(TRI_server_t*, TRI_voc_tick_t, bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief get a coordinator database by its id
/// this will increase the reference-counter for the database