github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/concurrency/testdata/lock_table/add_discovered (about)

     1  # -------------------------------------------------------------
     2  # In this test we create a lock wait-queue for a key. We then
     3  # have the head of the queue discover an existing lock on the
     4  # key. The lock is part of the same transaction as one of the
     5  # queued writes. The writer should stop waiting on the lock.
     6  #
     7  # NOTE: this test is somewhat synthetic and it's not clear that
     8  # there's currently a way to trigger this behavior if all lock
     9  # acquisitions are observed sequentially when starting from an
    10  # empty lock-table, given the current policy on how wait-queues
    11  # form in the lock-table. Still, this is worth handling correctly
    12  # in case this ever changes.
    13  #
    14  # Setup: txn1 acquires lock
    15  #        txn2 and txn3 enter wait-queue
    16  #        txn1 releases lock, txn2 becomes reservation holder
    17  #
    18  # Test:  discover lock from txn3
    19  #        txn3 should exit wait-queue
    20  # -------------------------------------------------------------
    21  
    22  new-lock-table maxlocks=10000
    23  ----
    24  
    25  new-txn txn=txn1 ts=10 epoch=0
    26  ----
    27  
    28  new-txn txn=txn2 ts=10 epoch=0
    29  ----
    30  
    31  new-txn txn=txn3 ts=10 epoch=0
    32  ----
    33  
    34  new-request r=req1 txn=txn1 ts=10,1 spans=w@a
    35  ----
    36  
    37  scan r=req1
    38  ----
    39  start-waiting: false
    40  
    41  acquire r=req1 k=a durability=u
    42  ----
    43  global: num=1
    44   lock: "a"
    45    holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0]
    46  local: num=0
    47  
    48  dequeue r=req1
    49  ----
    50  global: num=1
    51   lock: "a"
    52    holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0]
    53  local: num=0
    54  
    55  new-request r=req2 txn=txn2 ts=10,1 spans=w@a
    56  ----
    57  
    58  new-request r=req3 txn=txn3 ts=10,1 spans=w@a
    59  ----
    60  
    61  scan r=req2
    62  ----
    63  start-waiting: true
    64  
    65  scan r=req3
    66  ----
    67  start-waiting: true
    68  
    69  release txn=txn1 span=a
    70  ----
    71  global: num=1
    72   lock: "a"
    73    res: req: 2, txn: 00000000-0000-0000-0000-000000000002, ts: 0.000000010,1, seq: 0
    74     queued writers:
    75      active: true req: 3, txn: 00000000-0000-0000-0000-000000000003
    76     distinguished req: 3
    77  local: num=0
    78  
    79  guard-state r=req2
    80  ----
    81  new: state=doneWaiting
    82  
    83  guard-state r=req3
    84  ----
    85  new: state=waitForDistinguished txn=txn2 key="a" held=false guard-access=write
    86  
    87  # --------------------------------
    88  # Setup complete, test starts here
    89  # --------------------------------
    90  
    91  add-discovered r=req2 k=a txn=txn3
    92  ----
    93  global: num=1
    94   lock: "a"
    95    holder: txn: 00000000-0000-0000-0000-000000000003, ts: 0.000000010,1, info: repl epoch: 0, seqs: [0]
    96     queued writers:
    97      active: false req: 2, txn: 00000000-0000-0000-0000-000000000002
    98  local: num=0
    99  
   100  scan r=req2
   101  ----
   102  start-waiting: true
   103  
   104  guard-state r=req2
   105  ----
   106  new: state=waitForDistinguished txn=txn3 key="a" held=true guard-access=write
   107  
   108  guard-state r=req3
   109  ----
   110  new: state=doneWaiting
   111  
   112  dequeue r=req3
   113  ----
   114  global: num=1
   115   lock: "a"
   116    holder: txn: 00000000-0000-0000-0000-000000000003, ts: 0.000000010,1, info: repl epoch: 0, seqs: [0]
   117     queued writers:
   118      active: true req: 2, txn: 00000000-0000-0000-0000-000000000002
   119     distinguished req: 2
   120  local: num=0
   121  
   122  release txn=txn3 span=a
   123  ----
   124  global: num=1
   125   lock: "a"
   126    res: req: 2, txn: 00000000-0000-0000-0000-000000000002, ts: 0.000000010,1, seq: 0
   127  local: num=0
   128  
   129  guard-state r=req2
   130  ----
   131  new: state=doneWaiting
   132  
   133  dequeue r=req2
   134  ----
   135  global: num=0
   136  local: num=0