Skip to content

Conversation

@Suor
Copy link
Contributor

@Suor Suor commented Feb 21, 2020

No description provided.

@Suor Suor changed the title gdrive: a pair of cleanup refactors [WIP] gdrive: a pair of cleanup refactors Feb 21, 2020
@Suor
Copy link
Contributor Author

Suor commented Feb 21, 2020

@efiop do we skip GDrive tests on travis?

Suor added 2 commits February 21, 2020 19:35
Employ @Retry(filter_errors) and @wrap_prop() to pack things up a bit.
- cache root transparently
- make cache dirs and ids symmetric, i.e. both using full paths
- implement .list_cache_paths() instead of .all() like in the rest of
the remotes
@skshetry
Copy link
Collaborator

@Suor, it only runs on master AFAIK.

@efiop
Copy link
Contributor

efiop commented Feb 21, 2020

@skshetry is correct, but we also run on upstream branches too. So you could create a PR from an upstream branch instead.

raise
return result

retry_re = re.compile(r"HttpError (403|500|502|503|504)")
Copy link
Contributor

Choose a reason for hiding this comment

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

great!, but we'll need to rebuilt it on the PyDrive2 side to get rid of this fragile stuff

),
_wrap_pydrive_retriable,
)
return retry(
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a simple way to write a debug message on a retry, btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can wrap a func, which you retry into @log_errors():

# ...
return retry(...)(log_errors(logger.error, stack=False)(func))

This will show errors, but there is no non-hacky way to show retries.

def _get_cached_remote_ids(self, path):
if not path:
return [self._bucket]
if self._cache_initialized:
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic is important, we don't want to initialize cache if it's not initialized yet

Copy link
Contributor

Choose a reason for hiding this comment

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

cache property init makes a call to self._get_remote_id itself to get root id. I'm not sure who would it behave with these changes

cache = {"dirs": defaultdict(list), "ids": {}}

cache["root_id"] = self._get_remote_id(self.path_info)
self._cache_path(self.path_info.path, cache["root_id"], cache)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we did't cache root id before in the cache itself, it might affect list all below - before it was returning only actual files in cache, now also directories under the root?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cached path -> id in a way, made it separately. Plus extra code on cache read side. We did not cache id -> path though. This might affect listing cache, you are right.

if not self._gdrive:
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive
GoogleAuth.DEFAULT_SETTINGS["client_config_backend"] = "settings"
Copy link
Contributor

Choose a reason for hiding this comment

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

not directly related - would really love this to go away from the class ... is there a good way? or at least assign the whole dict at once to DEFAULT_SETTINGS? This way it is done now is quite ugly and bloated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is. One can use GoogleAuth.DEFAULT_SETTINGS.update(), but the right way would be to make GoogleAuth accept settings as a dict not only file.

@Suor
Copy link
Contributor Author

Suor commented Feb 22, 2020

Closed in favor if #3382

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants