Skip to content

Add runtime management of eligible server options via CONFIG GET/SET#1965

Open
vazois wants to merge 3 commits into
mainfrom
vazois/runtime-config
Open

Add runtime management of eligible server options via CONFIG GET/SET#1965
vazois wants to merge 3 commits into
mainfrom
vazois/runtime-config

Conversation

@vazois

@vazois vazois commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

Adds runtime management of eligible GarnetServerOptions through the RESP CONFIG GET / CONFIG SET commands. These options can be viewed and adjusted at runtime because they are read live at their point of use and require no physical change to the running server (no restart, no reallocation).

How

  • ServerConfigType (libs/server/ServerConfigType.cs) is now a public enum augmented with a member per runtime-adjustable option, plus a COUNT sentinel. Time-based members carry an explicit unit suffix (_MS / _SECONDS / _MICROS) matching the underlying GarnetServerOptions property so the unit is unambiguous at every use site.
  • RuntimeServerConfig (libs/server/RuntimeServerConfig.cs, new public class) is a long[]-backed table indexed by ServerConfigType. It is allocation-free, contiguous, O(1) indexed, and read/written with Volatile (atomic on 64-bit). Each slot is a raw 8-byte cell whose interpretation (int / long / bool / enum / seconds-based timeout / string) is described by per-option metadata (ConfigKind). Values are seeded from GarnetServerOptions at startup (Init) and mutated at runtime via TrySet (with per-option range/type validation).
  • The table is held on StoreWrapper.runtimeConfig so the live value is reachable across both the server and cluster layers. GarnetServerOptions remains on StoreWrapper for options that are not runtime-adjustable.
  • ServerConfig.cs: CONFIG GET/CONFIG SET resolve parameter names (honoring aliases, e.g. cluster-timeoutcluster-node-timeout) via RuntimeServerConfig.TryGetType and read/write the table.
  • Read-only params (timeout, save, appendonly, databases) are exposed through CONFIG GET / GET * but reject CONFIG SET with a clear "read-only" error; their values are computed from live server state.
  • slave-read-only stays per-session, following Redis READWRITE/READONLY semantics, and is resolved by the CONFIG GET handler which has the session in scope.
  • Migrated the live read sites across libs/server and libs/cluster to read from the table.

Runtime-adjustable options included

cluster-node-timeout, replica-sync-delay, replica-offset-max-lag, aof-tail-witness-freq, aof-replay-max-drift, repl-diskless-sync-delay, repl-attach-timeout, cluster-replication-reestablishment-timeout, compaction-max-segments, compaction-force-delete, compaction-type, slowlog-log-slower-than, object-scan-count-limit, sg-get.

Tests

  • New tests in test/standalone/Garnet.test/RespConfigTests.cs:
    • ConfigGetSetRuntimeOptionsTest — round-trips integer, long, boolean, enum, seconds-timeout, alias, and multi-option forms.
    • ConfigSetRuntimeOptionValidationTest — rejects malformed / out-of-range values without mutating state.
    • ConfigGetAllAndReadOnlyRejectionTest — read-only params reject SET; GET * includes read-only + per-session slave-read-only.
  • Existing RespAdminCommandsTests.SimpleConfigGet continues to pass (timeout/save/appendonly/slave-read-only/databases/cluster-node-timeout).
  • Server, cluster, and test projects build clean (0 warnings, TreatWarningsAsErrors on); dotnet format --verify-no-changes clean.

Notes

Scope was intentionally limited to "Category A" fully runtime-safe options; not every option is wired up yet. Some previously-considered options (e.g. repl-sync-timeout, gossip-delay) were left out because they are captured at startup and would require additional plumbing.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Copilot-Session: 16393bf0-b771-4b90-a5f5-49cc389cd3fc

@vazois
vazois marked this pull request as ready for review July 23, 2026 18:43
Copilot AI review requested due to automatic review settings July 23, 2026 18:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a centralized RuntimeServerConfig table and wires CONFIG GET/CONFIG SET to manage a subset of server options at runtime, with call sites updated across server + cluster layers to read live values.

Changes:

  • Introduces RuntimeServerConfig (long[] + metadata) and expands ServerConfigType to cover runtime-adjustable and read-only CONFIG parameters.
  • Updates CONFIG GET/SET handling to resolve parameters via RuntimeServerConfig (including aliases) and formats responses via canonical names.
  • Migrates multiple option read sites (object scan, sg-get, compaction, replication timeouts/delays, etc.) to read from the runtime table; adds tests for round-tripping and validation.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/standalone/Garnet.test/RespConfigTests.cs Adds tests covering runtime CONFIG GET/SET round-trips, validation failures, and GET * contents.
libs/server/StoreWrapper.cs Adds shared runtimeConfig to StoreWrapper and ensures clones share the same table.
libs/server/Storage/Session/StorageSession.cs Plumbs RuntimeServerConfig into StorageSession and removes cached object-scan limit.
libs/server/Storage/Session/ObjectStore/Common.cs Reads object scan count limit from runtimeConfig at use site.
libs/server/ServerConfigType.cs Makes enum public and adds runtime-adjustable options with unit-suffixed members + COUNT sentinel.
libs/server/ServerConfig.cs Routes CONFIG name parsing through RuntimeServerConfig; rewrites CONFIG GET/SET to use runtime table.
libs/server/RuntimeServerConfig.cs New runtime-config table with metadata, parsing/validation, formatting, and alias resolution.
libs/server/Resp/RespServerSession.cs Uses runtime config for slowlog threshold initialization; removes cached sg-get flag.
libs/server/Resp/Objects/SharedObjectCommands.cs Uses runtime config for object scan count limit in RESP object commands.
libs/server/Resp/BasicCommands.cs Uses runtime config for sg-get decision in GET dispatch path.
libs/server/Databases/DatabaseManagerBase.cs Uses runtime config for compaction parameters.
libs/cluster/Server/Replication/ReplicationManager.cs Uses runtime config for replication reestablishment timeout and AOF tail witness delay.
libs/cluster/Server/Replication/ReplicaOps/ReplicaDisklessSync.cs Uses runtime config for replica attach timeout.
libs/cluster/Server/Replication/ReplicaOps/ReplicaDiskbasedSync.cs Uses runtime config for replica attach timeout.
libs/cluster/Server/Replication/ReplicaOps/AOFReplay/ReplicaReplaySession.cs Uses runtime config for replication offset max lag checks / sync replay decision.
libs/cluster/Server/Replication/ReplicaOps/AOFReplay/ReplicaReplayDriver.cs Uses runtime config for replay max drift, sync delay, and max-lag throttling.
libs/cluster/Server/Replication/PrimaryOps/DisklessReplication/ReplicationSyncManager.cs Uses runtime config for diskless sync delay.
libs/cluster/Server/Replication/PrimaryOps/AofOperations/AofSyncTask.cs Uses runtime config for replica sync delay used by AOF sync consumption.
libs/cluster/Server/Replication/PrimaryOps/AofOperations/AofSyncDriver.cs Uses runtime config for AOF tail witness frequency delay.
libs/cluster/Server/ClusterProvider.cs Exposes replication_offset_max_lag from runtime config in replication info metrics.

Comment on lines +40 to 44
// Extract requested parameters. All CONFIG parameters (settable and read-only) are served
// through the runtime config table.
List<ServerConfigType> parameters = null;
var returnAll = false;
for (var i = 0; i < parseState.Count; i++)
Comment on lines +235 to +242
case ConfigKind.Seconds:
{
if (!int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var seconds))
return $"ERR Invalid value for '{meta.Name}': expected an integer number of seconds.";
// <= 0 is stored as-is and interpreted as an infinite timeout on read.
Volatile.Write(ref values[(int)type], seconds);
return null;
}
Comment on lines +316 to +318
var slowLogThresholdConfig = storeWrapper.runtimeConfig.GetInt(ServerConfigType.SLOWLOG_LOG_SLOWER_THAN_MICROS);
if (slowLogThresholdConfig > 0)
slowLogThreshold = (long)(slowLogThresholdConfig * OutputScalingFactor.TimeStampToMicroseconds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants