Skip to content

Commit 160b0e5

Browse files
craig[bot]wenyihu6
andcommitted
Merge #144119
144119: kvserver: export CachedClosedTimestampPolicy r=arulajmani a=wenyihu6 **kvserver: export CachedClosedTimestampPolicy in get, set** This commit adds two exported method to get and set the private field replica.CachedClosedTimestampPolicy, which will be accessed directly outside of the package for testing purposes. Release note: none Epic: none --- **kvserver/closedts: export DefaultMaxNetworkRTT** This commit exports closedts.defaultMaxNetworkRTT, which will be used as the fallback latency value when peer replica latency is unavailable. Release note: none Epic: none Co-authored-by: wenyihu6 <[email protected]>
2 parents a1e5fd4 + 7f07292 commit 160b0e5

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

pkg/kv/kvserver/closedts/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
const (
16-
defaultMaxNetworkRTT = 150 * time.Millisecond
16+
DefaultMaxNetworkRTT = 150 * time.Millisecond
1717
)
1818

1919
// computeLeadTimeForGlobalReads calculates how far ahead of the current time a
@@ -118,7 +118,7 @@ func TargetForPolicy(
118118
targetOffsetTime = leadTargetOverride
119119
break
120120
}
121-
targetOffsetTime = computeLeadTimeForGlobalReads(defaultMaxNetworkRTT,
121+
targetOffsetTime = computeLeadTimeForGlobalReads(DefaultMaxNetworkRTT,
122122
maxClockOffset, sideTransportCloseInterval)
123123
default:
124124
panic("unexpected RangeClosedTimestampPolicy")

pkg/kv/kvserver/replica.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,21 @@ func (r *Replica) GetMutexForTesting() *ReplicaMutex {
27372737
return &r.mu.ReplicaMutex
27382738
}
27392739

2740+
// TODO(wenyihu6): rename the *ForTesting functions to be Testing* (see
2741+
// #144119 for more details).
2742+
2743+
// SetCachedClosedTimestampPolicyForTesting sets the closed timestamp policy on r
2744+
// to be the given policy. It is a test-only helper method.
2745+
func (r *Replica) SetCachedClosedTimestampPolicyForTesting(policy ctpb.RangeClosedTimestampPolicy) {
2746+
r.cachedClosedTimestampPolicy.Store(int32(policy))
2747+
}
2748+
2749+
// GetCachedClosedTimestampPolicyForTesting returns the closed timestamp policy on r.
2750+
// It is a test-only helper method.
2751+
func (r *Replica) GetCachedClosedTimestampPolicyForTesting() ctpb.RangeClosedTimestampPolicy {
2752+
return ctpb.RangeClosedTimestampPolicy(r.cachedClosedTimestampPolicy.Load())
2753+
}
2754+
27402755
// maybeEnqueueProblemRange will enqueue the replica for processing into the
27412756
// replicate queue iff:
27422757
//

pkg/kv/kvserver/replica_closedts_internal_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/cockroachdb/cockroach/pkg/kv"
1717
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1818
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval"
19-
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/ctpb"
2019
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock"
2120
"github.com/cockroachdb/cockroach/pkg/roachpb"
2221
"github.com/cockroachdb/cockroach/pkg/testutils"
@@ -31,12 +30,6 @@ import (
3130
"golang.org/x/sync/errgroup"
3231
)
3332

34-
// TestingSetCachedClosedTimestampPolicy sets the closed timestamp policy on r
35-
// to be the given policy. It is a test-only helper method.
36-
func (r *Replica) TestingSetCachedClosedTimestampPolicy(policy ctpb.RangeClosedTimestampPolicy) {
37-
r.cachedClosedTimestampPolicy.Store(int32(policy))
38-
}
39-
4033
func TestSideTransportClosed(t *testing.T) {
4134
defer leaktest.AfterTest(t)()
4235
defer log.Scope(t).Close(t)

pkg/kv/kvserver/replica_closedts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ func TestClosedTimestampPolicyRefreshIntervalOnLeaseTransfers(t *testing.T) {
10951095
})
10961096

10971097
// Force repl2 policy to be LAG_BY_CLUSTER_SETTING.
1098-
repl2.TestingSetCachedClosedTimestampPolicy(ctpb.LAG_BY_CLUSTER_SETTING)
1098+
repl2.SetCachedClosedTimestampPolicyForTesting(ctpb.LAG_BY_CLUSTER_SETTING)
10991099
require.Equal(t, roachpb.LAG_BY_CLUSTER_SETTING, repl2.GetRangeInfo(ctx).ClosedTimestampPolicy)
11001100

11011101
// Ensure that transferring the lease to repl2 does trigger a lease refresh.

0 commit comments

Comments
 (0)