Skip to content

Provide an interface for generating sequences - #678

Open
VladislavBakshanskij wants to merge 7 commits into
gruelbox:masterfrom
VladislavBakshanskij:master
Open

VladislavBakshanskij wants to merge 7 commits into
gruelbox:masterfrom
VladislavBakshanskij:master

Conversation

@VladislavBakshanskij

@VladislavBakshanskij VladislavBakshanskij commented Jul 28, 2024

Copy link
Copy Markdown

fixes: #677

@VladislavBakshanskij VladislavBakshanskij changed the title Provide an interface for generating sequences #677 Provide an interface for generating sequences Jul 28, 2024
@VladislavBakshanskij

Copy link
Copy Markdown
Author

@badgerwithagun can u review?

2 similar comments
@VladislavBakshanskij

Copy link
Copy Markdown
Author

@badgerwithagun can u review?

@VladislavBakshanskij

Copy link
Copy Markdown
Author

@badgerwithagun can u review?

* @param sequenceGenerator The sequence generator used for ordered tasks. Required
*/
@SuppressWarnings("JavaDoc")
private final SequenceGenerator sequenceGenerator;

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.

On its own, this is a compatibility break; it requires all existing users to specify DefaultSequenceGenerator when creating a DefaultPersistor. I suggest changing this class to have a constructor annotated with @Builder; then you can accept null for sequenceGenerator and replace it with a DefaultSequenceGenerator.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

.persistor(
DefaultPersistor.builder()
.dialect(connectionDetails().dialect())
.sequenceGenerator(DefaultSequenceGenerator.builder()

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.

This shouldn't be necessary (see comments on DefaultPersistor)

// used correctly.
.dialect(Dialect.POSTGRESQL_9)
.dialect(dialect)
.sequenceGenerator(DefaultSequenceGenerator.builder().dialect(dialect).build())

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.

This shouldn't be necessary (see comments on DefaultPersistor)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

return DefaultPersistor.builder().dialect(dialect).build();
return DefaultPersistor.builder()
.dialect(dialect)
.sequenceGenerator(DefaultSequenceGenerator.builder().dialect(dialect).build())

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.

This shouldn't be necessary (see comments on DefaultPersistor)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

@badgerwithagun badgerwithagun 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.

One tweak needed to avoid any compatibility issues, but otherwise this looks fine.

I must caution you though: if you're planning on generating sequence numbers from outside the main DB transaction, you're going to get some unexpected timing differences.

There are several combinations to consider, but here's one:

  1. Thread A asks for a sequence number and gets 1
  2. Thread B asks for a sequence number and gets 2
  3. Thread B writes its outbox record (sequence 2) and commits
  4. flush() is called
  5. (2) is picked up and processed
  6. Thread A writes its outbox record (sequence 1) and commits
  7. flush() is called
  8. (1) is picked up and processed

The order of processing was actually 2, 1 instead of 1, 2.

So that's a bit potentially confusing, but another way of looking at this problem is that:

  • DefaultSequenceGenerator ensures that the order of commit of the source transactions align with the order of the outgoing messages.
  • A Redis implementation could only ensure that the order of the outgoing messages aligns with the point in time that the sequence number was requested.

@VladislavBakshanskij

Copy link
Copy Markdown
Author

@badgerwithagun I came back late of course with the fix of the comments, but I still corrected them. I ask you to do a second review

@VladislavBakshanskij

VladislavBakshanskij commented Dec 7, 2024

Copy link
Copy Markdown
Author

@badgerwithagun can u review this PR?

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.

Provide an interface for generating sequences

2 participants