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

Refactor to simplify merging child slabs in array #525

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fxamacker
Copy link
Member

Updates #464

Currently, ArrayMetaDataSlab.MergeOrRebalanceChildSlab() is complicated with over 300 lines of code.

This PR refactors merging in this function by adding new two helper functions mergeChildren() and updateChildrenHeadersAfterMerge().

This PR also uses go1.21 slices package to simplify slice operations.


  • Targeted PR against main branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Currently, ArrayMetaDataSlab.MergeOrRebalanceChildSlab() is
complicated with over 300 lines of code.

This commit refactors merging aspect of this function by
adding new two helper functions.

This commit also uses go1.21 slices package to simplify
slice operations.
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice work refactoring into smaller and reusable functions!

I assume the code was extracted using automatic refactoring (e.g. IDE)? I didn't fully check if it matches exactly the old code (given the diff is hard to read)

@fxamacker
Copy link
Member Author

I assume the code was extracted using automatic refactoring (e.g. IDE)? I didn't fully check if it matches exactly the old code (given the diff is hard to read)

@turbolent Yeah, the diff for this PR is hard to read.

The code was extracted with a combination of manual and automatic refactoring.

  • I created new variables leftSlab and rightSlab, and assigned them to different slabs depending on the merge conditions. For example, if child merges with rightSib then leftSlab, rightSlab = child, rightSib.
  • I extracted common functionality using IDE, followed by some manual adjustments.

I re-reviewed this PR and have been running brief smoke tests (on my desktop) for PRs with these types of changes and no problems were found.

After the remaining 10 PRs for issue #464 are merged I will:

  • run longer smoke tests on gcp.
  • look into including these changes in backwards compatibility test, etc.

Thanks again for these PR reviews and questions! 👍

@fxamacker fxamacker changed the base branch from fxamacker/use-slices-insert-and-delete-in-tests to main March 5, 2025 22:09
@turbolent
Copy link
Member

Thanks for the explanation and double checking! 👍

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