mirror of https://gitee.com/bigwinds/arangodb
create independent executeLockedRead and executeLockedWrite to speed performance (#4178)
This commit is contained in:
parent
1c01d07dbd
commit
41d1bfce23
|
@ -1529,7 +1529,14 @@ arangodb::consensus::index_t Agent::readDB(Node& node) const {
|
||||||
return _commitIndex;
|
return _commitIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::executeLocked(std::function<void()> const& cb) {
|
void Agent::executeLockedRead(std::function<void()> const& cb) {
|
||||||
|
_tiLock.assertNotLockedByCurrentThread();
|
||||||
|
MUTEX_LOCKER(ioLocker, _ioLock);
|
||||||
|
READ_LOCKER(oLocker, _outputLock);
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Agent::executeLockedWrite(std::function<void()> const& cb) {
|
||||||
_tiLock.assertNotLockedByCurrentThread();
|
_tiLock.assertNotLockedByCurrentThread();
|
||||||
MUTEX_LOCKER(ioLocker, _ioLock);
|
MUTEX_LOCKER(ioLocker, _ioLock);
|
||||||
WRITE_LOCKER(oLocker, _outputLock);
|
WRITE_LOCKER(oLocker, _outputLock);
|
||||||
|
|
|
@ -199,18 +199,32 @@ class Agent : public arangodb::Thread,
|
||||||
State const& state() const;
|
State const& state() const;
|
||||||
|
|
||||||
/// @brief execute a callback while holding _ioLock
|
/// @brief execute a callback while holding _ioLock
|
||||||
void executeLocked(std::function<void()> const& cb);
|
/// and read lock for _readDB
|
||||||
|
void executeLockedRead(std::function<void()> const& cb);
|
||||||
|
|
||||||
|
/// @brief execute a callback while holding _ioLock
|
||||||
|
/// and write lock for _readDB
|
||||||
|
void executeLockedWrite(std::function<void()> const& cb);
|
||||||
|
|
||||||
/// @brief Get read store and compaction index
|
/// @brief Get read store and compaction index
|
||||||
index_t readDB(Node&) const;
|
index_t readDB(Node&) const;
|
||||||
|
|
||||||
/// @brief Get read store
|
/// @brief Get read store
|
||||||
|
/// WARNING: this assumes caller holds appropriate
|
||||||
|
/// locks or will use executeLockedRead() or
|
||||||
|
/// executeLockedWrite() with a lambda function
|
||||||
Store const& readDB() const;
|
Store const& readDB() const;
|
||||||
|
|
||||||
/// @brief Get spearhead store
|
/// @brief Get spearhead store
|
||||||
|
/// WARNING: this assumes caller holds appropriate
|
||||||
|
/// locks or will use executeLockedRead() or
|
||||||
|
/// executeLockedWrite() with a lambda function
|
||||||
Store const& spearhead() const;
|
Store const& spearhead() const;
|
||||||
|
|
||||||
/// @brief Get transient store
|
/// @brief Get transient store
|
||||||
|
/// WARNING: this assumes caller holds appropriate
|
||||||
|
/// locks or will use executeLockedRead() or
|
||||||
|
/// executeLockedWrite() with a lambda function
|
||||||
Store const& transient() const;
|
Store const& transient() const;
|
||||||
|
|
||||||
/// @brief Serve active agent interface
|
/// @brief Serve active agent interface
|
||||||
|
|
|
@ -158,7 +158,7 @@ RestStatus RestAgencyHandler::handleStores() {
|
||||||
{
|
{
|
||||||
VPackObjectBuilder b(&body);
|
VPackObjectBuilder b(&body);
|
||||||
{
|
{
|
||||||
_agent->executeLocked([&]() {
|
_agent->executeLockedRead([&]() {
|
||||||
body.add(VPackValue("spearhead"));
|
body.add(VPackValue("spearhead"));
|
||||||
{
|
{
|
||||||
VPackArrayBuilder bb(&body);
|
VPackArrayBuilder bb(&body);
|
||||||
|
@ -167,9 +167,7 @@ RestStatus RestAgencyHandler::handleStores() {
|
||||||
body.add(VPackValue("read_db"));
|
body.add(VPackValue("read_db"));
|
||||||
{
|
{
|
||||||
VPackArrayBuilder bb(&body);
|
VPackArrayBuilder bb(&body);
|
||||||
_agent->executeLocked([&]() {
|
|
||||||
_agent->readDB().dumpToBuilder(body);
|
_agent->readDB().dumpToBuilder(body);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
body.add(VPackValue("transient"));
|
body.add(VPackValue("transient"));
|
||||||
{
|
{
|
||||||
|
|
|
@ -542,7 +542,7 @@ bool Supervision::updateSnapshot() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_agent->executeLocked([&]() {
|
_agent->executeLockedRead([&]() {
|
||||||
if (_agent->readDB().has(_agencyPrefix)) {
|
if (_agent->readDB().has(_agencyPrefix)) {
|
||||||
_snapshot = _agent->readDB().get(_agencyPrefix);
|
_snapshot = _agent->readDB().get(_agencyPrefix);
|
||||||
}
|
}
|
||||||
|
@ -582,7 +582,7 @@ void Supervision::run() {
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
MUTEX_LOCKER(locker, _lock);
|
MUTEX_LOCKER(locker, _lock);
|
||||||
_agent->executeLocked([&]() {
|
_agent->executeLockedRead([&]() {
|
||||||
if (_agent->readDB().has(supervisionNode)) {
|
if (_agent->readDB().has(supervisionNode)) {
|
||||||
try {
|
try {
|
||||||
_snapshot = _agent->readDB().get(supervisionNode);
|
_snapshot = _agent->readDB().get(supervisionNode);
|
||||||
|
|
Loading…
Reference in New Issue