Skip to content

Commit

Permalink
Merge pull request facebook#114 from bhatvinay/truncation-counters
Browse files Browse the repository at this point in the history
[kuduraft] add truncation counter in raft consensus
  • Loading branch information
bhatvinay authored Jun 21, 2021
2 parents f0427bb + e6221d0 commit 2294de8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/kudu/consensus/raft_consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ DEFINE_bool(track_removed_peers, true,

// Metrics
// ---------
METRIC_DEFINE_counter(server, raft_log_truncation_counter,
"Log truncation count",
kudu::MetricUnit::kRequests,
"Number of times ops written to raft log were truncated "
"as a result of the new leader overwriting ops");

METRIC_DEFINE_counter(server, follower_memory_pressure_rejections,
"Follower Memory Pressure Rejections",
kudu::MetricUnit::kRequests,
Expand Down Expand Up @@ -344,6 +350,9 @@ Status RaftConsensus::Start(const ConsensusBootstrapInfo& info,
DCHECK(log_ != NULL);
DCHECK(time_manager_ != NULL);

raft_log_truncation_counter_ =
metric_entity->FindOrCreateCounter(&METRIC_raft_log_truncation_counter);

term_metric_ = metric_entity->FindOrCreateGauge(&METRIC_raft_term, CurrentTerm());
follower_memory_pressure_rejections_ =
metric_entity->FindOrCreateCounter(&METRIC_follower_memory_pressure_rejections);
Expand Down Expand Up @@ -937,7 +946,13 @@ Status RaftConsensus::TruncateCallbackWithRaftLock(int64_t *index_if_truncated)
// We pass -1 to TruncateOpsAfter in the log abstraction
// It is the responsibility of the derived log to truncate from
// the cached truncation index and clear it.
return log_->TruncateOpsAfter(-1, index_if_truncated);
RETURN_NOT_OK(log_->TruncateOpsAfter(-1, index_if_truncated));

if (index_if_truncated && *index_if_truncated != -1) {
raft_log_truncation_counter_->Increment();
}

return Status::OK();
}

Status RaftConsensus::CheckLeadershipAndBindTerm(const scoped_refptr<ConsensusRound>& round) {
Expand Down
3 changes: 3 additions & 0 deletions src/kudu/consensus/raft_consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,9 @@ class RaftConsensus : public std::enable_shared_from_this<RaftConsensus>,
// restarts
bool new_leader_detected_failsafe_;

// Number of times ops in raft log were truncated as a result of new leader
// overwriting the log
scoped_refptr<Counter> raft_log_truncation_counter_;

// Proxy metrics.
scoped_refptr<Counter> raft_proxy_num_requests_received_;
Expand Down

0 comments on commit 2294de8

Please sign in to comment.