Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Transaction Manager Problems

I have the situation where a few embedded and non-embedded services all need to use transactions for objects that can be any partition in the space.

For this I use the distributed tx-manager like so


<tx:annotation-driven />
<os-core:distributed-tx-manager id="transactionManager" default-timeout="2000" />


My space looks like this


<os-core:space id="space" url="/./spaceFX" mirror="true" external-data-source="hibernateDataSource">
      <os-core:filter-provider ref="serviceExporter" />
      <os-core:properties>
        <props>
            <prop key="cluster-config.cache-loader.external-data-source">true</prop>
            <prop key="cluster-config.cache-loader.central-data-source">true</prop>
            <prop key="space-config.engine.cache_policy">1</prop>
            <prop key="space-config.external-data-source.usage">read-only</prop>
            <prop key="-Dcom.gs.cluster.cache-loader.central-data-source">true</prop>
        </props>
    </os-core:properties>
</os-core:space>

<os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager" />
<os-sla:sla cluster-schema="partitioned-sync2backup" number-of-instances="2" number-of-backups="1" max-instances-per-vm="1" />+


then this second interface for cluster wide operations I perform now and then.


<os-core:giga-space id="gigaSpaceCluster" space="space" clustered="true" tx-manager="transactionManager" />


all this works nicely, only I'm having issues getting the transactions to work.

I need to use transactions primarally inside notifications code, initially the doc seemed to suggest I could use @Transactional annotations anywhere I liked (which didn't work) a little more digging and I found that I needed something like this on each notify


<os-events:notify-container id="myNotifyContainer" giga-space="gigaSpace">
   <os-events:tx-support tx-manager="transactionManager" />
   <os-events:notify write="true" update="true" />
   <os-core:template>
      <bean class="MyClass" />
   </os-core:template>
   <os-events:listener>
      <os-events:annotation-adapter>
         <os-events:delegate ref="myService" />
      </os-events:annotation-adapter>
   </os-events:listener>
</os-events:notify-container>

...

public void onNotify(MyClass obj, GigaSpace gigaSpace, TransactionStatus txStatus, EntryArrivedRemoteEvent entryArrived) {
read from space
write to space
throw Exception(); // trigger rollback
}

from http://www.gigaspaces.com/wiki/display/XAP66/NotifyContainerComponent#NotifyContainerComponent-TransactionSupport


Now my understanding is that when the associated notify method in code throws any sort of exception it will trigger a rollback of all space writes etc. that occurred during the method.

To cut the story short my questions are

1) Am I doing this the right way, as I can't see that it's working
2) Where and when can/do I use @Transactional, (I want this for code that isn't part of a notify event) and what else do I need to configure etc. in order to use it with dist tx-manager.

Thanks, this is driving me nuts.

Attachments

  1. distTxTest.zip

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2008-11-25 09:19:52 -0500

aparry gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

Can you post a simple test case?
Shay

Attachments

  1. distTxTest.zip

answered 2008-11-26 07:57:20 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Sure, here's a test project, a thread feeds in 1 object to the cluster every 15 seconds, service picks up a write notify and writes another object type to the space as a tx.

I can now get the local and distributed managers both working as expected (no idea what the problem was before), my only issue is the @Transactional usage, in which a thread attempts a transaction. It doesn't seem to work at all, nothing in the space browser either for active transactions.

Another question, I noticed that during a tx the objects I write appear in the space straight away, even though the tx hasn't committed, is this any sort of problem for reads from non-tx code? are these uncommitted changes ignored by a regular space read without a transaction being present?

Edited by: Andrew Parry on Nov 27, 2008 1:34 PM

Edited by: Andrew Parry on Nov 27, 2008 1:35 PM h4. Attachments

[distTxTest.zip|/upfiles/13759713714766485.zip]

aparry gravatar imageaparry ( 2008-11-27 07:00:45 -0500 )edit

"Another question, I noticed that during a tx the objects I write appear in the space straight away, even though the tx hasn't committed"

Do you mean u see the class instance count change at the GS-UI?

Shay

shay hassidim gravatar imageshay hassidim ( 2008-11-27 09:47:49 -0500 )edit

Yes I see that count in gs-ui going up and then down.

Just noticed in the code I attached, when I write from the thread with @Transactional on, the notify for that write never gets fired at all, even though the object is written to the space. Soon as I comment the annotation it works fine, I was under the impression this is how we're supposed to invoke transactions without doing it programatically?

aparry gravatar imageaparry ( 2008-11-27 10:58:57 -0500 )edit

The instance count at the UI reflect also non committed objects. This is using special API (RunTimeInfo).

Once you commit the tx the object will be visible for other clients. Notifications will be triggered once the tx will be committed.

We will take a look on your code and let you know.

Shay

shay hassidim gravatar imageshay hassidim ( 2008-11-27 15:20:27 -0500 )edit

Thanks Shay, it's much appreciated.

aparry gravatar imageaparry ( 2008-11-28 11:06:17 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-11-25 09:19:52 -0500

Seen: 52 times

Last updated: Nov 26 '08