Reputation: 13
Could you please help me with following question:
I have the following configuration of partitioned cache cluster:
server nodes with writeThrough enabled. They are able to write data to DB by cacheStoreFactory=HibernateCacheStoreFactory
client nodes without writeThrough configuration but with clientMode=true
I perform put on client node, then I see, that this data is sent to server node, but server node performs put only to cache, but does not invoke cacheStoreFactory (writeThrough behaviour). So, data is only cached in cluster, but is not written to DB.
If I add writeThrough configuration to client nodes, writeThrough is invoked of course, but I would like to remove any dependencies on Hibernate from client nodes.
Also, if I enable writeBehind configuration on server side, then writeThrough functionality is invoked and server node, writes data from client node to DB asynchronously. But it does not satisfy my requirements, because I'd like to perform puts from client node in one transaction.
Is it possible to perform puts from client node to store data by server nodes with writeThrough in transaction without writeBehind?
Upvotes: 1
Views: 672
Reputation: 8390
Transactional cache writes to the persistence store from the node that initiated the transaction (in your case it's a client node). This is done because a transaction can potentially include entries that are stored on different nodes, and if the store will be also updated from different nodes, it would be impossible to maintain transactional consistency between cache and the database.
If you don't have access to the database on the client, you can send a closure to one of the servers and start a transaction there, like this:
Ignition.ignite().compute().run(new IgniteRunnable() {
@IgniteInstanceResource
private Ignite ignite;
@Override public void run() {
try (Transaction tx = ignite.transactions().txStart()) {
// Cache operations go here...
tx.commit();
}
}
});
Upvotes: 3