Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SharedCache to forward numeric id of wrapped cache #27172

Merged
merged 1 commit into from
Feb 21, 2017

Conversation

PVince81
Copy link
Contributor

Description

The SharedCache is a CacheJail which is a CacheWrapper.
Its method getNumericStorageId() was returning a non-existing attribute value $this->numericId which was always false.
This fix makes sure it returns the numeric id of the underlying $this->sourceCache instead.

Related Issue

None

Motivation and Context

Because it fixes the unit test for #27042 where a cross-storage move requires the numeric id of the source storage (shared cache).

How Has This Been Tested?

Unit test only and ran all tests locally on #27042 with mysql.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

TODO:

  • investigate all code paths using this method to make sure that returning a proper value doesn't cause other side effects

@jvillafanez crazy stuff...

@PVince81
Copy link
Contributor Author

Before this fix I ran all tests and added this:

diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index fb7f9596fe..7f2aa5d1e3 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -505,6 +505,13 @@ class Cache implements ICache {
                        list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
                        list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
 
+                       if (is_null($sourceStorageId) || $sourceStorageId === false) {
+                               throw new \Exception('Invalid source storage id: ' . $sourceStorageId);
+                       }
+                       if (is_null($targetStorageId) || $targetStorageId === false) {
+                               throw new \Exception('Invalid target storage id: ' . $targetStorageId);
+                       }
+
                        // sql for final update
                        $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` =  ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';

It seem no test failed, maybe no test covers this code path apart from my new test in #27042

@PVince81
Copy link
Contributor Author

Oh well, let's add it here as well. At least we can have this in 10.0 but I wouldn't backport unless we find a real bug associated with this.

@PVince81
Copy link
Contributor Author

AHA, see a real life manifestation of the bug through the OCS Share API (before the fix): storage is false
storage-false

@PVince81
Copy link
Contributor Author

I grepped the code for getNumericStorageId and all usage occurrences I found were from methods that get overridden by CacheWrapper (from SharedCache) which would redirect the call to the underlying source cache.

The only occurrence is the one I fixed in this PR.
Cache::getMoveInfo() is a protected method and is not part of the ICache interface, so is not overridden by CacheWrapper and so the internal call to getNumericStorageId would reach the top level method from SharedCache when called.

@PVince81
Copy link
Contributor Author

I have now removed SharedCache::getNumericStorageId() because it's parent class CacheWrapper::getNumericStorageId() already does what's necessary.

@PVince81
Copy link
Contributor Author

@jvillafanez please review

@PVince81
Copy link
Contributor Author

Tests passed on Jenkins but unpublished

@@ -505,6 +505,13 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);

if (is_null($sourceStorageId) || $sourceStorageId === false) {
throw new \Exception('Invalid source storage id: ' . $sourceStorageId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to throw a better exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions ? This should actually never happen... I added it here in case we missed some code paths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc says it throws a \OC\DatabaseException. I think it could fit if the expected handling for that exception matches what we want to do. We'll need to change the docs if it doesn't fit.

@jvillafanez
Copy link
Member

I guess this needs to be tested by QA. I can't foresee all the possibilities and error cases of this change

@PVince81
Copy link
Contributor Author

I already looked at all code paths leading to it here #27172 (comment).

Maybe the additional things to test, just in case, is related to cross-storage moving.

I'll check if there are integration tests for this.

@PVince81
Copy link
Contributor Author

@jvillafanez I just added integration tests for cross-storage move.

These did not trigger the exception in question from above, so it seems to work fine.

@PVince81
Copy link
Contributor Author

@jvillafanez I added the exception in the PHPDoc.

Funnily enough that method isn't on any public interface 🙈

@jvillafanez
Copy link
Member

I added the exception in the PHPDoc.

That's cheating!! 🤣

I guess it's fine since this is a bug fix. 👍

@PVince81
Copy link
Contributor Author

@DeepDiver1975 Jenkins needs the boot

14:56:24 Fire up the mysql docker
14:56:24 docker: Error response from daemon: grpc: the connection is unavailable.

(third observed occurrence on three different PRs)

The CacheWrapper will properly forward the call to the wrapped cache.
@PVince81
Copy link
Contributor Author

Rebased for CI

@PVince81
Copy link
Contributor Author

add backport of this onto #27172 which requires it

@lock
Copy link

lock bot commented Aug 3, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants