github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/metamorphic/testdata/key_manager (about)

     1  # run subcommands
     2  #
     3  # add-new-key <key>
     4  # keys
     5  # singledel-keys <writerID>
     6  # op <operation string as printed to ops files>
     7  
     8  run
     9  add-new-key foo
    10  add-new-key foo
    11  ----
    12  "foo" is new
    13  "foo" already tracked
    14  
    15  # Test SET; SINGLEDEL on DB.
    16  
    17  run
    18  keys
    19  singledel-keys db1
    20  singledel-keys batch1
    21  op db1.Set("foo", "foo")
    22  keys
    23  singledel-keys db1
    24  singledel-keys batch1
    25  bounds db1
    26  op db1.SingleDelete("foo", false)
    27  keys
    28  singledel-keys db1
    29  ----
    30  keys: "foo"
    31  can singledel on db1: "foo"
    32  can singledel on batch1: "foo"
    33  [db1.Set("foo", "foo")]
    34  keys: "foo"
    35  can singledel on db1: "foo"
    36  can singledel on batch1: "foo"
    37  db1: ["foo","foo"]
    38  [db1.SingleDelete("foo", false /* maybeReplaceDelete */)]
    39  keys: "foo"
    40  can singledel on db1: "foo"
    41  
    42  # Test SET; SINGLEDEL on batch on separate key.
    43  
    44  run
    45  add-new-key bar
    46  op batch1.Set("bar", "bar")
    47  keys
    48  singledel-keys db1
    49  singledel-keys batch1
    50  singledel-keys batch2
    51  op batch1.SingleDelete("bar", false)
    52  keys
    53  singledel-keys db1
    54  singledel-keys batch1
    55  op db1.Apply(batch1)
    56  singledel-keys db1
    57  ----
    58  "bar" is new
    59  [batch1.Set("bar", "bar")]
    60  keys: "bar", "foo"
    61  can singledel on db1: "bar", "foo"
    62  can singledel on batch1: "bar", "foo"
    63  can singledel on batch2: "bar", "foo"
    64  [batch1.SingleDelete("bar", false /* maybeReplaceDelete */)]
    65  keys: "bar", "foo"
    66  can singledel on db1: "bar", "foo"
    67  can singledel on batch1: "bar", "foo"
    68  [db1.Apply(batch1)]
    69  can singledel on db1: "bar", "foo"
    70  
    71  # Test SET on db; SINGLEDEL on batch.
    72  
    73  reset
    74  ----
    75  
    76  run
    77  add-new-key foo
    78  op db1.Set("foo", "foo")
    79  singledel-keys db1
    80  singledel-keys batch1
    81  op batch1.SingleDelete("foo", false)
    82  singledel-keys db1
    83  singledel-keys batch1
    84  op db1.Apply(batch1)
    85  singledel-keys db1
    86  op db1.Set("foo", "foo")
    87  singledel-keys db1
    88  singledel-keys batch1
    89  ----
    90  "foo" is new
    91  [db1.Set("foo", "foo")]
    92  can singledel on db1: "foo"
    93  can singledel on batch1: "foo"
    94  [batch1.SingleDelete("foo", false /* maybeReplaceDelete */)]
    95  can singledel on db1: "foo"
    96  can singledel on batch1: "foo"
    97  [db1.Apply(batch1)]
    98  can singledel on db1: "foo"
    99  [db1.Set("foo", "foo")]
   100  can singledel on db1: "foo"
   101  can singledel on batch1: "foo"
   102  
   103  # Test SET; DEL; SET; SingleDelete on db.
   104  
   105  reset
   106  ----
   107  
   108  run
   109  add-new-key foo
   110  op db1.Set("foo", "foo")
   111  op db1.Delete("foo")
   112  singledel-keys db1
   113  op db1.Set("foo", "foo")
   114  singledel-keys db1
   115  op db1.SingleDelete("foo", false)
   116  singledel-keys db1
   117  ----
   118  "foo" is new
   119  [db1.Set("foo", "foo")]
   120  [db1.Delete("foo")]
   121  can singledel on db1: "foo"
   122  [db1.Set("foo", "foo")]
   123  can singledel on db1: "foo"
   124  [db1.SingleDelete("foo", false /* maybeReplaceDelete */)]
   125  can singledel on db1: "foo"
   126  
   127  # Test SET; DEL; SET; DEL on batches.
   128  
   129  reset
   130  ----
   131  
   132  run
   133  add-new-key foo
   134  op batch1.Set("foo", "foo")
   135  op batch1.Delete("foo")
   136  op batch1.Set("foo", "foo")
   137  singledel-keys batch1
   138  op db1.Apply(batch1)
   139  ----
   140  "foo" is new
   141  [batch1.Set("foo", "foo")]
   142  [batch1.Delete("foo")]
   143  [batch1.Set("foo", "foo")]
   144  can singledel on batch1: "foo"
   145  [db1.Apply(batch1)]
   146  
   147  # "foo" should be eligible for single delete on db1 because a Delete separates
   148  # the two sets.
   149  
   150  run
   151  singledel-keys db1
   152  ----
   153  can singledel on db1: "foo"
   154  
   155  # A batch that contains its own Set and SingleDelete should conflict, because
   156  # the two Sets would stack.
   157  
   158  run
   159  op batch2.Set("foo", "foo")
   160  op batch2.SingleDelete("foo", false)
   161  conflicts batch2 db1
   162  ----
   163  [batch2.Set("foo", "foo")]
   164  [batch2.SingleDelete("foo", false /* maybeReplaceDelete */)]
   165  conflicts merging batch2 into db1: "foo"
   166  
   167  # Setting "foo" again on the DB should result in the key no longer be eligible
   168  # for single delete because there are two stacked SETs on db1.s
   169  
   170  run
   171  op db1.Set("foo", "foo")
   172  singledel-keys db1
   173  ----
   174  [db1.Set("foo", "foo")]
   175  can singledel on db1: (none)
   176  
   177  run
   178  op batch2.Delete("foo")
   179  op db1.Apply(batch2)
   180  singledel-keys db1
   181  op db1.Set("foo", "foo")
   182  singledel-keys db1
   183  ----
   184  [batch2.Delete("foo")]
   185  [db1.Apply(batch2)]
   186  can singledel on db1: "foo"
   187  [db1.Set("foo", "foo")]
   188  can singledel on db1: "foo"
   189  
   190  # Test SET; MERGE; DEL; SINGLEDEL on DB.
   191  
   192  reset
   193  ----
   194  
   195  run
   196  add-new-key foo
   197  op db.Set("foo", "foo")
   198  singledel-keys db1
   199  op db1.Merge("foo", "foo")
   200  singledel-keys db1
   201  op db1.Delete("foo")
   202  singledel-keys db1
   203  op db1.Set("foo", "foo")
   204  singledel-keys db1
   205  op db1.SingleDelete("foo", false)
   206  singledel-keys db1
   207  ----
   208  "foo" is new
   209  [db1.Set("foo", "foo")]
   210  can singledel on db1: "foo"
   211  [db1.Merge("foo", "foo")]
   212  can singledel on db1: (none)
   213  [db1.Delete("foo")]
   214  can singledel on db1: "foo"
   215  [db1.Set("foo", "foo")]
   216  can singledel on db1: "foo"
   217  [db1.SingleDelete("foo", false /* maybeReplaceDelete */)]
   218  can singledel on db1: "foo"
   219  
   220  # Test SET; DEL (db); SET; SINGLEDEL (batch)
   221  
   222  reset
   223  ----
   224  
   225  run
   226  add-new-key foo
   227  op db1.Set("foo", "foo")
   228  singledel-keys db1
   229  op db1.Delete("foo")
   230  singledel-keys db1
   231  op db1.Set("foo", "foo")
   232  singledel-keys db1
   233  singledel-keys batch1
   234  op batch1.SingleDelete("foo", false)
   235  singledel-keys db1
   236  singledel-keys batch1
   237  op db1.Apply(batch1)
   238  singledel-keys db1
   239  op db1.Set("foo", "foo")
   240  singledel-keys db1
   241  ----
   242  "foo" is new
   243  [db1.Set("foo", "foo")]
   244  can singledel on db1: "foo"
   245  [db1.Delete("foo")]
   246  can singledel on db1: "foo"
   247  [db1.Set("foo", "foo")]
   248  can singledel on db1: "foo"
   249  can singledel on batch1: "foo"
   250  [batch1.SingleDelete("foo", false /* maybeReplaceDelete */)]
   251  can singledel on db1: "foo"
   252  can singledel on batch1: "foo"
   253  [db1.Apply(batch1)]
   254  can singledel on db1: "foo"
   255  [db1.Set("foo", "foo")]
   256  can singledel on db1: "foo"
   257  
   258  # A delete range should "reset" keys, even if the delete range is applied to a
   259  # batch that doesn't yet contain the relevant key.
   260  
   261  reset
   262  ----
   263  
   264  run
   265  add-new-key foo
   266  add-new-key bar
   267  op db1.Set("foo", "foo")
   268  op db1.Set("foo", "foo")
   269  singledel-keys db1
   270  op batch1.DeleteRange("a", "z")
   271  conflicts collapsed batch1 db1
   272  op db1.Apply(batch1)
   273  singledel-keys db1
   274  ----
   275  "foo" is new
   276  "bar" is new
   277  [db1.Set("foo", "foo")]
   278  [db1.Set("foo", "foo")]
   279  can singledel on db1: "bar"
   280  [batch1.DeleteRange("a", "z")]
   281  conflicts merging batch1 (collapsed) into db1: (none)
   282  [db1.Apply(batch1)]
   283  can singledel on db1: "bar", "foo"
   284  
   285  # Ingestion flattens keys, with any range dels contained within the batch
   286  # semantically applying beneath the most recent point. In this case, foo should
   287  # remain eligible immediately after ingestion because the DeleteRange shadows
   288  # the original Set on db1. It should not be eligible after the final Set,
   289  # because the ingested set and the final set stack, both on top of the delete
   290  # range.
   291  
   292  reset
   293  ----
   294  
   295  run
   296  add-new-key foo
   297  add-new-key bar
   298  op db1.Set("foo", "foo")
   299  singledel-keys db1
   300  op batch1.Set("foo", "foo")
   301  op batch1.DeleteRange("a", "z")
   302  conflicts collapsed batch1 db1
   303  op db1.Ingest(batch1)
   304  singledel-keys db1
   305  op db1.Set("foo", "foo")
   306  singledel-keys db1
   307  bounds db1
   308  ----
   309  "foo" is new
   310  "bar" is new
   311  [db1.Set("foo", "foo")]
   312  can singledel on db1: "bar", "foo"
   313  [batch1.Set("foo", "foo")]
   314  [batch1.DeleteRange("a", "z")]
   315  conflicts merging batch1 (collapsed) into db1: (none)
   316  [db1.Ingest(batch1)]
   317  can singledel on db1: "bar", "foo"
   318  [db1.Set("foo", "foo")]
   319  can singledel on db1: "bar"
   320  db1: ["a","z")
   321  
   322  # Repeat the above test, but this time with an ingestion that should fail due to
   323  # overlapping key ranges.
   324  
   325  run
   326  add-new-key foo
   327  add-new-key bar
   328  op db1.Set("foo", "foo")
   329  singledel-keys db1
   330  op batch1.Set("foo", "foo")
   331  bounds batch1
   332  op batch1.DeleteRange("a", "z")
   333  bounds batch1
   334  op batch2.DeleteRange("y", "z")
   335  conflicts collapsed batch1 db1
   336  op db1.Ingest(batch1, batch2)
   337  singledel-keys db1
   338  op db1.Set("foo", "foo")
   339  singledel-keys db1
   340  bounds db1
   341  ----
   342  "foo" already tracked
   343  "bar" already tracked
   344  [db1.Set("foo", "foo")]
   345  can singledel on db1: "bar"
   346  [batch1.Set("foo", "foo")]
   347  batch1: ["foo","foo"]
   348  [batch1.DeleteRange("a", "z")]
   349  batch1: ["a","z")
   350  [batch2.DeleteRange("y", "z")]
   351  conflicts merging batch1 (collapsed) into db1: (none)
   352  [db1.Ingest(batch1, batch2)]
   353  can singledel on db1: "bar"
   354  [db1.Set("foo", "foo")]
   355  can singledel on db1: "bar"
   356  db1: ["a","z")
   357  
   358  # Since ingestion flattens keys, foo should be single-deletable on the db after
   359  # ingest, even though it couldn't be single deleted from the batch before
   360  # ingestion.
   361  
   362  reset
   363  ----
   364  
   365  run
   366  add-new-key foo
   367  op batch1.Set("foo", "foo")
   368  op batch1.Set("foo", "foo")
   369  conflicts collapsed batch1 db1
   370  singledel-keys batch1
   371  op db1.Ingest(batch1)
   372  singledel-keys db1
   373  ----
   374  "foo" is new
   375  [batch1.Set("foo", "foo")]
   376  [batch1.Set("foo", "foo")]
   377  conflicts merging batch1 (collapsed) into db1: (none)
   378  can singledel on batch1: (none)
   379  [db1.Ingest(batch1)]
   380  can singledel on db1: "foo"
   381  
   382  
   383  # Because ingestion flattens keys, foo remains eligible for single delete the
   384  # entire test case. During flattening, the Delete wins over the Set.
   385  
   386  reset
   387  ----
   388  
   389  run
   390  add-new-key foo
   391  op batch1.Set("foo", "foo")
   392  op batch1.Delete("foo")
   393  singledel-keys batch1
   394  op db1.Ingest(batch1)
   395  singledel-keys db1
   396  op db1.Set("foo", "foo")
   397  singledel-keys db1
   398  ----
   399  "foo" is new
   400  [batch1.Set("foo", "foo")]
   401  [batch1.Delete("foo")]
   402  can singledel on batch1: "foo"
   403  [db1.Ingest(batch1)]
   404  can singledel on db1: "foo"
   405  [db1.Set("foo", "foo")]
   406  can singledel on db1: "foo"
   407  
   408  # Ingestion flattening means that the batch1.Set sits semantically on top of the
   409  # delete range despite being inserted to the batch before the delete range.
   410  
   411  reset
   412  ----
   413  
   414  run
   415  add-new-key foo
   416  op batch1.Set("foo", "foo")
   417  op batch1.DeleteRange("a", "z")
   418  op db1.Ingest(batch1)
   419  op db1.Set("foo", "foo")
   420  singledel-keys db1
   421  ----
   422  "foo" is new
   423  [batch1.Set("foo", "foo")]
   424  [batch1.DeleteRange("a", "z")]
   425  [db1.Ingest(batch1)]
   426  [db1.Set("foo", "foo")]
   427  can singledel on db1: (none)
   428  
   429  # In this scenario batch1 would conflict with db1 if it were applied as a batch
   430  # commit, but when ingested and "collapsed" it does not conflict.
   431  
   432  reset
   433  ----
   434  
   435  run
   436  add-new-key foo
   437  op db1.Set("foo", "foo")
   438  op batch1.Set("foo", "foo")
   439  op batch1.SingleDelete("foo", false)
   440  conflicts batch1 db1
   441  conflicts collapsed batch1 db1
   442  op db1.Ingest(batch1)
   443  ----
   444  "foo" is new
   445  [db1.Set("foo", "foo")]
   446  [batch1.Set("foo", "foo")]
   447  [batch1.SingleDelete("foo", false /* maybeReplaceDelete */)]
   448  conflicts merging batch1 into db1: "foo"
   449  conflicts merging batch1 (collapsed) into db1: (none)
   450  [db1.Ingest(batch1)]
   451  
   452  # Allow a MERGE to be deleted by a single delete, as long as it's the only
   453  # value-carrying key.
   454  
   455  reset
   456  ----
   457  
   458  run
   459  add-new-key foo
   460  op db1.Merge("foo", "foo")
   461  singledel-keys db1
   462  op batch1.Merge("foo", "foo")
   463  op batch1.SingleDelete("foo", true)
   464  conflicts batch1 db1
   465  conflicts collapsed batch1 db1
   466  op db1.Merge("foo", "foo")
   467  singledel-keys db1
   468  ----
   469  "foo" is new
   470  [db1.Merge("foo", "foo")]
   471  can singledel on db1: "foo"
   472  [batch1.Merge("foo", "foo")]
   473  [batch1.SingleDelete("foo", true /* maybeReplaceDelete */)]
   474  conflicts merging batch1 into db1: "foo"
   475  conflicts merging batch1 (collapsed) into db1: (none)
   476  [db1.Merge("foo", "foo")]
   477  can singledel on db1: (none)