Thread: DB Rollback Questions for 10.1.3.1


Permlink Replies: 10 - Pages: 1 - Last Post: Aug 14, 2008 7:02 AM Last Post By: Rodrigo de Assu...
sandsing

Posts: 13
Registered: 02/24/04
DB Rollback Questions for 10.1.3.1
Posted: Mar 20, 2007 2:12 PM
Click to report abuse...   Click to reply to this thread Reply
Looking for information on Database Adapter rollback capabilities for 10.1.3.1

We need to build a process which inserts in about 9 tables (20-25 inserts) per process invocation. If any insert fails we need to roll back all previous inserts i.e. even if 25th insert fails the all previous inserts 1 thru 24 should rollback.

I have gone through the following posts:
http://forums.oracle.com/forums/thread.jspa?messageID=1391189?
http://forums.oracle.com/forums/thread.jspa?messageID=1300702?

I need clarification on the below

1. Do I have to build the BPEL process as synchronous in order to achieve this?
2. Do all inserts that participate in the transaction need to be in the same BPEL process?
3. Any pointers to BPEL capabilities for rollback for version 10.1.3.1
4. Will the rollback happen when any fault (handled by catch or catch all or unhandled) (runtime or business) occurs?

5. Would it be better to depend on rollback or use compensation handler?

Thanks
Stephen Mcritchie

Posts: 190
Registered: 08/21/02
Re: DB Rollback Questions for 10.1.3.1
Posted: Mar 20, 2007 3:27 PM   in response to: sandsing in response to: sandsing
Click to report abuse...   Click to reply to this thread Reply
1. Do I have to build the BPEL process as synchronous in order to achieve this?
Yes. By nature of XA only work that occurs in one thread can be synchronized.
2. Do all inserts that participate in the transaction need to be in the same BPEL process?
If the calls to child processes are synchronous and have the transaction participate property set they will commit/rollback as a unit.

3. Any pointers to BPEL capabilities for rollback for version 10.1.3.1

For 10.1.3.1 please see the README.txt to the XAInsert sample:

bpel/samples/tutorials/122.DBAdapter/advanced/dmlInvoke/XAInsert.

What it mentions about needing to set transaction participate and failed instances not showing up in the bpel console is still true.

Please also see the Deployment Section of the Adapter guide

http://download-east.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_db.htm#CHDEEIHJ

4. Will the rollback happen when any fault (handled by catch or catch all or unhandled) (runtime or business) occurs?

Good question. In 10.1.3.1 the TopLink stack underneath calls mark rollback only on failure, so it is impossible to handle/swallow the exception and try something else. In 10.1.3.3 the markRollbackOnly will happen only if an invoke executing multiple statements internally fails halfway. So you can handle an exception and proceed in cases where it is still safe to do so. Note that if you don't handle the fault and transaction participate is set on the bpel process level, rollback will still occur.

On encountering a remote (connection related) fault, the transaction is also rolled back and the instance goes into manual recovery. This is all in the XA case. Again this fault cannot be handled via partnerlink retries. In 10.1.3.3 that will no longer happen so long as the global transaction is still active, allowing you to configure partnerlink retries.

5. Would it be better to depend on rollback or use compensation handler?

You can depend on the XA rollback behavior. If using compensation do not use an XA datasource (and in oc4j-ra.xml set dataSourceName not xADataSourceName), and then have fault handlers.

If anything the XA rollback behavior just works a little too well. As can be seen we are attempting to make the XA behavior a little less severe in 10.1.3.3, within the bounds of the very strict XA contract. The nature XA itself causes problems. This is from the README:

It is something of conundrum, the report of success or failure must itself be
part of the global transaction, but it is theoretically impossible to report
failure as part of a global transaction that has failed (is being rolled back).

Also about syntax, transaction participate can be set both on the partnerlink level and the bpel level. On the global level the syntax is here:

</partnerLinkBindings>
<property name="transaction">participate</property>
</BPELProcess>
</BPELSuitcase>

On the partnerlink level it is:

<partnerLinkBinding name="Insert1Service">
<property name="transaction">participate</property>
...
</partnerLinkBinding>

It is transaction=participate (not participate=true). Setting the global property does not count as setting it on a per partnerlink basis. You must set both. You do not need to set it on the partnerlink level for dbadapter invokes. Just for calling external services/processes.

Thanks

Steve

sandsing

Posts: 13
Registered: 02/24/04
Re: DB Rollback Questions for 10.1.3.1
Posted: Mar 21, 2007 11:15 AM   in response to: Stephen Mcritchie in response to: Stephen Mcritchie
Click to report abuse...   Click to reply to this thread Reply
Steve,

Thanks for the prompt and detailed reply. I am not completely clear on #4 i.e. role of exceptional handling using catch & catchall w.r.t. database rollback.

Here is a scenario:

Lets assume we have scope1, scope 2 and scope 3 with their own catch and catchall branches where scope 1 is the main scope. Each scope has their own set of inserts, but they all need to commit as a unit.

Lets say scope1 was successfull and the inserts took place (not committed yet), scope 2 throws some fault, hence control gets into the catchall branch and catchall executes.

The way I have seen BPEL work is that the control will now pass to scope3 and the flow will continue from there.

w.r.t. rollback .... would the inserts in scope 3 be fired at all and then because scope 2 faulted everything (i.e. all inserts from scope1,2& 3 are rolledback)

or would scope 3 not be executed at all.

Scenario2: Lets say all inserts executed well (scope 1,2 & 3 are good), but there is another scope4 which calls an external WS that faulted (say binding fault). Would the rollback occur even in this scenario?

Sorry for the long post.

-- Thanks
Stephen Mcritchie

Posts: 190
Registered: 08/21/02
Re: DB Rollback Questions for 10.1.3.1
Posted: Mar 21, 2007 12:13 PM   in response to: sandsing in response to: sandsing
Click to report abuse...   Click to reply to this thread Reply
Hi,

there was one thing I neglected to mention in the above post. And that is all the above applies within a "transaction boundary".

So I think your question is what marks transaction boundaries in a synchronous process? From Clemens' blog (http://clemensblog.blogspot.com/2006/03/loosely-coupled-and-transacted.html),

"Understanding BPEL PMs transactional behaviour turns down to one question, when, at what points, does the engine commit.

These commits happen ..

* before a receive activity (but not the initial one!)

* before a wait activity (otherwise the engine could run into a tx timeout)

* before an onMessage, or pick(extended onMessage) activity

* when using checkPoint() within a bpelx:exec activity"

Note that the begin or end of a scope does not constitute a global transaction boundary in BPEL. So scopes define boundaries for compensation logic but not for XA rollback behavior.

This really means that compensation and XA are somewhat orthogonal approaches. If you are designing a process with compensation you will think about scopes. Designing a process with XA you will think about checkpoints.

So to answer your question the 4 scopes should commit or fail as a unit.

Thanks

Steve

sandsing

Posts: 13
Registered: 02/24/04
Re: DB Rollback Questions for 10.1.3.1
Posted: Mar 21, 2007 3:37 PM   in response to: Stephen Mcritchie in response to: Stephen Mcritchie
Click to report abuse...   Click to reply to this thread Reply
Steve,

So w.r.t. the sync process in my previous post

* before a receive activity (but not the initial one!)
(Commit will not happen here as I only have the initial recieve in my BPEL)

* before a wait activity (otherwise the engine could run into a tx timeout)
(Commit will not happen here as I do not have a wait in my BPEL)

* before an onMessage, or pick(extended onMessage) activity
(Commit will not happen here as I do not have an onMessage or pick in my BPEL)

* when using checkPoint() within a bpelx:exec activity"
(Commit will not happen here as I do not have a bpelx:exec in my BPEL)

So when will the commit happen. Are we missing some other events when the commit will take place? Like just before the reply activity.
sandsing

Posts: 13
Registered: 02/24/04
Re: DB Rollback Questions for 10.1.3.1 and 10.1.3.3
Posted: Aug 30, 2007 12:33 PM   in response to: sandsing in response to: sandsing
Click to report abuse...   Click to reply to this thread Reply
We recently upgraded from 10.1.3.1 to 10.1.3.3 and found that our database adapter rollbacks are not happening in 10.1.3.3. We have 4 database inserts one after the other and if the 4th failes the 1st 3 do not rollback.

Has something changed between 10.1.3.1 and 10.1.3.3. w.r.t to the way transactions are handled? Is there a way to get the old behaviour back without having to change our processes?
Stephen Mcritchie

Posts: 190
Registered: 08/21/02
Re: DB Rollback Questions for 10.1.3.1 and 10.1.3.3
Posted: Aug 30, 2007 3:15 PM   in response to: sandsing in response to: sandsing
Click to report abuse...   Click to reply to this thread Reply
Hi Sandeep,

there is a possibility for the 10.1.3.3 behavior to be more lenient and not always cause a rollback. Please see this below documentation for a good overview of the 10.1.3.3 behavior.

XA Configuration - 2 DBAdapter invokes committing/rolling back as a unit

To make 2 invokes commit or rollback as a unit requires the following: both DBAdapter invokes must be configured to participate in global transactions, both invokes must participate in the same global transaction, and the failure of either invoke must cause the global transaction to rollback.

1 Configuring DBAdapter for Global Transaction participation

In the deployment descriptor (oc4j-ra.xml), you must set xADataSourceName. The matching data-source entry (in data-sources.xml) must be configured for transaction participation, i.e.

<managed-data-source name="BPELSamplesDataSource" connection-pool-name="BPEL_POOL" jndi-name="jdbc/BPELSamplesDataSource" tx-level="global" />

Notice the tx-level="global" property. It can be omitted as "global" is the default value, but if the value is "local" then it is not configured correctly.

True XA: Two-Phase (XA) vs One-Phase (Emulated) Commit

XA is a two-phase commit protocol, which is more robust than a 1 phase commit or emulated protocol. The difference is that with a one-phase protocol you may very rarely still see message loss or other rollback/commit inconsistency, on the order of one per one thousand generally.

A true XA config in data-sources.xml is shown below:

<connection-pool name='dbSample_CONNECTION_POOL'
inactivity-timeout='60'
validate-connection='false'
num-cached-statements='5'
time-to-live-timeout='600'>

<connection-factory factory-class='oracle.jdbc.xa.client.OracleXADataSource'
user='scott'
password='tiger'
url="..."
</connection-factory>

</connection-pool>

<managed-data-source name='DBSampleNonEmulatedDS'
connection-pool-name='dbSample_CONNECTION_POOL'
jndi-name='jdbc/dbSample' tx-level="global" />

Notice the setting of connection-factory-class to an OracleXADataSource.

2 Both Invokes in Same Global Transaction

Once the invokes participate in global transactions, to commit/rollback as a unit they must be participating in the same global transaction. In BPEL this requires understanding where are the transaction boundaries, at what points a checkpoint to write to the dehydration store commits the current global transaction and starts a new one.

The 'transaction boundaries' in a BPEL process are:
-before a receive activity (but not the initial one!)
-before a wait activity (otherwise the engine could run into a tx timeout)
-before an onMessage, or pick(extended onMessage) activity
-when invoking a synchronous child BPEL process, unless the transaction participate property is set on the partnerlink. Otherwise the parent process is broken into two transactions and the child process executes in its own transaction.


3 Failure Must Cause Rollback

Finally, even if both invokes participate in the same global transaction, the failure of either invoke may not cause the global transaction to rollback.
The only cases where a failure can actually cause a global rollback are:

-A DBAdapter operation that inserts/updates multiple tables as part of one invoke fails after having succeeded in some writes but not others. In this case the adapter will mark the global transaction 'rollback only', as the invoke operation was not atomic and a commit could cause data corruption.

-The global transaction participate property is set in bpel.xml, so that when BPEL catches a fault from the DBAdapter invoke it will allow the fault to propogate up and cause a global rollback.

-The invoke retries multiple times in a database down scenario, until the global transaction times out and is rolled back.

-An explicit bpelx:rollback fault is thrown from within the BPEL process.

GetActiveUnitOfWork="true" in WSDL

GetActiveUnitOfWork is an advanced WSDL property you can set on any DBInteractionSpec. It causes the invoke to register itself with the two-phase commit callbacks, and all writes to the database are performed as part of the two-phase commit. By setting this property on any failure the transaction is automatically rolled back, as there is no way to 'handle' a fault at this late stage. The global transaction participate property is not required to be set. Likewise the same underlying TopLink session is used for both invokes, meaning if you merge the same object twice, it will only be inserted/updated once. All merge invokes which set GetActiveUnitOfWork="true" are cumulative.

Related Questions

Can I guarantee that both invokes use the same sql connection?

You cannot guarantee this but you can normally expect it. If you notice it is not the case, and you are using an XADataSource, you can set the property GetActiveUnitOfWork="true" on all participating invokes.
Does a scope form a transaction boundary?

No, a scope does not form a transaction boundary. XA commit/rollback and compensation are really orthogonal to each other. They ae also a little mutually exclusive. You should decide on one or the other.

I configured the process for XA but on failure no instance appears in the BPELConsole?

This is actually expected. The easiest test of whether the global transaction actually rolled back or not is to see if the instance appears in the BPELConsole. If it appears as faulted that means the transaction was committed anyway, so the auditing to the dehydration store could proceed.

How do you configure transaction participate?

On a child process invoke, set transaction participate on the partnerlink:

<partnerLinkBinding name="...">
<property name="transaction">participate</property>
</partnerLinkBinding>

To set the global property, so that a failed invoke will cause the entire transaction to rollback:

</partnerLinkBindings>
<configurations>
<property name="transaction">participate</property>
</configurations>
</BPELProcess>

How do you throw a rollback fault in bpel?

<throw name="Throw" faultName="bpelx:rollback"/>

How do I find out more about XA?

Please look at the DBAdapter samples 122.DBAdapter/advanced/dmlInvoke/XAInsert, and 122.DBAdapter/InsertWithCatch.

How to make a DBAdapter receive (polling) and invoke part of the same XA transaction?

You must configure the polling DBAdapter to synchronously initiate the BPEL process. Please see the README for 122.DBAdapter/advanced/endToEnd/DirectSqlPerformance/README.txt for step-by-step instructions.

Thanks

Steve

pravin.prakash@...

Posts: 25
Registered: 09/17/07
Re: DB Rollback Questions for 10.1.3.1 and 10.1.3.3
Posted: Sep 17, 2007 3:54 AM   in response to: Stephen Mcritchie in response to: Stephen Mcritchie
Click to report abuse...   Click to reply to this thread Reply
Hi,

I have a BPEL process in which i'm writing into a Database twice in a synchronous process using two separate DB adapters. After that I am using a throw block to throw an exception (forcedTermination in this case).
I am using 10.1.3.3. When I run it, there were no rollbacks for the previous two database transactions. And/But, i get a fault expression which looks like this :

<faultstring>com.oracle.bpel.client.delivery.ReceiveTimeOutException: Waiting for response has timed out. The conversation id is 677b9e75e3805022:322b0043:115156ea237:-7fa8. Please check the process instance for detail.</faultstring>

This happens at the point where I throw the fault.

But earlier, I did not have this throw block, instead I was trying to write to the database a third time so that there's a uniqe key violation. When this was the case, it was rolling back the previous two transactions too.
Can you tell me when all the rollbacks occur and when all it does not?

Thanks
Pravin
mmenezes

Posts: 134
Registered: 02/16/06
Re: DB Rollback Questions for 10.1.3.1 and 10.1.3.3
Posted: Sep 21, 2007 1:37 PM   in response to: Stephen Mcritchie in response to: Stephen Mcritchie
Click to report abuse...   Click to reply to this thread Reply
Hi Stephen

Just one question, when you said:

I configured the process for XA but on failure no instance appears in the BPELConsole?

This is actually expected. The easiest test of whether the global transaction actually rolled back or not is to see if the instance appears in the BPELConsole. If it appears as faulted that means the transaction was committed anyway, so the auditing to the dehydration store could proceed.

What is the relation between the dehydration store transactions and the business transactions?

I guess even if I have a business rollback (which cause a rollback on the business transaction ), the BPEL instance should be created (the dehydration store transaction should commit), isn´t it?

Thanks

user651980

Posts: 1
Registered: 08/14/08
Re: DB Rollback Questions for 10.1.3.1 and 10.1.3.3
Posted: Aug 14, 2008 1:49 AM   in response to: mmenezes in response to: mmenezes
Click to report abuse...   Click to reply to this thread Reply
Hi All,

Who the hell said that Oracle BPEL does transaction Roll Back. Can anybody provide me any BPEL process code which does roll back.

It does rollback only if system crashes.

I have tried all the ways suggested above and got frustated that didn't work.

First i have tried for DB Adapter but the above given fundas didn't work even for simple BPEL Transaction Roll Back for failure.
Rodrigo de Assu...

Posts: 21
Registered: 07/10/08
Re: DB Rollback Questions for 10.1.3.1 and 10.1.3.3
Posted: Aug 14, 2008 7:02 AM   in response to: mmenezes in response to: mmenezes
Click to report abuse...   Click to reply to this thread Reply
Hi Stephen,

I have a doubt...

In my process i have two DBAdapters, insert into tow distinct database. The first adapter realy insert and the second raise a pl/ssql raise_application_error.
I configure the connections to use the xaDataSource and transaction participate...

It's works fine, and the log for the instante not appears in the BPEL Console.
(like you say and the mmenezes question)

Then i put the assigns and invokes into a scope and this scope have a CatchAllBranch... With this changes the process not rollback the first adapter...

I'ts normal ?

Tks
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums