Search in sources :

Example 1 with GlobalTransaction

use of org.infinispan.transaction.xa.GlobalTransaction in project hibernate-orm by hibernate.

the class TxPutFromLoadInterceptor method endInvalidationAndInvokeNextInterceptor.

protected Object endInvalidationAndInvokeNextInterceptor(TxInvocationContext<?> ctx, VisitableCommand command) throws Throwable {
    try {
        if (ctx.isOriginLocal()) {
            // During evictAll inside transaction this would cause unnecessary invalidate command
            if (!ctx.getModifications().isEmpty()) {
                Object[] keys = ctx.getModifications().stream().flatMap(mod -> mod.getAffectedKeys().stream()).distinct().toArray();
                if (log.isTraceEnabled()) {
                    log.tracef("Sending end invalidation for keys %s asynchronously, modifications are %s", Arrays.toString(keys), ctx.getCacheTransaction().getModifications());
                }
                GlobalTransaction globalTransaction = ctx.getGlobalTransaction();
                EndInvalidationCommand commitCommand = cacheCommandInitializer.buildEndInvalidationCommand(cacheName, keys, globalTransaction);
                List<Address> members = stateTransferManager.getCacheTopology().getMembers();
                rpcManager.invokeRemotely(members, commitCommand, asyncUnordered);
                // we have to end invalidation from here manually (in successful case as well)
                for (Object key : keys) {
                    putFromLoadValidator.endInvalidatingKey(globalTransaction, key);
                }
            }
        }
    } finally {
        return invokeNextInterceptor(ctx, command);
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) EndInvalidationCommand(org.hibernate.cache.infinispan.util.EndInvalidationCommand) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Example 2 with GlobalTransaction

use of org.infinispan.transaction.xa.GlobalTransaction in project hibernate-orm by hibernate.

the class TxPutFromLoadInterceptor method beginInvalidating.

private void beginInvalidating(InvocationContext ctx, Object key) {
    TxInvocationContext txCtx = (TxInvocationContext) ctx;
    // make sure that the command is registered in the transaction
    txCtx.addAffectedKey(key);
    GlobalTransaction globalTransaction = txCtx.getGlobalTransaction();
    if (!putFromLoadValidator.beginInvalidatingKey(globalTransaction, key)) {
        log.failedInvalidatePendingPut(key, cacheName);
    }
}
Also used : TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Aggregations

GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)2 EndInvalidationCommand (org.hibernate.cache.infinispan.util.EndInvalidationCommand)1 TxInvocationContext (org.infinispan.context.impl.TxInvocationContext)1 Address (org.infinispan.remoting.transport.Address)1