1
0
Fork 0

less copying in ClusterInfo::loadPlan() (#9650)

This commit is contained in:
Jan 2019-08-08 10:04:36 +02:00 committed by GitHub
parent 4bb2e53b6d
commit 3219e63381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 8 deletions

View File

@ -366,6 +366,38 @@ AgencyCommResult::AgencyCommResult(int code, std::string const& message,
_statusCode(code),
_connected(false),
_sent(false) {}
AgencyCommResult::AgencyCommResult(AgencyCommResult&& other) noexcept
: _location(std::move(other._location)),
_message(std::move(other._message)),
_body(std::move(other._body)),
_values(std::move(other._values)),
_statusCode(other._statusCode),
_connected(other._connected),
_sent(other._sent),
_vpack(std::move(other._vpack)) {
other._statusCode = 0;
other._connected = false;
other._sent = false;
}
AgencyCommResult& AgencyCommResult::operator=(AgencyCommResult&& other) noexcept {
if (this != &other) {
_location = std::move(other._location);
_message = std::move(other._message);
_body = std::move(other._body);
_values = std::move(other._values);
_statusCode = other._statusCode;
_connected = other._connected;
_sent = other._sent;
_vpack = std::move(other._vpack);
other._statusCode = 0;
other._connected = false;
other._sent = false;
}
return *this;
}
void AgencyCommResult::set(int code, std::string const& message) {
_message = message;

View File

@ -236,6 +236,12 @@ class AgencyCommResult {
AgencyCommResult(int code, std::string const& message,
std::string const& transactionId = std::string());
AgencyCommResult(AgencyCommResult const& other) = delete;
AgencyCommResult& operator=(AgencyCommResult const& other) = delete;
AgencyCommResult(AgencyCommResult&& other) noexcept;
AgencyCommResult& operator=(AgencyCommResult&& other) noexcept;
~AgencyCommResult() = default;
public:

View File

@ -522,8 +522,7 @@ void ClusterInfo::loadPlan() {
if (result.successful()) {
VPackSlice slice = result.slice()[0].get(
std::vector<std::string>({AgencyCommManager::path(), "Plan"}));
auto planBuilder = std::make_shared<VPackBuilder>();
planBuilder->add(slice);
auto planBuilder = std::make_shared<VPackBuilder>(slice);
VPackSlice planSlice = planBuilder->slice();
@ -868,13 +867,13 @@ void ClusterInfo::loadPlan() {
// inside the IF
if (!isBuilding) {
// register with name as well as with id:
databaseCollections.emplace(std::make_pair(collectionName, newCollection));
databaseCollections.emplace(std::make_pair(collectionId, newCollection));
databaseCollections.emplace(collectionName, newCollection);
databaseCollections.emplace(collectionId, newCollection);
}
auto shardKeys =
std::make_shared<std::vector<std::string>>(newCollection->shardKeys());
newShardKeys.insert(make_pair(collectionId, shardKeys));
newShardKeys.emplace(collectionId, std::move(shardKeys));
auto shardIDs = newCollection->shardIds();
auto shards = std::make_shared<std::vector<std::string>>();
@ -888,7 +887,7 @@ void ClusterInfo::loadPlan() {
return std::strtol(a.c_str() + 1, nullptr, 10) <
std::strtol(b.c_str() + 1, nullptr, 10);
});
newShards.emplace(std::make_pair(collectionId, shards));
newShards.emplace(collectionId, std::move(shards));
} catch (std::exception const& ex) {
// The plan contains invalid collection information.
@ -923,12 +922,12 @@ void ClusterInfo::loadPlan() {
}
}
newCollections.emplace(std::make_pair(databaseName, databaseCollections));
newCollections.emplace(databaseName, std::move(databaseCollections));
}
}
WRITE_LOCKER(writeLocker, _planProt.lock);
_plan = planBuilder;
_plan = std::move(planBuilder);
_planVersion = newPlanVersion;
if (swapDatabases) {
_plannedDatabases.swap(newDatabases);