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

Eliminate unnecessary merge() if entity is non-versioned #3402

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Mar 18, 2024

Fix GH-3401

@mp911de
Copy link
Member

mp911de commented Mar 18, 2024

Can you please provide additional integration tests for the cases of optimistic locking failures and removal of an entity that contains modifications?

@quaff quaff marked this pull request as ready for review March 19, 2024 02:19
@quaff
Copy link
Contributor Author

quaff commented Mar 19, 2024

Can you please provide additional integration tests for the cases of optimistic locking failures and removal of an entity that contains modifications?

It's nothing related to optimistic locking but InvalidDataAccessApiUsage Removing a detached instance, and it's covered by existing tests, so I don't think additional integration tests is required here.

@quaff quaff changed the title Eliminate unnecessary merge() if possible Eliminate unnecessary merge() Mar 19, 2024
@schauder
Copy link
Contributor

The PR as it stands right now, is not acceptable. It will not throw an OptimisticLockingException in the case of concurrent modification.

It is not about avoiding optimistic locking exceptions.
These exceptions are an important feature!

@quaff
Copy link
Contributor Author

quaff commented Mar 19, 2024

The PR as it stands right now, is not acceptable. It will not throw an OptimisticLockingException in the case of concurrent modification.

It is not about avoiding optimistic locking exceptions. These exceptions are an important feature!

I get your point now, that's not covered by existing tests, I will try.

@quaff quaff marked this pull request as draft March 19, 2024 07:00
@quaff quaff marked this pull request as ready for review March 19, 2024 08:29
@quaff quaff changed the title Eliminate unnecessary merge() Eliminate unnecessary merge() if entity is non-versioned Mar 19, 2024
@quaff
Copy link
Contributor Author

quaff commented Mar 19, 2024

I've updated this PR, I suggest not to squash commits, at least the first commit should be kept as it is. @schauder

@schauder
Copy link
Contributor

Thanks for the additional test. There is still one scenario to investigate though.

What happens in the old and new version of the code when the entity (without optimistic locking) to be deleted contains changes, i.e. it is dirty.

The previous version might actually flush those changes, potentially triggering life cycle events, triggers and validations.
We need to make sure the new version behaves in the same way.

@quaff
Copy link
Contributor Author

quaff commented Mar 20, 2024

The previous version might actually flush those changes, potentially triggering life cycle events, triggers and validations. We need to make sure the new version behaves in the same way.

It's weird that flush changes before deletion, IMO we should eliminate those side effects for versioned entity too, by comparing versions between entity and existing.

@schauder
Copy link
Contributor

I'm very much against changing anything about the observed behaviour in this.
While I agree that a lot of it is weird, there are going to be people relying on it.
And I'm not going to fight them in order to get some minor optimization out of a method that is not often used anyway, since people tend to not delete data from their database outside tests.

@quaff
Copy link
Contributor Author

quaff commented Mar 20, 2024

I'm very much against changing anything about the observed behaviour in this. While I agree that a lot of it is weird, there are going to be people relying on it. And I'm not going to fight them in order to get some minor optimization out of a method that is not often used anyway, since people tend to not delete data from their database outside tests.

OK, should I update commits to only keep the first one?

@schauder
Copy link
Contributor

OK, should I update commits to only keep the first one?

I'm not sure I understand the intention with this one.
We need either full support by integration tests, or we'll have to decline this PR.

I honestly aren't sure how exactly the old and the proposed new version of the code behave.
That's why I'm insisting on the integration tests. Please let me know if you are going to try to provide such tests, otherwise I'll close this PR.

There is no blame in failing to optimise this method. At least I hope so because I tried myself before and failed miserably :o)

@quaff
Copy link
Contributor Author

quaff commented Mar 21, 2024

I don't understand integration tests that you said, the commit ac3f819 added test to guard current behavior that deleting stale detached entity should cause optimistic lock failure.

@schauder
Copy link
Contributor

But it does not test what happens, when you delete a managed dirty entity.

@quaff
Copy link
Contributor Author

quaff commented Mar 21, 2024

But it does not test what happens, when you delete a managed dirty entity.

JPA will guarantee it raise OptimisticLockException at flush stage, I added test to cover that, please review 7abb5e7

@schauder
Copy link
Contributor

In this scenario the interesting case is not for versioned entities, but for unversioned.

There is a risk that they get flushed to the database triggering life cycle events, database triggers and database constraints, while the new version won't

@quaff
Copy link
Contributor Author

quaff commented Mar 21, 2024

There is a risk that they get flushed to the database triggering life cycle events, database triggers and database constraints, while the new version won't

You mentioned it already, I agree that but I think the risk is tiny.
since it's applicative for both current and new version, should I split commit 7abb5e7 up to another dedicated PR?

@schauder
Copy link
Contributor

No, we need a test mitigating that risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
4 participants