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

Add Pagination to Listing Projects for Housekeeping #587

Merged
merged 5 commits into from
Aug 15, 2023

Conversation

tedkimdev
Copy link
Contributor

What this PR does / why we need it:

To avoid all project info being loaded from DB when doing housekeeping, pagination is added for listing projects and performing housekeeping in smaller portions.

Which issue(s) this PR fixes:

Fixes #569

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

@CLAassistant
Copy link

CLAassistant commented Jul 22, 2023

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Jul 22, 2023

Codecov Report

Merging #587 (5b0705d) into main (036a991) will decrease coverage by 0.22%.
Report is 9 commits behind head on main.
The diff coverage is 67.12%.

@@            Coverage Diff             @@
##             main     #587      +/-   ##
==========================================
- Coverage   51.11%   50.89%   -0.22%     
==========================================
  Files          66       69       +3     
  Lines        7008     7167     +159     
==========================================
+ Hits         3582     3648      +66     
- Misses       2952     3035      +83     
- Partials      474      484      +10     
Files Changed Coverage Δ
server/backend/housekeeping/housekeeping.go 0.00% <0.00%> (ø)
server/backend/database/mongo/client.go 41.96% <71.42%> (+2.54%) ⬆️
server/backend/database/memory/database.go 50.28% <84.21%> (-2.86%) ⬇️
server/backend/housekeeping/config.go 100.00% <100.00%> (ø)
server/config.go 42.52% <100.00%> (-1.38%) ⬇️

... and 16 files with indirect coverage changes

@krapie krapie self-requested a review July 22, 2023 05:38
@krapie krapie added the enhancement 🌟 New feature or request label Jul 22, 2023
@krapie krapie requested a review from hackerwins July 22, 2023 05:45
Copy link
Member

@krapie krapie left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!
I left a small request for you.

Since HousekeepingProjectFetchSize option is newly introduced, we need to add this option to the CLI flag.

Ref: #512

server/config.sample.yml Outdated Show resolved Hide resolved
Copy link
Member

@krapie krapie left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.
I left a comment.

server/backend/database/memory/database.go Outdated Show resolved Hide resolved
@hackerwins
Copy link
Member

No worries at the moment since we have small projects in https://yorkie.dev, and the offset/limit isn't causing any performance issues.

However, as our services grow, this could become problematic when fetching the first page. To address this potential issue, we could consider changing the interface and implementing it with keyset pagination.

For more information on this approach, you can check out: https://use-the-index-luke.com/no-offset

To avoid all project info being loaded from DB, pagination is added for projects and perform housekeeping in smaller portions.

* Add HousekeepingProjectFetchSize in config

Fix checking the last page

Add housekeeping project fetch size option to the CLI flag

* set project fetch size to 100 in config.sample.yml

fix lint

Move housekeepingProjectPage variable into the Housekeeping.run function

Add keyset pagination to find projects

* update housekeeping test not to set project id to zero value
@tedkimdev
Copy link
Contributor Author

@hackerwins I changed the database interface like you mentioned.
I did not call SetSort() when using Find() in the Mongodb client because the natural order refers to the default document ordering based on _id.
If I am not correct, please let me know.

Copy link
Member

@krapie krapie left a comment

Choose a reason for hiding this comment

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

keyset pagination looks awesome!
I left some small comments with my personal questions.

server/config.go Outdated Show resolved Hide resolved
server/backend/housekeeping/housekeeping.go Show resolved Hide resolved
server/backend/database/memory/database.go Outdated Show resolved Hide resolved
* Cleanup code
* add pagination test for memory db

Cleanup test
* add test code for mongo client

* clean up test code
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

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

Thanks for applying my requests.

I left one more comment about using indexes in MemDB.

server/backend/database/memory/database.go Outdated Show resolved Hide resolved
@hackerwins hackerwins self-requested a review August 11, 2023 00:53
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

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

Overall looks good.
I left minor style-related comments.

server/backend/database/database.go Outdated Show resolved Hide resolved
}

func createDBandProjects(t *testing.T) (*memory.DB, []*database.ProjectInfo) {
t.Helper()
Copy link
Member

Choose a reason for hiding this comment

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

This is the first time to see t.Helper. When is this useful? Would it be good to add t.Helper to other helper functions too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

t.Helper() indicates to the Go test runner that createDBandProjects() helper function is a test helper. It makes it easy to report test failures at the call site of the parent function rather than the call site of t.Error() and t.Errorf(). When t.Error() is called from createDBandProjects() function, the Go test runner will report the filename and line number of the code which called the createDBandProjects() function in the output.

@hackerwins hackerwins self-requested a review August 15, 2023 01:24
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@hackerwins hackerwins merged commit 21b3afc into yorkie-team:main Aug 15, 2023
1 check passed
Wu22e pushed a commit to Wu22e/yorkie that referenced this pull request Sep 3, 2023
* Add Pagination to Listing Projects for Housekeeping

To avoid all project info being loaded from DB, pagination is added for projects and perform housekeeping in smaller portions.

* Add HousekeepingProjectFetchSize in config

Add housekeeping project fetch size option to the CLI flag

* set project fetch size to 100 in config.sample.yml

Move housekeepingProjectPage variable into the Housekeeping.run function

Add keyset pagination to find projects

* update housekeeping test not to set project id to zero value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce Pagination for Housekeeping
4 participants