Repository navigation
feat(config): show and edit the Redis database number in settings - #2053
Conversation
Silo could only be pointed at one Redis address. After a Sentinel failover that address is a read-only replica, and Redis writes fail until an operator changes REDIS_URL and restarts. RedisConfig had Sentinel fields, but nothing could set the Sentinel addresses, so that branch never ran. A redis.url or REDIS_URL with a master_name parameter now names a Sentinel deployment, in the go-redis failover URL form. One parser builds every Redis client and the event bus. They ask Sentinel for the master and connect to it on the database number in the URL, and the event bus scopes its channels to that number as it does for a single server. Commands reach a new master when go-redis opens its next connection. A subscription moves only when its connection breaks, so behind Sentinel the event bus would stay subscribed to a master that froze or dropped off the network. For a Sentinel URL the bus reads its subscriptions with a deadline, pings them, and redials one that has been silent for 10 seconds. Close ends the redials before it closes the subscriptions, so it waits for the attempt in flight and not for one redial after another. A single-server URL keeps the receive path it had. go-redis dials a Sentinel client's subscription with no timeout unless the URL sets dial_timeout, so a redial to a master that is gone waits for the kernel. The parser fills in the 5 seconds go-redis uses everywhere else. The parser rejects what go-redis accepts in a Sentinel URL and then mishandles: the replica options (go-redis panics on two of them, and replica_only sends commands to a replica), a blank master name, a Sentinel address without a host and a port, a parameter go-redis would drop without an error, a + in a parameter, which go-redis reads as a space, and a dial_timeout or read_timeout of 0 or less. go-redis reads such a read timeout as no timeout, and a redial into a frozen master then never returns. With such a dial timeout it fails every dial at once. A single-server URL is read as before, with two exceptions. Whitespace around it is trimmed. A URL with a part go-redis drops, after a # or in a pair that contains a ;, is refused when master_name appears anywhere in its query string or fragment. Such a URL was most likely meant for Sentinel and would otherwise be used as a single-server URL for the Sentinel port. A Sentinel URL carries the Redis password in its query string. Parse errors no longer quote any part of the URL, and the event bus dials a value it could not parse only when it is a host:port or a socket path made of letters, digits, dots, hyphens and underscores. Both ended up in the log. Subscribe now returns an error once Close has begun. Close takes the list of subscriptions once, and a subscription confirmed after that kept its connection, and behind Sentinel its goroutines and handler, until the process ended. The SentinelMaster, SentinelAddresses and SentinelPassword fields are removed, with the two settings keys and silo.yaml import lines that fed the master name and the password. Refs Silo-Server#1844
The Redis database number is part of redis.url, and that setting is write-only. An admin could not see which number an install was on, and changing it meant entering the whole URL again, password included. The number is what keeps installs that share one Redis server apart, so it is a value an operator sets per install and wants to confirm. redis.db is a new setting: empty by default, otherwise a whole number of 0 or more. When it is set it replaces the database number in the saved redis.url, for a single-server URL and for a Sentinel URL. RedisConfig carries it and RedisConfig.Options applies it. Every Redis client, the event bus with its @dbn channel names, and the connection check are built from those options. A change needs a restart, like redis.url. An error from Options names the value it could not read, so a number that is not valid is no longer reported as an invalid URL. While redis.db is empty, GET /api/v2/admin/settings/effective reports the number in use under redis.db: the one in the saved URL, or 0 when the URL has none. What a save of redis.db stores depends only on the settings that save leaves in place, on the batch endpoint and the single-key endpoint alike: nothing when there is no redis.url, nothing when the URL already names the number, and the number otherwise. A batch that also sets redis.url is judged against the URL it sets. Earlier saves do not change the outcome, so an install that once had a number saved and cleared behaves like one that never had one. A save that does not include redis.db leaves the stored number alone. A process started with REDIS_URL takes the whole connection from the environment, database number included, and does not apply redis.db. There a save of a number is refused, and the effective value is the number in REDIS_URL, or 0 when REDIS_URL cannot be parsed. Clearing redis.db is accepted, so a saved number can be removed while the environment supplies the connection. The startup code that hands REDIS_URL to the config and to the settings handlers moves into two functions with tests. The Redis section of the infrastructure settings page and the Redis row of the setup wizard get a "Database number" field under the connection URL. It is read-only when REDIS_URL supplies the connection. Editing the URL stages the number the field shows along with it, so the number on screen is the number the save keeps and the connection check tests. A new URL would otherwise move the install to the number in that URL while the field still showed the old one. Clearing the field makes the install follow the URL, and switching Redis off clears the number with the URL. The settings search finds the field. docs/admin-settings-api.md describes how the setting is read and written, and docs/architecture/redis-event-bus.md says which number the channel names follow. The silo.yaml import does not read redis.db. The key never existed in silo.yaml, and the number in an imported redis.url keeps working. Refs Silo-Server#1863
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (25)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| if err != nil { | ||
| // If the URL cannot be parsed, treat it as a simple address. | ||
| opts = &redis.Options{Addr: redisURL} | ||
| client = redis.NewClient(unparsedRedisOptions(cfg.URL, err)) |
There was a problem hiding this comment.
Database mismatch in internal/cache/redis.go occurs because the bare-address fallback builds Redis options from cfg.URL alone and discards the new redis.db override: the admin save paths accept a legacy host:port with redis.db set to 5 and display database 5, but the event bus still connects and scopes its channels to database 0. Apply the validated database override to the fallback options before constructing the client.
Prompt for LLM
File internal/cache/redis.go:
Line 176:
Database mismatch in internal/cache/redis.go occurs because the bare-address fallback builds Redis options from cfg.URL alone and discards the new redis.db override: the admin save paths accept a legacy host:port with redis.db set to 5 and display database 5, but the event bus still connects and scopes its channels to database 0. Apply the validated database override to the fallback options before constructing the client.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
This was right for 3ec80d1 and is fixed in 4ae8bc5. unparsedRedisOptions now validates redis.db with config.NormalizeRedisDB and sets Options.DB on the bare-address options before building the client (internal/cache/redis.go). The protocol cases in redis_eventbus_test.go ("redis.db on a bare address", "normalized redis.db on a bare address", "redis.db 0 on a bare address") check the selected database and the channel scope. internal/cache tests pass at the current head.
There was a problem hiding this comment.
Thanks for the follow-up. Based on your description, 4ae8bc5e3 addresses the original finding: the bare-address fallback now validates redis.db and applies it to Options.DB before constructing the client.
The protocol tests cover database selection and channel scope for explicit, normalized, and zero overrides. With internal/cache tests passing, I consider this finding addressed based on the reported changes; I haven’t independently inspected the updated commit.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Quick104
left a comment
There was a problem hiding this comment.
Reviewed the two commits after the #1859 prerequisite (3ec80d1e1, 4ae8bc5e3). One finding, inline below.
I'm also merging main into the branch to clear the conflict left by #1859 landing. It's a merge commit, not a rebase, so nothing gets force-pushed. A summary with the scores follows once the fixes are pushed.
Silo-Server#1859 landed on main as 387b2db with the same content as the prerequisite commit 3bf59f5. The conflicts were in files this branch changes on top of that commit, and keep this branch's side. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
In the setup wizard, emptying the Connection URL staged an empty redis.db, and typing a URL again left it empty. The save then moved the install to the database the new URL names instead of the number on screen. The admin settings page was not affected, because its secret field turns an emptied input into "keep saved". stageRedisUrl now stages the number on screen with every URL edit, including an empty URL. The server already stores no redis.db when the same write leaves no redis.url, so switching Redis off still removes a saved number. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Review summaryReviewed head: Addressed
Remaining
Validated featuresI couldn't read the validation board, because the token used for this review lacks User manual and clients
Review methodClaude Code (claude-opus-5-5[1m]) ran a multi-angle review with verification, and Codex (gpt-6.1-sol) ran one adversarial round. Codex found the wizard defect. Its fit note on v1 is the open question above. VerdictFit: 7/10 · Readiness: 7/10 — conditional
|
|
The setup wizard’s Redis URL empty-and-retype behavior is not covered by the described recording. Please add a short recording of clearing the URL and entering it again while the displayed database number stays unchanged ( Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Problem
Closes #1863
Related issue: N/A
Validation tasks: none
Admins cannot see or change the Redis database number without re-entering the whole connection URL, including its credentials. This adds a Database number field under Connection URL in Admin > Settings > Storage & Database > Redis and in the setup wizard.
Approach
The non-secret
redis.dbsetting shows the database in use. An empty value follows the number in the saved URL; a number overrides it for every Redis client and the event bus, including the event bus’s legacy bare-address fallback. Changing it requires a restart. Editing the URL preserves the number shown in the field unless the admin clears that field, and the connection check uses both staged values.REDIS_URLowns the whole connection when it is supplied by the environment. Both forms show its number read-only, and the wizard offers View so it remains inspectable and checkable. Apple, Android, and Jellyfin clients need no UI changes; this is server administration. The settings API documentation is updated. User-manual updates are tracked in Silo-Server/siloserver.org#82.Dependency: #1859 has merged. The branch merges
main, so its diff againstmainholds only the database-number change.Validation
@db5channels.4b93d049e: in the setup wizard, emptying the URL and typing it again no longer drops the database number. Regression tests inredisDraft.test.tsandStorageStep.test.tsxfail before the fix and pass after it; theredisDraft,InfrastructureSettings, andStorageStepsuites pass, along with prettier, eslint, andtsc.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2053/
Desktop and mobile comparisons show the new field in Admin Settings and the setup wizard, including read-only environment-managed connections. A recording shows editing, checking, saving, and reloading. Before:
3bf59f5ec; after frontend:3ec80d1e1. The evidence page identifies the API builds and test data.Risks
Changing the number selects a different Redis database and event-channel namespace after restart. Check the connection before saving, and keep every process of an install on the same number.
REDIS_URLstill takes precedence. This does not migrate Redis data or prevent saving a number the Redis server cannot provide.Checklist
AI Disclosure
main, and wrote4b93d049e.Note
Add
redis.dbsetting to show and edit the Redis database numberredis.dbsetting that overrides the database number parsed fromredis.url. It is shown and editable in admin infrastructure settings and the setup wizard storage step, with read-only display whenREDIS_URLmanages Redis.RedisConfigviaRedisConfig.Options, so the database override applies everywhere (redis.go, admin_settings.go).redis.dbrow when it differs from the URL's database; redundant rows are removed and invalid values (negative, fractional, nonnumeric) are rejected.REDIS_URLnow discards any storedredis.dboverride (seeRedisConfig.WithBootstrapURLin admin_settings.go and watcher.go); constructor signatures forcache.NewEventBusandcache.newRedisClientchanged from URL strings toRedisConfig.Macroscope summarized 4b93d04.