nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.32k stars 4.06k forks source link

Clarification: Is APCu acceptable for `memcache.locking`? #43895

Open joshtrichards opened 8 months ago

joshtrichards commented 8 months ago

Is APCu acceptable for usage for transactional file locking under any circumstances we consider "supported"? If it's acceptable, are there caveats?

Background: Last year @linuxserver set a default value of for memcache.locking that utilizes APCu in their Nextcloud image: https://github.com/linuxserver/docker-nextcloud/commit/aaa5539e72f9539724962f62eb5b355aee53d90e via linuxserver/docker-nextcloud#317.

This was apparently in response to the performance warning added in v27 (when the database is being used for locking - i.e. when Redis isn't configured): linuxserver/docker-nextcloud#319

The end result is that all LinuxServer image users are now using APCu for transactional file locking rather than the database (unless the admin has explicitly configured Redis). This achieved their goal: no longer a warning about using the database for locking.

But is this a valid configuration?

Our documentation is not 100% clear whether we support the use of APCu for memcache.locking:

We have fallback code that appears to prefer a NULL_CACHE (over using APCu as a fallback) for locking: https://github.com/nextcloud/server/blob/f2f1074396b12be31f84a3db30f7e95c501c4aab/lib/private/Memcache/Factory.php#L101-L103

My understanding is that APCu can maybe work for mod_php and some PHP-FPM operating modes. The key requirement being that the operating mode in-use must permit all processes to use a shared APCu cache. However, even if the application server layer is fine, anything happening at the command-line will not use the same APCu cache (effectively being blind to Transaction File Locking). This could lead to problems in areas like occ files commands (and possibly others) I'd think.

So is APCu acceptable at all? Is it worse - or better - than a NULL_CACHE?

TODO:

solracsf commented 8 months ago

This answers part of it:

https://github.com/nextcloud/server/blob/6cac8d0df459dc921e022b4368ee968013fddc02/config/config.sample.php#L2198-L2199

Basically, every time PHP get's restarted, APCu is cleared, so are the locks. This is not the case with Redis by default.

Adding a check that explicitly disallows APCu for memcache.locking even if specified explicitly in the config?

I would say push a warning basically with the same message than above 👍

kesselb commented 8 months ago

https://github.com/nextcloud/server/issues/38796#issuecomment-1593782871