Skip to content

Commit ddcbada

Browse files
committed
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
1 parent 8086302 commit ddcbada

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

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)