github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/replica_closedts.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package kvserver 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/ctpb" 17 ) 18 19 // EmitMLAI registers the replica's last assigned max lease index with the 20 // closed timestamp tracker. This is called to emit an update about this 21 // replica in the absence of write activity. 22 func (r *Replica) EmitMLAI() { 23 r.mu.RLock() 24 lai := r.mu.proposalBuf.LastAssignedLeaseIndexRLocked() 25 if r.mu.state.LeaseAppliedIndex > lai { 26 lai = r.mu.state.LeaseAppliedIndex 27 } 28 epoch := r.mu.state.Lease.Epoch 29 isLeaseholder := r.mu.state.Lease.Replica.ReplicaID == r.mu.replicaID 30 r.mu.RUnlock() 31 32 // If we're the leaseholder of an epoch-based lease, notify the minPropTracker 33 // of the current LAI to trigger a re-broadcast of this range's LAI. 34 if isLeaseholder && epoch > 0 { 35 ctx := r.AnnotateCtx(context.Background()) 36 _, untrack := r.store.cfg.ClosedTimestamp.Tracker.Track(ctx) 37 untrack(ctx, ctpb.Epoch(epoch), r.RangeID, ctpb.LAI(lai)) 38 } 39 }