Code Monkey home page Code Monkey logo

Comments (6)

masbug avatar masbug commented on June 23, 2024 1

@gcilinskas
As @erikn69 pointed out, extensive object caching breaks concurrency. The code of this adapter assumes that it's operating alone on a selected drive.
One way to partially work around this would be to disable all caching in the code (which would slow everything down considerably)...but that's only half of the fix - there's still the issue of mixing write, read, delete, create operations and you'd still have race conditions to solve.
Perhaps you can just change the approach and not work on the same folder from multiple threads/jobs/queues? Or just not delete the folder after you're done with it (I assume you use one job to fill the folder and another to consume what's in it and then delete the folder)?

from flysystem-google-drive-ext.

gcilinskas avatar gcilinskas commented on June 23, 2024 1

Yeah, manual human interaction with gdrive is possible on our side so removal of folders might be at random times. We are fetching data from api and saving its assets to gdrive in structured folders hierarchy.

clearCache method helped for now, performance for gdrive upload is not crucial for us. Regarding to racing conditions we did some workarounds with sleep functions, currently seems to work

We don't have options to change approaches in usage of gdrive folders

from flysystem-google-drive-ext.

masbug avatar masbug commented on June 23, 2024 1

Ok. So I guess you're doing something similar to:

lRetry:
try {
  ... small set of operations on the drive or a complete set with error mitigation
} catch(\Throwable $e) {
  sleep(rand()%4);
  $adapter->clearCache();
  if($retry-->0)
     goto lRetry;
}

from flysystem-google-drive-ext.

erikn69 avatar erikn69 commented on June 23, 2024

This package is using a little cache trick, if you delete a folder in Google drive manually, that folder still remains in cache even though it no longer exists in google drive (if you are using a long running script, because on every new instance it starts the connection and cache), maybe the function Storage::disk('google')->getDriver()->getAdapter()->clearCache(); before createDir will be useful to you (maybe with catch, only when there is these exception).

public function clearCache()
{
$this->cachedPaths = [];
$this->requestedIds = [];
$this->cacheFileObjects = [];
$this->cacheHasDirs = [];
}

@masbug is this a bug?, maybe i can make a fix

from flysystem-google-drive-ext.

gcilinskas avatar gcilinskas commented on June 23, 2024

Storage::disk('google')->getDriver()->getAdapter()->clearCache();
This one helped, thanks!
Just for information, Since I use queued jobs, I had to call this clearCache command not only once before creating directories, but also in every job class that was using google drive upload

from flysystem-google-drive-ext.

erikn69 avatar erikn69 commented on June 23, 2024

On limitation's section

Using display paths as identifiers for folders and files requires them to be unique. Unfortunately Google Drive allows users to create files and folders with same (displayed) names. In such cases when unique path cannot be determined this adapter chooses the oldest (first) instance

Concurrent use of same Google Drive might lead to unexpected problems due to heavy caching of file/folder identifiers and file objects.

So, for concurrent threads of queued jobs you have to do this workaround with cache, otherwise you get those errors, or when create a directory duplicate(created at the same time with same name) and you put a unique file or folder inside, the adapter will be able to reach it properly because it chooses the oldest (first), so, create directory, uncache the folder, then put file inside
I make a PR with uncacheFolder function, if it is merged it be available on the next release

$disk=\Storage::disk('google');    
$disk->createDir('test/testa');
//manually delete without adapter or other job create it first 
$dir=$disk->getDriver()->getAdapter()->getMetadata('test/testa');
$disk->getDriver()->getAdapter()->getService()->files->delete($dir['id']); 
//uncache
$disk->getDriver()->getAdapter()->uncacheFolder('test/testa'); 
// refresh id and put file
$disk->put('test/testa/file.txt', 'Contents1'); 

from flysystem-google-drive-ext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.