github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/testdata/iter_histories/lazy_combined_iteration (about) 1 # Test a lazy-combined iteration edge case. Consider the LSM: 2 # 3 # L5: 000003:[bar.DEL.3, foo.RANGEKEYSET.4] 4 # L6: 000001:[bar.SET.1] 000002:[bax.RANGEKEYSET.2] 5 # 6 # A call to First() seeks the levels to files L5.000003 and L6.000001. 7 # The L5 levelIter observes that L5.000003 contains the range key with 8 # start key `foo`, and triggers a switch to combined iteration, setting 9 # `combinedIterState.key` = `foo`. While switching to combined iteration, the 10 # iterator must recognize that `foo` > `bar`, and there may yet exist range keys 11 # that begin before `foo` (in this case `bax`). 12 13 reset 14 ---- 15 16 batch commit 17 set bar bar 18 ---- 19 committed 1 keys 20 21 flush 22 ---- 23 24 batch commit 25 range-key-set bax zoo @1 foo 26 ---- 27 committed 1 keys 28 29 flush 30 ---- 31 32 batch commit 33 del bar 34 range-key-set foo zoo @2 bar 35 ---- 36 committed 2 keys 37 38 flush 39 ---- 40 41 lsm 42 ---- 43 0.1: 44 000009:[bar#12,DEL-zoo#inf,RANGEKEYSET] 45 0.0: 46 000005:[bar#10,SET-bar#10,SET] 47 000007:[bax#11,RANGEKEYSET-zoo#inf,RANGEKEYSET] 48 49 # Assert that First correctly finds [bax,zoo), despite the discovery of 50 # [foo,zoo) triggering the switch to combined iteration. 51 52 combined-iter 53 first 54 next 55 ---- 56 bax: (., [bax-foo) @1=foo UPDATED) 57 foo: (., [foo-zoo) @2=bar, @1=foo UPDATED) 58 59 # Test seeking into the middle of a range key during lazy-combined iteration. 60 # The iterator should surface Key() = the seek key. 61 62 combined-iter 63 seek-ge bop 64 ---- 65 bop: (., [bax-foo) @1=foo UPDATED) 66 67 combined-iter 68 last 69 ---- 70 foo: (., [foo-zoo) @2=bar, @1=foo UPDATED) 71 72 # Test a lazy combined iterator that must next/prev through fileMetdata when 73 # skipping through a RANGEDEL. 74 # 75 # L5 76 # b-----------------------y RANGEDEL 77 # L6 78 # [a] [[d,e)@1] [[l,m)@1] [z] 79 # 80 # A SeekGE(k) must surface [l,m)@1 and a SeekLT(k) must surface [d,e)@1. 81 82 reset 83 ---- 84 85 batch commit 86 set a a 87 ---- 88 committed 1 keys 89 90 flush 91 ---- 92 93 batch commit 94 set z z 95 ---- 96 committed 1 keys 97 98 flush 99 ---- 100 101 batch commit 102 range-key-set d e @1 foo 103 ---- 104 committed 1 keys 105 106 flush 107 ---- 108 109 batch commit 110 range-key-set l m @1 foo 111 ---- 112 committed 1 keys 113 114 flush 115 ---- 116 117 batch commit 118 del-range b y 119 ---- 120 committed 1 keys 121 122 flush 123 ---- 124 125 lsm 126 ---- 127 0.1: 128 000013:[b#14,RANGEDEL-y#inf,RANGEDEL] 129 0.0: 130 000005:[a#10,SET-a#10,SET] 131 000009:[d#12,RANGEKEYSET-e#inf,RANGEKEYSET] 132 000011:[l#13,RANGEKEYSET-m#inf,RANGEKEYSET] 133 000007:[z#11,SET-z#11,SET] 134 135 combined-iter 136 seek-ge k 137 next 138 ---- 139 l: (., [l-m) @1=foo UPDATED) 140 z: (z, . UPDATED) 141 142 combined-iter 143 seek-lt k 144 prev 145 ---- 146 d: (., [d-e) @1=foo UPDATED) 147 a: (a, . UPDATED) 148 149 150 reset 151 ---- 152 153 batch commit 154 set a a 155 set b b 156 set c c 157 set e e 158 range-key-del a f 159 range-key-unset a f @5 160 ---- 161 committed 6 keys 162 163 flush 164 ---- 165 166 wait-table-stats 167 ---- 168 169 # The lazy iterator shouldn't switch to combined iteration when it encounters a 170 # file that is known to only contain RANGEKEYDELs and RANGEKEYUNSETs. 171 172 combined-iter 173 is-using-combined 174 seek-ge a 175 seek-ge b 176 is-using-combined 177 ---- 178 using lazy iterator 179 a: (a, .) 180 b: (b, .) 181 using lazy iterator 182 183 # Write a range key to the memtable. The combined iterator should be forced to 184 # use non-lazy iteration. 185 186 batch commit 187 range-key-set m z @5 foo 188 set s s 189 ---- 190 committed 2 keys 191 192 combined-iter 193 is-using-combined 194 seek-ge a 195 is-using-combined 196 seek-ge n 197 is-using-combined 198 ---- 199 using combined (non-lazy) iterator 200 a: (a, .) 201 using combined (non-lazy) iterator 202 n: (., [m-z) @5=foo UPDATED) 203 using combined (non-lazy) iterator 204 205 flush 206 ---- 207 208 # Now that the range key is flushed, a switch to combined iteration should only 209 # happen once the sstable containing the set is encountered. 210 211 combined-iter 212 is-using-combined 213 seek-ge a 214 is-using-combined 215 seek-ge n 216 is-using-combined 217 ---- 218 using lazy iterator 219 a: (a, .) 220 using lazy iterator 221 n: (., [m-z) @5=foo UPDATED) 222 using combined (non-lazy) iterator 223 224 # Regression tests for #2210 metamorphic test failure. 225 # 226 # Lazy-combined iteration depends on individual point level iterators triggering 227 # a switch to combined iteration when they observe a file containing relevant 228 # range keys. Previously, this switch did not happen if the observed range 229 # keys all lied outside the current iteration prefix. 230 # 231 # This made it possible for a level to become positioned beyond the file 232 # containing range keys, without ever triggering the switch to combined 233 # iteration. A subsequent seek that made use of the TrySeekUsingNext 234 # optimization would never observe the file containing range keys, and omit the 235 # range keys. 236 237 define 238 L6 239 bax.DEL.9: 240 L6 241 rangekey:c-d:{(#0,RANGEKEYSET,@1,foo)} 242 L6 243 d@2.SET.2:v 244 ---- 245 6: 246 000004:[bax#9,DEL-bax#9,DEL] 247 000005:[c#0,RANGEKEYSET-d#inf,RANGEKEYSET] 248 000006:[d@2#2,SET-d@2#2,SET] 249 250 combined-iter 251 seek-prefix-ge bax 252 seek-prefix-ge cat 253 ---- 254 . 255 cat: (., [cat-"cat\x00") @1=foo UPDATED) 256 257 # Another regression test for the #2210 metamorphic test failure, this one using 258 # a MERGE key to force the Iterator to step the internal iterator beyond the 259 # range key file. 260 261 define 262 L6 263 bax.MERGE.9:v 264 L6 265 rangekey:c-d:{(#0,RANGEKEYSET,@1,foo)} 266 L6 267 d@2.SET.2:v 268 ---- 269 6: 270 000004:[bax#9,MERGE-bax#9,MERGE] 271 000005:[c#0,RANGEKEYSET-d#inf,RANGEKEYSET] 272 000006:[d@2#2,SET-d@2#2,SET] 273 274 combined-iter 275 seek-prefix-ge bax 276 seek-prefix-ge cat 277 ---- 278 bax: (v, .) 279 cat: (., [cat-"cat\x00") @1=foo UPDATED)