github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/concurrency/testdata/lock_table/clear (about) 1 new-lock-table maxlocks=10000 2 ---- 3 4 # Define three transaction that we'll use below. 5 6 new-txn txn=txn1 ts=10,1 epoch=0 7 ---- 8 9 new-txn txn=txn2 ts=8,1 epoch=0 10 ---- 11 12 new-txn txn=txn3 ts=12,1 epoch=0 13 ---- 14 15 # txn1 acquires unreplicated exclusive locks at a and b. 16 17 new-request r=req1 txn=txn1 ts=10,1 spans=w@a+w@b 18 ---- 19 20 scan r=req1 21 ---- 22 start-waiting: false 23 24 guard-state r=req1 25 ---- 26 new: state=doneWaiting 27 28 acquire r=req1 k=a durability=u 29 ---- 30 global: num=1 31 lock: "a" 32 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 33 local: num=0 34 35 acquire r=req1 k=b durability=u 36 ---- 37 global: num=2 38 lock: "a" 39 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 40 lock: "b" 41 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 42 local: num=0 43 44 dequeue r=req1 45 ---- 46 global: num=2 47 lock: "a" 48 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 49 lock: "b" 50 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 51 local: num=0 52 53 # In its next request, txn1 discovers a lock at c held by txn2. 54 55 new-request r=req2 txn=txn1 ts=10,1 spans=r@c 56 ---- 57 58 scan r=req2 59 ---- 60 start-waiting: false 61 62 guard-state r=req2 63 ---- 64 new: state=doneWaiting 65 66 add-discovered r=req2 k=c txn=txn2 67 ---- 68 global: num=3 69 lock: "a" 70 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 71 lock: "b" 72 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 73 lock: "c" 74 holder: txn: 00000000-0000-0000-0000-000000000002, ts: 0.000000008,1, info: repl epoch: 0, seqs: [0] 75 local: num=0 76 77 # A non-transactional read comes in at a and blocks on the lock. 78 79 new-request r=req3 txn=none ts=10,1 spans=r@a 80 ---- 81 82 scan r=req3 83 ---- 84 start-waiting: true 85 86 guard-state r=req3 87 ---- 88 new: state=waitForDistinguished txn=txn1 key="a" held=true guard-access=read 89 90 # Similarly, a non-transactional write at a arrives and blocks. 91 92 new-request r=req4 txn=none ts=10,1 spans=w@a 93 ---- 94 95 scan r=req4 96 ---- 97 start-waiting: true 98 99 guard-state r=req4 100 ---- 101 new: state=waitFor txn=txn1 key="a" held=true guard-access=write 102 103 # txn3 tries to write to b which also has a lock held, so txn3 has to wait. 104 105 new-request r=req5 txn=txn3 ts=12,1 spans=w@b 106 ---- 107 108 scan r=req5 109 ---- 110 start-waiting: true 111 112 guard-state r=req5 113 ---- 114 new: state=waitForDistinguished txn=txn1 key="b" held=true guard-access=write 115 116 print 117 ---- 118 global: num=3 119 lock: "a" 120 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 121 waiting readers: 122 req: 3, txn: none 123 queued writers: 124 active: true req: 4, txn: none 125 distinguished req: 3 126 lock: "b" 127 holder: txn: 00000000-0000-0000-0000-000000000001, ts: 0.000000010,1, info: unrepl epoch: 0, seqs: [0] 128 queued writers: 129 active: true req: 5, txn: 00000000-0000-0000-0000-000000000003 130 distinguished req: 5 131 lock: "c" 132 holder: txn: 00000000-0000-0000-0000-000000000002, ts: 0.000000008,1, info: repl epoch: 0, seqs: [0] 133 local: num=0 134 135 # Clearing removes all locks and allows all waiting requests to proceed. 136 137 clear 138 ---- 139 global: num=0 140 local: num=0 141 142 guard-state r=req2 143 ---- 144 old: state=doneWaiting 145 146 scan r=req2 147 ---- 148 start-waiting: false 149 150 guard-state r=req3 151 ---- 152 new: state=doneWaiting 153 154 scan r=req3 155 ---- 156 start-waiting: false 157 158 dequeue r=req3 159 ---- 160 global: num=0 161 local: num=0 162 163 guard-state r=req4 164 ---- 165 new: state=doneWaiting 166 167 scan r=req4 168 ---- 169 start-waiting: false 170 171 dequeue r=req4 172 ---- 173 global: num=0 174 local: num=0 175 176 guard-state r=req5 177 ---- 178 new: state=doneWaiting 179 180 scan r=req5 181 ---- 182 start-waiting: false 183 184 dequeue r=req5 185 ---- 186 global: num=0 187 local: num=0