# Waiting states when waiting for reservation or lock holder from same txn.

new-lock-table maxlocks=10000
----

# ---------------------------------------------------------------------------------
# req4 is waiting on locked "a", and req2 from the same txn acquires the
# reservation. req4 transitions to waitForSelf state
# ---------------------------------------------------------------------------------

new-txn txn=txn1 ts=10 epoch=0
----

new-txn txn=txn2 ts=10 epoch=0
----

new-txn txn=txn3 ts=10 epoch=0
----

new-request r=req1 txn=txn1 ts=10 spans=exclusive@a
----

new-request r=req2 txn=txn2 ts=10 spans=exclusive@a
----

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

new-request r=req4 txn=txn2 ts=10 spans=exclusive@a
----

scan r=req1
----
start-waiting: false

acquire r=req1 k=a durability=u strength=exclusive
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000001 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: unrepl [(str: Exclusive seq: 0)]

dequeue r=req1
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000001 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: unrepl [(str: Exclusive seq: 0)]

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

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

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

guard-state r=req2
----
new: state=waitFor txn=txn1 key="a" held=true guard-strength=Exclusive

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

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

print
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000001 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: unrepl [(str: Exclusive seq: 0)]
   queued locking requests:
    active: true req: 2, strength: Exclusive, txn: 00000000-0000-0000-0000-000000000002
    active: true req: 3, strength: Intent, txn: 00000000-0000-0000-0000-000000000003
    active: true req: 4, strength: Exclusive, txn: 00000000-0000-0000-0000-000000000002

release txn=txn1 span=a
----
num=1
 lock: "a"
   queued locking requests:
    active: false req: 2, strength: Exclusive, txn: 00000000-0000-0000-0000-000000000002
    active: true req: 3, strength: Intent, txn: 00000000-0000-0000-0000-000000000003
    active: true req: 4, strength: Exclusive, txn: 00000000-0000-0000-0000-000000000002

guard-state r=req2
----
new: state=doneWaiting

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

guard-state r=req4
----
new: state=waitSelf

print
----
num=1
 lock: "a"
   queued locking requests:
    active: false req: 2, strength: Exclusive, txn: 00000000-0000-0000-0000-000000000002
    active: true req: 3, strength: Intent, txn: 00000000-0000-0000-0000-000000000003
    active: true req: 4, strength: Exclusive, txn: 00000000-0000-0000-0000-000000000002

# Stays in waitSelf state if scans again.
scan r=req4
----
start-waiting: true

guard-state r=req4
----
new: state=waitSelf

# ---------------------------------------------------------------------------------
# req4 is waiting on claimed "a", and req2 from the same txn acquires the
# lock. req4 stops waiting.
# ---------------------------------------------------------------------------------

acquire r=req2 k=a durability=u strength=exclusive
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000002 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: unrepl [(str: Exclusive seq: 0)]
   queued locking requests:
    active: true req: 3, strength: Intent, txn: 00000000-0000-0000-0000-000000000003

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

guard-state r=req4
----
new: state=doneWaiting

scan r=req4
----
start-waiting: false
