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

Performance and safety Improvements to PartitionedJournalDao #155

Open
fredfp opened this issue Apr 1, 2021 · 0 comments
Open

Performance and safety Improvements to PartitionedJournalDao #155

fredfp opened this issue Apr 1, 2021 · 0 comments

Comments

@fredfp
Copy link
Contributor

fredfp commented Apr 1, 2021

Safety issue

Since https://github.com/SwissBorg/akka-persistence-postgres/releases/tag/v0.5.0-M1, unicity of sequence_number per persistence_id is guaranteed across a single partition. We still should guarantee it across all partitions.

Performance issues

A few queries are slow because they require scanning all available partitions.

Possible fix

Create a metadata table that is automatically checked and updated on insertions, and query that table instead of scanning all partitions.

Columns for new metadata table:

  • persistence_id (PK)
  • id (bigserial unique)
  • max_sequence_number
  • min_ordering
  • max_ordering

When inserting a new message for a given persistence_id, use trigger to:

  • ensure new sequence_number > metadata.max_sequence_number
  • update metadata set max_sequence_number = new sequence_number
  • update metadata set min_ordering = min(min_ordering, new ordering
  • update metadata set max_ordering = new ordering

Queries we could improve:

Consider how to partition/shard such table:

  • it might not be needed for journals with bounded set of persistence_id
  • could be sharded per persistence_id otherwise

Later, if data and index sizes need to be reduced, consider using metadata.id as foreign key in the journal table instead of persistence_id.

@fredfp fredfp changed the title PartitionedJournalDao does not gurantee unicity of sequence_number per persistence_id Performance and safety Improvements to PartitionedJournalDao May 7, 2021
tiagomota added a commit that referenced this issue Aug 29, 2023
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

No branches or pull requests

1 participant