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

FIX: nested NOT_SUPPORTED transaction with an inner REQUIRES transaction #3288

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

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Dec 8, 2023

Hello Rob, we discovered a strange behaviour, when using NOT_SUPPORTED transaction.

We have some import code in our application Our use case is as follow:

try (Transaction txn1 = DB.beginTransaction()) {
      ImportStatus status = DB.find(ImportStatus.class).forUpdate()...findOne(); // find status entity and place lock

      try (Transaction txn2 = DB.beginTransaction(TxScope.notSupported())) {
        // pause current transaction and run import without an active txn
        runImport();
        txn2.commit(); // not really neccessary, it's the NO_TRANSACTION
        status.setSuccess(true);
      } catch (Throwable t) {
        status.setSuccess(false);
      }
      DB.save(status)
}

This works fine, as long the "runImport" will not open new transactions. In this case, the next DB.beginTransaction() will not detect the open stack of txn1 and txn2 and will effectively overwrite the existing txnContainer.

*/
private ScopedTransaction activeScoped() {
return (ScopedTransaction) scopeManager.active();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not longer in use

@@ -499,7 +492,7 @@ public final ScopedTransaction externalBeginTransaction(SpiTransaction transacti
*/
public final ScopedTransaction beginScopedTransaction(TxScope txScope) {
txScope = initTxScope(txScope);
ScopedTransaction txnContainer = activeScoped();
ScopedTransaction txnContainer = (ScopedTransaction) inScope();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it possible (or allowed) that we will get an instance not implementing ScopedTransaction here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if a DB.save(entityWithPersistAction) creates an implicit transaction, we will fail here, if a callback or @PrePersist action tries to create a nested transaction, because implicit transactions are not nestable

@rPraml
Copy link
Contributor Author

rPraml commented Dec 8, 2023

Hmm. There are still some issues, when ebean tries to open some implicit transactions.
See last commit.

I've tried to start fixing it here: 38b5ac2 but I think this will go into the wrong direction.

So the question is: Means "NOT_SUPPORTED" really: Pause current transaction and behave like never a transaction was opened

Note: As workaround we currently experiment with:

try (Transaction txn = DB.beginTransaction()) {
  // find status
  Thread t = new Thread(()-> { /* runs without txn */});
  t.start();
  t.join();
  // update status
} 

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.

1 participant