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

feat: Postgres partition implementation #2506

Merged
merged 25 commits into from
Mar 6, 2024
Merged

Conversation

Ivansete-status
Copy link
Collaborator

Description

First of all, special thanks to @NagyZoltanPeter for suggesting such a great partition proposal 🥳 !

In this PR we start managing the partition creation and deletion.
This is interesting from the database size maintenance pov.

There will always be a current partition.
The loopPartitionFactory proc responsible for making sure that there will always be a future partition available.

The loopPartitionFactory will check every DefaultDatabasePartitionCheckTimeInterval (10 minutes hard-coded) whether a new partition should be created or not.

The PartitionsRangeInterval is also hard-coded (1 hour.) This value establishes the time window to store messaged based in their storedAt (epoch time in nanoseconds.)

Notice that the partitions are only removed when size retention policy is being applied.

image

Changes

  • Avoid using require on postgres tests. I've noticed that it doesn't handle the failure cases very well.
  • Bump the Postgres schema version to 2 (waku/waku_archive/driver/postgres_driver/migrations.nim.)
  • New waku/waku_archive/driver/postgres_driver/partitions_manager.nim that just keeps track the partitions. The partitions are being created from within the postgres_driver.nim (loopPartitionFactory.) and removed from the size retention policy.
  • Cleanup in postgres_driver.nim. Removes createMessageTable, init, and deleteMessageTable procs.
  • Notice that the forceRemoval: bool = false param in decreaseDatabaseSize is for testing purposes, to allow forcing all the partitions.

The new proc, decreaseDatabaseSize, will have different implementations
per each driver. For example, in future commits we will implement a size
retention policy thanks for partitions management, in Postgres.
Completing implementation of partition factory and partition deletion.
There may still be some bugs that need adjustment.
The new proc, decreaseDatabaseSize, will have different implementations
per each driver. For example, in future commits we will implement a size
retention policy thanks to partitions management, in Postgres.
…g times.now()

times.now() returns time in seconds but we need to be in nanoseconds
Copy link

github-actions bot commented Mar 5, 2024

This PR may contain changes to database schema of one of the drivers.

If you are introducing any changes to the schema, make sure the upgrade from the latest release to this change passes without any errors/issues.

Please make sure the label release-notes is added to make sure upgrade instructions properly highlight this change.

@Ivansete-status Ivansete-status self-assigned this Mar 5, 2024
Copy link

github-actions bot commented Mar 5, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2506

Built from 8aff169

@Ivansete-status Ivansete-status marked this pull request as ready for review March 6, 2024 09:55
@SionoiS SionoiS mentioned this pull request Mar 6, 2024
6 tasks
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

Overall, I'm amazed how wonderful this PR is!
As we discussed it many times I was excited to see already. This is a real win!
Thank you for it.
Approved! Only left some questions and stuff to consider for the future.
Let's see it live working!

Copy link
Contributor

@SionoiS SionoiS left a comment

Choose a reason for hiding this comment

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

Amazing. Thanks!

Hope it works as well as it sounds.

Copy link
Contributor

@gabrielmer gabrielmer left a comment

Choose a reason for hiding this comment

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

Amazing PR! Thanks so much! 😍

if beginning <= targetMoment and targetMoment < `end`:
return ok(partition)

return err("Could'nt find a partition table for given time: " & $targetMoment)
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitpick 😶

Suggested change
return err("Could'nt find a partition table for given time: " & $targetMoment)
return err("Couldn't find a partition table for given time: " & $targetMoment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Super nitpick 😶

Thanks! Covered in 62e7b3e

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

Great work, @Ivansete-status (and @NagyZoltanPeter). :)

@Ivansete-status Ivansete-status merged commit 161a10e into master Mar 6, 2024
9 of 10 checks passed
@Ivansete-status Ivansete-status deleted the feat-pg-enhancements branch March 6, 2024 19:50
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.

None yet

5 participants