github.com/cockroachdb/pebble@v1.1.2/internal/keyspan/testdata/interleaving_iter_masking (about)

     1  # Test the scenario illustrated in the below visualization.
     2  #
     3  #        ^
     4  #     @9 |        •―――――――――――――――○ [e,m)@9
     5  #   s  8 |                      • l@8
     6  #   u  7 |------------------------------------ @7 masking
     7  #   f  6 |      [h,q)@6 •―――――――――――――――――○     threshold
     8  #   f  5 |              • h@5
     9  #   f  4 |                          • n@4
    10  #   i  3 |          •―――――――――――○ [f,l)@3
    11  #   x  2 |  • b@2
    12  #      1 |
    13  #      0 |___________________________________
    14  #         a b c d e f g h i j k l m n o p q
    15  #
    16  
    17  define-rangekeys
    18  e-f:{(#1,RANGEKEYSET,@9,foo)}
    19  f-h:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@3,bar)}
    20  h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
    21  l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
    22  m-q:{(#1,RANGEKEYSET,@6,bax)}
    23  ----
    24  OK
    25  
    26  define-pointkeys
    27  b@2.SET.1
    28  h@5.SET.1
    29  l@8.SET.1
    30  n@4.SET.1
    31  ----
    32  OK
    33  
    34  set-masking-threshold
    35  @7
    36  ----
    37  OK
    38  
    39  iter
    40  first
    41  next
    42  next
    43  next
    44  next
    45  next
    46  next
    47  next
    48  ----
    49  -- SpanChanged(nil)
    50  -- SpanChanged(nil)
    51  PointKey: b@2#1,1
    52  Span: <invalid>
    53  -
    54  -- SpanChanged(e-f:{(#1,RANGEKEYSET,@9,foo)})
    55  PointKey: e#72057594037927935,21
    56  Span: e-f:{(#1,RANGEKEYSET,@9,foo)}
    57  -
    58  -- SpanChanged(f-h:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@3,bar)})
    59  PointKey: f#72057594037927935,21
    60  Span: f-h:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@3,bar)}
    61  -
    62  -- SpanChanged(h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)})
    63  PointKey: h#72057594037927935,21
    64  Span: h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
    65  -
    66  -- SpanChanged(l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)})
    67  PointKey: l#72057594037927935,21
    68  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
    69  -
    70  PointKey: l@8#1,1
    71  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
    72  -
    73  -- SpanChanged(m-q:{(#1,RANGEKEYSET,@6,bax)})
    74  PointKey: m#72057594037927935,21
    75  Span: m-q:{(#1,RANGEKEYSET,@6,bax)}
    76  -
    77  -- SpanChanged(nil)
    78  .
    79  
    80  iter
    81  last
    82  prev
    83  prev
    84  prev
    85  prev
    86  prev
    87  prev
    88  prev
    89  ----
    90  -- SpanChanged(nil)
    91  -- SpanChanged(m-q:{(#1,RANGEKEYSET,@6,bax)})
    92  PointKey: m#72057594037927935,21
    93  Span: m-q:{(#1,RANGEKEYSET,@6,bax)}
    94  -
    95  -- SpanChanged(l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)})
    96  PointKey: l@8#1,1
    97  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
    98  -
    99  PointKey: l#72057594037927935,21
   100  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
   101  -
   102  -- SpanChanged(h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)})
   103  PointKey: h#72057594037927935,21
   104  Span: h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
   105  -
   106  -- SpanChanged(f-h:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@3,bar)})
   107  PointKey: f#72057594037927935,21
   108  Span: f-h:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@3,bar)}
   109  -
   110  -- SpanChanged(e-f:{(#1,RANGEKEYSET,@9,foo)})
   111  PointKey: e#72057594037927935,21
   112  Span: e-f:{(#1,RANGEKEYSET,@9,foo)}
   113  -
   114  -- SpanChanged(nil)
   115  PointKey: b@2#1,1
   116  Span: <invalid>
   117  -
   118  -- SpanChanged(nil)
   119  .
   120  
   121  iter
   122  seek-ge a
   123  seek-ge c
   124  seek-ge h
   125  seek-ge i
   126  seek-ge l
   127  next
   128  seek-ge m
   129  seek-ge r
   130  ----
   131  -- SpanChanged(nil)
   132  -- SpanChanged(nil)
   133  PointKey: b@2#1,1
   134  Span: <invalid>
   135  -
   136  -- SpanChanged(nil)
   137  -- SpanChanged(e-f:{(#1,RANGEKEYSET,@9,foo)})
   138  PointKey: e#72057594037927935,21
   139  Span: e-f:{(#1,RANGEKEYSET,@9,foo)}
   140  -
   141  -- SpanChanged(nil)
   142  -- SpanChanged(h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)})
   143  PointKey: h#72057594037927935,21
   144  Span: h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
   145  -
   146  -- SpanChanged(nil)
   147  -- SpanChanged(h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)})
   148  PointKey: i#72057594037927935,21
   149  Span: h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
   150  -
   151  -- SpanChanged(nil)
   152  -- SpanChanged(l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)})
   153  PointKey: l#72057594037927935,21
   154  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
   155  -
   156  PointKey: l@8#1,1
   157  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
   158  -
   159  -- SpanChanged(nil)
   160  -- SpanChanged(m-q:{(#1,RANGEKEYSET,@6,bax)})
   161  PointKey: m#72057594037927935,21
   162  Span: m-q:{(#1,RANGEKEYSET,@6,bax)}
   163  -
   164  -- SpanChanged(nil)
   165  -- SpanChanged(nil)
   166  .
   167  
   168  # Setting the masking threshold to @9 should result in l@8 being masked by
   169  # [e,m)@9.
   170  
   171  set-masking-threshold
   172  @9
   173  ----
   174  OK
   175  
   176  iter
   177  seek-ge l
   178  next
   179  seek-lt l
   180  seek-lt ll
   181  prev
   182  ----
   183  -- SpanChanged(nil)
   184  -- SpanChanged(l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)})
   185  PointKey: l#72057594037927935,21
   186  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
   187  -
   188  -- SpanChanged(m-q:{(#1,RANGEKEYSET,@6,bax)})
   189  PointKey: m#72057594037927935,21
   190  Span: m-q:{(#1,RANGEKEYSET,@6,bax)}
   191  -
   192  -- SpanChanged(nil)
   193  -- SpanChanged(h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)})
   194  PointKey: h#72057594037927935,21
   195  Span: h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
   196  -
   197  -- SpanChanged(nil)
   198  -- SpanChanged(l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)})
   199  PointKey: l#72057594037927935,21
   200  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
   201  -
   202  -- SpanChanged(h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)})
   203  PointKey: h#72057594037927935,21
   204  Span: h-l:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax) (#1,RANGEKEYSET,@3,bar)}
   205  -
   206  
   207  iter
   208  seek-ge l
   209  next
   210  ----
   211  -- SpanChanged(nil)
   212  -- SpanChanged(l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)})
   213  PointKey: l#72057594037927935,21
   214  Span: l-m:{(#1,RANGEKEYSET,@9,foo) (#1,RANGEKEYSET,@6,bax)}
   215  -
   216  -- SpanChanged(m-q:{(#1,RANGEKEYSET,@6,bax)})
   217  PointKey: m#72057594037927935,21
   218  Span: m-q:{(#1,RANGEKEYSET,@6,bax)}
   219  -
   220  
   221  define-rangekeys
   222  a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   223  ----
   224  OK
   225  
   226  define-pointkeys
   227  a.SET.1
   228  a@3.SET.1
   229  a@12.SET.1
   230  b@2.SET.1
   231  ----
   232  OK
   233  
   234  set-masking-threshold
   235  @10
   236  ----
   237  OK
   238  
   239  # Test that both a@3 and b@2 are masked by the rangekey.
   240  # The unsuffixed point key 'a' and the point key at a higher timestamp 'a@12'
   241  # are not masked.
   242  
   243  iter
   244  first
   245  next
   246  next
   247  next
   248  ----
   249  -- SpanChanged(nil)
   250  -- SpanChanged(a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)})
   251  PointKey: a#72057594037927935,21
   252  Span: a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   253  -
   254  PointKey: a#1,1
   255  Span: a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   256  -
   257  PointKey: a@12#1,1
   258  Span: a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   259  -
   260  -- SpanChanged(nil)
   261  .
   262  
   263  iter
   264  last
   265  prev
   266  prev
   267  prev
   268  ----
   269  -- SpanChanged(nil)
   270  -- SpanChanged(a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)})
   271  PointKey: a@12#1,1
   272  Span: a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   273  -
   274  PointKey: a#1,1
   275  Span: a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   276  -
   277  PointKey: a#72057594037927935,21
   278  Span: a-c:{(#1,RANGEKEYSET,@5,apples) (#1,RANGEKEYSET,@2,bananas)}
   279  -
   280  -- SpanChanged(nil)
   281  .
   282  
   283  # Try the same test, but with a range key that sorts before the masking
   284  # threshold (eg, higher MVCC timestamp). Nothing should be masked.
   285  
   286  define-rangekeys
   287  a-c:{(#2,RANGEKEYSET,@20,apples)}
   288  ----
   289  OK
   290  
   291  iter
   292  first
   293  next
   294  next
   295  next
   296  next
   297  next
   298  ----
   299  -- SpanChanged(nil)
   300  -- SpanChanged(a-c:{(#2,RANGEKEYSET,@20,apples)})
   301  PointKey: a#72057594037927935,21
   302  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   303  -
   304  PointKey: a#1,1
   305  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   306  -
   307  PointKey: a@3#1,1
   308  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   309  -
   310  PointKey: a@12#1,1
   311  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   312  -
   313  PointKey: b@2#1,1
   314  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   315  -
   316  -- SpanChanged(nil)
   317  .
   318  
   319  iter
   320  last
   321  prev
   322  prev
   323  prev
   324  prev
   325  prev
   326  ----
   327  -- SpanChanged(nil)
   328  -- SpanChanged(a-c:{(#2,RANGEKEYSET,@20,apples)})
   329  PointKey: b@2#1,1
   330  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   331  -
   332  PointKey: a@12#1,1
   333  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   334  -
   335  PointKey: a@3#1,1
   336  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   337  -
   338  PointKey: a#1,1
   339  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   340  -
   341  PointKey: a#72057594037927935,21
   342  Span: a-c:{(#2,RANGEKEYSET,@20,apples)}
   343  -
   344  -- SpanChanged(nil)
   345  .
   346  
   347  # Try the original test, but with an internal range key containing just an
   348  # Unset, and no Set. Nothing should be masked. No range keys should be surfaced,
   349  # because there are none.
   350  
   351  define-rangekeys
   352  a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   353  ----
   354  OK
   355  
   356  iter
   357  first
   358  next
   359  next
   360  next
   361  next
   362  ----
   363  -- SpanChanged(nil)
   364  -- SpanChanged(a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)})
   365  PointKey: a#72057594037927935,20
   366  Span: a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   367  -
   368  PointKey: a#1,1
   369  Span: a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   370  -
   371  PointKey: a@12#1,1
   372  Span: a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   373  -
   374  -- SpanChanged(nil)
   375  .
   376  -- SpanChanged(nil)
   377  .
   378  
   379  iter
   380  last
   381  prev
   382  prev
   383  prev
   384  prev
   385  ----
   386  -- SpanChanged(nil)
   387  -- SpanChanged(a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)})
   388  PointKey: a@12#1,1
   389  Span: a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   390  -
   391  PointKey: a#1,1
   392  Span: a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   393  -
   394  PointKey: a#72057594037927935,20
   395  Span: a-c:{(#1,RANGEKEYUNSET,@5) (#1,RANGEKEYUNSET,@2)}
   396  -
   397  -- SpanChanged(nil)
   398  .
   399  -- SpanChanged(nil)
   400  .
   401  
   402  # Test a scenario where a point key is masked in the forward direction, which in
   403  # turn requires nexting to the next range key as well.
   404  
   405  define-rangekeys
   406  a-c:{(#1,RANGEKEYSET,@5,apples)}
   407  c-z:{(#1,RANGEKEYSET,@10,bananas)}
   408  ----
   409  OK
   410  
   411  define-pointkeys
   412  b@3.SET.2
   413  d@9.SET.4
   414  j@11.SET.3
   415  ----
   416  OK
   417  
   418  set-masking-threshold
   419  @20
   420  ----
   421  OK
   422  
   423  iter
   424  first
   425  next
   426  next
   427  ----
   428  -- SpanChanged(nil)
   429  -- SpanChanged(a-c:{(#1,RANGEKEYSET,@5,apples)})
   430  PointKey: a#72057594037927935,21
   431  Span: a-c:{(#1,RANGEKEYSET,@5,apples)}
   432  -
   433  -- SpanChanged(c-z:{(#1,RANGEKEYSET,@10,bananas)})
   434  PointKey: c#72057594037927935,21
   435  Span: c-z:{(#1,RANGEKEYSET,@10,bananas)}
   436  -
   437  PointKey: j@11#3,1
   438  Span: c-z:{(#1,RANGEKEYSET,@10,bananas)}
   439  -
   440  
   441  iter
   442  last
   443  prev
   444  prev
   445  ----
   446  -- SpanChanged(nil)
   447  -- SpanChanged(c-z:{(#1,RANGEKEYSET,@10,bananas)})
   448  PointKey: j@11#3,1
   449  Span: c-z:{(#1,RANGEKEYSET,@10,bananas)}
   450  -
   451  PointKey: c#72057594037927935,21
   452  Span: c-z:{(#1,RANGEKEYSET,@10,bananas)}
   453  -
   454  -- SpanChanged(a-c:{(#1,RANGEKEYSET,@5,apples)})
   455  PointKey: a#72057594037927935,21
   456  Span: a-c:{(#1,RANGEKEYSET,@5,apples)}
   457  -
   458  
   459  # Test a scenario where a there's an empty range key, requiring the interleaving
   460  # iter to call SpanChanged(nil) which should clear the previous mask.
   461  
   462  define-rangekeys
   463  a-c:{(#1,RANGEKEYSET,@10,apples)}
   464  c-e:{}
   465  e-f:{(#1,RANGEKEYSET,@5,bananas)}
   466  ----
   467  OK
   468  
   469  define-pointkeys
   470  a@2.SET.4
   471  b@9.SET.2
   472  d@9.SET.3
   473  ----
   474  OK
   475  
   476  set-masking-threshold
   477  @20
   478  ----
   479  OK
   480  
   481  iter
   482  seek-ge a
   483  next
   484  next
   485  next
   486  ----
   487  -- SpanChanged(nil)
   488  -- SpanChanged(a-c:{(#1,RANGEKEYSET,@10,apples)})
   489  PointKey: a#72057594037927935,21
   490  Span: a-c:{(#1,RANGEKEYSET,@10,apples)}
   491  -
   492  -- SpanChanged(nil)
   493  PointKey: d@9#3,1
   494  Span: <invalid>
   495  -
   496  -- SpanChanged(e-f:{(#1,RANGEKEYSET,@5,bananas)})
   497  PointKey: e#72057594037927935,21
   498  Span: e-f:{(#1,RANGEKEYSET,@5,bananas)}
   499  -
   500  -- SpanChanged(nil)
   501  .