mirror of https://gitee.com/bigwinds/arangodb
[devel] ClientID Agency Transaction (#8652)
* Changed clientId to format <serverid>:<uuid>. * Changed behavior if id is not known.
This commit is contained in:
parent
1408654d2c
commit
c99e8e8973
|
@ -249,6 +249,17 @@ bool AgencyWriteTransaction::validate(AgencyCommResult const& result) const {
|
|||
result.slice().get("results").isArray());
|
||||
}
|
||||
|
||||
std::string AgencyWriteTransaction::randomClientId() {
|
||||
std::string uuid = to_string(boost::uuids::random_generator()()), id;
|
||||
|
||||
auto ss = ServerState::instance();
|
||||
if (ss != nullptr && !ss->getId().empty()) {
|
||||
return ss->getId() + ":" + uuid;
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- AgencyTransientTransaction
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -357,23 +357,26 @@ class AgencyTransaction {
|
|||
|
||||
struct AgencyWriteTransaction : public AgencyTransaction {
|
||||
public:
|
||||
|
||||
static std::string randomClientId();
|
||||
|
||||
explicit AgencyWriteTransaction(AgencyOperation const& operation)
|
||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
||||
: clientId(randomClientId()) {
|
||||
operations.push_back(operation);
|
||||
}
|
||||
|
||||
explicit AgencyWriteTransaction(std::vector<AgencyOperation> const& _opers)
|
||||
: operations(_opers), clientId(to_string(boost::uuids::random_generator()())) {}
|
||||
: operations(_opers), clientId(randomClientId()) {}
|
||||
|
||||
AgencyWriteTransaction(AgencyOperation const& operation, AgencyPrecondition const& precondition)
|
||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
||||
: clientId(randomClientId()) {
|
||||
operations.push_back(operation);
|
||||
preconditions.push_back(precondition);
|
||||
}
|
||||
|
||||
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
||||
AgencyPrecondition const& precondition)
|
||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
||||
: clientId(randomClientId()) {
|
||||
std::copy(opers.begin(), opers.end(),
|
||||
std::back_inserter(operations));
|
||||
preconditions.push_back(precondition);
|
||||
|
@ -381,7 +384,7 @@ struct AgencyWriteTransaction : public AgencyTransaction {
|
|||
|
||||
AgencyWriteTransaction(AgencyOperation const& operation,
|
||||
std::vector<AgencyPrecondition> const& precs)
|
||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
||||
: clientId(randomClientId()) {
|
||||
operations.push_back(operation);
|
||||
std::copy(precs.begin(), precs.end(),
|
||||
std::back_inserter(preconditions));
|
||||
|
@ -389,14 +392,14 @@ struct AgencyWriteTransaction : public AgencyTransaction {
|
|||
|
||||
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
||||
std::vector<AgencyPrecondition> const& precs)
|
||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
||||
: clientId(randomClientId()) {
|
||||
std::copy(opers.begin(), opers.end(),
|
||||
std::back_inserter(operations));
|
||||
std::copy(precs.begin(), precs.end(),
|
||||
std::back_inserter(preconditions));
|
||||
}
|
||||
|
||||
AgencyWriteTransaction() = default;
|
||||
AgencyWriteTransaction() : clientId(randomClientId()) {};
|
||||
|
||||
void toVelocyPack(arangodb::velocypack::Builder& builder) const override final;
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ bool ServerState::integrateIntoCluster(ServerState::RoleEnum role,
|
|||
id = getPersistedId();
|
||||
LOG_TOPIC("db3ce", DEBUG, Logger::CLUSTER) << "Restarting with persisted UUID " << id;
|
||||
}
|
||||
_id = id;
|
||||
setId(id);
|
||||
_myEndpoint = myEndpoint;
|
||||
_advertisedEndpoint = advEndpoint;
|
||||
TRI_ASSERT(!_myEndpoint.empty());
|
||||
|
@ -690,7 +690,7 @@ void ServerState::setRole(ServerState::RoleEnum role) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string ServerState::getId() const {
|
||||
READ_LOCKER(readLocker, _lock);
|
||||
std::lock_guard<std::mutex> guard(_idLock);
|
||||
return _id;
|
||||
}
|
||||
|
||||
|
@ -703,7 +703,7 @@ void ServerState::setId(std::string const& id) {
|
|||
return;
|
||||
}
|
||||
|
||||
WRITE_LOCKER(writeLocker, _lock);
|
||||
std::lock_guard<std::mutex> guard(_idLock);
|
||||
_id = id;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#ifndef ARANGOD_CLUSTER_SERVER_STATE_H
|
||||
#define ARANGOD_CLUSTER_SERVER_STATE_H 1
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "Basics/Common.h"
|
||||
#include "Basics/ReadWriteSpinLock.h"
|
||||
#include "VocBase/voc-types.h"
|
||||
|
@ -283,8 +285,10 @@ class ServerState {
|
|||
/// @brief r/w lock for state
|
||||
mutable arangodb::basics::ReadWriteSpinLock _lock;
|
||||
|
||||
/// @brief the server's id, can be set just once
|
||||
/// @brief the server's id, can be set just once, use getId and setId, do not access directly
|
||||
std::string _id;
|
||||
/// @brief lock for writing and reading server id
|
||||
mutable std::mutex _idLock;
|
||||
|
||||
/// @brief the server's short id, can be set just once
|
||||
std::atomic<uint32_t> _shortId;
|
||||
|
|
Loading…
Reference in New Issue