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

Chaining multiple suspended transactions #1477

Open
nareshbaliga opened this issue Mar 18, 2022 · 2 comments
Open

Chaining multiple suspended transactions #1477

nareshbaliga opened this issue Mar 18, 2022 · 2 comments

Comments

@nareshbaliga
Copy link

Hi,

I have a service that opens a newSuspendedTransaction() at the top level. Thereafter, there are numerous calls across multiple service and DAOs that open their own transactions.

If I want to commit or rollback across all these services and DAOs, at the top level service that initiated the chain, how do I go about doing that?

I'm essentially looking for transaction propagation.

newSuspendedTransaction {
    suspendedTransaction {
     commit()
   }
  suspendedTransaction {
   commit()
  }
 ....
 rollback()
}

The above code works. That is, the last rollback() at the top level transaction, rolls back all the child transactions.

But my problem is that all the code that forms the child suspended transactions are not available in one block, in one method.

They are dispersed/delegated across several services and DAOs. How do I go about having transactions in those child services and DAOs "participate" in the parent transaction?

The entire chain uses suspend functions.

Are there any examples of this?

Thanks.

@nareshbaliga
Copy link
Author

If it clarifies further, in a non-suspend world, I can open multiple transactions at various points, and the transaction always looks for currentOrNull and knows to participate in an ongoing transaction.

However in a suspend world, I cannot open a simple transaction, unless I only call non-suspend functions thereafter.

So I have to use newSuspendedTransaction to begin with, but later on I don't have an ongoing transaction to call suspendedTransaction for child transactions.

The only way I see is to actually pass the parent transaction around into every Service and DAO have them call suspendedTransaction on it. That way seems incredibly painful.

@AlexeySoshin
Copy link
Contributor

Seems related to that discussion:
#1586

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

No branches or pull requests

2 participants