Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: truncate aggressively only after 4mb of logs #32437

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions pkg/storage/raft_log_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,22 @@ func newTruncateDecision(ctx context.Context, r *Replica) (*truncateDecision, er

r.mu.Lock()
raftLogSize := r.mu.raftLogSize
// We target the raft log size at the size of the replicated data. When
// writing to a replica, it is common for the raft log to become larger than
// the replicated data as the raft log contains the overhead of the
// BatchRequest which includes the full transaction state as well as begin
// and end transaction operations. If the estimated raft log size becomes
// larger than the replica size, we're better off recovering the replica
// using a snapshot.
targetSize := r.mu.state.Stats.Total()
// A "cooperative" truncation (i.e. one that does not cut off followers from
// the log) takes place whenever there are more than
// RaftLogQueueStaleThreshold entries or the log's estimated size is above
// RaftLogQueueStaleSize bytes. This is fairly aggressive, so under normal
// conditions, the log is very small.
//
// If followers start falling behind, at some point the logs still need to
// be truncated. We do this either when the size of the log exceeds
// RaftLogTruncationThreshold (or, in eccentric configurations, the zone's
// RangeMaxBytes). This captures the heuristic that at some point, it's more
// efficient to catch up via a snapshot than via applying a long tail of log
// entries.
targetSize := r.store.cfg.RaftLogTruncationThreshold
if targetSize > *r.mu.zone.RangeMaxBytes {
targetSize = *r.mu.zone.RangeMaxBytes
}
if targetSize > r.store.cfg.RaftLogTruncationThreshold {
targetSize = r.store.cfg.RaftLogTruncationThreshold
}
raftStatus := r.raftStatusRLocked()

firstIndex, err := r.raftFirstIndexLocked()
Expand Down