raft_consensus: avoid some unecessary allocations in hot path In the stress cluster I noticed that UpdateConsensus does a lot of allocation in LockForUpdate. In particular, it was constructing a ConsensusStatusPB just to check whether it was currently a voter, and that only to provide a log message. That PB has a lot of various strings and other objects inside of it which caused unnecessary allocation.
We can already get this same information from the existing RaftConfigPB object in ConsensusMeta, and a lot cheaper. Change-Id: I75abcaaaed281e5ac1768ea3014064925db6c030 Reviewed-on: http://gerrit.cloudera.org:8080/5344 Tested-by: Kudu Jenkins Reviewed-by: Mike Percy <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/e14b8249 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/e14b8249 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/e14b8249 Branch: refs/heads/master Commit: e14b82496da992c40af3fbf2c24a97f38b1d96cc Parents: 4a8c86b Author: Todd Lipcon <[email protected]> Authored: Fri Dec 2 18:15:10 2016 -0800 Committer: Mike Percy <[email protected]> Committed: Mon Dec 5 17:39:32 2016 +0000 ---------------------------------------------------------------------- src/kudu/consensus/raft_consensus_state.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/e14b8249/src/kudu/consensus/raft_consensus_state.cc ---------------------------------------------------------------------- diff --git a/src/kudu/consensus/raft_consensus_state.cc b/src/kudu/consensus/raft_consensus_state.cc index a0b38d4..af5943b 100644 --- a/src/kudu/consensus/raft_consensus_state.cc +++ b/src/kudu/consensus/raft_consensus_state.cc @@ -145,7 +145,7 @@ Status ReplicaState::LockForUpdate(UniqueLock* lock) const { if (PREDICT_FALSE(state_ != kRunning)) { return Status::IllegalState("Replica not in running state"); } - if (!IsRaftConfigVoter(peer_uuid_, ConsensusStateUnlocked(CONSENSUS_CONFIG_ACTIVE).config())) { + if (!IsRaftConfigVoter(peer_uuid_, cmeta_->active_config())) { LOG_WITH_PREFIX_UNLOCKED(INFO) << "Allowing update even though not a member of the config"; } lock->swap(l);
