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

# ------------------------------------------------------------------------------
# Acquire a lock on key a at timestamp 10,1 at multiple sequence numbers.
# ------------------------------------------------------------------------------

new-txn txn=txn1 ts=10,1 epoch=0 seq=1
----

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

new-txn txn=txn1 ts=10,1 epoch=0 seq=2
----

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

new-txn txn=txn1 ts=10,1 epoch=0 seq=3
----

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

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

scan r=req2
----
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,1, info: unrepl [(str: Exclusive seq: 1)]

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

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


# ------------------------------------------------------------------------------
# Re-acquire the (unreplicated) lock at a higher sequence number. Pass in 2 and
# 3 as ignored.
# ------------------------------------------------------------------------------

new-txn txn=txn1 ts=10,1 epoch=0 seq=5
----

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

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

# ------------------------------------------------------------------------------
# Re-acquire the (unreplicated) lock at a higher sequence number. This time,
# pass in a sequence number as ignored at which the lock wasn't acquired.
# ------------------------------------------------------------------------------

new-txn txn=txn1 ts=10,1 epoch=0 seq=8
----

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

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

# ------------------------------------------------------------------------------
# Ensure sequence numbers get pruned when acquiring replicated locks, and the
# the lock acquisition struct says a sequence number at which an unreplicated
# lock is held is considered ignored.
# ------------------------------------------------------------------------------

# First, add a waiting writer on this lock so that it counts as contended.

new-txn txn=txn2 ts=12,1 epoch=0
----

new-request r=req6 txn=txn2 ts=12,1 spans=intent@a
----

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

new-txn txn=txn1 ts=10,1 epoch=0 seq=9
----

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

# Because the lock is being acquired as a replicated lock nothing in the
# unreplicated sequence number tracking gets pruned.

acquire r=req7 k=a durability=r ignored-seqs=8 strength=intent
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000001 epoch: 0, iso: Serializable, ts: 10.000000000,1, info: repl [Intent], unrepl [(str: Exclusive seq: 1)]
   queued locking requests:
    active: true req: 3, strength: Intent, txn: 00000000-0000-0000-0000-000000000002

# However, unreplicated lock acquisition with the same ignored sequence number
# (8) will result in the list of sequence numbers getting pruned.
new-request r=req8 txn=txn1 ts=10,1 spans=exclusive@a
----

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

# ------------------------------------------------------------------------------
# Ensure ignoring a range of sequence numbers works as expected.
# ------------------------------------------------------------------------------

new-txn txn=txn1 ts=10,1 epoch=0 seq=11
----

new-request r=req9 txn=txn1 ts=10,1 spans=exclusive@a
----

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

# ------------------------------------------------------------------------------
# Ensure acquiring a replicated lock at a higher epoch than the one with which
# an unreplicated lock is held with clears out the sequence numbers being
# tracked for the prior epoch. Moreover, the epoch associated with the txn
# meta should also be updated.
# ------------------------------------------------------------------------------

new-txn txn=txn1 ts=11,1 epoch=1 seq=12
----

new-request r=req10 txn=txn1 ts=11,1 spans=intent@a
----

acquire r=req10 k=a durability=r strength=intent
----
num=1
 lock: "a"
  holder: txn: 00000000-0000-0000-0000-000000000001 epoch: 1, iso: Serializable, ts: 11.000000000,1, info: repl [Intent]
   queued locking requests:
    active: true req: 3, strength: Intent, txn: 00000000-0000-0000-0000-000000000002
