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());
|
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
|
// --SECTION-- AgencyTransientTransaction
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -1186,13 +1197,13 @@ bool AgencyComm::ensureStructureInitialized() {
|
||||||
|
|
||||||
LOG_TOPIC("17e16", TRACE, Logger::AGENCYCOMM)
|
LOG_TOPIC("17e16", TRACE, Logger::AGENCYCOMM)
|
||||||
<< "Agency is fresh. Needs initial structure.";
|
<< "Agency is fresh. Needs initial structure.";
|
||||||
|
|
||||||
if (tryInitializeStructure()) {
|
if (tryInitializeStructure()) {
|
||||||
LOG_TOPIC("4c5aa", TRACE, Logger::AGENCYCOMM)
|
LOG_TOPIC("4c5aa", TRACE, Logger::AGENCYCOMM)
|
||||||
<< "Successfully initialized agency";
|
<< "Successfully initialized agency";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_TOPIC("63f7b", WARN, Logger::AGENCYCOMM)
|
LOG_TOPIC("63f7b", WARN, Logger::AGENCYCOMM)
|
||||||
<< "Initializing agency failed. We'll try again soon";
|
<< "Initializing agency failed. We'll try again soon";
|
||||||
// We should really have exclusive access, here, this is strange!
|
// We should really have exclusive access, here, this is strange!
|
||||||
|
@ -1818,18 +1829,18 @@ bool AgencyComm::shouldInitializeStructure() {
|
||||||
auto result = getValues("Plan");
|
auto result = getValues("Plan");
|
||||||
|
|
||||||
if (!result.successful()) { // Not 200 - 299
|
if (!result.successful()) { // Not 200 - 299
|
||||||
|
|
||||||
if (result.httpCode() == 401) {
|
if (result.httpCode() == 401) {
|
||||||
// unauthorized
|
// unauthorized
|
||||||
LOG_TOPIC("32781", FATAL, Logger::STARTUP) << "Unauthorized. Wrong credentials.";
|
LOG_TOPIC("32781", FATAL, Logger::STARTUP) << "Unauthorized. Wrong credentials.";
|
||||||
FATAL_ERROR_EXIT();
|
FATAL_ERROR_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agency not ready yet
|
// Agency not ready yet
|
||||||
LOG_TOPIC("36253", TRACE, Logger::AGENCYCOMM)
|
LOG_TOPIC("36253", TRACE, Logger::AGENCYCOMM)
|
||||||
<< "waiting for agency to become ready";
|
<< "waiting for agency to become ready";
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Sanity
|
// Sanity
|
||||||
|
@ -1858,9 +1869,9 @@ bool AgencyComm::shouldInitializeStructure() {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,23 +357,26 @@ class AgencyTransaction {
|
||||||
|
|
||||||
struct AgencyWriteTransaction : public AgencyTransaction {
|
struct AgencyWriteTransaction : public AgencyTransaction {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static std::string randomClientId();
|
||||||
|
|
||||||
explicit AgencyWriteTransaction(AgencyOperation const& operation)
|
explicit AgencyWriteTransaction(AgencyOperation const& operation)
|
||||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
: clientId(randomClientId()) {
|
||||||
operations.push_back(operation);
|
operations.push_back(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit AgencyWriteTransaction(std::vector<AgencyOperation> const& _opers)
|
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)
|
AgencyWriteTransaction(AgencyOperation const& operation, AgencyPrecondition const& precondition)
|
||||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
: clientId(randomClientId()) {
|
||||||
operations.push_back(operation);
|
operations.push_back(operation);
|
||||||
preconditions.push_back(precondition);
|
preconditions.push_back(precondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
||||||
AgencyPrecondition const& precondition)
|
AgencyPrecondition const& precondition)
|
||||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
: clientId(randomClientId()) {
|
||||||
std::copy(opers.begin(), opers.end(),
|
std::copy(opers.begin(), opers.end(),
|
||||||
std::back_inserter(operations));
|
std::back_inserter(operations));
|
||||||
preconditions.push_back(precondition);
|
preconditions.push_back(precondition);
|
||||||
|
@ -381,7 +384,7 @@ struct AgencyWriteTransaction : public AgencyTransaction {
|
||||||
|
|
||||||
AgencyWriteTransaction(AgencyOperation const& operation,
|
AgencyWriteTransaction(AgencyOperation const& operation,
|
||||||
std::vector<AgencyPrecondition> const& precs)
|
std::vector<AgencyPrecondition> const& precs)
|
||||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
: clientId(randomClientId()) {
|
||||||
operations.push_back(operation);
|
operations.push_back(operation);
|
||||||
std::copy(precs.begin(), precs.end(),
|
std::copy(precs.begin(), precs.end(),
|
||||||
std::back_inserter(preconditions));
|
std::back_inserter(preconditions));
|
||||||
|
@ -389,14 +392,14 @@ struct AgencyWriteTransaction : public AgencyTransaction {
|
||||||
|
|
||||||
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
||||||
std::vector<AgencyPrecondition> const& precs)
|
std::vector<AgencyPrecondition> const& precs)
|
||||||
: clientId(to_string(boost::uuids::random_generator()())) {
|
: clientId(randomClientId()) {
|
||||||
std::copy(opers.begin(), opers.end(),
|
std::copy(opers.begin(), opers.end(),
|
||||||
std::back_inserter(operations));
|
std::back_inserter(operations));
|
||||||
std::copy(precs.begin(), precs.end(),
|
std::copy(precs.begin(), precs.end(),
|
||||||
std::back_inserter(preconditions));
|
std::back_inserter(preconditions));
|
||||||
}
|
}
|
||||||
|
|
||||||
AgencyWriteTransaction() = default;
|
AgencyWriteTransaction() : clientId(randomClientId()) {};
|
||||||
|
|
||||||
void toVelocyPack(arangodb::velocypack::Builder& builder) const override final;
|
void toVelocyPack(arangodb::velocypack::Builder& builder) const override final;
|
||||||
|
|
||||||
|
|
|
@ -368,7 +368,7 @@ bool ServerState::integrateIntoCluster(ServerState::RoleEnum role,
|
||||||
id = getPersistedId();
|
id = getPersistedId();
|
||||||
LOG_TOPIC("db3ce", DEBUG, Logger::CLUSTER) << "Restarting with persisted UUID " << id;
|
LOG_TOPIC("db3ce", DEBUG, Logger::CLUSTER) << "Restarting with persisted UUID " << id;
|
||||||
}
|
}
|
||||||
_id = id;
|
setId(id);
|
||||||
_myEndpoint = myEndpoint;
|
_myEndpoint = myEndpoint;
|
||||||
_advertisedEndpoint = advEndpoint;
|
_advertisedEndpoint = advEndpoint;
|
||||||
TRI_ASSERT(!_myEndpoint.empty());
|
TRI_ASSERT(!_myEndpoint.empty());
|
||||||
|
@ -690,7 +690,7 @@ void ServerState::setRole(ServerState::RoleEnum role) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string ServerState::getId() const {
|
std::string ServerState::getId() const {
|
||||||
READ_LOCKER(readLocker, _lock);
|
std::lock_guard<std::mutex> guard(_idLock);
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,7 +703,7 @@ void ServerState::setId(std::string const& id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE_LOCKER(writeLocker, _lock);
|
std::lock_guard<std::mutex> guard(_idLock);
|
||||||
_id = id;
|
_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#ifndef ARANGOD_CLUSTER_SERVER_STATE_H
|
#ifndef ARANGOD_CLUSTER_SERVER_STATE_H
|
||||||
#define ARANGOD_CLUSTER_SERVER_STATE_H 1
|
#define ARANGOD_CLUSTER_SERVER_STATE_H 1
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
#include "Basics/ReadWriteSpinLock.h"
|
#include "Basics/ReadWriteSpinLock.h"
|
||||||
#include "VocBase/voc-types.h"
|
#include "VocBase/voc-types.h"
|
||||||
|
@ -283,8 +285,10 @@ class ServerState {
|
||||||
/// @brief r/w lock for state
|
/// @brief r/w lock for state
|
||||||
mutable arangodb::basics::ReadWriteSpinLock _lock;
|
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;
|
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
|
/// @brief the server's short id, can be set just once
|
||||||
std::atomic<uint32_t> _shortId;
|
std::atomic<uint32_t> _shortId;
|
||||||
|
|
Loading…
Reference in New Issue