Thursday 11 July 2013

SOA : Tranasaction/Scope/Rollback

PROBLEM STATEMENT:
------------------
Transaction in a scope doesn't rollback when a fault is received from a partner link.

1.AsynchronousBPEL is 1-way async process which inserts records into test2 table
2.SynchronousBPEL is sync bpel process inserting records into test1 table,
transaction set to "required" which gets executed in same transaction from
parent
3.col1 on both tables will always have a constant value as "Test" assignedin BPEL
4.Col2 will have the input value passed from AsyncBPEL process 

After updating the test1 table with a duplicate entry, the test2 table
throws a key violation. This should cause the test1 table value to be
rolled back.

EXPLANATION:
---------
Though the user case reproduces the issue , the cause lies with the design of the BPEL process itself .

The CatchAll{} fault handler in the main scope of AsynchronousBPEL process prevents the fault/exception from bubbling up to the engine .
Since the fault is handled by the BPEL process  , the engine is unaware of the exception -
causing the transaction in SynchronousBPEL to be not rolled back.

This behavior can be verified by looking through the audit trail.
In the audit trail we will observe that the state of the SynchronousBPEL 
would remain as "Completed" meaning that , the transaction in SynchronousBPEL
 was never rolled back.

Until the BPEL engine is notified of the underlying exception , it cannot
ascertain the cause and rollback the dependent transactions.


To achieve this , the use case will have to "Rethrow" the fault from
CatchAll{} fault handler in the main scope of AsynchronousBPEL process.This
way , the engine will be notified of the exception and appropriate action
initiated(In this case ,transaction rollback of SynchronousBPEL).
Of course , this rethrow can happen after the required action has been
undertaken
(e.g) notification via email.
  <faultHandlers>
    <catchAll>
      <sequence name="Sequence1">
        <invoke name="Notify"/>    <!--  action on the fault -->
        <rethrow name="Rethrow"/>  <!-- throw back the exception to the
engine --->
      </sequence>
    </catchAll>
  </faultHandlers>


With this change in place , a failure in inserting data into
table test 2(Invoke2) would also result in rollback of the insert into table
test1.

No comments:

Post a Comment