Skip to content

Commit

Permalink
concurrency: correctly print guard-state in lock table tests
Browse files Browse the repository at this point in the history
Followup from cockroachdb#102647. In that patch, we decided to translate the
strength field on a lock table guard back to a `SpanAccess` to
defer some test churn. This patch addresses that TODO; it's entirely
mechanical.

Informs: cockroachdb#102008

Release note: None
  • Loading branch information
arulajmani committed May 4, 2023
1 parent 5c97460 commit 54d50fe
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 91 deletions.
17 changes: 2 additions & 15 deletions pkg/kv/kvserver/concurrency/lock_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,21 +578,8 @@ func TestLockTableBasic(t *testing.T) {
if txnS == "" {
txnS = fmt.Sprintf("unknown txn with ID: %v", state.txn.ID)
}
// TODO(arul): We're translating the lock strength back to guardAccess
// for now to reduce test churn. A followup patch should teach these
// datadriven tests to use lock.Strength correctly -- both in its input
// and output.
var sa spanset.SpanAccess
switch state.guardStrength {
case lock.None:
sa = spanset.SpanReadOnly
case lock.Intent:
sa = spanset.SpanReadWrite
default:
t.Fatalf("unexpected guard strength %s", state.guardStrength)
}
return fmt.Sprintf("%sstate=%s txn=%s key=%s held=%t guard-access=%s",
str, typeStr, txnS, state.key, state.held, sa)
return fmt.Sprintf("%sstate=%s txn=%s key=%s held=%t guard-strength=%s",
str, typeStr, txnS, state.key, state.held, state.guardStrength)

case "resolve-before-scanning":
var reqName string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ new: state=doneWaiting

guard-state r=req3
----
new: state=waitForDistinguished txn=txn2 key="a" held=false guard-access=write
new: state=waitForDistinguished txn=txn2 key="a" held=false guard-strength=Intent

# --------------------------------
# Setup complete, test starts here
Expand All @@ -99,7 +99,7 @@ start-waiting: true

guard-state r=req2
----
new: state=waitForDistinguished txn=txn3 key="a" held=true guard-access=write
new: state=waitForDistinguished txn=txn3 key="a" held=true guard-strength=Intent

guard-state r=req3
----
Expand Down
38 changes: 19 additions & 19 deletions pkg/kv/kvserver/concurrency/testdata/lock_table/basic
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ start-waiting: true

guard-state r=req4
----
new: state=waitForDistinguished txn=txn1 key="b" held=true guard-access=write
new: state=waitForDistinguished txn=txn1 key="b" held=true guard-strength=Intent

# 3s passes while req4 is waiting on locks on b,c
time-tick s=3
Expand All @@ -145,7 +145,7 @@ num=3

guard-state r=req4
----
new: state=waitForDistinguished txn=txn1 key="c" held=true guard-access=write
new: state=waitForDistinguished txn=txn1 key="c" held=true guard-strength=Intent

# 1s passes while req4 continues to wait on c (and only has reservation on b)
time-tick s=1
Expand Down Expand Up @@ -241,7 +241,7 @@ time-tick s=2

guard-state r=req4
----
new: state=waitForDistinguished txn=txn3 key="a" held=true guard-access=write
new: state=waitForDistinguished txn=txn3 key="a" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -537,7 +537,7 @@ topklocksbywaitduration:

guard-state r=req6
----
new: state=waitForDistinguished txn=txn2 key="b" held=false guard-access=write
new: state=waitForDistinguished txn=txn2 key="b" held=false guard-strength=Intent

# 250ms passes between req6 and req7
time-tick ms=250
Expand Down Expand Up @@ -571,7 +571,7 @@ start-waiting: true

guard-state r=req7
----
new: state=waitForDistinguished txn=txn2 key="c" held=false guard-access=write
new: state=waitForDistinguished txn=txn2 key="c" held=false guard-strength=Intent

print
----
Expand Down Expand Up @@ -737,11 +737,11 @@ num=5

guard-state r=req4
----
new: state=waitForDistinguished txn=txn3 key="f" held=true guard-access=read
new: state=waitForDistinguished txn=txn3 key="f" held=true guard-strength=None

guard-state r=req6
----
old: state=waitForDistinguished txn=txn2 key="b" held=false guard-access=write
old: state=waitForDistinguished txn=txn2 key="b" held=false guard-strength=Intent

print
----
Expand Down Expand Up @@ -948,11 +948,11 @@ num=4

guard-state r=req6
----
new: state=waitForDistinguished txn=txn2 key="b" held=true guard-access=write
new: state=waitForDistinguished txn=txn2 key="b" held=true guard-strength=Intent

guard-state r=req7
----
new: state=waitForDistinguished txn=txn2 key="c" held=true guard-access=write
new: state=waitForDistinguished txn=txn2 key="c" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -1121,7 +1121,7 @@ new: state=doneWaiting

guard-state r=req6
----
old: state=waitForDistinguished txn=txn2 key="b" held=true guard-access=write
old: state=waitForDistinguished txn=txn2 key="b" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -1377,7 +1377,7 @@ start-waiting: true

guard-state r=req7
----
new: state=waitForDistinguished txn=txn1 key="c" held=false guard-access=write
new: state=waitForDistinguished txn=txn1 key="c" held=false guard-strength=Intent

scan r=req6
----
Expand Down Expand Up @@ -1422,7 +1422,7 @@ start-waiting: true

guard-state r=req8
----
new: state=waitForDistinguished txn=txn1 key="e" held=true guard-access=write
new: state=waitForDistinguished txn=txn1 key="e" held=true guard-strength=Intent

dequeue r=req8
----
Expand Down Expand Up @@ -1655,7 +1655,7 @@ start-waiting: true

guard-state r=req10
----
new: state=waitForDistinguished txn=txn1 key="c" held=true guard-access=write
new: state=waitForDistinguished txn=txn1 key="c" held=true guard-strength=Intent

new-request r=req11 txn=txn3 ts=6 spans=w@c
----
Expand All @@ -1666,7 +1666,7 @@ start-waiting: true

guard-state r=req11
----
new: state=waitFor txn=txn1 key="c" held=true guard-access=write
new: state=waitFor txn=txn1 key="c" held=true guard-strength=Intent

new-request r=req12 txn=txn2 ts=8,12 spans=w@c
----
Expand All @@ -1677,7 +1677,7 @@ start-waiting: true

guard-state r=req12
----
new: state=waitFor txn=txn1 key="c" held=true guard-access=write
new: state=waitFor txn=txn1 key="c" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -1796,7 +1796,7 @@ new: state=doneWaiting

guard-state r=req11
----
new: state=waitForDistinguished txn=txn2 key="c" held=false guard-access=write
new: state=waitForDistinguished txn=txn2 key="c" held=false guard-strength=Intent

guard-state r=req12
----
Expand Down Expand Up @@ -1916,7 +1916,7 @@ num=1

guard-state r=req11
----
new: state=waitForDistinguished txn=txn2 key="c" held=true guard-access=write
new: state=waitForDistinguished txn=txn2 key="c" held=true guard-strength=Intent

# Since req10 that is also txn2 has acquired the lock, req12 does not need to wait here anymore.
guard-state r=req12
Expand Down Expand Up @@ -2051,7 +2051,7 @@ num=1

guard-state r=req11
----
old: state=waitForDistinguished txn=txn2 key="c" held=true guard-access=write
old: state=waitForDistinguished txn=txn2 key="c" held=true guard-strength=Intent

release txn=txn2 span=b,d
----
Expand Down Expand Up @@ -2475,7 +2475,7 @@ num=2

guard-state r=req18
----
new: state=waitFor txn=txn1 key="d" held=true guard-access=write
new: state=waitFor txn=txn1 key="d" held=true guard-strength=Intent

print
----
Expand Down
6 changes: 3 additions & 3 deletions pkg/kv/kvserver/concurrency/testdata/lock_table/clear
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ start-waiting: true

guard-state r=req3
----
new: state=waitForDistinguished txn=txn1 key="a" held=true guard-access=read
new: state=waitForDistinguished txn=txn1 key="a" held=true guard-strength=None

# Similarly, a non-transactional write at a arrives and blocks.

Expand All @@ -94,7 +94,7 @@ start-waiting: true

guard-state r=req4
----
new: state=waitFor txn=txn1 key="a" held=true guard-access=write
new: state=waitFor txn=txn1 key="a" held=true guard-strength=Intent

# txn3 tries to write to b which also has a lock held, so txn3 has to wait.

Expand All @@ -107,7 +107,7 @@ start-waiting: true

guard-state r=req5
----
new: state=waitForDistinguished txn=txn1 key="b" held=true guard-access=write
new: state=waitForDistinguished txn=txn1 key="b" held=true guard-strength=Intent

print
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ start-waiting: true

guard-state r=req1
----
new: state=waitForDistinguished txn=txn4 key="c" held=true guard-access=write
new: state=waitForDistinguished txn=txn4 key="c" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -417,11 +417,11 @@ start-waiting: true

guard-state r=req6
----
new: state=waitFor txn=txn2 key="a" held=true guard-access=write
new: state=waitFor txn=txn2 key="a" held=true guard-strength=Intent

guard-state r=req5
----
new: state=waitForDistinguished txn=txn2 key="a" held=true guard-access=write
new: state=waitForDistinguished txn=txn2 key="a" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -452,7 +452,7 @@ num=2

guard-state r=req6
----
new: state=waitForDistinguished txn=txn1 key="a" held=false guard-access=write
new: state=waitForDistinguished txn=txn1 key="a" held=false guard-strength=Intent

guard-state r=req5
----
Expand Down Expand Up @@ -527,7 +527,7 @@ start-waiting: true

guard-state r=req7
----
new: state=waitForDistinguished txn=txn2 key="a" held=true guard-access=write
new: state=waitForDistinguished txn=txn2 key="a" held=true guard-strength=Intent

print
----
Expand Down Expand Up @@ -641,7 +641,7 @@ start-waiting: true

guard-state r=req9
----
new: state=waitForDistinguished txn=txn4 key="c" held=true guard-access=read
new: state=waitForDistinguished txn=txn4 key="c" held=true guard-strength=None

print
----
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/concurrency/testdata/lock_table/disable
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ start-waiting: true

guard-state r=req2
----
new: state=waitForDistinguished txn=txn2 key="a" held=true guard-access=write
new: state=waitForDistinguished txn=txn2 key="a" held=true guard-strength=Intent

release txn=txn2 span=a
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ start-waiting: true

guard-state r=req1
----
new: state=waitForDistinguished txn=txn4 key="d" held=true guard-access=write
new: state=waitForDistinguished txn=txn4 key="d" held=true guard-strength=Intent

dequeue r=req1
----
Expand Down
Loading

0 comments on commit 54d50fe

Please sign in to comment.