Understanding File Locking and Redis

Hi,

I’m trying to understand and troubleshoot how transactional file locking works in Nextcloud as it relates to Redis.

I’m running Nextcloud in Docker with Apache, Postgres, and Redis, behind a separate nginx proxy for HTTPS. The problem I’ve noticed is that if I make lots of filesystem changes in a row (like, for example, deleting a folder with lots of items and then immediately recreating it with a fresh set of files), my sync client picks the changes up and hammers the server with requests. This causes many files to become locked in Postgres until I delete the locks manually in the database. I wasn’t originally using Redis to try to solve this problem, but have since added it to try to address it.

The docs are a bit vague in this aspect, but I was under the impression that Redis is a lot more reliable with regards to transactional file locking, and that Postgres isn’t used for locking files if Redis is present. Yet my installation is creating locks in the database still.

Is my understanding of how this works incorrect? And if not, how should I set about troubleshooting this problem?

Thanks for any advice you can offer.

Nextcloud version (eg, 12.0.2): 13.0.2
Operating system and version (eg, Ubuntu 17.04): Ubuntu 18.04 (containerized using Docker)
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.10 (Debian)
PHP version (eg, 7.1): 7.1.17

$ cat app/redis.config.php
<?php
$CONFIG = array (
  'filelocking.enabled' => true,
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => array(
    'host' => 'redis',
    'port' => 6379,
  ),
);

$ 

I figured it out!

For anyone who was having problems diagnosing file locking and Redis, hit this endpoint (as an admin) and see what it says:

https://[YOUR NEXTCLOUD HOSTNAME]/ocs/v2.php/apps/serverinfo/api/v1/info

As it turns out, this endpoint gives you a lot of useful debugging info, including whether Redis is used for caching. In my case, it wasn’t.

    <memcache.local>\OC\Memcache\APCu</memcache.local>
    <memcache.distributed>none</memcache.distributed>
    <filelocking.enabled>yes</filelocking.enabled>
    <memcache.locking>none</memcache.locking>

And it turned out that the file I was editing in my Docker configs was being copied to the wrong place! Once I figured it out, I was able to update my config file:

<?php
$CONFIG = array (
  'filelocking.enabled' => 'true',
  'memcache.local' => '\OC\Memcache\Redis',
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => array(
    'host' => 'redis',
    'port' => 6379,
  ),
);

After moving it to my Nextcloud install (under the config directory), I’m now using Redis for caching and locking!

    <memcache.local>\OC\Memcache\Redis</memcache.local>
    <memcache.distributed>none</memcache.distributed>
    <filelocking.enabled>yes</filelocking.enabled>
    <memcache.locking>\OC\Memcache\Redis</memcache.locking>

It remains to be seen if this solves the file locking issues I saw, but at least I have a chance of that now. :slight_smile:

3 Likes