• Moti Cohen's avatar
    modules API: Support register unprefixed config parameters (#13656) · 15563450
    Moti Cohen authored
    PR #10285 introduced support for modules to register four types of
    configurations — Bool, Numeric, String, and Enum. Accessible through the
    Redis config file and the CONFIG command.
    
    With this PR, it will be possible to register configuration parameters
    without automatically prefixing the parameter names. This provides
    greater flexibility in configuration naming, enabling, for instance,
    both `bf-initial-size` or `initial-size` to be defined in the module
    without automatically prefixing with `<MODULE-NAME>.`. In addition it
    will also be possible to create a single additional alias via the same
    API. This brings us another step closer to integrate modules into redis
    core.
    
    **Example:** Register a configuration parameter `bf-initial-size` with
    an alias `initial-size` without the automatic module name prefix, set
    with new `REDISMODULE_CONFIG_UNPREFIXED` flag:
    ```
    RedisModule_RegisterBoolConfig(ctx, "bf-initial-size|initial-size", default_val, optflags | REDISMODULE_CONFIG_UNPREFIXED, getfn, setfn, applyfn, privdata);
    ```
    # API changes
    Related functions that now support unprefixed configuration flag
    (`REDISMODULE_CONFIG_UNPREFIXED`) along with optional alias:
    ```
    RedisModule_RegisterBoolConfig
    RedisModule_RegisterEnumConfig
    RedisModule_RegisterNumericConfig
    RedisModule_RegisterStringConfig
    ```
    
    # Implementation Details:
    `config.c`: On load server configuration, at function
    `loadServerConfigFromString()`, it collects all unknown configurations
    into `module_configs_queue` dictionary. These may include valid module
    configurations or invalid ones. They will be validated later by
    `loadModuleConfigs()` against the configurations declared by the loaded
    module(s).
    `Module.c:` The `ModuleConfig` structure has been modified to store now:
    (1) Full configuration name (2) Alias (3) Unprefixed flag status -
    ensuring that configurations retain their original registration format
    when triggered in notifications.
    
    Added error printout:
    This change introduces an error printout for unresolved configurations,
    detailing each unresolved parameter detected during startup. The last
    line in the output existed prior to this change and has been retained to
    systems relies on it:
    ```
    595011:M 18 Nov 2024 08:26:23.616 # Unresolved Configuration(s) Detected:
    595011:M 18 Nov 2024 08:26:23.616 #  >>> 'bf-initiel-size 8'
    595011:M 18 Nov 2024 08:26:23.616 #  >>> 'search-sizex 32'
    595011:M 18 Nov 2024 08:26:23.616 # Module Configuration detected without loadmodule directive or no ApplyConfig call: aborting
    ```
    
    # Backward Compatibility:
    Existing modules will function without modification, as the new
    functionality only applies if REDISMODULE_CONFIG_UNPREFIXED is
    explicitly set.
    
    # Module vs. Core API Conflict Behavior
    The new API allows to modules loading duplication of same configuration
    name or same configuration alias, just like redis core configuration
    allows (i.e. the users sets two configs with a different value, but
    these two configs are actually the same one). Unlike redis core, given a
    name and its alias, it doesn't allow have both configuration on load. To
    implement it, it is required to modify DS `module_configs_queue` to
    reflect the order of their loading and later on, during
    `loadModuleConfigs()`, resolve pairs of names and aliases and which one
    is the last one to apply. "Relaxing" this limitation can be deferred to
    a future update if necessary, but for now, we error in this case.
    15563450
redismodule.h 98.8 KB