Skip to main content

discard.go

discard.go - Overview

This file implements a mechanism for tracking and managing discard stats for value log files. It uses a memory-mapped file to persist the discard information.

discardStats

  • Purpose: Keeps track of the amount of data that could be discarded for a given logfile.
  • Fields:
    • MmapFile: *z.MmapFile - Memory-mapped file for persistent storage.
    • opt: Options - Database options.
    • nextEmptySlot: int - Index of the next available slot in the memory-mapped file.

InitDiscardStats

  • Purpose: Initializes the discard stats by opening or creating the memory-mapped file.
  • Parameters:
    • opt: Options - Database options.
  • Returns:
    • *discardStats - A pointer to the initialized discardStats struct.
    • error - An error, if any.

discardStats.Len

  • Purpose: Returns the number of entries in the discard stats.
  • Parameters: None
  • Returns: int - The number of entries.

discardStats.Less

  • Purpose: Compares two discard stats entries.
  • Parameters:
    • i: int - Index of the first entry.
    • j: int - Index of the second entry.
  • Returns: bool - True if the first entry's file ID is less than the second's, false otherwise.

discardStats.Swap

  • Purpose: Swaps two discard stats entries.
  • Parameters:
    • i: int - Index of the first entry.
    • j: int - Index of the second entry.
  • Returns: None

discardStats.get

  • Purpose: Retrieves a uint64 value from the memory-mapped file at a given offset.
  • Parameters:
    • offset: int - The offset in the memory-mapped file.
  • Returns: uint64 - The value at the specified offset.

discardStats.set

  • Purpose: Sets a uint64 value in the memory-mapped file at a given offset.
  • Parameters:
    • offset: int - The offset in the memory-mapped file.
    • val: uint64 - The value to set.
  • Returns: None

discardStats.zeroOut

  • Purpose: Zeroes out the next empty slot in the memory-mapped file.
  • Parameters: None
  • Returns: None

discardStats.maxSlot

  • Purpose: Returns the maximum number of slots available in the memory-mapped file.
  • Parameters: None
  • Returns: int - The maximum number of slots.

discardStats.Update

  • Purpose: Updates the discard stats for a given file ID.
  • Parameters:
    • fidu: uint32 - The file ID.
    • discard: int64 - The amount to increment the discard stats by (can be negative to reset).
  • Returns: int64 - The updated discard value.

discardStats.Iterate

  • Purpose: Iterates over the discard stats, calling a function for each entry.
  • Parameters:
    • f: func(fid, stats uint64) - The function to call for each entry (file ID and stats).
  • Returns: None

discardStats.MaxDiscard

  • Purpose: Returns the file ID with the maximum discard bytes.
  • Parameters: None
  • Returns:
    • uint32 - The file ID with the maximum discard.
    • int64 - The maximum discard value.