mirror of https://gitee.com/bigwinds/arangodb
fix slow queries
This commit is contained in:
parent
fbb14ceffc
commit
8e51e3ba50
|
@ -528,33 +528,35 @@ void Constituent::run() {
|
||||||
// single instance
|
// single instance
|
||||||
_id = _agent->config().id();
|
_id = _agent->config().id();
|
||||||
|
|
||||||
TRI_ASSERT(_vocbase != nullptr);
|
{
|
||||||
auto bindVars = std::make_shared<VPackBuilder>();
|
TRI_ASSERT(_vocbase != nullptr);
|
||||||
bindVars->openObject();
|
auto bindVars = std::make_shared<VPackBuilder>();
|
||||||
bindVars->close();
|
bindVars->openObject();
|
||||||
|
bindVars->close();
|
||||||
|
|
||||||
// Most recent vote
|
// Most recent vote
|
||||||
std::string const aql("FOR l IN election SORT l._key DESC LIMIT 1 RETURN l");
|
std::string const aql("FOR l IN election SORT l._key DESC LIMIT 1 RETURN l");
|
||||||
arangodb::aql::Query query(false, _vocbase, aql.c_str(), aql.size(), bindVars,
|
arangodb::aql::Query query(false, _vocbase, aql.c_str(), aql.size(), bindVars,
|
||||||
nullptr, arangodb::aql::PART_MAIN);
|
nullptr, arangodb::aql::PART_MAIN);
|
||||||
|
|
||||||
auto queryResult = query.execute(_queryRegistry);
|
auto queryResult = query.execute(_queryRegistry);
|
||||||
if (queryResult.code != TRI_ERROR_NO_ERROR) {
|
if (queryResult.code != TRI_ERROR_NO_ERROR) {
|
||||||
THROW_ARANGO_EXCEPTION_MESSAGE(queryResult.code, queryResult.details);
|
THROW_ARANGO_EXCEPTION_MESSAGE(queryResult.code, queryResult.details);
|
||||||
}
|
}
|
||||||
|
|
||||||
VPackSlice result = queryResult.result->slice();
|
VPackSlice result = queryResult.result->slice();
|
||||||
|
|
||||||
if (result.isArray()) {
|
if (result.isArray()) {
|
||||||
for (auto const& i : VPackArrayIterator(result)) {
|
for (auto const& i : VPackArrayIterator(result)) {
|
||||||
auto ii = i.resolveExternals();
|
auto ii = i.resolveExternals();
|
||||||
try {
|
try {
|
||||||
MUTEX_LOCKER(locker, _castLock);
|
MUTEX_LOCKER(locker, _castLock);
|
||||||
_term = ii.get("term").getUInt();
|
_term = ii.get("term").getUInt();
|
||||||
_votedFor = ii.get("voted_for").copyString();
|
_votedFor = ii.get("voted_for").copyString();
|
||||||
} catch (std::exception const&) {
|
} catch (std::exception const&) {
|
||||||
LOG_TOPIC(ERR, Logger::AGENCY)
|
LOG_TOPIC(ERR, Logger::AGENCY)
|
||||||
<< "Persisted election entries corrupt! Defaulting term,vote (0,0)";
|
<< "Persisted election entries corrupt! Defaulting term,vote (0,0)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue