(t *testing.T)
| 331 | } |
| 332 | |
| 333 | func TestCompactionTwoVersions(t *testing.T) { |
| 334 | // Disable compactions and keep two versions of each key. |
| 335 | opt := DefaultOptions("").WithNumCompactors(0).WithNumVersionsToKeep(2) |
| 336 | opt.managedTxns = true |
| 337 | t.Run("with overlap", func(t *testing.T) { |
| 338 | runBadgerTest(t, &opt, func(t *testing.T, db *DB) { |
| 339 | l1 := []keyValVersion{{"foo", "bar", 3, 0}, {"fooz", "baz", 1, bitDelete}} |
| 340 | l2 := []keyValVersion{{"foo", "bar", 2, 0}} |
| 341 | l3 := []keyValVersion{{"foo", "bar", 1, 0}} |
| 342 | createAndOpen(db, l1, 1) |
| 343 | createAndOpen(db, l2, 2) |
| 344 | createAndOpen(db, l3, 3) |
| 345 | |
| 346 | // Set a high discard timestamp so that all the keys are below the discard timestamp. |
| 347 | db.SetDiscardTs(10) |
| 348 | |
| 349 | getAllAndCheck(t, db, []keyValVersion{ |
| 350 | {"foo", "bar", 3, 0}, |
| 351 | {"foo", "bar", 2, 0}, |
| 352 | {"foo", "bar", 1, 0}, |
| 353 | {"fooz", "baz", 1, 1}, |
| 354 | }) |
| 355 | cdef := compactDef{ |
| 356 | thisLevel: db.lc.levels[1], |
| 357 | nextLevel: db.lc.levels[2], |
| 358 | top: db.lc.levels[1].tables, |
| 359 | bot: db.lc.levels[2].tables, |
| 360 | } |
| 361 | require.NoError(t, db.lc.runCompactDef(1, cdef)) |
| 362 | // Nothing should be dropped after compaction because number of |
| 363 | // versions to keep is 2. |
| 364 | getAllAndCheck(t, db, []keyValVersion{ |
| 365 | {"foo", "bar", 3, 0}, |
| 366 | {"foo", "bar", 2, 0}, |
| 367 | {"foo", "bar", 1, 0}, |
| 368 | {"fooz", "baz", 1, 1}, |
| 369 | }) |
| 370 | |
| 371 | cdef = compactDef{ |
| 372 | thisLevel: db.lc.levels[2], |
| 373 | nextLevel: db.lc.levels[3], |
| 374 | top: db.lc.levels[2].tables, |
| 375 | bot: db.lc.levels[3].tables, |
| 376 | } |
| 377 | require.NoError(t, db.lc.runCompactDef(2, cdef)) |
| 378 | getAllAndCheck(t, db, []keyValVersion{ |
| 379 | {"foo", "bar", 3, 0}, |
| 380 | {"foo", "bar", 2, 0}, |
| 381 | }) |
| 382 | }) |
| 383 | }) |
| 384 | } |
| 385 | |
| 386 | func TestCompactionAllVersions(t *testing.T) { |
| 387 | // Disable compactions and keep all versions of the each key. |
nothing calls this directly
no test coverage detected
searching dependent graphs…