Skip to content

drive: constrain list by filter - #5023

Merged
ivandeex merged 1 commit into
rclone:masterfrom
ivandeex:pr-gdrivetrick
Oct 7, 2021
Merged

ivandeex merged 1 commit into
rclone:masterfrom
ivandeex:pr-gdrivetrick

Conversation

@ivandeex

@ivandeex ivandeex commented Feb 13, 2021 •

Copy link
Copy Markdown
Member

What is the purpose of this change?

The Google Drive API allows to place a clause like modifiedTime > '2012-06-04T12:00:00' in the query parameters, so the filterflags --max-age and --min-age can be applied directly at the directory listing phase rather than in a filter. This is extremely helpful when we want to do an incremental backup of a remote drive with large number of files but the number of recently changed file is small.

Was the change discussed in an issue or in the forum before?

This PR is recovered from the dead PR #3806. See discussion there.

The approach looks very ingenious
I'm a bit concerned about the muddling of the layers - however that is the way of most optimizations!
I think there might be a better way of getting the info from the sync layer to the backend layer but I haven't figured it out yet.
I don't think this optimization will work with rclone sync --delete-excluded

We now have the machinery to do this patch properly. Namely we are passing the filter flags in the context. So the google drive backend could read the min age and max age directly from there.
So I think it would be worth rescuing and adjusting to the new context use (calling filter.GetConfig(ctx))

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@ivandeex ivandeex self-assigned this Feb 15, 2021
@ivandeex
ivandeex marked this pull request as draft February 15, 2021 06:03
@ivandeex
ivandeex marked this pull request as ready for review February 16, 2021 23:47
@ivandeex
ivandeex requested a review from ncw February 16, 2021 23:47
@ivandeex

ivandeex commented Feb 16, 2021 •

Copy link
Copy Markdown
Member Author

@ncw
Please review this one

@ivandeex

Copy link
Copy Markdown
Member Author

Integration tests pass for me.

@edwardxml edwardxml mentioned this pull request Feb 21, 2021
2 of 5 tasks
@ivandeex ivandeex removed their assignment Feb 25, 2021
@ivandeex

This comment has been minimized.

Comment thread fs/sync/sync.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What you are trying to do is make the filters apply to just the backend in question.

However I don't like this approach - there could easily be multiple syncs running at once using the same fi block.

Perhaps what we need is an explicit marker to say to all backends - use the filters. This could be passed in the context.

This needs to pass down the value of the includeAll flag as used in fs/walk and fs/march - applying the flag to the context in those places will make it work for all backends.

So if we made a context variable UseFilters and applied it in those places in fs/walk and fs/march where we actually call Fs.List or Fs.ListR then this would fix it up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ncw Done! PTAL...

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologies for the delay in reviewing - every time I've looked at this PR something has seemed wrong, but I haven't been able to work out why!

I finally figured it out - see the inline comment.

I like the idea of this - it is a great idea and it is worth making work.

@ivandeex ivandeex self-assigned this Mar 11, 2021
@ivandeex ivandeex mentioned this pull request Jul 7, 2021
5 tasks done
@ivandeex ivandeex removed the thinking label Aug 15, 2021
@ivandeex
ivandeex marked this pull request as ready for review August 15, 2021 19:31
@ivandeex
ivandeex marked this pull request as draft August 16, 2021 22:52
@ivandeex ivandeex modified the milestones: v1.57, v1.58 Sep 26, 2021
@ivandeex
ivandeex marked this pull request as ready for review October 5, 2021 12:58
@ivandeex
ivandeex requested a review from ncw October 5, 2021 16:50
@ivandeex ivandeex modified the milestones: v1.58, v1.57 Oct 5, 2021

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nearly there - looking nice :-)

I put a couple of comments for thought inline.

Comment thread fs/march/march.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think useFilter should always be !includeAll...

Does that seem correct to you?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note:

I didn't introduce the new context flag in every public march/walk function. Instead, I added them selectively in the functions called from sync.Copy/Paste, from operations.List and in Walk which is called from some of them. I didn't touch e.g. list.NewDirList but modified march initialization instead.

I tagged involved functions by a comment line containing the word filter-aware so to simplify analysis a little.

@ivandeex ivandeex Oct 6, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To me the call stack in march and walk feels so complex that I initially decided to treat such notions as "march side" and "include all" separately:

  • passed the "march side" (aka useFilter which is true on the source side) down the stack in context.
  • passed includeAll term as an argument like before. This has an advantage that I don't need to look in every place in the code where it's used.

Now rewritten to obey your review. Then I had to modify the unit test (put in a sidecar commit for visibility) because now query constraining can happen even if drive remote appears on the right side (it's now controlled purely by the march's src/dst includeAll flags).

PTAL 🙏

Comment thread backend/drive/drive.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there no timezone in this time? Or is it guaranteed to be UTC? EIther way this doesn't seem quite right.

@ivandeex ivandeex Oct 6, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ivandeex
ivandeex force-pushed the pr-gdrivetrick branch 2 times, most recently from 89ba6bc to 59e9337 Compare October 6, 2021 07:47
@ivandeex ivandeex changed the title drive: optimize performance for --min-age, --max-age (recovered) drive: constrain list by filter Oct 6, 2021
@ivandeex
ivandeex requested a review from ncw October 7, 2021 13:19

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That looks great now. Not changing the parameters has made the patch quite a bit smaller.

Please merge when ready - thank you :-)

Google Drive API allows for clauses like "modifiedTime > '2012-06-04T12:00:00'"
in the query param, so the filter flags --max-age and --min-age can be applied
directly at the directory listing phase rather than in a filter.
This is extremely helpful when we want to do an incremental backup of a remote
drive with many files but the number of recently changed file is small.

Co-authored-by: fotile96 <[email protected]>
@ivandeex
ivandeex merged commit a254506 into rclone:master Oct 7, 2021
@ivandeex
ivandeex deleted the pr-gdrivetrick branch October 7, 2021 19:11
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
Google Drive API allows for clauses like "modifiedTime > '2012-06-04T12:00:00'"
in the query param, so the filter flags --max-age and --min-age can be applied
directly at the directory listing phase rather than in a filter.
This is extremely helpful when we want to do an incremental backup of a remote
drive with many files but the number of recently changed file is small.

Co-authored-by: fotile96 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants