Skip to content

Commit

Permalink
Fixed a race condtion after Hotbackup Restore, and after adding a DBS…
Browse files Browse the repository at this point in the history
…erver, the List of Databases could be empty.
  • Loading branch information
mchacki committed May 17, 2024
1 parent e6bf32d commit f2999dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 38 deletions.
44 changes: 7 additions & 37 deletions arangod/Cluster/ClusterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,6 @@ bool ClusterInfo::doesDatabaseExist(std::string_view databaseID) {
////////////////////////////////////////////////////////////////////////////////

std::vector<DatabaseID> ClusterInfo::databases() {
std::vector<DatabaseID> result;

if (_clusterId.empty()) {
loadClusterId();
}
Expand All @@ -947,44 +945,16 @@ std::vector<DatabaseID> ClusterInfo::databases() {
}
}

if (!_currentProt.isValid) {
Result r = waitForCurrent(1).get();
if (r.fail()) {
THROW_ARANGO_EXCEPTION(r);
}
}

if (!_dbServersProt.isValid) {
loadCurrentDBServers();
}

// From now on we know that all data has been valid once, so no need
// to check the isValid flags again under the lock.

size_t expectedSize;
{
READ_LOCKER(readLocker, _dbServersProt.lock);
expectedSize = _dbServers.size();
}

// The _plannedDatabases map contains all Databases that
// are planned to exist, and that do not have the "isBuilding"
// flag set. Hence those databases have been successfully created
// and should be listed.
std::vector<DatabaseID> result;
{
READ_LOCKER(readLockerPlanned, _planProt.lock);
READ_LOCKER(readLockerCurrent, _currentProt.lock);
// _plannedDatabases is a map-type<DatabaseID, VPackSlice>
auto it = _plannedDatabases.begin();

while (it != _plannedDatabases.end()) {
// _currentDatabases is:
// a map-type<DatabaseID, a map-type<ServerID, VPackSlice>>
auto it2 = _currentDatabases.find((*it).first);

if (it2 != _currentDatabases.end()) {
if ((*it2).second.size() >= expectedSize) {
result.push_back((*it).first);
}
}

++it;
for (auto const& it : _plannedDatabases) {
result.emplace_back(it.first);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function HotBackupSuite () {
dropExtraCollections();
db._create(colNameTwo);
assertAdditionalDataDoesNotExist();
require("internal").print(JSON.stringify(backupGood));

// Validate we can restore the backup with Analyzers entry, just for good measure.
arango.POST("/_admin/backup/restore", {id: backupGood.id});
Expand Down

0 comments on commit f2999dd

Please sign in to comment.