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(engine): thread-safe transient subscription state #13072

Merged
merged 4 commits into from Jun 15, 2023

Conversation

oleschoenburg
Copy link
Member

@oleschoenburg oleschoenburg commented Jun 12, 2023

Closes #12798 by making TransientSubscriptionCommandState thread safe. This allows data sharing between scheduled tasks and processing.

The real change is 839744f with two follow up commits that significantly simplify the class hierarchy but add lot of diff noise. The refactorings can be split off if necessary.

This changes the existing transient state holder to be thread safe.
Allows for future changes where we need concurrent read and write
operations.
The previous class hierarchy was a bit confusing. With these changes
here, the `DbMessageSubscriptionState` is responsible for all state
changes. When necessary, it reads from and writes to the transient state
directly.

This also adjusts names and package paths to indicate that reading and
writing transient state is not a mutable operation.
The previous class hierarchy was a bit confusing. With these changes
here, the `DbProcessMessageSubscriptionState` is responsible for all
state changes. When necessary, it reads from and writes to the transient
state directly.

This also adjusts names and package paths to indicate that reading and
writing transient state is not a mutable operation.
@korthout
Copy link
Member

Thanks @oleschoenburg ❤️ I'll have a look at this tomorrow

@korthout
Copy link
Member

Sorry @oleschoenburg, I forgot about this one. It'll be my top priority tomorrow 🙇

Copy link
Member

@korthout korthout left a comment

Choose a reason for hiding this comment

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

Thanks @oleschoenburg 👏

👍 Another amazing set of changes!

❌ I'm not confident about the thread safety of the TransientPendingSubscriptionState. I might misunderstand how the ConcurrentHashMap works, but please have another look.

Copy link
Member

@korthout korthout left a comment

Choose a reason for hiding this comment

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

🔧 I also noticed this still after my review

@@ -151,13 +155,20 @@ public void updateToCorrelatingState(final MessageSubscriptionRecord record) {

updateCorrelatingFlag(subscription, true);

transientState.add(record);
transientState.add(
Copy link
Member

Choose a reason for hiding this comment

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

🔧 Although the implementation of add and update are equivalent, semantically, it might make more sense to use update here.

}

@Override
public void updateToOpeningState(final ProcessMessageSubscriptionRecord record) {
update(record, s -> s.setRecord(record).setOpening());
transientState.add(record);
transientState.add(
Copy link
Member

Choose a reason for hiding this comment

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

🔧 Although the implementation of add and update are equivalent, semantically, it might make more sense to use update here.

}

@Override
public void updateToClosingState(final ProcessMessageSubscriptionRecord record) {
update(record, s -> s.setRecord(record).setClosing());
transientState.add(record);
transientState.add(
Copy link
Member

Choose a reason for hiding this comment

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

🔧 Although the implementation of add and update are equivalent, semantically, it might make more sense to use update here.

Copy link
Member

@korthout korthout left a comment

Choose a reason for hiding this comment

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

@oleschoenburg You have convinced me here that this is indeed thread safe.

👍 LGTM (please consider my suggestion before merging)

Although the implementation is equivalent, using `update` instead of
`add` is clearer.
@oleschoenburg
Copy link
Member Author

bors merge

@zeebe-bors-camunda
Copy link
Contributor

Build succeeded:

@zeebe-bors-camunda zeebe-bors-camunda bot merged commit d9a98fb into main Jun 15, 2023
31 checks passed
@zeebe-bors-camunda zeebe-bors-camunda bot deleted the os/fix-mutable-pending-msg-state branch June 15, 2023 16:06
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.

Don't share mutable state through MutablePendingMessageSubscriptionState
2 participants