Search in sources :

Example 1 with TxState

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

the class SetPreparedFunction method apply.

@Override
public Byte apply(EntryView.ReadWriteEntryView<CacheXid, TxState> view) {
    if (view.find().isPresent()) {
        TxState state = view.get();
        if (state.getStatus() != PREPARING) {
            return state.getStatus().value;
        }
        view.set(state.setStatus(PREPARED, false, timeService));
        return OK.value;
    } else {
        return NO_TRANSACTION.value;
    }
}
Also used : TxState(org.infinispan.server.hotrod.tx.table.TxState)

Example 2 with TxState

use of org.infinispan.server.hotrod.tx.table.TxState 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 3 with TxState

use of org.infinispan.server.hotrod.tx.table.TxState 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 TxState

use of org.infinispan.server.hotrod.tx.table.TxState 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 TxState

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

the class SetCompletedTransactionFunction method apply.

@Override
public Byte apply(EntryView.ReadWriteEntryView<CacheXid, TxState> view) {
    if (view.find().isPresent()) {
        TxState state = view.get();
        view.set(state.setStatus(committed ? COMMITTED : ROLLED_BACK, true, timeService));
        return OK.value;
    } else {
        return NO_TRANSACTION.value;
    }
}
Also used : TxState(org.infinispan.server.hotrod.tx.table.TxState)

Aggregations

TxState (org.infinispan.server.hotrod.tx.table.TxState)8 CacheXid (org.infinispan.server.hotrod.tx.table.CacheXid)4 GlobalTxTable (org.infinispan.server.hotrod.tx.table.GlobalTxTable)3 Status (org.infinispan.server.hotrod.tx.table.Status)2 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 CreateStateFunction (org.infinispan.server.hotrod.tx.table.functions.CreateStateFunction)1 TxFunction (org.infinispan.server.hotrod.tx.table.functions.TxFunction)1