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

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-txn txn=txn4 ts=10 epoch=0
----

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

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

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

# req1 is a writer that must wait for discovered intents to be finalized.

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

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

pushed-txn-updated txn=txn2 status=aborted
----

# Don't consult txnStatusCache.
add-discovered r=req1 k=a txn=txn2 consult-txn-status-cache=false
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000002 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: repl [Intent] [holder finalized: aborted]
   queued locking requests:
    active: false req: 1, strength: Intent, txn: 00000000-0000-0000-0000-000000000001

# Nothing to resolve yet.
resolve-before-scanning r=req1
----

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

# The scan picks up the intent to resolve.
guard-state r=req1
----
new: state=doneWaiting
Intents to resolve:
 key="a" txn=00000000 status=ABORTED

print
----
num=1
 lock: "a"
   queued locking requests:
    active: false req: 1, strength: Intent, txn: 00000000-0000-0000-0000-000000000001

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

pushed-txn-updated txn=txn3 status=aborted
----

# Txn is finalized and txnStatusCache is consulted.
add-discovered r=req1 k=b txn=txn3 consult-txn-status-cache=true
----
num=1
 lock: "a"
   queued locking requests:
    active: false req: 1, strength: Intent, txn: 00000000-0000-0000-0000-000000000001

# Txn is finalized and txnStatusCache is consulted.
add-discovered r=req1 k=c txn=txn3 consult-txn-status-cache=true
----
num=1
 lock: "a"
   queued locking requests:
    active: false req: 1, strength: Intent, txn: 00000000-0000-0000-0000-000000000001

# Txn is not finalized and txnStatusCache is consulted.
add-discovered r=req1 k=d txn=txn4 consult-txn-status-cache=true
----
num=2
 lock: "a"
   queued locking requests:
    active: false req: 1, strength: Intent, txn: 00000000-0000-0000-0000-000000000001
 lock: "d"
  holder: txn: 00000000-0000-0000-0000-000000000004 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: repl [Intent]
   queued locking requests:
    active: false req: 1, strength: Intent, txn: 00000000-0000-0000-0000-000000000001

# Locks for b and c were not added to lock table.
resolve-before-scanning r=req1
----
Intents to resolve:
 key="b" txn=00000000 status=ABORTED
 key="c" txn=00000000 status=ABORTED

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

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

dequeue r=req1
----
num=1
 lock: "d"
  holder: txn: 00000000-0000-0000-0000-000000000004 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: repl [Intent]

clear
----
num=0

# req2 is a reader that must wait for discovered intents to be finalized or
# pushed.

new-request r=req2 txn=txn1 ts=10 spans=none@e,i
----

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

pushed-txn-updated txn=txn5 status=pending ts=11,0
----

# Don't consult txnStatusCache.
add-discovered r=req2 k=e txn=txn5 consult-txn-status-cache=false
----
num=1
 lock: "e"
  holder: txn: 00000000-0000-0000-0000-000000000005 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: repl [Intent]

# Nothing to resolve yet.
resolve-before-scanning r=req2
----

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

# The scan picks up the intent to resolve.
guard-state r=req2
----
new: state=doneWaiting
Intents to resolve:
 key="e" txn=00000000 status=PENDING

update txn=txn5 ts=11,1 epoch=0 span=e
----
num=0

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

pushed-txn-updated txn=txn6 status=aborted
----

# Txn is pushed and txnStatusCache is consulted.
add-discovered r=req2 k=f txn=txn5 consult-txn-status-cache=true
----
num=0

# Txn is finalized and txnStatusCache is consulted.
add-discovered r=req2 k=g txn=txn6 consult-txn-status-cache=true
----
num=0

# Txn is not pushed or finalized and txnStatusCache is consulted.
add-discovered r=req2 k=g txn=txn7 consult-txn-status-cache=true
----
num=1
 lock: "g"
  holder: txn: 00000000-0000-0000-0000-000000000007 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: repl [Intent]

# Locks for f and g were not added to lock table.
resolve-before-scanning r=req2
----
Intents to resolve:
 key="f" txn=00000000 status=PENDING
 key="g" txn=00000000 status=ABORTED

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

guard-state r=req2
----
new: state=waitFor txn=txn7 key="g" held=true guard-strength=None

dequeue r=req2
----
num=1
 lock: "g"
  holder: txn: 00000000-0000-0000-0000-000000000007 epoch: 0, iso: Serializable, ts: 10.000000000,0, info: repl [Intent]

clear
----
num=0
