Skip to content

Commit

Permalink
concurrency: use lock strength to declare spans in datadriven tests
Browse files Browse the repository at this point in the history
In 5418acd we switched to declaring
lock spans using lock strength instead of span access; this patch
changes datadriven test input for lock table tests to do the same.

Closes #102008

Release note: None
  • Loading branch information
arulajmani committed May 5, 2023
1 parent 54d50fe commit 342f39b
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 153 deletions.
41 changes: 23 additions & 18 deletions pkg/kv/kvserver/concurrency/lock_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ new-txn txn=<name> ts=<int>[,<int>] epoch=<int> [seq=<int>]
Creates a TxnMeta.
new-request r=<name> txn=<name>|none ts=<int>[,<int>] spans=r|w@<start>[,<end>]+... [skip-locked] [max-lock-wait-queue-length=<int>]
new-request r=<name> txn=<name>|none ts=<int>[,<int>] spans=none|shared|update|exclusive|intent@<start>[,<end>]+... [skip-locked] [max-lock-wait-queue-length=<int>]
----
Creates a Request.
Expand Down Expand Up @@ -112,7 +112,7 @@ add-discovered r=<name> k=<key> txn=<name> [lease-seq=<seq>] [consult-finalized-
Adds a discovered lock that is discovered by the named request.
check-opt-no-conflicts r=<name> spans=r|w@<start>[,<end>]+...
check-opt-no-conflicts r=<name> spans=none|shared|update|exclusive|intent@<start>[,<end>]+...
----
no-conflicts: <bool>
Expand Down Expand Up @@ -697,35 +697,38 @@ func scanSpans(
lockSpans := &lockspanset.LockSpanSet{}
var spansStr string
d.ScanArgs(t, "spans", &spansStr)
parts := strings.Split(spansStr, "+")
for _, p := range parts {
if len(p) < 2 || p[1] != '@' {
d.Fatalf(t, "incorrect span with access format: %s", p)
lockSpanStrs := strings.Split(spansStr, "+")
for _, lockSpanStr := range lockSpanStrs {
parts := strings.Split(lockSpanStr, "@")
if len(parts) != 2 {
d.Fatalf(t, "incorrect span with strength format: %s", parts)
}
c := p[0]
p = p[2:]
strS := parts[0]
spanStr := parts[1]
str := getStrength(t, d, strS)
// Compute latch span access based on the supplied strength.
var sa spanset.SpanAccess
var str lock.Strength
// TODO(arul): Switch the datadriven input to use lock strengths instead.
switch c {
case 'r':
switch str {
case lock.None:
sa = spanset.SpanReadOnly
str = lock.None
case 'w':
case lock.Intent:
sa = spanset.SpanReadWrite
str = lock.Intent
default:
d.Fatalf(t, "incorrect span access: %c", c)
d.Fatalf(t, "unsupported lock strength: %s", str)
}
latchSpans.AddMVCC(sa, getSpan(t, d, p), ts)
lockSpans.Add(str, getSpan(t, d, p))
latchSpans.AddMVCC(sa, getSpan(t, d, spanStr), ts)
lockSpans.Add(str, getSpan(t, d, spanStr))
}
return latchSpans, lockSpans
}

func ScanLockStrength(t *testing.T, d *datadriven.TestData) lock.Strength {
var strS string
d.ScanArgs(t, "strength", &strS)
return getStrength(t, d, strS)
}

func getStrength(t *testing.T, d *datadriven.TestData, strS string) lock.Strength {
switch strS {
case "none":
return lock.None
Expand All @@ -735,6 +738,8 @@ func ScanLockStrength(t *testing.T, d *datadriven.TestData) lock.Strength {
return lock.Update
case "exclusive":
return lock.Exclusive
case "intent":
return lock.Intent
default:
d.Fatalf(t, "unknown lock strength: %s", strS)
return 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ new-lock-table maxlocks=10000
new-txn txn=txn1 ts=10,1 epoch=0 seq=1
----

new-request r=req1 txn=txn1 ts=10,1 spans=w@a
new-request r=req1 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req1
Expand All @@ -36,7 +36,7 @@ num=1
new-txn txn=txn1 ts=10,1 epoch=0 seq=2
----

new-request r=req2 txn=txn1 ts=10,1 spans=w@a
new-request r=req2 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req2
Expand All @@ -58,7 +58,7 @@ num=1
new-txn txn=txn1 ts=10,1 epoch=0 seq=4
----

new-request r=req3 txn=txn1 ts=10,1 spans=w@a
new-request r=req3 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req3
Expand All @@ -84,7 +84,7 @@ num=1
new-txn txn=txn1 ts=10,1 epoch=0 seq=4
----

new-request r=req3 txn=txn1 ts=10,1 spans=w@a
new-request r=req3 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req3
Expand All @@ -110,7 +110,7 @@ num=1
new-txn txn=txn1 ts=10,1 epoch=0 seq=2
----

new-request r=req4 txn=txn1 ts=10,1 spans=w@a
new-request r=req4 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req4
Expand Down Expand Up @@ -138,7 +138,7 @@ num=1
new-txn txn=txn1 ts=10,1 epoch=0 seq=3
----

new-request r=req5 txn=txn1 ts=10,1 spans=w@a
new-request r=req5 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req5
Expand All @@ -164,7 +164,7 @@ num=1
new-txn txn=txn1 ts=10,1 epoch=0 seq=5
----

new-request r=req6 txn=txn1 ts=10,1 spans=w@a
new-request r=req6 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ new-txn txn=txn2 ts=10 epoch=0
new-txn txn=txn3 ts=10 epoch=0
----

new-request r=req1 txn=txn1 ts=10,1 spans=w@a
new-request r=req1 txn=txn1 ts=10,1 spans=intent@a
----

scan r=req1
Expand All @@ -50,10 +50,10 @@ num=1
lock: "a"
holder: txn: 00000000-0000-0000-0000-000000000001, ts: 10.000000000,1, info: unrepl epoch: 0, seqs: [0]

new-request r=req2 txn=txn2 ts=10,1 spans=w@a
new-request r=req2 txn=txn2 ts=10,1 spans=intent@a
----

new-request r=req3 txn=txn3 ts=10,1 spans=w@a
new-request r=req3 txn=txn3 ts=10,1 spans=intent@a
----

scan r=req2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ new-txn txn=txn1 ts=10 epoch=0
new-txn txn=txn2 ts=10 epoch=0
----

new-request r=req1 txn=txn1 ts=10 spans=w@a+r@b+w@c
new-request r=req1 txn=txn1 ts=10 spans=intent@a+none@b+intent@c
----

clear disable
Expand Down
46 changes: 23 additions & 23 deletions pkg/kv/kvserver/concurrency/testdata/lock_table/basic
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new-txn txn=txn1 ts=10,1 epoch=0

# req1 will acquire locks for txn1

new-request r=req1 txn=txn1 ts=10,1 spans=r@a,b+w@c,f
new-request r=req1 txn=txn1 ts=10,1 spans=none@a,b+intent@c,f
----

scan r=req1
Expand Down Expand Up @@ -51,7 +51,7 @@ time-tick ms=200

# req2 is also for txn1 and will not wait for locks that are held by self.

new-request r=req2 txn=txn1 ts=10,2 spans=w@b,d+r@d,g
new-request r=req2 txn=txn1 ts=10,2 spans=intent@b,d+none@d,g
----

scan r=req2
Expand Down Expand Up @@ -89,7 +89,7 @@ new-txn txn=txn2 ts=8,12 epoch=0
----

# A read request for txn2 does not need to wait for locks held by txn1.
new-request r=req3 txn=txn2 ts=8,12 spans=r@a,g
new-request r=req3 txn=txn2 ts=8,12 spans=none@a,g
----

scan r=req3
Expand All @@ -114,7 +114,7 @@ time-tick ms=200
# req4 from txn2 will conflict with locks on b, c since wants to write to [a, d). But does
# not conflict with lock on e since wants to read there and the read is at a lower timestamp
# than the lock.
new-request r=req4 txn=txn2 ts=8,12 spans=w@a,d+r@d,g
new-request r=req4 txn=txn2 ts=8,12 spans=intent@a,d+none@d,g
----

scan r=req4
Expand Down Expand Up @@ -368,7 +368,7 @@ time-tick ms=300
# req5 is again from transaction 1. Since it is reading from b, c, and even though txn1
# conflicts with the reservation holder since txn1.ts > txn2.ts, reads don't wait for
# reservations.
new-request r=req5 txn=txn1 ts=11,1 spans=r@b+r@c
new-request r=req5 txn=txn1 ts=11,1 spans=none@b+none@c
----

scan r=req5
Expand Down Expand Up @@ -399,7 +399,7 @@ time-tick ms=100

# req6 from txn1 conflicts with lock at f, and reservations at b, c.

new-request r=req6 txn=txn1 ts=11,1 spans=r@f+w@b,d
new-request r=req6 txn=txn1 ts=11,1 spans=none@f+intent@b,d
----

scan r=req6
Expand Down Expand Up @@ -546,7 +546,7 @@ time-tick ms=250

# req7 from txn3 only wants to write to c

new-request r=req7 txn=txn3 ts=6 spans=w@c
new-request r=req7 txn=txn3 ts=6 spans=intent@c
----

scan r=req7
Expand Down Expand Up @@ -1413,7 +1413,7 @@ time-tick s=15
----


new-request r=req8 txn=txn3 ts=6 spans=w@e
new-request r=req8 txn=txn3 ts=6 spans=intent@e
----

scan r=req8
Expand Down Expand Up @@ -1533,7 +1533,7 @@ topklocksbywaitduration:
# All requests have been retired and the lock table is empty.
# The following tests multiple requests from the same transaction.

new-request r=req9 txn=txn1 ts=10,1 spans=w@c
new-request r=req9 txn=txn1 ts=10,1 spans=intent@c
----

scan r=req9
Expand Down Expand Up @@ -1646,7 +1646,7 @@ topklocksbywaitduration:
waitdurationnanos: 0
maxwaitdurationnanos: 0

new-request r=req10 txn=txn2 ts=8,12 spans=w@c
new-request r=req10 txn=txn2 ts=8,12 spans=intent@c
----

scan r=req10
Expand All @@ -1657,7 +1657,7 @@ guard-state r=req10
----
new: state=waitForDistinguished txn=txn1 key="c" held=true guard-strength=Intent

new-request r=req11 txn=txn3 ts=6 spans=w@c
new-request r=req11 txn=txn3 ts=6 spans=intent@c
----

scan r=req11
Expand All @@ -1668,7 +1668,7 @@ guard-state r=req11
----
new: state=waitFor txn=txn1 key="c" held=true guard-strength=Intent

new-request r=req12 txn=txn2 ts=8,12 spans=w@c
new-request r=req12 txn=txn2 ts=8,12 spans=intent@c
----

scan r=req12
Expand Down Expand Up @@ -2163,7 +2163,7 @@ num=0
# Tests with non-transactional requests that triggered nil pointer
# dereference bugs.

new-request r=req13 txn=txn2 ts=8,12 spans=w@c
new-request r=req13 txn=txn2 ts=8,12 spans=intent@c
----

scan r=req13
Expand All @@ -2176,14 +2176,14 @@ num=1
lock: "c"
holder: txn: 00000000-0000-0000-0000-000000000002, ts: 8.000000000,12, info: unrepl epoch: 0, seqs: [0]

new-request r=req14 txn=txn1 ts=9,0 spans=w@c
new-request r=req14 txn=txn1 ts=9,0 spans=intent@c
----

scan r=req14
----
start-waiting: true

new-request r=req15 txn=none ts=10,12 spans=r@c
new-request r=req15 txn=none ts=10,12 spans=none@c
----

scan r=req15
Expand All @@ -2202,7 +2202,7 @@ num=1
lock: "c"
res: req: 14, txn: 00000000-0000-0000-0000-000000000001, ts: 9.000000000,0, seq: 0

new-request r=req16 txn=none ts=10,12 spans=r@c
new-request r=req16 txn=none ts=10,12 spans=none@c
----

scan r=req16
Expand Down Expand Up @@ -2312,7 +2312,7 @@ topklocksbywaitduration:
# transaction that eventually grabs a reservation. Triggered a bug
# in not replacing the distinguished waiter.

new-request r=req17 txn=txn1 ts=9,0 spans=w@c+w@d
new-request r=req17 txn=txn1 ts=9,0 spans=intent@c+intent@d
----

scan r=req17
Expand Down Expand Up @@ -2341,14 +2341,14 @@ num=2
lock: "d"
holder: txn: 00000000-0000-0000-0000-000000000001, ts: 9.000000000,0, info: unrepl epoch: 1, seqs: [0]

new-request r=req18 txn=txn2 ts=10,0 spans=w@c+w@d
new-request r=req18 txn=txn2 ts=10,0 spans=intent@c+intent@d
----

scan r=req18
----
start-waiting: true

new-request r=req19 txn=txn2 ts=10,0 spans=w@d
new-request r=req19 txn=txn2 ts=10,0 spans=intent@d
----

scan r=req19
Expand Down Expand Up @@ -2628,7 +2628,7 @@ num=0
# Reservation can be broken while holding latches because a different
# lock is released

new-request r=req20 txn=txn1 ts=10 spans=w@c
new-request r=req20 txn=txn1 ts=10 spans=intent@c
----

scan r=req20
Expand All @@ -2647,7 +2647,7 @@ num=1
lock: "c"
holder: txn: 00000000-0000-0000-0000-000000000001, ts: 10.000000000,0, info: unrepl epoch: 1, seqs: [0]

new-request r=req21 txn=txn1 ts=10 spans=w@d
new-request r=req21 txn=txn1 ts=10 spans=intent@d
----

scan r=req21
Expand All @@ -2670,7 +2670,7 @@ num=2
lock: "d"
holder: txn: 00000000-0000-0000-0000-000000000001, ts: 10.000000000,0, info: unrepl epoch: 1, seqs: [0]

new-request r=req22 txn=txn2 ts=10 spans=w@c+w@d
new-request r=req22 txn=txn2 ts=10 spans=intent@c+intent@d
----

scan r=req22
Expand Down Expand Up @@ -2779,7 +2779,7 @@ topklocksbywaitduration:
waitdurationnanos: 0
maxwaitdurationnanos: 0

new-request r=req23 txn=txn3 ts=10 spans=w@d
new-request r=req23 txn=txn3 ts=10 spans=intent@d
----

scan r=req23
Expand Down
Loading

0 comments on commit 342f39b

Please sign in to comment.