Skip to main content

levels_test.go

levels_test.go - Overview

This file contains unit tests for the levelsController functionality in BadgerDB, covering areas like overlap checks, compaction processes, and discard timestamp handling.

Detailed Documentation

func createAndOpen

func createAndOpen(db *DB, td []keyValVersion, level int)
  • Purpose: Creates a table with the given data and adds it to the specified level.
  • Parameters:
    • db: Pointer to the DB struct.
    • td: Slice of keyValVersion structs representing the data to be added to the table.
    • level: The level to which the table should be added.
  • Returns: None. Panics on error.

type keyValVersion

type keyValVersion struct {
key string
val string
version int
meta byte
}
  • Purpose: keyValVersion represents a key-value pair with a version and metadata.
  • Fields:
    • key: The key string.
    • val: The value string.
    • version: The version integer.
    • meta: The metadata byte.

func TestCheckOverlap

func TestCheckOverlap(t *testing.T)
  • Purpose: Tests the checkOverlap function of the levelsController.
  • Parameters:
    • t: Testing object.
  • Tests: Checks different scenarios of overlapping tables on different levels.

func getAllAndCheck

func getAllAndCheck(t *testing.T, db *DB, expected []keyValVersion)
  • Purpose: Retrieves all keys and values from the database and checks if they match the expected values.
  • Parameters:
    • t: Testing object.
    • db: Pointer to the DB struct.
    • expected: Slice of keyValVersion structs representing the expected data in the database.

func TestCompaction

func TestCompaction(t *testing.T)
  • Purpose: Tests various compaction scenarios, including L0 to L1 compactions, and handling of duplicate keys.
  • Parameters:
    • t: Testing object.

func TestCompactionTwoVersions

func TestCompactionTwoVersions(t *testing.T)
  • Purpose: Tests compaction scenarios with NumVersionsToKeep set to 2.
  • Parameters:
    • t: Testing object.

func TestCompactionAllVersions

func TestCompactionAllVersions(t *testing.T)
  • Purpose: Tests compaction scenarios where all versions of keys are kept (NumVersionsToKeep set to math.MaxInt32).
  • Parameters:
    • t: Testing object.

func TestDiscardTs

func TestDiscardTs(t *testing.T)
  • Purpose: Tests the behavior of compaction with different discard timestamps.
  • Parameters:
    • t: Testing object.

func TestDiscardFirstVersion

func TestDiscardFirstVersion(t *testing.T)
  • Purpose: Tests to ensure that the first entry with DiscardEarlierversion bit < DiscardTs is kept around (when numversionstokeep is infinite).
  • Parameters:
    • t: Testing object.

func TestL1Stall

func TestL1Stall(t *testing.T)
  • Purpose: Tests the L1 stall condition.
  • Parameters:
    • t: Testing object.

func createEmptyTable

func createEmptyTable(db *DB) *table.Table
  • Purpose: Creates an empty table (with a single key added to allow opening).
  • Parameters:
    • db: Pointer to the DB struct.
  • Returns: A pointer to the new table.Table struct.

func TestL0Stall

func TestL0Stall(t *testing.T)
  • Purpose: Tests the L0 stall condition.
  • Parameters:
    • t: Testing object.

func TestLevelGet

func TestLevelGet(t *testing.T)
  • Purpose: Tests the get function.
  • Parameters:
    • t: Testing object.

func TestKeyVersions

func TestKeyVersions(t *testing.T)
  • Purpose: Test key versions
  • Parameters:
    • t: Testing object.

func TestSameLevel

func TestSameLevel(t *testing.T)
  • Purpose: Tests same level compaction.
  • Parameters:
    • t: Testing object.

func TestTableContainsPrefix

func TestTableContainsPrefix(t *testing.T)
  • Purpose: Tests that checks a table contains prefix or not
  • Parameters:
    • t: Testing object.

func TestFillTableCleanup

func TestFillTableCleanup(t *testing.T)
  • Purpose: Tests compaction failure cleanup.
  • Parameters:
    • t: Testing object.

func TestStaleDataCleanup

func TestStaleDataCleanup(t *testing.T)
  • Purpose: Tests stale data cleanup.
  • Parameters:
    • t: Testing object.

Getting Started Relevance