Skip to main content

config.go

config.go - Overview

This file defines and manages the configuration settings for the DiceDB application, including reading from and writing to a configuration file, handling command-line flags, and setting default values.

Detailed Documentation

DiceDBVersion

  • Purpose: Stores the version of DiceDB. Initialized in the init function.
  • Type: string

init

  • Purpose: Initializes the DiceDBVersion variable by reading the VERSION file from the project root.
  • Parameters: None
  • Returns: None

Config

  • Purpose: A global variable that holds the DiceDB configuration.
  • Type: *DiceDBConfig

DiceDBConfig

  • Purpose: Defines the structure of the DiceDB configuration, including host, port, username, password, log level, and various engine and WAL-related settings.
  • Fields:
    • Host: The host address to bind to. (default: "0.0.0.0")
    • Port: The port to bind to. (default: 7379)
    • Username: The username to use for authentication. (default: "dicedb")
    • Password: The password to use for authentication. (default: "")
    • LogLevel: The log level. (default: "info")
    • EnableWatch: Enable support for .WATCH commands and real-time reactivity. (default: false)
    • MaxClients: The maximum number of clients to accept. (default: 20000)
    • NumShards: Number of shards to create. Defaults to the number of cores. (default: -1)
    • Engine: The engine to use, values: ironhawk. (default: "ironhawk")
    • EnableWAL: Enable write-ahead logging. (default: false)
    • WALDir: The directory to store WAL segments. (default: "/var/log/dicedb")
    • WALMode: WAL mode to use, values: buffered, unbuffered. (default: "buffered")
    • WALWriteMode: WAL file write mode to use, values: default, fsync. (default: "default")
    • WALBufferSizeMB: The size of the wal write buffer in megabytes. (default: 1)
    • WALRotationMode: WAL rotation mode to use, values: segment-size, time. (default: "segment-size")
    • WALMaxSegmentSizeMB: The maximum size of a wal segment file in megabytes before rotation. (default: 16)
    • WALMaxSegmentRotationTimeSec: The time interval (in seconds) after which a wal segment is rotated. (default: 60)
    • WALBufferSyncIntervalMillis: The interval (in milliseconds) at which the wal write buffer is synced to disk. (default: 200)
    • WALRetentionMode: The new horizon for wal segment post cleanup. values: num-segments, time, checkpoint. (default: "num-segments")
    • WALMaxSegmentCount: The maximum number of segments to retain, if the retention mode is 'num-segments'. (default: 10)
    • WALMaxSegmentRetentionDurationSec: The maximum duration (in seconds) for wal segments retention. (default: 600)
    • WALRecoveryMode: WAL recovery mode in case of a corruption, values: strict, truncate, ignore. (default: "strict")

Load

  • Purpose: Loads the configuration from a file and command-line flags using viper.
  • Parameters:
    • flags: A pointer to a pflag.FlagSet containing command-line flags.
  • Returns: None

InitConfig

  • Purpose: Initializes the configuration file. Creates a new one if it doesn't exist or overwrites the existing config with new key-values based on the --overwrite flag.
  • Parameters:
    • flags: A pointer to a pflag.FlagSet containing command-line flags, including the --overwrite flag.
  • Returns: None

configureMetadataDir

  • Purpose: Creates the default metadata directory with owner-only permissions. If creation fails, it falls back to using the current directory.
  • Parameters: None
  • Returns: None

initDefaultConfig

  • Purpose: Initializes a DiceDBConfig struct with default values specified in the struct's default tags.
  • Parameters: None
  • Returns: A pointer to a DiceDBConfig struct with default values.

ForceInit

  • Purpose: Initializes the given configuration with default values for any fields that are currently set to their zero value.
  • Parameters:
    • config: A pointer to a DiceDBConfig struct to initialize.
  • Returns: None

Code Examples

Not applicable.

Getting Started Relevance