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

New Cacheable Flysystem Adapter #29077

Merged
merged 4 commits into from
Nov 3, 2017

Conversation

Hemant-Mann
Copy link
Contributor

@Hemant-Mann Hemant-Mann commented Sep 21, 2017

Description

I have added a new cacheable flysystem adapter in owncloud so that we can connect flysystem adapters and owncloud storage

Related Issue

None

Motivation and Context

This change is required because current flysystem implementation does not utilize caching and according to owncloud documentation this should be a must feature

Within a single PHP request, ownCloud might call the same storage methods repeatedly, due to different checks which it needs to carry out. As a result, there is the potential to incur significant overhead, when working with the underlying filesystem

How Has This Been Tested?

This has been tested with the new Dropbox App in which instead of extending the storage OCP\Files\Storage\FlysystemStorageAdapter I now extend it with OCP\Files\Storage\CacheableFlysystemAdapter

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.

@phil-davis
Copy link
Contributor

Note: the Travis-CI UI test jobs that make use of SauceLabs fail because they do not have any SauceLabs credentials. This is because the PR has come from a forked repo. Only PRs coming from the "master" ownCloud core repo have access to the ownCloud SauceLabs credentials, which are stored securely in the ownCloud Travis-CI account.

@pmaier1 pmaier1 added this to the development milestone Sep 28, 2017
@pmaier1 pmaier1 added the p2-high Escalation, on top of current planning, release blocker label Sep 28, 2017
$this->cacheContents[$location] = $this->flysystem->getMetadata($location);
} catch (FileNotFoundException $e) {
// do not store this info in cache as it might interfere with Upload process
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

@CLAassistant
Copy link

CLAassistant commented Oct 9, 2017

CLA assistant check
All committers have signed the CLA.


public function buildPath($path) {
$location = parent::buildPath($path);
if ($this->isCaseInsensitiveStorage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ewww, is that a thing in Dropbox ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes unfortunately it is
Suppose you have the following directory structure

Foo/
├── bar
│   ├── foo.txt
│   └── some_another_file.txt
└── somefile.txt

In one case dropbox api was returning the folder name Foo as both Foo and foo due to which the directory list of the folder Foo was coming as empty but in reality it was not

* Check if Cache Contains the data for given path, if not then get the data
* from flysystem and store it in cache for this request lifetime
*
* @param string $path Path to file/folder
Copy link
Contributor

Choose a reason for hiding this comment

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

document $overRideCache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done see below this line

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

See comments above, more to come

try {
$this->cacheContents[$location] = $this->flysystem->getMetadata($location);
} catch (FileNotFoundException $e) {
// do not store this info in cache as it might interfere with Upload process
Copy link
Contributor

Choose a reason for hiding this comment

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

We should look into storing this info at some point. I know it works because we do this for other storages like DAV.

Maybe the upload interference is a missing stat clear in another place in the code.

I suggest to look into this separately.

Copy link
Contributor Author

@Hemant-Mann Hemant-Mann Oct 10, 2017

Choose a reason for hiding this comment

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

Yes i faced some problem with upload process if i stored the info that file is not present in storage. i don't remember exactly what it was

* Public Cacheable storage adapter to be extended to connect to
* flysystem adapters
*
* @since 10.0.x
Copy link
Contributor

Choose a reason for hiding this comment

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

make that 10.0.4

* @return string storage id
* @since 10.0
*/
abstract public function getId();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you should redefined this.

Please make the CacheableFlysystemAdpater extend directly from FlysystemStorageAdapter which already provides this method.

@PVince81
Copy link
Contributor

Is this mtime caching specific to Dropbox ? https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L71

Isn't this information already available in this cache ? If not, does it make sense to bring this into your cacheable adapter as well or is it very specific to Dropbox ?

@PVince81
Copy link
Contributor

Shouldn't you cache the results you got here https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L144 into the local cache as well ?

@PVince81
Copy link
Contributor

Seems isCaseInsensitiveStorage is unused, remove ? https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L58


default:
unset($this->cacheContents[$this->getCacheLocation($path)]);
return parent::fopen($path, $mode);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@Hemant-Mann Hemant-Mann Oct 10, 2017

Choose a reason for hiding this comment

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

it should be possible to invalidate the cache after an upload, see how it's done here: https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/DAV.php#L405

But then I'll have to modify the original Flysystem.php which does not have any concept of cache
OR
i'll have to duplicate the fopen function here and then add cache clear line after upload

I added it before to prevent copy/paste of duplicate code and even if file upload failed the cache is only set for a single request so I did not think it would be an issue

@Hemant-Mann
Copy link
Contributor Author

Is this mtime caching specific to Dropbox ? https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L71

Isn't this information already available in this cache ? If not, does it make sense to bring this into your cacheable adapter as well or is it very specific to Dropbox ?

Yes it is specific to dropbox because in API v2 we don't get the modified time of folders so what I did was find the modified time of the files in the folder and get the largest of those values and this info is not available in cache

@Hemant-Mann
Copy link
Contributor Author

Shouldn't you cache the results you got here https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L144 into the local cache as well ?

Uhh I am only fetching this info if not found in cache here https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L139

because the cache is only for a single request cycle i think this should work

@Hemant-Mann
Copy link
Contributor Author

Seems isCaseInsensitiveStorage is unused, remove ? https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/Dropbox.php#L58

Yes it is unused in Storage/Dropbox.php so we can remove it
but it is used here -https://github.com/owncloud/files_external_dropbox/blob/master/lib/Storage/CacheableFlysystemAdapter.php#L69

Where you asked

ewww, is that a thing in Dropbox ?!

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍 fine for now, will need further optimizations in the future by adding the cache stuff in more code paths (fopen, etc)

@PVince81
Copy link
Contributor

PVince81 commented Nov 2, 2017

@Hemant-Mann can you rebase ? Then do another PR to backport to stable10.

@Hemant-Mann
Copy link
Contributor Author

Okay I'll do that

@Hemant-Mann
Copy link
Contributor Author

Stable 10 PR #29414

👍 fine for now, will need further optimizations in the future by adding the cache stuff in more code paths (fopen, etc)

Yes we can definitely add cache stuff at more places like fopen

@PVince81
Copy link
Contributor

PVince81 commented Nov 2, 2017

@Hemant-Mann thanks for the backport, can you also rebase this PR to kick CI ?

@phil-davis
Copy link
Contributor

phil-davis commented Nov 2, 2017

Note: this PR is coming from a forked repo, so the Travis-Saucelabs UI tests will fail due to Saucelabs authentication issues.

@Hemant-Mann
Copy link
Contributor Author

Hemant-Mann commented Nov 2, 2017

@PVince81 Can you explain a little bit as to why I have to rebase it?

Is it related to @phil-davis issue

Note: this PR is coming from a forked repo, so the Travis-Saucelabs UI tests will fail due to Saucelabs authentication issues.

@phil-davis
Copy link
Contributor

I see it also did not trigger the drone CI. There were some times recently when drone was down, so the job did not trigger. So rebasing will make the drone CI run.
(It will make all the other CI run also, and Travis will fail for the reason above, which is fine since we understand why)

@Hemant-Mann
Copy link
Contributor Author

I rebased the branch with master but while pushing it rejected the commits and then I had to do a git pull which resulted in a merge commit

commit 5b1a17b6df9316d02f01d095ca64afc8a8869f60 (HEAD -> cacheable_storage_adapter)
Merge: b066f40340 fb6e3978b9
Author: Hemant Mann <hemant.mann121@gmail.com>
Date:   Thu Nov 2 22:01:50 2017 +0530

    Merge branch 'cacheable_storage_adapter' of https://github.com/Hemant-Mann/owncloud_core into cacheable_storage_adapter

So should I push this rebased branch?

@phil-davis
Copy link
Contributor

You can locally do an interactive rebase:

git rebase -i master

and squash the commits together in whatever way seems logical (squashing out the merge commit...)
then force push:

git push -f

that will replace whatever is here in the PR branch with whatever you have done locally.

@Hemant-Mann
Copy link
Contributor Author

Hemant-Mann commented Nov 2, 2017

Thanks I was just missing the -f flag in push that's why it was rejecting it

@PVince81 PVince81 merged commit 817d730 into owncloud:master Nov 3, 2017
@lock
Copy link

lock bot commented Aug 2, 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 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4 - To release p2-high Escalation, on top of current planning, release blocker status/STALE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants