Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
111309: kvnemesis: teach KVNemesis about replicated locks r=miraradeva a=arulajmani

This patch teaches KVNemesis to optionally use replicated locks for operations/batches that perform locking reads.

Closes #100195

Release note: None

111393: kv: remove replica_consistency_diff test file r=nvanbenschoten a=nvanbenschoten

This file has been unused since a8a10a4, which deleted `TestDiffRange`.

Epic: None
Release note: None

Co-authored-by: Arul Ajmani <[email protected]>
Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
3 people committed Sep 28, 2023
3 parents 199219d + 37d6ca2 + 160b94b commit 6e49f7f
Show file tree
Hide file tree
Showing 23 changed files with 571 additions and 150 deletions.
38 changes: 27 additions & 11 deletions pkg/kv/kvnemesis/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ func applyClientOp(ctx context.Context, db clientI, op *Operation, inTxn bool) {
b.Header.WaitPolicy = lock.WaitPolicy_SkipLocked
}
dur := kvpb.BestEffort
if o.GuaranteedDurability {
dur = kvpb.GuaranteedDurability
}
if o.ForUpdate {
b.GetForUpdate(o.Key, dur)
} else if o.ForShare {
Expand Down Expand Up @@ -321,6 +324,9 @@ func applyClientOp(ctx context.Context, db clientI, op *Operation, inTxn bool) {
b.Header.WaitPolicy = lock.WaitPolicy_SkipLocked
}
dur := kvpb.BestEffort
if o.GuaranteedDurability {
dur = kvpb.GuaranteedDurability
}
if o.Reverse {
if o.ForUpdate {
b.ReverseScanForUpdate(o.Key, o.EndKey, dur)
Expand Down Expand Up @@ -443,6 +449,9 @@ func applyBatchOp(
switch subO := o.Ops[i].GetValue().(type) {
case *GetOperation:
dur := kvpb.BestEffort
if subO.GuaranteedDurability {
dur = kvpb.GuaranteedDurability
}
if subO.ForUpdate {
b.GetForUpdate(subO.Key, dur)
} else if subO.ForShare {
Expand All @@ -455,18 +464,25 @@ func applyBatchOp(
setLastReqSeq(b, subO.Seq)
case *ScanOperation:
dur := kvpb.BestEffort
if subO.Reverse && subO.ForUpdate {
b.ReverseScanForUpdate(subO.Key, subO.EndKey, dur)
} else if subO.Reverse && subO.ForShare {
b.ReverseScanForShare(subO.Key, subO.EndKey, dur)
} else if subO.Reverse {
b.ReverseScan(subO.Key, subO.EndKey)
} else if subO.ForUpdate {
b.ScanForUpdate(subO.Key, subO.EndKey, dur)
} else if subO.ForShare {
b.ScanForShare(subO.Key, subO.EndKey, dur)
if subO.GuaranteedDurability {
dur = kvpb.GuaranteedDurability
}
if subO.Reverse {
if subO.ForUpdate {
b.ReverseScanForUpdate(subO.Key, subO.EndKey, dur)
} else if subO.ForShare {
b.ReverseScanForShare(subO.Key, subO.EndKey, dur)
} else {
b.ReverseScan(subO.Key, subO.EndKey)
}
} else {
b.Scan(subO.Key, subO.EndKey)
if subO.ForUpdate {
b.ScanForUpdate(subO.Key, subO.EndKey, dur)
} else if subO.ForShare {
b.ScanForShare(subO.Key, subO.EndKey, dur)
} else {
b.Scan(subO.Key, subO.EndKey)
}
}
case *DeleteOperation:
b.Del(subO.Key)
Expand Down
58 changes: 58 additions & 0 deletions pkg/kv/kvnemesis/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,61 @@ func TestApplier(t *testing.T) {
{
"get-for-update", step(getForUpdate(k1)),
},
{
"get-for-update-guaranteed-durability", step(getForUpdateGuaranteedDurability(k1)),
},
{
"get-for-share", step(getForShare(k1)),
},
{
"get-for-share-guaranteed-durability", step(getForShareGuaranteedDurability(k1)),
},
{
"get-skip-locked", step(getSkipLocked(k1)),
},
{
"get-for-update-skip-locked", step(getForUpdateSkipLocked(k1)),
},
{
"get-for-update-skip-locked-guaranteed-durability",
step(getForUpdateSkipLockedGuaranteedDurability(k1)),
},
{
"get-for-share-skip-locked", step(getForShareSkipLocked(k1)),
},
{
"get-for-share-skip-locked-guaranteed-durability",
step(getForShareSkipLockedGuaranteedDurability(k1)),
},
{
"scan-for-update", step(scanForUpdate(k1, k3)),
},
{
"scan-for-update-guaranteed-durability", step(scanForUpdateGuaranteedDurability(k1, k3)),
},
{
"scan-for-share", step(scanForShare(k1, k3)),
},
{
"scan-for-share-guaranteed-durability", step(scanForShareGuaranteedDurability(k1, k3)),
},
{
"scan-skip-locked", step(scanSkipLocked(k1, k3)),
},
{
"scan-for-update-skip-locked", step(scanForUpdateSkipLocked(k1, k3)),
},
{
"scan-for-update-skip-locked-guaranteed-durability",
step(scanForUpdateSkipLockedGuaranteedDurability(k1, k3)),
},
{
"scan-for-share-skip-locked", step(scanForShareSkipLocked(k1, k3)),
},
{
"scan-for-share-skip-locked-guaranteed-durability",
step(scanForShareSkipLockedGuaranteedDurability(k1, k3)),
},
{
"batch", step(batch(put(k1, 21), delRange(k2, k3, 22))),
},
Expand All @@ -127,18 +155,34 @@ func TestApplier(t *testing.T) {
{
"rscan-for-update", step(reverseScanForUpdate(k1, k2)),
},
{
"rscan-for-update-guaranteed-durability",
step(reverseScanForUpdateGuaranteedDurability(k1, k2)),
},
{
"rscan-for-share", step(reverseScanForShare(k1, k2)),
},
{
"rscan-for-share-guaranteed-durability",
step(reverseScanForShareGuaranteedDurability(k1, k2)),
},
{
"rscan-skip-locked", step(reverseScanSkipLocked(k1, k2)),
},
{
"rscan-for-update-skip-locked", step(reverseScanForUpdateSkipLocked(k1, k2)),
},
{
"rscan-for-update-skip-locked-guaranteed-durability",
step(reverseScanForUpdateSkipLockedGuaranteedDurability(k1, k2)),
},
{
"rscan-for-share-skip-locked", step(reverseScanForShareSkipLocked(k1, k2)),
},
{
"rscan-for-share-skip-locked-guaranteed-durability",
step(reverseScanForShareSkipLockedGuaranteedDurability(k1, k2)),
},
{
"del", step(del(k2, 1)),
},
Expand Down Expand Up @@ -169,9 +213,15 @@ func TestApplier(t *testing.T) {
{
"scan-for-update-err", step(scanForUpdate(k1, k3)),
},
{
"scan-for-update-guaranteed-durability-err", step(scanForUpdateGuaranteedDurability(k1, k3)),
},
{
"scan-for-share-err", step(scanForShare(k1, k3)),
},
{
"scan-for-share-guaranteed-durability-err", step(scanForShareGuaranteedDurability(k1, k3)),
},
{
"scan-skip-locked-err", step(scanSkipLocked(k1, k3)),
},
Expand All @@ -181,9 +231,17 @@ func TestApplier(t *testing.T) {
{
"rscan-for-update-err", step(reverseScanForUpdate(k1, k3)),
},
{
"rscan-for-update-guaranteed-durability-err",
step(reverseScanForUpdateGuaranteedDurability(k1, k3)),
},
{
"rscan-for-share-err", step(reverseScanForShare(k1, k3)),
},
{
"rscan-for-share-guaranteed-durability-err",
step(reverseScanForShareGuaranteedDurability(k1, k3)),
},
{
"rscan-skip-locked-err", step(reverseScanSkipLocked(k1, k3)),
},
Expand Down
Loading

0 comments on commit 6e49f7f

Please sign in to comment.