Hi,

I observed one more behavior. I am using executor service to execute the tasks.
When I submit a task to remove entries from cache, I get transaction optimistic exception.
But instead of submitting the task, if I just call task.run() method it works fine.


Thanks,
Prasad

On Tue, Jun 5, 2018 at 7:07 PM, Andrey Mashenkov <andrey.mashenkov@gmail.com> wrote:
Hi,

We'll check this case. 
Please, share a reproducer if possible.

On Tue, Jun 5, 2018 at 3:53 PM, Prasad Bhalerao <prasadbhalerao1983@gmail.com> wrote:
Hi,

In my case only one transaction is in progress. In this transaction I update few entries in cache and then re-read these entries and updates it again in some other method.
When I read the entry after first update operations, transaction entry read version(IgniteTxEntry-entryReadVersion) changes. This version is validated in GridDhtTxPrepareFuture::checkReadConflict method.

But I don't understand why transaction fails if the entry is modified after read operation in same transaction?

Thanks,
Prasad

On Tue, Jun 5, 2018 at 6:07 PM, Andrey Mashenkov <andrey.mashenkov@gmail.com> wrote:
Hi,

It is ok, Optimistic transaction failed on commit with TransactionOptimisticException due to write\read conflict.
See javadoc [1] and documentation [2] for details.

Javadoc says:
*  However, in {@link TransactionConcurrency#OPTIMISTIC} mode, if some transactions cannot be serially isolated
 *  from each other, then one winner will be picked and the other transactions in conflict will result in
 * {@link TransactionOptimisticException} being thrown.


On Tue, Jun 5, 2018 at 3:19 PM, Prasad Bhalerao <prasadbhalerao1983@gmail.com> wrote:
Hi,
I tried this with simple code and it works fine. 
But in my application when I do similar thing I get following exception when I do commit. I am getting transaction as follows.

    IgniteTransactions igniteTx = getServiceContext().getGridService().getTransaction();
    try (Transaction transaction = igniteTx
        .txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.SERIALIZABLE)) {

Can you please advise?

Caused by: org.apache.ignite.transactions.TransactionOptimisticException: Failed to prepare transaction, read/write conflict [key=DefaultDataAffinityKey{id=1556524, affinityId=1}, keyCls=com.qls.agms.grid.data.key.DefaultDataAffinityKey, val=null, cache=IPV4_ASSET_GROUP_DETAIL_CACHE, thread=IgniteThread [compositeRwLockIdx=7, stripe=-1, plc=0, name=pub-#53%springDataNode%]]
            at org.apache.ignite.internal.util.IgniteUtils$14.apply(IgniteUtils.java:895)
            at org.apache.ignite.internal.util.IgniteUtils$14.apply(IgniteUtils.java:893)
            at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:975)
            at org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl.commit(TransactionProxyImpl.java:296)
            at com.qls.agms.task.ignite.EditAssetGroupIgniteTask.run(EditAssetGroupIgniteTask.java:44)
            at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C4.execute(GridClosureProcessor.java:1944)
            at org.apache.ignite.internal.processors.job.GridJobWorker$2.call(GridJobWorker.java:566)
            at org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6623)
            at org.apache.ignite.internal.processors.job.GridJobWorker.execute0(GridJobWorker.java:560)
            ... 5 common frames omitted
Caused by: org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException: Failed to prepare transaction, read/write conflict [key=DefaultDataAffinityKey{id=1556524, affinityId=1}, keyCls=com.qls.agms.grid.data.key.DefaultDataAffinityKey, val=null, cache=IPV4_ASSET_GROUP_DETAIL_CACHE, thread=IgniteThread [compositeRwLockIdx=7, stripe=-1, plc=0, name=pub-#53%springDataNode%]]
            at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture.versionCheckError(GridDhtTxPrepareFuture.java:1190)
            at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture.checkReadConflict(GridDhtTxPrepareFuture.java:1138)
            at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture.prepare0(GridDhtTxPrepareFuture.java:1205)
            at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture.mapIfLocked(GridDhtTxPrepareFuture.java:671)
            at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture.prepare(GridDhtTxPrepareFuture.java:1048)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal.prepareAsyncLocal(GridNearTxLocal.java:3452)
            at org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler.prepareColocatedTx(IgniteTxHandler.java:257)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticSerializableTxPrepareFuture.prepareLocal(GridNearOptimisticSerializableTxPrepareFuture.java:580)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticSerializableTxPrepareFuture.prepare(GridNearOptimisticSerializableTxPrepareFuture.java:494)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticSerializableTxPrepareFuture.prepare(GridNearOptimisticSerializableTxPrepareFuture.java:408)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticSerializableTxPrepareFuture.prepare0(GridNearOptimisticSerializableTxPrepareFuture.java:315)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFutureAdapter.prepareOnTopology(GridNearOptimisticTxPrepareFutureAdapter.java:137)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFutureAdapter.prepare(GridNearOptimisticTxPrepareFutureAdapter.java:74)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal.prepareNearTxLocal(GridNearTxLocal.java:3161)
            at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal.commitNearTxLocalAsync(GridNearTxLocal.java:3221)
            at org.apache.ignite.internal.processors.cache.GridCacheAdapter.commitTxAsync(GridCacheAdapter.java:4019)
            at org.apache.ignite.internal.processors.cache.GridCacheSharedContext.commitTxAsync(GridCacheSharedContext.java:975)
            at org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl.commit(TransactionProxyImpl.java:288)
            ... 10 common frames omitted

Thanks,
Prasad

On Tue, Jun 5, 2018 at 2:18 PM, Andrey Mashenkov <andrey.mashenkov@gmail.com> wrote:
Hi,

Sure, multiple actions with same query within same transaction should work.

Please, let us know if you observe unexpected behavior.
Any reproducer will be appreciated.


On Tue, Jun 5, 2018 at 10:36 AM, Prasad Bhalerao <prasadbhalerao1983@gmail.com> wrote:
Hi,

Can I update the same entry multiple time inside ignite transaction?
Or
Can I update an entry and then remove the same entry in ignite transaction?

Thanks,
Prasad



--
Best regards,
Andrey V. Mashenkov




--
Best regards,
Andrey V. Mashenkov




--
Best regards,
Andrey V. Mashenkov