Skip to content

Commit e1318fa

Browse files
committed
kvserver: add per-operation lock reliability settings
Preserving unreplicated locks during split, merge, and lease transfers have different trade offs. For instance, during a split all lock updates are done in memory without any new replicated writes, whereas for merge and lease transfers requiring replicating locks through raft. Here, we put the different operations under different settings since we may want to ship different defaults for the different operations. Epic: none Release note: None
1 parent 61700b1 commit e1318fa

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

Diff for: pkg/kv/kvserver/client_replica_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5781,7 +5781,7 @@ func TestLeaseTransferReplicatesLocks(t *testing.T) {
57815781
// txn2 is never unblocked (from the perspective of the client).
57825782
ctx := context.Background()
57835783
st := cluster.MakeClusterSettings()
5784-
concurrency.UnreplicatedLockReliability.Override(ctx, &st.SV, true)
5784+
concurrency.UnreplicatedLockReliabilityLeaseTransfer.Override(ctx, &st.SV, true)
57855785
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{
57865786
ServerArgs: base.TestServerArgs{
57875787
Settings: st,
@@ -5891,7 +5891,7 @@ func TestMergeReplicatesLocks(t *testing.T) {
58915891
ctx = context.Background()
58925892
st = cluster.MakeClusterSettings()
58935893
)
5894-
concurrency.UnreplicatedLockReliability.Override(ctx, &st.SV, true)
5894+
concurrency.UnreplicatedLockReliabilityMerge.Override(ctx, &st.SV, true)
58955895

58965896
for _, b := range []bool{true, false} {
58975897
name := "lhs-lock"

Diff for: pkg/kv/kvserver/concurrency/concurrency_manager.go

+27-9
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,31 @@ var BatchPushedLockResolution = settings.RegisterBoolSetting(
114114
true,
115115
)
116116

117-
// UnreplicatedLockReliability controls whether the replica will attempt
118-
// to keep unreplicated locks during node operations such as split.
119-
var UnreplicatedLockReliability = settings.RegisterBoolSetting(
117+
// UnreplicatedLockReliabilitySplit controls whether the replica will attempt
118+
// to keep unreplicated locks during range split operations.
119+
var UnreplicatedLockReliabilitySplit = settings.RegisterBoolSetting(
120120
settings.SystemOnly,
121-
"kv.lock_table.unreplicated_lock_reliability.enabled",
122-
"whether the replica should attempt to keep unreplicated locks during various node operations",
123-
metamorphic.ConstantWithTestBool("kv.lock_table.unreplicated_lock_reliability.enabled", true),
121+
"kv.lock_table.unreplicated_lock_reliability.split.enabled",
122+
"whether the replica should attempt to keep unreplicated locks during range splits",
123+
metamorphic.ConstantWithTestBool("kv.lock_table.unreplicated_lock_reliability.split.enabled", true),
124+
)
125+
126+
// UnreplicatedLockReliabilityLeaseTransfer controls whether the replica will attempt
127+
// to keep unreplicated locks during lease transfer operations.
128+
var UnreplicatedLockReliabilityLeaseTransfer = settings.RegisterBoolSetting(
129+
settings.SystemOnly,
130+
"kv.lock_table.unreplicated_lock_reliability.lease_transfer.enabled",
131+
"whether the replica should attempt to keep unreplicated locks during lease transfers",
132+
metamorphic.ConstantWithTestBool("kv.lock_table.unreplicated_lock_reliability.lease_transfer.enabled", true),
133+
)
134+
135+
// UnreplicatedLockReliabilityMerge controls whether the replica will
136+
// attempt to keep unreplicated locks during range merge operations.
137+
var UnreplicatedLockReliabilityMerge = settings.RegisterBoolSetting(
138+
settings.SystemOnly,
139+
"kv.lock_table.unreplicated_lock_reliability.merge.enabled",
140+
"whether the replica should attempt to keep unreplicated locks during range merges",
141+
metamorphic.ConstantWithTestBool("kv.lock_table.unreplicated_lock_reliability.merge.enabled", true),
124142
)
125143

126144
// managerImpl implements the Manager interface.
@@ -590,7 +608,7 @@ var allKeysSpan = roachpb.Span{Key: keys.MinKey, EndKey: keys.MaxKey}
590608

591609
// OnRangeLeaseTransferEval implements the RangeStateListener interface.
592610
func (m *managerImpl) OnRangeLeaseTransferEval() []*roachpb.LockAcquisition {
593-
if !UnreplicatedLockReliability.Get(&m.st.SV) {
611+
if !UnreplicatedLockReliabilityLeaseTransfer.Get(&m.st.SV) {
594612
return nil
595613
}
596614

@@ -606,7 +624,7 @@ func (m *managerImpl) OnRangeLeaseTransferEval() []*roachpb.LockAcquisition {
606624
// during evalutation of Subsume. The returned LockAcquisition structs represent
607625
// held locks that we may want to flush to disk as replicated.
608626
func (m *managerImpl) OnRangeSubsumeEval() []*roachpb.LockAcquisition {
609-
if !UnreplicatedLockReliability.Get(&m.st.SV) {
627+
if !UnreplicatedLockReliabilityMerge.Get(&m.st.SV) {
610628
return nil
611629
}
612630

@@ -636,7 +654,7 @@ func (m *managerImpl) OnRangeLeaseUpdated(seq roachpb.LeaseSequence, isLeasehold
636654
// LHS replica of a split and should be passed the new RHS start key (LHS
637655
// EndKey).
638656
func (m *managerImpl) OnRangeSplit(rhsStartKey roachpb.Key) []roachpb.LockAcquisition {
639-
if UnreplicatedLockReliability.Get(&m.st.SV) {
657+
if UnreplicatedLockReliabilitySplit.Get(&m.st.SV) {
640658
lockToMove := m.lt.ClearGE(rhsStartKey)
641659
m.twq.ClearGE(rhsStartKey)
642660
return lockToMove

Diff for: pkg/kv/kvserver/concurrency/concurrency_manager_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ func newClusterWithSettings(st *clustersettings.Settings) *cluster {
735735
// Set the latch manager's long latch threshold to infinity to disable
736736
// logging, which could cause a test to erroneously fail.
737737
spanlatch.LongLatchHoldThreshold.Override(context.Background(), &st.SV, math.MaxInt64)
738-
concurrency.UnreplicatedLockReliability.Override(context.Background(), &st.SV, true)
738+
concurrency.UnreplicatedLockReliabilitySplit.Override(context.Background(), &st.SV, true)
739+
concurrency.UnreplicatedLockReliabilityMerge.Override(context.Background(), &st.SV, true)
740+
concurrency.UnreplicatedLockReliabilityLeaseTransfer.Override(context.Background(), &st.SV, true)
739741
manual := timeutil.NewManualTime(timeutil.Unix(123, 0))
740742
return &cluster{
741743
nodeDesc: &roachpb.NodeDescriptor{NodeID: 1},

Diff for: pkg/kv/kvserver/replica_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ func (r *Replica) AdminMerge(
915915
// This must be a single request in a BatchRequest: there are multiple
916916
// places that do special logic (needed for safety) that rely on
917917
// BatchRequest.IsSingleSubsumeRequest() returning true.
918-
shouldPreserveLocks := concurrency.UnreplicatedLockReliability.Get(&r.ClusterSettings().SV)
918+
shouldPreserveLocks := concurrency.UnreplicatedLockReliabilityMerge.Get(&r.ClusterSettings().SV)
919919
br, pErr := kv.SendWrapped(ctx, r.store.DB().NonTransactionalSender(),
920920
&kvpb.SubsumeRequest{
921921
RequestHeader: kvpb.RequestHeader{

0 commit comments

Comments
 (0)