Search in sources :

Example 1 with CacheXid

use of org.infinispan.server.hotrod.tx.table.CacheXid in project infinispan by infinispan.

the class LifecycleCallbacks method createGlobalTxTable.

private synchronized void createGlobalTxTable(EmbeddedCacheManager cacheManager) {
    if (!registered) {
        Cache<CacheXid, TxState> cache = cacheManager.getCache(GLOBAL_TX_TABLE_CACHE_NAME);
        GlobalTxTable txTable = new GlobalTxTable(cache, globalComponentRegistry);
        globalComponentRegistry.registerComponent(txTable, GlobalTxTable.class);
        registered = true;
    }
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) TxState(org.infinispan.server.hotrod.tx.table.TxState) GlobalTxTable(org.infinispan.server.hotrod.tx.table.GlobalTxTable)

Example 2 with CacheXid

use of org.infinispan.server.hotrod.tx.table.CacheXid in project infinispan by infinispan.

the class TxReaperAndRecoveryTest method initGlobalTxTable.

private void initGlobalTxTable(int index, XidImpl xid, Address address, boolean recoverable, Status status) {
    GlobalTxTable globalTxTable = globalTxTable(index);
    CacheXid cacheXid = new CacheXid(fromString(cacheName()), xid);
    List<TxFunction> functions = new ArrayList<>(5);
    GlobalTransaction gtx = address == null ? newGlobalTransaction(cacheName(), index) : newGlobalTransaction(cacheName(), index, address);
    switch(status) {
        case ACTIVE:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            break;
        case PREPARING:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            functions.add(new PreparingDecisionFunction(Collections.emptyList()));
            break;
        case PREPARED:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            functions.add(new PreparingDecisionFunction(Collections.emptyList()));
            functions.add(new SetPreparedFunction());
            break;
        case MARK_ROLLBACK:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            functions.add(new PreparingDecisionFunction(Collections.emptyList()));
            functions.add(new SetPreparedFunction());
            functions.add(new SetDecisionFunction(false));
            break;
        case MARK_COMMIT:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            functions.add(new PreparingDecisionFunction(Collections.emptyList()));
            functions.add(new SetPreparedFunction());
            functions.add(new SetDecisionFunction(true));
            break;
        case ROLLED_BACK:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            functions.add(new PreparingDecisionFunction(Collections.emptyList()));
            functions.add(new SetPreparedFunction());
            functions.add(new SetDecisionFunction(false));
            functions.add(new SetCompletedTransactionFunction(false));
            break;
        case COMMITTED:
            functions.add(new CreateStateFunction(gtx, recoverable, 1));
            functions.add(new PreparingDecisionFunction(Collections.emptyList()));
            functions.add(new SetPreparedFunction());
            functions.add(new SetDecisionFunction(true));
            functions.add(new SetCompletedTransactionFunction(true));
            break;
        default:
            throw new IllegalStateException();
    }
    for (TxFunction function : functions) {
        assertEquals(Status.OK, globalTxTable.update(cacheXid, function, 30000));
    }
    assertEquals(status, globalTxTable.getState(cacheXid).getStatus());
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) SetCompletedTransactionFunction(org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction) ArrayList(java.util.ArrayList) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction) CreateStateFunction(org.infinispan.server.hotrod.tx.table.functions.CreateStateFunction) PreparingDecisionFunction(org.infinispan.server.hotrod.tx.table.functions.PreparingDecisionFunction) GlobalTxTable(org.infinispan.server.hotrod.tx.table.GlobalTxTable) SetDecisionFunction(org.infinispan.server.hotrod.tx.table.functions.SetDecisionFunction) SetPreparedFunction(org.infinispan.server.hotrod.tx.table.functions.SetPreparedFunction)

Example 3 with CacheXid

use of org.infinispan.server.hotrod.tx.table.CacheXid in project infinispan by infinispan.

the class TopologyChangeFunctionalTest method testOriginatorLeftBeforePrepare.

public void testOriginatorLeftBeforePrepare(Method method) {
    final byte[] k1 = k(method, "k1");
    final byte[] k2 = k(method, "k2");
    final byte[] v1 = v(method, "v1");
    final byte[] v2 = v(method, "v2");
    RemoteTransaction tx = RemoteTransaction.startTransaction(clients().get(0));
    tx.set(k1, v1);
    tx.set(k2, v2);
    tx.getAndAssert(k1, v1);
    tx.getAndAssert(k2, v2);
    tx.prepareAndAssert(XAResource.XA_OK);
    killNode(0);
    // set the tx state to running
    GlobalTxTable transactionTable = extractGlobalComponent(manager(0), GlobalTxTable.class);
    CacheXid cacheXid = new CacheXid(ByteString.fromString(cacheName()), tx.getXid());
    TxState state = transactionTable.getState(cacheXid);
    transactionTable.remove(cacheXid);
    TxFunction function = new CreateStateFunction(state.getGlobalTransaction(), false, 60000);
    transactionTable.update(cacheXid, function, 60000);
    // index 0 is removed, index 0 is the old index 1
    tx.prepareAndAssert(clients().get(0), XAResource.XA_OK);
    tx.commitAndAssert(clients().get(0), XAResource.XA_OK);
    tx.forget(clients().get(0));
    assertData(k1, v1);
    assertData(k2, v2);
    assertServerTransactionTableEmpty();
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) RemoteTransaction(org.infinispan.server.hotrod.test.RemoteTransaction) TxState(org.infinispan.server.hotrod.tx.table.TxState) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction) CreateStateFunction(org.infinispan.server.hotrod.tx.table.functions.CreateStateFunction) GlobalTxTable(org.infinispan.server.hotrod.tx.table.GlobalTxTable)

Example 4 with CacheXid

use of org.infinispan.server.hotrod.tx.table.CacheXid in project infinispan by infinispan.

the class TxReaperAndRecoveryTest method assertStatus.

private void assertStatus(boolean timeout, boolean recoverable, XidImpl... xids) {
    GlobalTxTable globalTxTable = globalTxTable(0);
    for (XidImpl xid : xids) {
        CacheXid cacheXid = new CacheXid(fromString(cacheName()), xid);
        TxState state = globalTxTable.getState(cacheXid);
        assertEquals(recoverable, state.isRecoverable());
        assertEquals(timeout, state.hasTimedOut(timeService.time()));
    }
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) TxState(org.infinispan.server.hotrod.tx.table.TxState) XidImpl(org.infinispan.commons.tx.XidImpl) GlobalTxTable(org.infinispan.server.hotrod.tx.table.GlobalTxTable)

Example 5 with CacheXid

use of org.infinispan.server.hotrod.tx.table.CacheXid in project infinispan by infinispan.

the class BaseCompleteTransactionOperation method completeCache.

/**
 * Completes the transaction for a specific cache.
 */
private CompletionStage<Void> completeCache(ByteString cacheName) throws Throwable {
    TxState state = globalTxTable.getState(new CacheXid(cacheName, xid));
    HotRodServer.ExtendedCacheInfo cacheInfo = server.getCacheInfo(cacheName.toString(), header.getVersion(), header.getMessageId(), true);
    AdvancedCache<?, ?> cache = server.cache(cacheInfo, header, subject);
    RpcManager rpcManager = cache.getRpcManager();
    if (rpcManager == null || rpcManager.getAddress().equals(state.getOriginator())) {
        if (log.isTraceEnabled()) {
            log.tracef("[%s] Completing local executed transaction.", xid);
        }
        return asyncCompleteLocalTransaction(cache, state.getTimeout());
    } else if (rpcManager.getMembers().contains(state.getOriginator())) {
        if (log.isTraceEnabled()) {
            log.tracef("[%s] Forward remotely executed transaction to %s.", xid, state.getOriginator());
        }
        return forwardCompleteCommand(cacheName, rpcManager, state);
    } else {
        if (log.isTraceEnabled()) {
            log.tracef("[%s] Originator, %s, left the cluster.", xid, state.getOriginator());
        }
        return completeWithRemoteCommand(cache, rpcManager, state);
    }
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) RpcManager(org.infinispan.remoting.rpc.RpcManager) TxState(org.infinispan.server.hotrod.tx.table.TxState) HotRodServer(org.infinispan.server.hotrod.HotRodServer)

Aggregations

CacheXid (org.infinispan.server.hotrod.tx.table.CacheXid)6 GlobalTxTable (org.infinispan.server.hotrod.tx.table.GlobalTxTable)5 TxState (org.infinispan.server.hotrod.tx.table.TxState)4 TxFunction (org.infinispan.server.hotrod.tx.table.functions.TxFunction)3 CreateStateFunction (org.infinispan.server.hotrod.tx.table.functions.CreateStateFunction)2 SetCompletedTransactionFunction (org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction)2 ArrayList (java.util.ArrayList)1 XidImpl (org.infinispan.commons.tx.XidImpl)1 RpcManager (org.infinispan.remoting.rpc.RpcManager)1 HotRodServer (org.infinispan.server.hotrod.HotRodServer)1 RemoteTransaction (org.infinispan.server.hotrod.test.RemoteTransaction)1 PerCacheTxTable (org.infinispan.server.hotrod.tx.table.PerCacheTxTable)1 PreparingDecisionFunction (org.infinispan.server.hotrod.tx.table.functions.PreparingDecisionFunction)1 SetDecisionFunction (org.infinispan.server.hotrod.tx.table.functions.SetDecisionFunction)1 SetPreparedFunction (org.infinispan.server.hotrod.tx.table.functions.SetPreparedFunction)1 EmbeddedTransaction (org.infinispan.transaction.tm.EmbeddedTransaction)1 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)1