-
Notifications
You must be signed in to change notification settings - Fork 40
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
Provide an interface for generating sequences #678
base: master
Are you sure you want to change the base?
Conversation
@badgerwithagun can u review? |
* @param sequenceGenerator The sequence generator used for ordered tasks. Required | ||
*/ | ||
@SuppressWarnings("JavaDoc") | ||
private final SequenceGenerator sequenceGenerator; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -30,6 +30,9 @@ final void workAlwaysSerialized() throws Exception { | |||
.persistor( | |||
DefaultPersistor.builder() | |||
.dialect(connectionDetails().dialect()) | |||
.sequenceGenerator(DefaultSequenceGenerator.builder() |
There was a problem hiding this comment.
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
)
@@ -47,7 +48,8 @@ void test() { | |||
DefaultPersistor.builder() | |||
// Selecting the right SQL dialect ensures that features such as SKIP LOCKED are | |||
// used correctly. | |||
.dialect(Dialect.POSTGRESQL_9) | |||
.dialect(dialect) | |||
.sequenceGenerator(DefaultSequenceGenerator.builder().dialect(dialect).build()) |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
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:
- Thread A asks for a sequence number and gets 1
- Thread B asks for a sequence number and gets 2
- Thread B writes its outbox record (sequence 2) and commits
flush()
is called- (2) is picked up and processed
- Thread A writes its outbox record (sequence 1) and commits
flush()
is called- (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.
a2d4ea8
to
690545b
Compare
@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 |
ee67b1c
to
86378f8
Compare
e5e8905
to
cacd8da
Compare
@badgerwithagun can u review this PR? |
fixes: #677