Skip to content

Commit 3930324

Browse files
committed
kvserver: wait for lease upgrade
This fixes the race between a lease upgrade request and BumpSideTransportClosed, which fails if there is a pending proposal. Epic: none Release note: none
1 parent d150c61 commit 3930324

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/kv/kvserver/replica_closedts_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ func TestRejectedLeaseDoesntDictateClosedTimestamp(t *testing.T) {
694694
// we eliminate some memory copying and pass the node liveness record in to the
695695
// function so that we only have to grab it once instead of on each call to
696696
// BumpSideTransportClosed, we should be able to reach our target latency.
697+
// TODO(pav-kv): in 2025, this shows about 180-200ns.
697698
func BenchmarkBumpSideTransportClosed(b *testing.B) {
698699
defer leaktest.AfterTest(b)()
699700
defer log.Scope(b).Close(b)
@@ -721,6 +722,22 @@ func BenchmarkBumpSideTransportClosed(b *testing.B) {
721722
now := s.Clock().NowAsClockTimestamp()
722723
targets := map[ctpb.RangeClosedTimestampPolicy]hlc.Timestamp{}
723724

725+
// Wait for the scratch range's lease upgrade from expiration-based lease. The
726+
// closed timestamp bumping requires for there to be no in-flight proposals,
727+
// so a racing lease upgrade can cause a test failure like in #151295.
728+
//
729+
// TODO(pav-kv): share this code with TestCluster.MaybeWaitForLeaseUpgrade().
730+
testutils.SucceedsSoon(b, func() error {
731+
lease, _, err := s.GetRangeLease(ctx, key, roachpb.QueryLocalNodeOnly)
732+
require.NoError(b, err)
733+
typ := lease.Current().Type()
734+
if typ == roachpb.LeaseExpiration {
735+
return errors.Errorf("still on expiration-based lease")
736+
}
737+
b.Logf("lease is now of type: %s", typ)
738+
return nil
739+
})
740+
724741
b.ResetTimer()
725742
for i := 0; i < b.N; i++ {
726743
// Advance time and the closed timestamp target.

0 commit comments

Comments
 (0)