Hi,
We have a batch process for example 1 process need to iterate 300 hundreds records to Insert / Update a few entities into DB. But there is a problem, we want to Rollback the previous insertion / update that had been done.
For my scenario, I have 3 modules.
Module A consume Module B
Module B consume Module C
Here the step for the batch process.
Can someone give some idea or perspective on how to tackle this scenario. How is the exception handling rollback works? How to rollback previous iterations?
Many Thanks
Ezra
Hi Ezra,
Assuming you use Server actions, not Service actions, then all database actions run in the same database transaction. This means that if you perform an explicit rollback (calling AbortTransaction) or an exception is generated that has its "Abort Transaction" property set to "Yes", all database actions in the current transaction are rolled back.
If you somehow find that less than the expected number of transactions are rolled back, this means that there is an explicit commit (calling CommitTransaction) somewhere. This can be in your own code, or in some action you are calling (direct or indirect). If you really have no idea where it is, you could generate explicit rollbacks, and see to which point it rolls back. If there's no rollback at all, you know the previous action has a commit somewhere.
Again note that Service actions or REST method calls do not run in the same database transaction, and will not be rolled back. This is especially useful for error reporting. But it seems you are talking about regular Server actions only, so that shouldn't be the problem.
Hi Kilian,
Thank you for your reply. This give us some idea on how to check back our business logic. We will try to check back which point in our action that having an explicit commit.
Regarding the service actions or REST method class, these action when triggered are running in different transaction. What happen if there is an explicit commit used in service actions or REST method class. Will it effect the main transaction from the server action?
For example,
Let say I'm using a service action in Module C with an explicit commit.
After the 200th iteration in Module A, if an exception is raised in Module C, will it rollback all records from previous iteration or all the records from previous iteration were committed due to an explicit commit triggered by the service action in Module C?
Regards,
Being in different transactions means that a commit or rollback has no effect on other transactions. So if a REST method does a commit, that's just for that method's transaction. The code calling that method has still its own, uncomitted, transaction.
However, if a REST method produces an unhandled exception, or it explicitly returns an HTTP status code other than in the 200-range, the platform generates an exception in the calling module, which may cause an abort transaction if not handled properly.
Can you please provide a screenshot of the processing done. As you mentioned its a batch process, i believe all the processing is done in a server flow, and from a client action you are not calling each of the said server actions.
Saurabh
Hi Saurabh,
Thank you for your reply, unfortunately i cant share the screenshot on how the processing is done since the original process are extracted into multiple sub-level server action to meet our business logic requirement. I try to simplify the process into scenario as stated above.