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

Ask Your Question

Data feeder and transaction

How to feed objects to space so when failover happens (with sync2backup enabled) then no multiple objects are inserted to space? From the example: Should I use different txManager (jini)? Should I do something with failed tx?

    IJSpace space = (IJSpace)SpaceFinder.find( "jini://*/*/space" );
    TransactionManager trManager = LocalTransactionManager.getInstance(space);
        boolean inserted = false
        do {
            try {
                created = TransactionFactory.create(trManager, 60*1000);
                space.write(new Object(), created.transaction, Lease.FOREVER);
                inserted = true;                        
            } catch (Exception e) {
                if (created != null) {
                    try {
                    } catch (Exception ex) {
        } while (!inserted);

h4. Attachments



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

asked 2008-05-11 09:46:58 -0500

kaarelk gravatar image

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

jaissefsfex gravatar image
edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

When using transactions , if the space fails , you will get TransactionException and the operation will be routed to the backup space that turned to be the primary. There is no need to call SpaceFinder again.
With non transactional operations, the client will be routed to the backup implicitly.

If you are using partitioned space and the objects involved with the transaction have different routing field value , you should use Jini distributed transaction , otherwise you should use Local Transaction.

See more:

If you are using distributed transaction don't miss this:


answered 2008-05-12 21:31:26 -0500

shay hassidim gravatar image
edit flag offensive delete link more

My current use case requires transaction on one partition (but with sync2backup enabled). So LocalTransactionManager is correct one to use?

I skipped some of the code from the example last time. I added whole prototype as attachment. Problem is that with that implementation of Feeder class there will be more Message objects inserted to space than there is for iterations. Should I do sth extra with failed transaction object?

My test: started single partition space with a backup. Started 3 feeders. Terminated primary partition. After feeders finished there job there were 30002 message objects in space. Only one of the feeders failed to abort the failed transaction (i.e caught exception while aborting).

I noticed that each transaction has unique ID. Can I check transaction status from space based on that ID? h4. Attachments


answered 2008-05-13 04:15:10 -0500

kaarelk gravatar image
edit flag offensive delete link more


Yes – with your case you can use Local Transaction Manager. Which build you are using?

Please note your code write the same POJO object twice. In some cases the second write would be in fact an update operation. I’m not sure this is what you want.

Can you test this with 6.5 M11? We might have fixed something that is relevant for your case.

You can get the list of locked objects and their related operations using the JMX Transaction Admin API: http://www.gigaspaces.com/wiki/displa...

The com.j_spaces.core.client.TransactionInfo includes the actual info.


shay hassidim gravatar imageshay hassidim ( 2008-05-13 10:52:56 -0500 )edit

{quote:title=Shay wrote:}{quote}Please note your code write the same POJO object twice. In some cases the second write would be in fact an update operation. I?m not sure this is what you want. No this is not the case. Messages are meant for consuming and there is no guarantee that consumer won't take already inserted message before external service will try to insert it again. I used SpaceId(autogenerate=true) to emulate this situation (i.e no updates occur).

{quote:title=Shay wrote:}{quote}Can you test this with 6.5 M11?

I tried this with: 6.0, 6.5 M9 and 6.5 M11

Main problem is described in attached diagram. Every DB suffers from the same problem but I hoped you have some built in solution to deal with it. Possible solutions in order of preference: * GigaSpace has built in and transparent support for it * GigaSpace stores transaction backlog and I can check transaction status (after transaction is already over) * each application builds its own solution for idempotence (e.g keeping backlog of consumed messages)

Edited by: Kaarel Kann on May 14, 2008 6:29 AM

Edited by: Kaarel Kann on May 14, 2008 8:47 AM h4. Attachments


answered 2008-05-14 02:44:14 -0500

kaarelk gravatar image
edit flag offensive delete link more

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


Asked: 2008-05-11 09:46:58 -0500

Seen: 216 times

Last updated: May 14 '08