Hi NC Community,
Thanks for providing a huge backlog on all kinds of things, it has helped me over and over again before I made an account, because this time I can’t figure out a solution. Sorry for the long read!
TL;DR: oc_filecache is larger than the amount of files hosted (440GB vs 360GB). I try to delete records from it. I can read/write SQL, but PHP not so well. I have a hard time.
Nextcloud version (eg, 20.0.5): 18
Operating system and version (eg, Ubuntu 20.04): Debian 10
Apache or nginx version (eg, Apache 2.4.25): nxinx
PHP version (eg, 7.4):
The issue you are facing:
Nextcloud 18 is running fine. I installed it via the excellent Yunohost platform. The Yunohost bit is not relevant for my problem, I include it for completenes.
Now an upgrade from NC 18 to NC 20 is available.
Yunohost was not able to perform the upgrade. It makes a backup of NC18 (duplicating the database), then upgrades NC18 to NC20 (creating a new instance of the database), finally dropping the not needed NC18 copies in case of succes or rolling back changes when a problem is encountered.
The process was not quite clear to me, so I ran the upgrade while the system was using about 90% disk space, ie, 0.9TB out of about 1TB. 100GB seemed enough headroom for the upgrade.
The upgrade took quite long, and I found that one table in particular was larger than I expected, oc_filecache, at some 440GB. The upgrade failed, clearly due to lack of space.
I can increase the diskspace, but I really want to shrink the space used by oc_filecache.
I found I should use, and did run,
sudo -u nextcloud php /var/www/nextcloud/occ files:cleanup
for a week.
I also found that occ files:cleanup deletes records in oc_filecache that are related to non-existant storage ID’s. Some external storage has been configured, so I removed all of those.
Besides running occ files:cleanup, I ran manual deletes on the table (at higher fileid ranges) for records with storage ID not in the storage table. After a week I was down from 321 million to 318 million records; in MySQL show processlist;
told me the cleanup was at fileid 80 million of 420 million, so about 20% tablespace in one week.
I ran a delete on the database with a fixed storage ID, instead of a subselect on the storage table. That ran 5-10 times faster than the subselect variant.
I quit occ files:cleanup. Unexpectedly, it still caused a rollback. The processlist showed discrete deletes per record, so I expected them to be separate transactions. It seems that my manual deletes got caught in the same transaction, because after quitting occ files:cleanup, I was back at 321 million records in oc_filecache.
The loss of deletes would be temporary though, because now I could run manual deletes much faster. A batch of 10000 deletes would take just over 2 minutes, and a batch of 100000 scaled nicely to 18 minutes.
I took my chances with a batch of 1000000. That turned out too much at once:
MariaDB [nextcloud]> delete from oc_filecache where storage = 22 and fileid > 100000000 limit 1000000 ;
Query OK, 1000000 rows affected (10 hours 26 min 0.573 sec)
Not only did it run for 10 hours, somewhere after completion a rollback was triggered. This morning I was back at 321 million records, once again.
The data file does not use freed up space either, or is growing faster than I can pump deletes into it:
ls -hs oc_filecache.ibd
441G oc_filecache.ibd
How can I remove records from oc_filecache, and preferably return the freed space to the OS?
Is this the first time you’ve seen this error? (Y/N):
Not sure whether it’s an error, or the result of not expected but explainable behaviour.
Steps to replicate it:
I think this is the culprit:
- Configure external storage
- Browse external storage
- Files are copied from external storage to the database
The output of your Nextcloud log in Admin > Logging:
It is rather largish; the downloaded log is 28M (it doesn’t take the log level ticks in regard) . Mostly it’s Error and Fatal, Doctrine\DBAL\Exception\LockWaitTimeoutException, I expect while running large batches of manual deletes. There are no errors after 20210203.
[core] Error: Doctrine\DBAL\Exception\LockWaitTimeoutException: An exception occurred while executing 'DELETE FROM `oc_share` WHERE `item_type` in ('file', 'folder') AND NOT EXISTS (SELECT `fileid` FROM `oc_filecache` WHERE `file_source` = `fileid`)':
SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction at <<closure>>
0. /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 169
Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException("An exception oc ... n", Doctrine\DBAL\Dr ... ]})
1. /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 145
Doctrine\DBAL\DBALException::wrapException(Doctrine\DBAL\Driver\PDOMySql\Driver {}, Doctrine\DBAL\Dr ... ]}, "An exception oc ... n")
2. /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 1063
Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Doctrine\DBAL\Driver\PDOMySql\Driver {}, Doctrine\DBAL\Dr ... ]}, "DELETE FROM `oc ... )", [])
3. /var/www/nextcloud/lib/private/DB/Connection.php line 220
Doctrine\DBAL\Connection->executeUpdate("DELETE FROM `oc ... )", [], [])
4. /var/www/nextcloud/apps/files_sharing/lib/DeleteOrphanedSharesJob.php line 62
OC\DB\Connection->executeUpdate("DELETE FROM `oc ... )")
5. /var/www/nextcloud/lib/private/BackgroundJob/Job.php line 61
OCA\Files_Sharing\DeleteOrphanedSharesJob->run(null)
6. /var/www/nextcloud/lib/private/BackgroundJob/TimedJob.php line 55
OC\BackgroundJob\Job->execute(OC\BackgroundJob\JobList {}, OC\Log {})
7. /var/www/nextcloud/cron.php line 125
OC\BackgroundJob\TimedJob->execute(OC\BackgroundJob\JobList {}, OC\Log {})
at 2021-02-03T14:41:01+00:00
The output of your config.php file in /path/to/nextcloud
(make sure you remove any identifiable information!):
# cat /var/www/nextcloud/config/config.php
<?php
$CONFIG = array (
'passwordsalt' => '',
'secret' => '',
'trusted_domains' =>
array (
0 => '',
1 => '',
),
'datadirectory' => '/home/yunohost.app/nextcloud/data',
'dbtype' => 'mysql',
'version' => '18.0.4.2',
'overwrite.cli.url' => 'https://online.osba.nl',
'dbname' => 'nextcloud',
'dbhost' => 'localhost',
'dbport' => '',
'dbtableprefix' => 'oc_',
'dbuser' => '',
'dbpassword' => '',
'installed' => true,
'instanceid' => '',
'ldapIgnoreNamingRules' => false,
'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
'updatechecker' => false,
'memcache.local' => '\\OC\\Memcache\\APCu',
'integrity.check.disabled' => true,
'filelocking.enabled' => true,
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => 'localhost',
'port' => '6379',
'timeout' => '0.0',
'password' => '',
),
'logout_url' => 'https://online.osba.nl/yunohost/sso/?action=logout',
'maintenance' => false,
'loglevel' => 2,
'config_is_read_only' => true,
'hashing_default_password' => true,
'app_install_overwrite' =>
array (
0 => 'calendar',
1 => 'social',
2 => 'spreed',
3 => 'folderplayer',
),
);
The output of your Apache/nginx/system log in /var/log/____
:
It does not seem there’s much Nextcloud-related. I will paste more on request