mirror of https://gitee.com/bigwinds/arangodb
agencycommresult with clientids
This commit is contained in:
parent
c3f7a0b774
commit
54ccffc0ee
|
@ -224,7 +224,7 @@ void AgencyWriteTransaction::toVelocyPack(VPackBuilder& builder) const {
|
||||||
VPackObjectBuilder guard3(&builder);
|
VPackObjectBuilder guard3(&builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.add(VPackValue(transactionId)); // Transactions
|
builder.add(VPackValue(clientId)); // Transactions
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AgencyWriteTransaction::validate(AgencyCommResult const& result) const {
|
bool AgencyWriteTransaction::validate(AgencyCommResult const& result) const {
|
||||||
|
@ -283,7 +283,7 @@ void AgencyGeneralTransaction::toVelocyPack(VPackBuilder& builder) const {
|
||||||
} else {
|
} else {
|
||||||
std::get<0>(operation).toGeneralBuilder(builder);
|
std::get<0>(operation).toGeneralBuilder(builder);
|
||||||
std::get<1>(operation).toGeneralBuilder(builder);
|
std::get<1>(operation).toGeneralBuilder(builder);
|
||||||
builder.add(VPackValue(transactionId));
|
builder.add(VPackValue(clientId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,18 +328,23 @@ AgencyCommResult::AgencyCommResult()
|
||||||
_body(),
|
_body(),
|
||||||
_values(),
|
_values(),
|
||||||
_statusCode(0),
|
_statusCode(0),
|
||||||
_connected(false) {}
|
_connected(false),
|
||||||
|
_clientId("") {}
|
||||||
|
|
||||||
AgencyCommResult::AgencyCommResult(int code, std::string const& message)
|
AgencyCommResult::AgencyCommResult(
|
||||||
|
int code, std::string const& message, std::string const& clientId)
|
||||||
: _location(),
|
: _location(),
|
||||||
_message(message),
|
_message(message),
|
||||||
_body(),
|
_body(),
|
||||||
_values(),
|
_values(),
|
||||||
_statusCode(code),
|
_statusCode(code),
|
||||||
_connected(false) {}
|
_connected(false),
|
||||||
|
_clientId(clientId) {}
|
||||||
|
|
||||||
bool AgencyCommResult::connected() const { return _connected; }
|
bool AgencyCommResult::connected() const { return _connected; }
|
||||||
|
|
||||||
|
std::string AgencyCommResult::clientId() const { return _clientId; }
|
||||||
|
|
||||||
int AgencyCommResult::httpCode() const { return _statusCode; }
|
int AgencyCommResult::httpCode() const { return _statusCode; }
|
||||||
|
|
||||||
int AgencyCommResult::errorCode() const {
|
int AgencyCommResult::errorCode() const {
|
||||||
|
|
|
@ -218,7 +218,9 @@ class AgencyOperation {
|
||||||
class AgencyCommResult {
|
class AgencyCommResult {
|
||||||
public:
|
public:
|
||||||
AgencyCommResult();
|
AgencyCommResult();
|
||||||
AgencyCommResult(int code, std::string const& message);
|
AgencyCommResult(int code, std::string const& message,
|
||||||
|
std::string const& transactionId = std::string());
|
||||||
|
|
||||||
~AgencyCommResult() = default;
|
~AgencyCommResult() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -230,6 +232,8 @@ class AgencyCommResult {
|
||||||
|
|
||||||
int errorCode() const;
|
int errorCode() const;
|
||||||
|
|
||||||
|
std::string clientId() const;
|
||||||
|
|
||||||
std::string errorMessage() const;
|
std::string errorMessage() const;
|
||||||
|
|
||||||
std::string errorDetails() const;
|
std::string errorDetails() const;
|
||||||
|
@ -256,6 +260,8 @@ class AgencyCommResult {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<velocypack::Builder> _vpack;
|
std::shared_ptr<velocypack::Builder> _vpack;
|
||||||
|
|
||||||
|
std::string _clientId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -272,7 +278,8 @@ public:
|
||||||
virtual std::string toJson() const = 0;
|
virtual std::string toJson() const = 0;
|
||||||
virtual void toVelocyPack(arangodb::velocypack::Builder&) const = 0;
|
virtual void toVelocyPack(arangodb::velocypack::Builder&) const = 0;
|
||||||
virtual std::string const& path() const = 0;
|
virtual std::string const& path() const = 0;
|
||||||
|
virtual std::string getClientId() const = 0;
|
||||||
|
|
||||||
virtual bool validate(AgencyCommResult const& result) const = 0;
|
virtual bool validate(AgencyCommResult const& result) const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -285,14 +292,14 @@ struct AgencyGeneralTransaction : public AgencyTransaction {
|
||||||
|
|
||||||
explicit AgencyGeneralTransaction(
|
explicit AgencyGeneralTransaction(
|
||||||
std::pair<AgencyOperation,AgencyPrecondition> const& operation) :
|
std::pair<AgencyOperation,AgencyPrecondition> const& operation) :
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {
|
clientId(to_string(boost::uuids::random_generator()())) {
|
||||||
operations.push_back(operation);
|
operations.push_back(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit AgencyGeneralTransaction(
|
explicit AgencyGeneralTransaction(
|
||||||
std::vector<std::pair<AgencyOperation,AgencyPrecondition>> const& _opers) :
|
std::vector<std::pair<AgencyOperation,AgencyPrecondition>> const& _opers) :
|
||||||
operations(_opers),
|
operations(_opers),
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {}
|
clientId(to_string(boost::uuids::random_generator()())) {}
|
||||||
|
|
||||||
AgencyGeneralTransaction() = default;
|
AgencyGeneralTransaction() = default;
|
||||||
|
|
||||||
|
@ -305,12 +312,16 @@ struct AgencyGeneralTransaction : public AgencyTransaction {
|
||||||
|
|
||||||
void push_back(std::pair<AgencyOperation,AgencyPrecondition> const&);
|
void push_back(std::pair<AgencyOperation,AgencyPrecondition> const&);
|
||||||
|
|
||||||
inline std::string const& path() const override final {
|
inline virtual std::string const& path() const override final {
|
||||||
return AgencyTransaction::TypeUrl[2];
|
return AgencyTransaction::TypeUrl[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline virtual std::string getClientId() const override final {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool validate(AgencyCommResult const& result) const override final;
|
virtual bool validate(AgencyCommResult const& result) const override final;
|
||||||
std::string transactionId;
|
std::string clientId;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -323,24 +334,24 @@ struct AgencyWriteTransaction : public AgencyTransaction {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit AgencyWriteTransaction(AgencyOperation const& operation) :
|
explicit AgencyWriteTransaction(AgencyOperation const& operation) :
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {
|
clientId(to_string(boost::uuids::random_generator()())) {
|
||||||
operations.push_back(operation);
|
operations.push_back(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit AgencyWriteTransaction (std::vector<AgencyOperation> const& _opers) :
|
explicit AgencyWriteTransaction (std::vector<AgencyOperation> const& _opers) :
|
||||||
operations(_opers),
|
operations(_opers),
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {}
|
clientId(to_string(boost::uuids::random_generator()())) {}
|
||||||
|
|
||||||
AgencyWriteTransaction(AgencyOperation const& operation,
|
AgencyWriteTransaction(AgencyOperation const& operation,
|
||||||
AgencyPrecondition const& precondition) :
|
AgencyPrecondition const& precondition) :
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {
|
clientId(to_string(boost::uuids::random_generator()())) {
|
||||||
operations.push_back(operation);
|
operations.push_back(operation);
|
||||||
preconditions.push_back(precondition);
|
preconditions.push_back(precondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
AgencyWriteTransaction(std::vector<AgencyOperation> const& _operations,
|
AgencyWriteTransaction(std::vector<AgencyOperation> const& _operations,
|
||||||
AgencyPrecondition const& precondition) :
|
AgencyPrecondition const& precondition) :
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {
|
clientId(to_string(boost::uuids::random_generator()())) {
|
||||||
for (auto const& op : _operations) {
|
for (auto const& op : _operations) {
|
||||||
operations.push_back(op);
|
operations.push_back(op);
|
||||||
}
|
}
|
||||||
|
@ -349,7 +360,7 @@ public:
|
||||||
|
|
||||||
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
AgencyWriteTransaction(std::vector<AgencyOperation> const& opers,
|
||||||
std::vector<AgencyPrecondition> const& precs) :
|
std::vector<AgencyPrecondition> const& precs) :
|
||||||
transactionId(to_string(boost::uuids::random_generator()())) {
|
clientId(to_string(boost::uuids::random_generator()())) {
|
||||||
for (auto const& op : opers) {
|
for (auto const& op : opers) {
|
||||||
operations.push_back(op);
|
operations.push_back(op);
|
||||||
}
|
}
|
||||||
|
@ -365,15 +376,19 @@ public:
|
||||||
|
|
||||||
std::string toJson() const override final;
|
std::string toJson() const override final;
|
||||||
|
|
||||||
inline std::string const& path() const override final {
|
inline virtual std::string const& path() const override final {
|
||||||
return AgencyTransaction::TypeUrl[1];
|
return AgencyTransaction::TypeUrl[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline virtual std::string getClientId() const override final {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool validate(AgencyCommResult const& result) const override final;
|
virtual bool validate(AgencyCommResult const& result) const override final;
|
||||||
|
|
||||||
std::vector<AgencyPrecondition> preconditions;
|
std::vector<AgencyPrecondition> preconditions;
|
||||||
std::vector<AgencyOperation> operations;
|
std::vector<AgencyOperation> operations;
|
||||||
std::string transactionId;
|
std::string clientId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -427,6 +442,10 @@ public:
|
||||||
return AgencyTransaction::TypeUrl[3];
|
return AgencyTransaction::TypeUrl[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline virtual std::string getClientId() const override final {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool validate(AgencyCommResult const& result) const override final;
|
virtual bool validate(AgencyCommResult const& result) const override final;
|
||||||
|
|
||||||
std::vector<AgencyPrecondition> preconditions;
|
std::vector<AgencyPrecondition> preconditions;
|
||||||
|
@ -454,10 +473,14 @@ public:
|
||||||
|
|
||||||
std::string toJson() const override final;
|
std::string toJson() const override final;
|
||||||
|
|
||||||
inline std::string const& path() const override final {
|
inline virtual std::string const& path() const override final {
|
||||||
return AgencyTransaction::TypeUrl[0];
|
return AgencyTransaction::TypeUrl[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline virtual std::string getClientId() const override final {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool validate(AgencyCommResult const& result) const override final;
|
virtual bool validate(AgencyCommResult const& result) const override final;
|
||||||
|
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
|
|
|
@ -810,7 +810,6 @@ void Agent::run() {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_appendCV.wait(1000000);
|
_appendCV.wait(1000000);
|
||||||
updateConfiguration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -910,9 +909,9 @@ void Agent::detectActiveAgentFailures() {
|
||||||
system_clock::now() - lastAcked.at(id)).count();
|
system_clock::now() - lastAcked.at(id)).count();
|
||||||
if (ds > 180.0) {
|
if (ds > 180.0) {
|
||||||
std::string repl = _config.nextAgentInLine();
|
std::string repl = _config.nextAgentInLine();
|
||||||
LOG_TOPIC(DEBUG, Logger::AGENCY) << "Active agent " << id << " has failed. << "
|
LOG_TOPIC(DEBUG, Logger::AGENCY)
|
||||||
<< repl << " will be promoted to active agency membership";
|
<< "Active agent " << id << " has failed. << " << repl
|
||||||
// Guarded in ::
|
<< " will be promoted to active agency membership";
|
||||||
_activator = std::make_unique<AgentActivator>(this, id, repl);
|
_activator = std::make_unique<AgentActivator>(this, id, repl);
|
||||||
_activator->start();
|
_activator->start();
|
||||||
return;
|
return;
|
||||||
|
@ -923,13 +922,6 @@ void Agent::detectActiveAgentFailures() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Agent::updateConfiguration() {
|
|
||||||
|
|
||||||
// First ask last know leader
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Orderly shutdown
|
/// Orderly shutdown
|
||||||
void Agent::beginShutdown() {
|
void Agent::beginShutdown() {
|
||||||
Thread::beginShutdown();
|
Thread::beginShutdown();
|
||||||
|
|
|
@ -223,9 +223,6 @@ class Agent : public arangodb::Thread {
|
||||||
/// @brief persist agency configuration in RAFT
|
/// @brief persist agency configuration in RAFT
|
||||||
void persistConfiguration(term_t t);
|
void persistConfiguration(term_t t);
|
||||||
|
|
||||||
/// @brief Update my configuration as passive agent
|
|
||||||
void updateConfiguration();
|
|
||||||
|
|
||||||
/// @brief Find out, if we've had acknowledged RPCs recent enough
|
/// @brief Find out, if we've had acknowledged RPCs recent enough
|
||||||
bool challengeLeadership();
|
bool challengeLeadership();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue