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

Ask Your Question
0

Local/JINI transactions

So I have a few questions that I'm having a hard time finding definitive answers in the docs or the FAQ.

  1. We have an application that uses a partitioned sync2backup space. Most of the object types that are contained in that space are routed based on the same identifier, therefore they all end up in the same space. In this case, I believe it is OK to use the local transaction manager vs. mahalo? Is my assumption correct?

  2. We use a polling container and a listener that is annotated with @SpaceDataEvent. I understand Spring's declarative transaction handling, but no where in my xml nor annotations am I declaring the @SpaceDataEvent as @Transactional. So I'm trying to figure out how the transactions are used in that case? Am I not utilizing transactions and each operation is just transactional by default? It would seem so, as I'm also writing an object to the space that is not routed using same identifier as the rest, which would allow it to be written to a different partition, which should generate a transaction error. No transactions errors are ever thrown, which leads be to believe that the method is not a transactional unit.

  3. I'm trying to stay away from using jini distributed transactions as much as possible. Most of our operations that are performed in the listener are not atomic, though we're fine with not utilizing an atomic listener @SpaceDataEvent method. But I'm trying to understand what happens in the case where there is a read/write of an object that I need to get an exclusive lock on. So I do this...

SomeObject obj = eventSpace.readIfExists( new SomeObject(...), Long.MAX_VALUE, ReadModifiers.EXCLUSIVE_READ_LOCK );

Then later in the same method we update the object in the space with write(). Between the read and write ops, there quite possibly could be other writes to space of different objects. I need the read/write on that particular object to be atomic. Do I have to programmatically create a new transaction? Or does the exclusive read lock gets released when I write the object back into space?

Thanks.

Ilya Sterin

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2376]{quote}

asked 2008-06-10 10:37:42 -0500

isterin 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

Hi,

You are right on the first one; it is even preferred to use local transaction when possible. In this model scalability is higher.

For an example on how to use transactional polling container refer to either the data example under - ${gs.home}/examples/openspaces/data
Another option is to try the maven templates under tools which comes with the new 6.5 rc1.

If the operations described under section 3 are all under the same transaction, the space transaction semantics supports reentrancy.

Cheers,
Guy

answered 2008-06-10 10:45:19 -0500

nirpaz gravatar image
edit flag offensive delete link more

Comments

Guy, thanks for the reply. I think I didn't explain myself clearly on #3.

Say I have a @SpaceDataEvent method. I'm rightly assuming it's not transactional by default?

My polling container config looks somewhat like this...

<os-core:space id="events" url="jini://*/*/eventSpace" schema="default"/>

<os-core:local-tx-manager id="eventsTransactionManager" space="events" default-timeout="20000"> <os-core:renew pool-size="5" duration="1000" round-trip-time="500"/> </os-core:local-tx-manager>

<os-core:giga-space id="eventSpace" space="events" tx-manager="eventsTransactionManager"/>

<bean id="raceEventProcesor" .......=""/>

<os-events:polling-container id="raceEventProcessorPollingEventContainer" giga-space="eventSpace" recovery-interval="10" concurrent-consumers="5" max-concurrent-consumers="10" receive-timeout="1000"> <os-events:receive-operation-handler> <bean class="org.openspaces.events.polling.receive.SingleTakeReceiveOperationHandler"> <property name="nonBlocking" value="true"/> <property name="nonBlockingFactor" value="10"/> </bean> </os-events:receive-operation-handler> <os-events:tx-support tx-manager="eventsTransactionManager"/> <os-core:template> <bean class="com.bazumedia.race.entry.RaceEvent" >="" <property="" name="status" value="processingReady"/> </bean> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <os-events:delegate ref="raceEventProcessor"/> </os-events:annotation-adapter> </os-events:listener> </os-events:polling-container>

So I'm assuming that the polling container operations utilize the tx manager, the actual raceEventProcessor does not, since the bean's method is not annotated as @Transactional. I can find very little in the documentation about this.

Now, I'm actually ok with not executing the @SpaceDataEvent method as an atomic unit. If I do, I'm forced into using the jini tx manager, since there are writes there that write beans not routed based on same semantics, though operations will occur in different partitions. But I have this question, say this is my order of operations...

@SpaceDataEvent public RaceEvent processRaceEvent(RaceEvent raceEvent) { ..... // Routed to partition1 SomeObject obj2 = eventSpace.readIfExists( new SomeObject(...), Long.MAX_VALUE, ReadModifiers.EXCLUSIVE_READ_LOCK ); // Routed to partition 2 eventSpace.write(obj2);

// Routed to partition 1 eventSpace.write(obj2);

..... }

If the actual method is not transactional, how does the exclusive read lock get released as a part of the same transaction when I write obj2 back into space. The lock is acquired as a part of a transaction that's created when I read the object. That same transaction is not communicated the write(obj2).
Maybe my assumption that each operation uses a new transaction is wrong, but if it is, why doesn't the transaction fail, since I'm writing to two different partitions with a local tx manager.

Hopefully the above is a bit clearer.

Ilya

isterin gravatar imageisterin ( 2008-06-10 11:03:44 -0500 )edit

Ilya, If you want to see current transactions and the associated object use the UI. It will show you list of active transactions where double click on the object ID will show you the object.

AFAIK - Once your polling container associated with a space which have a transaction associated the @SpaceDataEvent is implicitly transactional.All the operations will be conducted with the same transaction.

When the @SpaceDataEvent method is completed and returns , it is committing the transaction and release the locks.

The GigaSpace interface has the getCurrentTransaction method which you can use to debug your code together with the UI.

Shay

shay hassidim gravatar imageshay hassidim ( 2008-06-10 11:19:59 -0500 )edit

Ok, I'll take a look. Is it correct that if you use a local tx manager to handle operational units that write to multiple partitions you would get an exception? It just seems weird that I've been using a local transaction manager and writing three objects that are routed on different data to 4 partitions and have never experienced an exception. That would be true if @SpaceDataEvent is an atomic transactional unit. But that assumption is either not true or I'm not understanding something else about local tx managers and multi partitioned operations. I've been writing thousands of objects into the space so the chance that they somehow luckily ended up in same partition is probably nil.

Ilya

isterin gravatar imageisterin ( 2008-06-10 13:21:09 -0500 )edit

If you use local transaction manager and had objects written to multiple partitions you should be getting an exception.

Shay

shay hassidim gravatar imageshay hassidim ( 2008-06-10 13:23:54 -0500 )edit

Ok, then something is explicitly happening to route an object. The object that I'm writing into the space that was not explicitly routed to same index doesn't have a @SpaceRouting annotation. I believe without it it chooses the first attribute (indexed) and routes based on that. Is that correct? Can it somehow explicitly route into same partitions that other objects are written to? I haven't had a single exception and these objects where distributed differently when I looked at space object counts.

isterin gravatar imageisterin ( 2008-06-10 13:40:24 -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-06-10 10:37:42 -0500

Seen: 59 times

Last updated: Jun 10 '08