Skip to content

Integrity violation during parallel DELETE #28981

Closed

Description

@PVince81

Edit: steps here #28981 (comment)

Observed on 10.0.3 RC1.

Steps

All I did was delete a bunch of files within a folder with desktop client 2.3.3rc2.

Expected

All files deleted

Actual

The first deleted file IMG_1472.JPG did not get deleted. Sync client reports locking error.
Log contains integrity check error which likely exited the PHP request and didn't release the locks.

Server Environment

ownCloud Server 10.0.3RC1
openSUSE Leap 42.2
apache2-2.4.23-8.9.1.x86_64
apache2-mod_php7-7.0.7-14.9.1.x86_64

user-key encryption enabled
folder is shared with one user and one link share.

Client Environment

openSUSE Leap 42.3
Desktop client 2.3.3rc2

Investigation

First DELETE entry in owncloud.log:

{
  "reqId": "Wbbhw38AAAIAAE6ypX8AAAAM",
  "level": 4,
  "time": "2017-09-11T19:19:32+00:00",
  "remoteAddr": "77.177.215.233",
  "user": "vincent",
  "app": "webdav",
  "method": "DELETE",
  "url": "/remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG",
  "message": "Exception: 
{"Message":"An exception occurred while executing '
UPDATE `oc_filecache` SET `storage` =  ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =?
WHERE `fileid` = ?' with params [
	1,
	"files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572",
	"cac9d13bb8d42fd3e25767a9859e2577",
	"IMG_1472.JPG.d1505157572",
	129728,
	127965
]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-cac9d13bb8d42fd3e25767a9859e2577' for key 'fs_storage_path_hash'","Exception":"Doctrine\\\\DBAL\\\\Exception\\\\UniqueConstraintViolationException","Code":0,"Trace":"
#0 /srv/www/htdocs/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(128): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))\n
#1 /srv/www/htdocs/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(855): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'UPDATE `oc_file...', Array)\n
#2 /srv/www/htdocs/owncloud/lib/private/DB/Connection.php(190): Doctrine\DBAL\Connection->executeQuery('UPDATE `oc_file...', Array, Array, NULL)\n
#3 /srv/www/htdocs/owncloud/lib/private/Files/Cache/Cache.php(534): OC\DB\Connection->executeQuery('UPDATE `oc_file...', Array)\n
#4 /srv/www/htdocs/owncloud/lib/private/Files/Cache/Cache.php(476): OC\Files\Cache\Cache->moveFromCache(Object(OC\Files\Cache\HomeCache), 'files_encryptio...', 'files_encryptio...')\n
#5 /srv/www/htdocs/owncloud/lib/private/Files/Cache/Updater.php(196): OC\Files\Cache\Cache->move('files_encryptio...', 'files_encryptio...')\n
#6 /srv/www/htdocs/owncloud/lib/private/Files/View.php(326): OC\Files\Cache\Updater->renameFromStorage(Object(OCA\Files_Trashbin\Storage), 'files_encryptio...', 'files_encryptio...')\n
#7 /srv/www/htdocs/owncloud/lib/private/Files/View.php(803): OC\Files\View->renameUpdate(Object(OCA\Files_Trashbin\Storage), Object(OCA\Files_Trashbin\Storage), 'files_encryptio...', 'files_encryptio...')\n
#8 /srv/www/htdocs/owncloud/lib/private/Encryption/Keys/Storage.php(284): OC\Files\View->rename('/vincent/files_...', '/vincent/files_...')\n
#9 /srv/www/htdocs/owncloud/lib/private/Files/Storage/Wrapper/Encryption.php(286): OC\Encryption\Keys\Storage->renameKeys('/vincent/files/...', '/vincent/files_...')\n
#10 /srv/www/htdocs/owncloud/lib/private/Files/Storage/Wrapper/Wrapper.php(272): OC\Files\Storage\Wrapper\Encryption->rename('files/clientsyn...', 'files_trashbin/...')\n
#11 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Storage.php(103): OC\Files\Storage\Wrapper\Wrapper->rename('files/clientsyn...', 'files_trashbin/...')\n
#12 /srv/www/htdocs/owncloud/lib/private/Files/Storage/Wrapper/Wrapper.php(566): OCA\Files_Trashbin\Storage->rename('files/clientsyn...', 'files_trashbin/...')\n
#13 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Trashbin.php(278): OC\Files\Storage\Wrapper\Wrapper->moveFromStorage(Object(OCA\Files_Trashbin\Storage), 'files/clientsyn...', 'files_trashbin/...')\n
#14 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Storage.php(185): OCA\Files_Trashbin\Trashbin::move2trash('clientsync/petr...')\n
#15 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Storage.php(120): OCA\Files_Trashbin\Storage->doDelete('files/clientsyn...', 'unlink')\n
#16 /srv/www/htdocs/owncloud/lib/private/Files/View.php(1123): OCA\Files_Trashbin\Storage->unlink('files/clientsyn...')\n
#17 /srv/www/htdocs/owncloud/lib/private/Files/View.php(693): OC\Files\View->basicOperation('unlink', '/clientsync/pet...', Array)\n
#18 /srv/www/htdocs/owncloud/apps/dav/lib/Connector/Sabre/File.php(366): OC\Files\View->unlink('/clientsync/pet...')\n
#19 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/Tree.php(179): OCA\DAV\Connector\Sabre\File->delete()\n
#20 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/CorePlugin.php(287): Sabre\DAV\Tree->delete('files/vincent/c...')\n
#21 [internal function]: Sabre\DAV\CorePlugin->httpDelete(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n
#22 /srv/www/htdocs/owncloud/lib/composer/sabre/event/lib/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n
#23 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/Server.php(479): Sabre\Event\EventEmitter->emit('method:DELETE', Array)\n
#24 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/Server.php(254): Sabre\DAV\Server->invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n
#25 /srv/www/htdocs/owncloud/apps/dav/lib/Server.php(234): Sabre\DAV\Server->exec()\n
#26 /srv/www/htdocs/owncloud/apps/dav/appinfo/v2/remote.php(31): OCA\DAV\Server->exec()\n
#27 /srv/www/htdocs/owncloud/remote.php(165): require_once('/srv/www/htdocs...')\n
#28 {main}","File":"/srv/www/htdocs/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php","Line":66,"User":"vincent"}
}

access log grep:

vincent-server:/var/log/apache2 # grep IMG_1472 owncloud.vincentpetry.net-access_log
77.177.215.233 - vincent Wbbhw38AAAIAAE6ypX8AAAAM [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 500 686 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbh938AAAIAAE9563sAAAAH [11/Sep/2017:21:20:23 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 423 269 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbh@38AAAIAACpyBcIAAAAF [11/Sep/2017:21:20:27 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 423 269 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"

access log from the same time:

77.177.215.233 - vincent Wbbhw38AAAIAAE6ypX8AAAAM [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 500 686 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAB2ddrIAAAAA [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130774.webm HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAE9cuygAAAAP [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130704.JPG HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAAu1gdsAAAAE [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130600.webm HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAE9466cAAAAD [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130763.webm HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"

Looks like a parallel DELETE.

DB entries from after the failure

MariaDB [owncloud]> select * from oc_filecache where path like '%IMG_1472%' order by path;
+--------+---------+----------------------------------------------------------------------------------------------------------------------------+----------------------------------+--------+----------------------------+----------+----------+---------+------------+-----------+----------------------------------+------------------+---------------+-------------+-----------------------------------------------------------------------------------------------------+
| fileid | storage | path                                                                                                                       | path_hash                        | parent | name                       | mimetype | mimepart | size    | mtime      | encrypted | etag                             | unencrypted_size | storage_mtime | permissions | checksum                                                                                            |
+--------+---------+----------------------------------------------------------------------------------------------------------------------------+----------------------------------+--------+----------------------------+----------+----------+---------+------------+-----------+----------------------------------+------------------+---------------+-------------+-----------------------------------------------------------------------------------------------------+
| 127967 |       1 | files/clientsync/petry/pics/Family_Private/IMG_1472.JPG                                                                    | 94339a8a9ef196f7b338d8acf73afe96 | 107288 | IMG_1472.JPG               |       15 |        6 | 1492862 | 1500557250 |         1 | 1dc429800fe05c0fc36a496a5668d16d |                0 |    1500557250 |          27 | SHA1:752b3d229855f8f97f4b389e282ca1257c2b7914 MD5:7e3f101c4ed7f4921e2583d6256b38d6 ADLER32:8cc8df85 |
| 127965 |       1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG                                              | a2a584c289342fe39befa9d961a2bd0b | 107291 | IMG_1472.JPG               |        1 |        2 |    1568 | 1501949677 |         0 | 5985eeed4713c                    |                0 |    1501949677 |          31 |                                                                                                     |
| 127966 |       1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE                            | 092a3ad1a1b8b25b5337c6b6f4aa55ad | 127965 | OC_DEFAULT_MODULE          |        1 |        2 |    1568 | 1501949677 |         0 | 5985eeed4bdcf                    |                0 |    1501949677 |          31 |                                                                                                     |
| 127976 |       1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/fileKey                    | 075d589573878f57448940ec045808fa | 127966 | fileKey                    |       21 |       14 |      32 | 1501949677 |         0 | 4565f9a1d0e223dd62f6bc75b9967192 |                0 |    1501949677 |          27 |                                                                                                     |
| 127977 |       1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/pubShare_0a1edf68.shareKey | f62c36fbf2af0683a8b74097879e7664 | 127966 | pubShare_0a1edf68.shareKey |       21 |       14 |     512 | 1501949677 |         0 | 639ade4f028dc745a6282559f3becfe1 |                0 |    1501949677 |          27 |                                                                                                     |
| 127978 |       1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/tingting.shareKey          | a9d66d3aebea7776d020c7fe7e4961a9 | 127966 | tingting.shareKey          |       21 |       14 |     512 | 1501949677 |         0 | b3ad5c37a87a042199fb1220c4ddd8e0 |                0 |    1501949677 |          27 |                                                                                                     |
| 127975 |       1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/vincent.shareKey           | 12cb611b6f2eae5b6d81ee7d1febce9c | 127966 | vincent.shareKey           |       21 |       14 |     512 | 1501949677 |         0 | 42ddeeb0675e28384ced4627ce5bbbcc |                0 |    1501949677 |          27 |                                                                                                     |
| 129729 |       1 | files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572                                                        | cac9d13bb8d42fd3e25767a9859e2577 | 129728 | IMG_1472.JPG.d1505157572   |        1 |        2 |      -1 | 1501949677 |         0 | 59b6e1c412236                    |                0 |    1501949677 |          31 |                                                                                                     |
+--------+---------+----------------------------------------------------------------------------------------------------------------------------+----------------------------------+--------+----------------------------+----------+----------+---------+------------+-----------+----------------------------------+------------------+---------------+-------------+-----------------------------------------------------------------------------------------------------+
8 rows in set (0.03 sec)

Disk entries

data/vincent/files_trashbin/files/IMG_1472.JPG.d1505157572
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/vincent.shareKey
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/fileKey
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/pubShare_0a1edf68.shareKey
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/tingting.shareKey

What we observe:

  • file was physically moved to trash but not in filecache
  • file keys folder and contents was moved to trash, but only the main folder's entry was moved to trash in filecache
  • file keys entry already exists in trash but at the same time still exists in the original location, with its original file id
  • from looking at the file id of the deleted file keys folder in trash, the fileid is much higher so this entry was inserted, not moved. the original entry still has a lower file id so it's likely to be the correct one

What ghost has created this bogus trash key entry ?

Order of operations (as tested locally with v10.0.3RC1 and encryption):

  1. Webdav DELETE on remote.php/dav/...
  2. move2trash: file is physically moved to the trashbin
  3. move2trash deeper: keys folder is physically moved to trashbin
  4. keys folder trashbin update in filecache
  5. back to move2trash: trashstorage cache updater rename of original file

Ideas to explore:

  • this is the new DAV endpoint that sets up more than necessary on delete: implicit scan of the keys during deletion ??

  • did a cron run at this time and somehow triggered a scan ? (background scan on size=-1 folders?) => seems not, could not reproduce with local breakpoint / sleep

  • it's the parallel DELETE that caused some implicit rescans ? => not reproducible locally, but could still be that

    • with a sleep before renaming keys I get a mysql deadlock
  • it's not getstoragestats as there was no such call around this

  • parent "files_trashbin/files" has been recreated in a haste after emptying trashbin ?? (I did empty the trashbin before the deletion) => likely unrelated

Activity

  1. added
    p2-high
    on Sep 11, 2017
  2. added this to the milestone on Sep 11, 2017
  3. self-assigned this
    on Sep 11, 2017
  4. PVince81 commented on Sep 11, 2017

    @PVince81
    ContributorAuthor

    Note, this is not an "upsert" like issue. There is clearly some process that somehow has inserted the key folder entry in the filecache before the code from the deletion could do it.

    I suspect some background scanner or some other process that scanned the encryption folder for keys.

  5. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    One potential bug I see is that it seems the background scanner (in cron) is scanning any entry that has size=-1 regardless where it is in the cash, even if it's on the home storage outside of "files/". I have observed already that encryption keys are not always stored properly in oc_filecache and running the background scan makes these appear. Since they are outside of "files/" I assume the background scanner is scanning there.

    Now maybe there's a race condition where it is possible for the unscanned encryption key folders (size=-1) to be partially moved to trash on-disk but not yet in the file cache, and the background scanner when running decides to scan this folder because it finds a parent entry with size=-1. This would explain why the extra encryption folder entry has been created.

    I'm now trying to find a way to reproduce this theory by putting sleep calls in specific locations.

    In the end I think we'll need to fix the background scanner to be limited to "files/" when dealing with the home storage. I'd still like to have a reproducible case to be able to confirm that this is indeed the problem and that the fix resolves this.

  6. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    Note: the bogus additional entry has size=-1 in my DB but the other key entries didn't, so this means they were scanned already previously. The question so far is what folder would need to have size=-1 to be rescanned.

  7. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    Uh oh, it looks like it's even more complex. This might mean that I'm really unlucky with race conditions...

    I have stepped through a single DELETE operation and observed the contents of the database.
    The order is as follows:

    1. Webdav DELETE arrives on remote.php/dav/files/...
    2. move2trash is called at some point
    3. file is moved to trash physically
    4. encryption keys are moved to trash physically
    5. filecache update for encryption keys
    6. filecache update for original file

    Now what I observed is that directly after step 5, the database looked like this:

    MariaDB [owncloud]> select * from oc_filecache where size=-1;
    +--------+---------+-----------------------------------------------------------------------------------+----------------------------------+--------+----------------------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+----------+
    | fileid | storage | path                                                                              | path_hash                        | parent | name                 | mimetype | mimepart | size | mtime      | storage_mtime | encrypted | unencrypted_size | etag          | permissions | checksum |
    +--------+---------+-----------------------------------------------------------------------------------+----------------------------------+--------+----------------------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+----------+
    |      9 |       2 |                                                                                   | d41d8cd98f00b204e9800998ecf8427e |     -1 |                      |        2 |        1 |   -1 | 1505208832 |    1505208832 |         0 |                0 | 59b7aa00accbe |          23 |          |
    |     28 |       1 | files_encryption                                                                  | 171a8829416be21834bef1b79079dde8 |      1 | files_encryption     |        2 |        1 |   -1 | 1505207189 |    1505207189 |         0 |                0 | 59b7a3880d317 |          31 |          |
    |     32 |       1 | files_encryption/keys                                                             | c2d6b95afad8b0ebffae4702fceab715 |     28 | keys                 |        2 |        1 |   -1 | 1505209113 |    1505209113 |         0 |                0 | 59b7a395df131 |          31 |          |
    |    863 |       1 | files_encryption/keys/files_trashbin/files/test.txt.d1505208968                   | f5e671286aa8fdd01a8226030d32ded4 |    869 | test.txt.d1505208968 |        2 |        1 |   -1 | 1505208904 |    1505208904 |         0 |                0 | 59b7aa4887980 |          31 |          |
    |    864 |       1 | files_encryption/keys/files_trashbin/files/test.txt.d1505208968/OC_DEFAULT_MODULE | c7ed15682a0a626b626f255365d5fc59 |    863 | OC_DEFAULT_MODULE    |        2 |        1 |   -1 | 1505208904 |    1505208904 |         0 |                0 | 59b7aa4888b95 |          31 |          |
    |    868 |       1 | files_encryption/keys/files_trashbin                                              | 88c7f524b7a398637bd8a7446fffab76 |     32 | files_trashbin       |        2 |        1 |   -1 | 1505209113 |    1505209113 |         0 |                0 | 59b7ab198e1a3 |          31 |          |
    |    869 |       1 | files_encryption/keys/files_trashbin/files                                        | 1c9f05bf71d1f3602de8c2d8ec61ca7e |    868 | files                |        2 |        1 |   -1 | 1505209129 |    1505209129 |         0 |                0 | 59b7ab1995010 |          31 |          |
    +--------+---------+-----------------------------------------------------------------------------------+----------------------------------+--------+----------------------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+----------+
    

    As you can see, the folder "files_encryption/keys/files_trashbin/files" has a size of -1.

    Now for this one deletion it isn't that bad because we already moved the keys to trash. Running cron.php at this stage would just adjust the sizes and also find the other keys that weren't in oc_filecache in the first place.

    The deletion succeeds.

    But now, with this knowledge, imagine what happens with a parallel delete and spray some cron background scan magic in the mix. If we go through the stages above and stop after step 5), let's call this one delete A. Now have a parallel delete for another file B that stops at step 4). Our database now has "files_encryption/keys/files_trashbin/files" entry with a size of -1, but also there's a deletion process for file B that has moved its keys folder physically but hasn't updated the filecache yet. Now start cron.php and have the background scanner run. The background scanner sees that "files_encryption/keys/files_trashbin/files" has a size of -1 so it rescans it, and finds the keys from B that are on disk but not in-filecache. 💥 we have a new filecache entry for the keys. Once deletion for B continues, it will try and update the filecache by moving the keys entries, but can't, because this one already exists! => integrity constraint violation.

    This is still theoretical but still possible. I'll try and reproduce it with some sleep magic... Stay tuned.

  8. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    Ah, and usually the scanner sets scan locks but such locks are limited to the "files/" folder. So the race condition above cannot be caught by locks as there is no lock on the "files_encryption" folder...

  9. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    Could not reproduce the issue so far.

    I do observe the "size=-1" after a single deletion.

    It seems that the steps so far are as follows:

    1. Empty trashbin: this would also remove the "files_encryption/keys/files_trashbin/files" entry completely. (I did empty trashbin on my server as well, so it is likely related!)
    2. Delete any file: the keys are moved to trash and the entry "files_encryption/keys/files_trashbin/files"
    3. ???
    4. Run background scanner to have it scan un-indexed entries

    From here, I need to find what step 3 is. It likely involves deleting another file but having it sleep between moving keys on FS and moving keys in filecache. My repeated local attempts have failed. Need to look deeper to find out why.

  10. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    Found improved but more complex steps:

    1. occ app:enable encryption
    2. occ encryption:enable
    3. occ encryption:select-encryption-type user-keys -y
    4. Delete some stuff to trash (ex: welcome.txt)
    5. Empty trash, this deletes the "files_encryption/keys/files_trashbin/files" entry.
    6. Create a file "deletea.txt"
    7. update oc_jobs set last_run=0,last_checked=0,reserved_at=0;
    8. Run cron.php to have the background scan get rid of the "-1" sizes for "deletea.txt" (important to control scan priority)
    9. Create a file "test.txt". This one will only have partial keys in filecache with size "-1"
    10. Delete "test.txt" with webdav new endpoint, this recreates "files_encryption/keys/files_trashbin/files" with size -1
    11. Apply patch from below
    12. update oc_jobs set last_run=0,last_checked=0,reserved_at=0;
    13. Delete "deletea.txt" with webdav new endpoint
    14. While it's sleeping, rerun cron.php to have background job scan: this rescans "files_encryption/keys/files_trashbin/files" and would find the keys that are on-disk and not in filecache
    15. Wait for the sleep to end

    Sleep Patch:

    diff --git a/lib/private/Files/Cache/Updater.php b/lib/private/Files/Cache/Updater.php
    index a9e15ca50c..174b01db7f 100644
    --- a/lib/private/Files/Cache/Updater.php
    +++ b/lib/private/Files/Cache/Updater.php
    @@ -192,6 +192,9 @@ class Updater implements IUpdater {
                                    $this->cache->remove($target);
                            }
     
    +                       if ((strpos($target, 'trash') !== false) && (strpos($target, 'deletea.txt') !== false)) {
    +                               sleep(30);
    +                       }
                            if ($sourceStorage === $this->storage) {
                                    $this->cache->move($source, $target);
                            } else {

    The patch is for pausing at the exact moment where the cache update started and the move is done.
    This is important because the cache update usually checks if the target exists and deletes it first. Here we put the sleep just after that check but before the actual moving of cache entries.

    Result:

    {"reqId":"SQFZjXGpuk3XF5DGHPdr","level":4,"time":"2017-09-12T12:54:30+00:00","remoteAddr":"127.0.0.1","user":"admin","app":"webdav","method":"DELETE","url":"\/owncloud\/remote.php\/dav\/files\/admin\/test\/sub\/deletea.txt","message":"Exception: {\"Message\":\"An exception occurred while executing 'UPDATE `oc_filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?' with params [2, \\\"files_encryption\\\\\\\/keys\\\\\\\/files_trashbin\\\\\\\/files\\\\\\\/deletea.txt.d1505220840\\\\\\\/OC_DEFAULT_MODULE\\\", \\\"17e9aa1a2c36824c9f5e637df155442e\\\", \\\"64\\\"]:\\n\\nSQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-17e9aa1a2c36824c9f5e637df155442e' for key 'fs_storage_path_hash'\",\"Exception\":\"Doctrine\\\\DBAL\\\\Exception\\\\UniqueConstraintViolationException\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/DBALException.php(128): Doctrine\\\\DBAL\\\\Driver\\\\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException))\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/Statement.php(177): Doctrine\\\\DBAL\\\\DBALException::driverExceptionDuringQuery(Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOMySql\\\\Driver), Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException), 'UPDATE `oc_file...', Array)\\n#2 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Cache\\\/Cache.php(532): Doctrine\\\\DBAL\\\\Statement->execute(Array)\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Cache\\\/Cache.php(476): OC\\\\Files\\\\Cache\\\\Cache->moveFromCache(Object(OC\\\\Files\\\\Cache\\\\HomeCache), 'files_encryptio...', 'files_encryptio...')\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Cache\\\/Updater.php(199): OC\\\\Files\\\\Cache\\\\Cache->move('files_encryptio...', 'files_encryptio...')\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php(326): OC\\\\Files\\\\Cache\\\\Updater->renameFromStorage(Object(OCA\\\\Files_Trashbin\\\\Storage), 'files_encryptio...', 'files_encryptio...')\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php(803): OC\\\\Files\\\\View->renameUpdate(Object(OCA\\\\Files_Trashbin\\\\Storage), Object(OCA\\\\Files_Trashbin\\\\Storage), 'files_encryptio...', 'files_encryptio...')\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Encryption\\\/Keys\\\/Storage.php(284): OC\\\\Files\\\\View->rename('\\\/admin\\\/files_en...', '\\\/admin\\\/files_en...')\\n#8 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Storage\\\/Wrapper\\\/Encryption.php(286): OC\\\\Encryption\\\\Keys\\\\Storage->renameKeys('\\\/admin\\\/files\\\/te...', '\\\/admin\\\/files_tr...')\\n#9 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Storage\\\/Wrapper\\\/Wrapper.php(272): OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption->rename('files\\\/test\\\/sub\\\/...', 'files_trashbin\\\/...')\\n#10 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_trashbin\\\/lib\\\/Storage.php(103): OC\\\\Files\\\\Storage\\\\Wrapper\\\\Wrapper->rename('files\\\/test\\\/sub\\\/...', 'files_trashbin\\\/...')\\n#11 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Storage\\\/Wrapper\\\/Wrapper.php(566): OCA\\\\Files_Trashbin\\\\Storage->rename('files\\\/test\\\/sub\\\/...', 'files_trashbin\\\/...')\\n#12 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_trashbin\\\/lib\\\/Trashbin.php(278): OC\\\\Files\\\\Storage\\\\Wrapper\\\\Wrapper->moveFromStorage(Object(OCA\\\\Files_Trashbin\\\\Storage), 'files\\\/test\\\/sub\\\/...', 'files_trashbin\\\/...')\\n#13 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_trashbin\\\/lib\\\/Storage.php(185): OCA\\\\Files_Trashbin\\\\Trashbin::move2trash('test\\\/sub\\\/delete...')\\n#14 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_trashbin\\\/lib\\\/Storage.php(120): OCA\\\\Files_Trashbin\\\\Storage->doDelete('files\\\/test\\\/sub\\\/...', 'unlink')\\n#15 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php(1123): OCA\\\\Files_Trashbin\\\\Storage->unlink('files\\\/test\\\/sub\\\/...')\\n#16 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php(693): OC\\\\Files\\\\View->basicOperation('unlink', '\\\/test\\\/sub\\\/delet...', Array)\\n#17 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/dav\\\/lib\\\/Connector\\\/Sabre\\\/File.php(366): OC\\\\Files\\\\View->unlink('\\\/test\\\/sub\\\/delet...')\\n#18 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Tree.php(179): OCA\\\\DAV\\\\Connector\\\\Sabre\\\\File->delete()\\n#19 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/CorePlugin.php(287): Sabre\\\\DAV\\\\Tree->delete('files\\\/admin\\\/tes...')\\n#20 [internal function]: Sabre\\\\DAV\\\\CorePlugin->httpDelete(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#21 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/sabre\\\/event\\\/lib\\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\\n#22 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(479): Sabre\\\\Event\\\\EventEmitter->emit('method:DELETE', Array)\\n#23 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(254): Sabre\\\\DAV\\\\Server->invokeMethod(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#24 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/dav\\\/lib\\\/Server.php(234): Sabre\\\\DAV\\\\Server->exec()\\n#25 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/dav\\\/appinfo\\\/v2\\\/remote.php(31): OCA\\\\DAV\\\\Server->exec()\\n#26 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/remote.php(165): require_once('\\\/srv\\\/www\\\/htdocs...')\\n#27 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/composer\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/Driver\\\/AbstractMySQLDriver.php\",\"Line\":66,\"User\":\"admin\"}"}
    
  11. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor
    • fix background scan
    • search all issues for similar messages, could be exactly this case => none found, am I really that unlucky ?
  12. PVince81 commented on Sep 12, 2017

    @PVince81
    ContributorAuthor

    Fix is here: #28987

  13. modified the milestones: , QA on Sep 13, 2017
  14. lock commented on Aug 1, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  15. locked as resolved and limited conversation to collaborators on Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type:Bugp2-highstatus/STALE

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions