Skip to content

feat(config): support multiple memcached servers via OWNCLOUD_MEMCACHED_SERVERS#517

Merged
DeepDiver1975 merged 2 commits into
masterfrom
feat/memcached-multiple-servers
Jul 9, 2026
Merged

feat(config): support multiple memcached servers via OWNCLOUD_MEMCACHED_SERVERS#517
DeepDiver1975 merged 2 commits into
masterfrom
feat/memcached-multiple-servers

Conversation

@DeepDiver1975

@DeepDiver1975 DeepDiver1975 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements Option A from the discussion on #489: adds a single JSON-encoded env var to define multiple memcached servers (with optional per-server weights).

Previously the memcached block in v24.04/overlay/etc/templates/config.php hard-coded exactly one [host, port] pair from OWNCLOUD_MEMCACHED_HOST / OWNCLOUD_MEMCACHED_PORT, while ownCloud core's memcached_servers accepts a list of [host, port] or [host, port, weight] tuples.

Details

  • New var OWNCLOUD_MEMCACHED_SERVERS — a JSON-encoded array of tuples, decoded with json_decode(...) guarded by is_array (the same pattern as OWNCLOUD_LOG_CONDITIONS):
    OWNCLOUD_MEMCACHED_SERVERS='[["mem1",11211,33],["mem2",11211]]'
    
  • Backward compatible: when the var is unset — or the JSON is invalid — it falls back to the existing single [HOST, PORT] pair. Existing single-server deployments are completely unaffected (var is unset by default).
  • v24.04 only, matching the convention that v20.04/v22.04 templates are frozen and only 22.04/24.04 are built by CI.
  • The container startup wait for memcached (wait-for-it in 15-database.sh) is skipped when OWNCLOUD_MEMCACHED_SERVERS is set, mirroring how the redis wait is skipped when OWNCLOUD_REDIS_SEEDS is set. This avoids the container failing to start by probing the default single HOST:PORT when the real cache is defined via the multi-server list.

Verification

  • php -l passes; bash -n 15-database.sh passes.
  • Behavioral check via php -r dumping $CONFIG['memcached_servers']:
    • multi-server JSON → two-server list with weight preserved;
    • unset → single ['memcached','11211'] fallback;
    • invalid JSON → single-pair fallback (guarded);
    • memcache.distributed/memcache.locking still \OC\Memcache\Memcached.
  • Startup-wait guard (stubbed wait-for-it): ENABLED=true+SERVERS unset → waits; ENABLED=true+SERVERS set → skipped; ENABLED=false → skipped.

Closes #489

🤖 Generated with Claude Code

…ED_SERVERS

The memcached config block hard-coded a single [host, port] pair built
from OWNCLOUD_MEMCACHED_HOST / OWNCLOUD_MEMCACHED_PORT, with no way to
define multiple servers or per-server weights that core's
'memcached_servers' supports.

Add OWNCLOUD_MEMCACHED_SERVERS, a JSON-encoded list of [host, port] or
[host, port, weight] tuples, reusing the json_decode pattern already used
for OWNCLOUD_LOG_CONDITIONS. It overrides the single-server pair when set
and falls back to it when unset or when the JSON is invalid, so existing
deployments are unaffected. Added to v24.04 only, matching the convention
that v20.04/v22.04 are frozen.

The container startup readiness probe (wait-for-it in 15-database.sh)
still targets HOST:PORT only and is intentionally left unchanged.

Closes #489

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>
@DeepDiver1975 DeepDiver1975 force-pushed the feat/memcached-multiple-servers branch from 976d3f3 to 4ae86e4 Compare July 8, 2026 19:38
@DeepDiver1975 DeepDiver1975 requested a review from phil-davis July 8, 2026 19:48
Comment thread ENVIRONMENT.md Outdated
The startup wait in 15-database.sh probed OWNCLOUD_MEMCACHED_HOST:PORT
whenever memcached was enabled and exited on timeout. With
OWNCLOUD_MEMCACHED_SERVERS set (and HOST left at its default), the
container could fail to start even though the configured servers are
reachable.

Guard the wait with `&& [[ ${OWNCLOUD_MEMCACHED_SERVERS} == "" ]]`,
mirroring how the redis wait is skipped when OWNCLOUD_REDIS_SEEDS is set.
Also drop the now-inaccurate ENVIRONMENT.md note that described the old
probing behaviour as a caveat of the new variable.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>
@DeepDiver1975 DeepDiver1975 merged commit f6ba3ed into master Jul 9, 2026
6 checks passed
@DeepDiver1975 DeepDiver1975 deleted the feat/memcached-multiple-servers branch July 9, 2026 14:26
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.

What is the correct way defining multiple memcached servers with envvars

2 participants