Skip to content

Conversation

@dreab8
Copy link
Member

@dreab8 dreab8 commented Nov 4, 2025

Fix #2651

The PR implements the Reactive version of JdbcSelectWithActions and of the new PostAction and PreAction (ReactiveLockTimeoutHandler and ReactiveLockTimeoutHandler).

The PR does not implement the Reactive version of CollectionLockingAction but in order to use it a Reactive version of org.hibernate.query.SelectionQuery#setLockScope(Locking.Scope lockScope); method need to be added.

@hibernate-github-bot hibernate-github-bot bot changed the title Implemented Reactive versions of PostAction, PreAction and JdbcSelectWithActions [wip/4.2] Implemented Reactive versions of PostAction, PreAction and JdbcSelectWithActions Nov 4, 2025
@hibernate-github-bot hibernate-github-bot bot added the wip/4.2 Label for pull requests targeting [wip/4.2] branch. label Nov 4, 2025
public String name;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you should change the mapping of an existing test. ALso, does it matter if you use lazy here?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the new Lock implementation in ORM, it affects the number of queries executed.
I'm going to revert this change and modify the testFindUpgradeNoWait assertions accrdingly

@dreab8 dreab8 force-pushed the issue#2651_4.2 branch 3 times, most recently from 4189a5f to 229542e Compare November 6, 2025 10:35
@DavideD DavideD force-pushed the wip/4.2 branch 2 times, most recently from b0fdbef to b543eb0 Compare November 10, 2025 16:30
@DavideD DavideD added the waiting We are waiting for another PR or issue to be solved before merging this one label Nov 10, 2025
@DavideD DavideD added this to the 4.2.0.Beta1 milestone Nov 10, 2025
@DavideD
Copy link
Member

DavideD commented Nov 10, 2025

We need to wait for the next ORM 7.2 release

Copy link
Member

@DavideD DavideD left a comment

Choose a reason for hiding this comment

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

Thanks @dreab8,
it looks good overall, but there some small things to change.

* Reactive version of {@link ConnectionLockTimeoutStrategy}
*/
public interface ReactiveConnectionLockTimeoutStrategy extends ConnectionLockTimeoutStrategy {
Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );
Copy link
Member

Choose a reason for hiding this comment

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

I know that we use this pattern in some places, but
I think it's better if we don't put the LOG in the interface and override the method in the implemetations instead, even if it means we have some duplication.


@FunctionalInterface
public interface TimeoutExtractor {
CompletionStage<Timeout> extractFrom(ReactiveConnection.Result resultSet);
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this needs to return a CompletionStage? All the implementations I see return a constant.

Copy link
Member

Choose a reason for hiding this comment

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

I did a little refactoring and it seems you can just return a Timeout object: DavideD@f76290d

Feel free to squash the commit in your PR, if you agree with the changes

return LockHelper.getLockTimeout(
"show lock_timeout",
(resultSet) -> {
// see https://dev.mysql.com/doc/refman/8.4/en/innodb-parameters.html#sysvar_innodb_lock_wait_timeout
Copy link
Member

Choose a reason for hiding this comment

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

I think you copied and paste the link: it links to the MySQL docs but it's in the code for the Cockroach strategy

The same error happens in all the other implementations

Timeout timeout,
ReactiveConnection connection,
SessionFactoryImplementor factory) {
return LockHelper.setLockTimeout(
Copy link
Member

Choose a reason for hiding this comment

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

This code is the same as the one in Postgres. If Cockroach calls the one in Postgres, we remove some duplicated code.

* Reactive version of {@link TableLock}
*/
public class ReactiveTableLock extends TableLock {
Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );
Copy link
Member

Choose a reason for hiding this comment

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

this LOG should be private static final

ReactiveListResultsConsumer.UniqueSemantic.ALLOW
).thenCompose( results -> {
if ( isEmpty( results ) ) {
throw new AssertionFailure( "Expecting results" );
Copy link
Member

Choose a reason for hiding this comment

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

Can't we add anything else to the error message? What should have the query returned? Something related to a lock I imagine.

reference = null;
}
applyLoadedState( entityDetails, statePosition, reference );
applyModelState( entityDetails, statePosition, reference );
Copy link
Member

Choose a reason for hiding this comment

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

reference is always null

}

@Override
public CompletionStage<Void> reactiveApplyResult(
Copy link
Member

Choose a reason for hiding this comment

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

Unless I'm missing something, nothing in this method seems reactive. Do you need to return a CompletionStage?

if ( stateValue == null ) {
if ( !toOne.isNullable() ) {
throw new IllegalStateException( "Retrieved key was null, but to-one is not nullable : " + toOne.getNavigableRole()
.getFullPath() );
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this have a error code in the Log?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting We are waiting for another PR or issue to be solved before merging this one wip/4.2 Label for pull requests targeting [wip/4.2] branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants