Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected store call behavior #506

Closed
sergioasantiago opened this issue Jun 14, 2013 · 0 comments

Comments

Projects
None yet
2 participants
@sergioasantiago
Copy link

commented Jun 14, 2013

Hazelcast Version 2.6

I 've been developing an application which uses Hazelcast to store some orders data.
Everything was pretty nice until the moment when I needed to change my StoreClass. Before my changes my StoreClass implements only the MapLoader interface. Now my class implements MapStore interface, since I need start storing data rather than only read it.
Now I'm facing the following problem:
Every time when I use the 'get' method in a transaction, when commit method is called, I got an exception " Duplicated key order_id". In other words, the commit method is calling store even though I didn't put anything else new in my map.

Is this behavior expected or am I missing something?

PS: I can't just remove this 'get' call from my transaction, because in some cases (It depends of an if condition) I really need to call put method to store a new data.

Here is my piece of code where I call get method:

// Calling get method
CacheManager.transactionDo(new Runnable() {
@override
public void run() {
if (newAccounts != null) {
accountCache.put(acc_id, order);
}
ClientSession.this.accounts = accountCache.get(acc_id);
}
});

// Create a hazelcast transaction and commit it in case of success otherwise rollback.
public static boolean transactionDo(Runnable r) {
Transaction tx = Hazelcast.getTransaction();
tx.begin();
try {
r.run();
tx.commit();
} catch(RollbackException e) {
tx.rollback();
return false;
} catch (Throwable e) {
logger.error(e.getMessage(), e);
tx.rollback();
return false;
}
return true;
}

@enesakar enesakar closed this in 98b900c Jul 2, 2013

@ghost ghost assigned enesakar Jul 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.