Skip to content

Commit

Permalink
kvserver: improve logging for follower reads
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
andreimatei committed Jul 16, 2020
1 parent 2c57b3a commit e242fb2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/kv/kvserver/replica_follower_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package kvserver

import (
"context"
"time"

"github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/ctpb"
ctstorage "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/storage"
Expand Down Expand Up @@ -40,6 +41,7 @@ func (r *Replica) canServeFollowerRead(
ctx context.Context, ba *roachpb.BatchRequest, pErr *roachpb.Error,
) *roachpb.Error {
canServeFollowerRead := false
var tsDiff time.Duration
if lErr, ok := pErr.GetDetail().(*roachpb.NotLeaseHolderError); ok &&
lErr.LeaseHolder != nil && lErr.Lease.Type() == roachpb.LeaseEpoch &&
(!ba.IsLocking() && ba.IsAllTransactional()) && // followerreadsccl.batchCanBeEvaluatedOnFollower
Expand Down Expand Up @@ -67,10 +69,13 @@ func (r *Replica) canServeFollowerRead(

maxClosed, _ := r.maxClosed(ctx)
canServeFollowerRead = ts.LessEq(maxClosed)
tsDiff = ts.GoTime().Sub(maxClosed.GoTime())
if !canServeFollowerRead {
// We can't actually serve the read based on the closed timestamp.
// Signal the clients that we want an update so that future requests can succeed.
r.store.cfg.ClosedTimestamp.Clients.Request(lErr.LeaseHolder.NodeID, r.RangeID)
log.Eventf(ctx, "can't serve follower read; closed timestamp too low by: %s; maxClosed: %s ts: %s maxTS: %s",
tsDiff, maxClosed, ba.Timestamp, ba.Txn.MaxTimestamp)

if false {
// NB: this can't go behind V(x) because the log message created by the
Expand All @@ -93,7 +98,7 @@ func (r *Replica) canServeFollowerRead(
//
// TODO(tschottdorf): once a read for a timestamp T has been served, the replica may
// serve reads for that and smaller timestamps forever.
log.Event(ctx, "serving via follower read")
log.Eventf(ctx, "serving via follower read; query timestamp below closed timestamp by %s", -tsDiff)
r.store.metrics.FollowerReadsCount.Inc(1)
return nil
}
Expand Down

0 comments on commit e242fb2

Please sign in to comment.