Skip to main content

value_test.go

value_test.go - Overview

This file contains various tests for the value log functionality in BadgerDB, including tests for dynamic value thresholds, value log garbage collection (GC), checksum verification, handling of partial appends to the value log, and ensuring data consistency during value log operations.

Detailed Documentation

Function: TestDynamicValueThreshold

  • Purpose: This test dynamically adjusts the value threshold and verifies its behavior by writing data of varying sizes to the value log.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueBasic

  • Purpose: Tests basic value log operations like writing and reading values.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueGCManaged

  • Purpose: Tests value log garbage collection in managed mode.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueGC

  • Purpose: Tests value log garbage collection functionality.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueGC2

  • Purpose: Tests value log garbage collection functionality with a modified dataset.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueGC3

  • Purpose: Tests value log garbage collection with an active iterator.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueGC4

  • Purpose: Tests value log garbage collection across multiple value log files.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestPersistLFDiscardStats

  • Purpose: Tests the persistence of discard statistics for log files.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueChecksums

  • Purpose: Tests the integrity of values in the value log using checksums.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestPartialAppendToWAL

  • Purpose: Tests the handling of partial appends to the write-ahead log (WAL).
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestReadOnlyOpenWithPartialAppendToWAL

  • Purpose: Tests read-only opening of the database with partial appends to WAL.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueLogTrigger

  • Purpose: Tests the triggering of value log garbage collection.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: createMemFile

  • Purpose: Creates a memFile with given entries and returns the last valid offset.
  • Parameters:
    • t (*testing.T): Testing object.
    • entries ([]*Entry): List of entries to write to the memFile.
  • Returns:
    • []byte: Buffer containing the memFile data.
    • uint32: Last valid offset in the buffer.

Function: TestPenultimateMemCorruption

  • Purpose: Tests recovery from corruption in the penultimate memtable.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: checkKeys

  • Purpose: Checks if the provided keys exist in the database.
  • Parameters:
    • t (*testing.T): Testing object.
    • kv (*DB): Database instance.
    • keys ([][]byte): List of keys to check.
  • Returns: None.

Type: testHelper

  • Purpose: Helper struct for simplifying tests.
  • Fields:
    • db (*DB): Database instance.
    • t (*testing.T): Testing object.
    • val ([]byte): Value buffer.

Method: key (testHelper)

  • Purpose: Generates a key based on the given integer.
  • Parameters:
    • i (int): Integer to be converted to a key.
  • Returns:
    • []byte: Key generated from the integer.

Method: value (testHelper)

  • Purpose: Returns a pre-generated random value, or generates one if it doesn't exist.
  • Parameters: None.
  • Returns:
    • []byte: A byte slice representing the value.

Method: writeRange (testHelper)

  • Purpose: Writes a range of keys to the database.
  • Parameters:
    • from (int): Starting key.
    • to (int): Ending key.
  • Returns: None.

Method: readRange (testHelper)

  • Purpose: Reads a range of keys from the database and verifies their values.
  • Parameters:
    • from (int): Starting key.
    • to (int): Ending key.
  • Returns: None.

Function: TestBug578

  • Purpose: Tests a specific bug where older versions of data can appear newer due to value log GC.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: BenchmarkReadWrite

  • Purpose: Benchmarks read and write performance of the value log.
  • Parameters:
    • b (*testing.B): Benchmark object.
  • Returns: None.

Function: TestValueLogTruncate

  • Purpose: Tests whether fully corrupted memtables are deleted on database re-opening.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestSafeEntry

  • Purpose: Tests the creation of a safe entry.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueEntryChecksum

  • Purpose: Tests the checksum verification of entries in the value log.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValidateWrite

  • Purpose: Tests the validation of writes to prevent overflow in value log file size.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestValueLogMeta

  • Purpose: Tests that value log entries do not contain txn meta, while LSM tree entries do.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Function: TestFirstVlogFile

  • Purpose: Tests if value log file IDs start from 1.
  • Parameters:
    • t (*testing.T): Testing object.
  • Returns: None.

Getting Started Relevance