Search in sources :

Example 1 with MvccSnapshotResponse

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.

the class CacheMvccTransactionsTest method testInternalApi.

/**
 * @throws IgniteCheckedException If failed.
 */
@Test
public void testInternalApi() throws Exception {
    Ignite node = startGrid(0);
    IgniteCache cache = node.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, 1));
    GridCacheContext cctx = ((IgniteKernal) node).context().cache().context().cacheContext(CU.cacheId(cache.getName()));
    MvccProcessorImpl crd = mvccProcessor(node);
    // Start query to prevent cleanup.
    MvccSnapshotFuture fut = new MvccSnapshotFuture();
    crd.requestReadSnapshotAsync(crd.currentCoordinator(), fut);
    fut.get();
    final int KEYS = 1000;
    for (int i = 0; i < 10; i++) {
        for (int k = 0; k < KEYS; k++) {
            final Integer key = k;
            try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.put(key, i);
                tx.commit();
            }
        }
    }
    for (int k = 0; k < KEYS; k++) {
        final Integer key = k;
        KeyCacheObject key0 = cctx.toCacheKeyObject(key);
        List<IgniteBiTuple<Object, MvccVersion>> vers = cctx.offheap().mvccAllVersions(cctx, key0);
        assertEquals(10, vers.size());
        CacheDataRow row = cctx.offheap().read(cctx, key0);
        Object val = ((CacheObject) vers.get(0).get1()).value(cctx.cacheObjectContext(), false);
        checkRow(cctx, row, key0, val);
        for (IgniteBiTuple<Object, MvccVersion> ver : vers) {
            MvccVersion cntr = ver.get2();
            MvccSnapshot readVer = new MvccSnapshotWithoutTxs(cntr.coordinatorVersion(), cntr.counter(), MvccUtils.MVCC_READ_OP_CNTR, 0);
            row = cctx.offheap().mvccRead(cctx, key0, readVer);
            Object verVal = ((CacheObject) ver.get1()).value(cctx.cacheObjectContext(), false);
            checkRow(cctx, row, key0, verVal);
        }
        checkRow(cctx, cctx.offheap().mvccRead(cctx, key0, version(vers.get(0).get2().coordinatorVersion() + 1, 1)), key0, val);
        checkRow(cctx, cctx.offheap().mvccRead(cctx, key0, version(vers.get(0).get2().coordinatorVersion(), vers.get(0).get2().counter() + 1)), key0, val);
        MvccSnapshotResponse ver = version(vers.get(0).get2().coordinatorVersion(), 100000);
        for (int v = 0; v < vers.size(); v++) {
            MvccVersion cntr = vers.get(v).get2();
            ver.addTx(cntr.counter());
            row = cctx.offheap().mvccRead(cctx, key0, ver);
            if (v == vers.size() - 1)
                assertNull(row);
            else {
                Object nextVal = ((CacheObject) vers.get(v + 1).get1()).value(cctx.cacheObjectContext(), false);
                checkRow(cctx, row, key0, nextVal);
            }
        }
    }
    KeyCacheObject key = cctx.toCacheKeyObject(KEYS);
    cache.put(key, 0);
    cache.remove(key);
    cctx.offheap().mvccRemoveAll((GridCacheMapEntry) cctx.cache().entryEx(key));
    crd.ackQueryDone(fut.get(), MVCC_TRACKER_ID_NA);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteCache(org.apache.ignite.IgniteCache) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Test(org.junit.Test)

Example 2 with MvccSnapshotResponse

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.

the class CacheMvccTransactionsTest method version.

/**
 * @param crdVer Coordinator version.
 * @param cntr Counter.
 * @return Version.
 */
private MvccSnapshotResponse version(long crdVer, long cntr) {
    MvccSnapshotResponse res = new MvccSnapshotResponse();
    res.init(0, crdVer, cntr, MvccUtils.MVCC_START_OP_CNTR, MvccUtils.MVCC_COUNTER_NA, 0);
    return res;
}
Also used : MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse)

Example 3 with MvccSnapshotResponse

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.

the class MvccProcessorImpl method assignTxSnapshot.

/**
 */
private MvccSnapshotResponse assignTxSnapshot(long futId, UUID nearId, boolean client) {
    assert initFut.isDone() && curCrd.local();
    MvccSnapshotResponse res = new MvccSnapshotResponse();
    long ver, cleanup, tracking;
    synchronized (this) {
        ver = mvccCntr.incrementAndGet();
        tracking = ver;
        cleanup = committedCntr.get() + 1;
        for (Map.Entry<Long, ActiveTx> entry : activeTxs.entrySet()) {
            cleanup = Math.min(entry.getValue().tracking, cleanup);
            tracking = Math.min(entry.getKey(), tracking);
            res.addTx(entry.getKey());
        }
        ActiveTx activeTx = client ? new ActiveTx(tracking, nearId) : new ActiveServerTx(tracking, nearId);
        boolean add = activeTxs.put(ver, activeTx) == null;
        assert add : ver;
    }
    long minQry = activeQueries.minimalQueryCounter();
    if (minQry != -1)
        cleanup = Math.min(cleanup, minQry);
    cleanup = prevQueries.done() ? cleanup - 1 : MVCC_COUNTER_NA;
    res.init(futId, curCrd.version(), ver, MVCC_START_OP_CNTR, cleanup, tracking);
    return res;
}
Also used : GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 4 with MvccSnapshotResponse

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.

the class MvccProcessorImpl method processCoordinatorTxSnapshotRequest.

/**
 * @param nodeId Sender node ID.
 * @param msg Message.
 */
private void processCoordinatorTxSnapshotRequest(UUID nodeId, MvccTxSnapshotRequest msg) {
    ClusterNode node = ctx.discovery().node(nodeId);
    if (node == null) {
        if (log.isDebugEnabled())
            log.debug("Ignore tx snapshot request processing, node left [msg=" + msg + ", node=" + nodeId + ']');
        return;
    }
    MvccSnapshotResponse res = assignTxSnapshot(msg.futureId(), nodeId, node.isClient());
    boolean finishFailed = true;
    try {
        sendMessage(node.id(), res);
        finishFailed = false;
    } catch (ClusterTopologyCheckedException e) {
        if (log.isDebugEnabled())
            log.debug("Failed to send tx snapshot response, node left [msg=" + msg + ", node=" + nodeId + ']');
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send tx snapshot response [msg=" + msg + ", node=" + nodeId + ']', e);
    }
    if (finishFailed)
        onTxDone(res.counter(), false);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 5 with MvccSnapshotResponse

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.

the class MvccProcessorImpl method processCoordinatorQuerySnapshotRequest.

/**
 * @param nodeId Sender node ID.
 * @param msg Message.
 */
private void processCoordinatorQuerySnapshotRequest(UUID nodeId, MvccQuerySnapshotRequest msg) {
    ClusterNode node = ctx.discovery().node(nodeId);
    if (node == null) {
        if (log.isDebugEnabled())
            log.debug("Ignore query counter request processing, node left [msg=" + msg + ", node=" + nodeId + ']');
        return;
    }
    MvccSnapshotResponse res = activeQueries.assignQueryCounter(nodeId, msg.futureId());
    try {
        sendMessage(node.id(), res);
    } catch (ClusterTopologyCheckedException e) {
        if (log.isDebugEnabled())
            log.debug("Failed to send query counter response, node left [msg=" + msg + ", node=" + nodeId + ']');
    } catch (IgniteCheckedException e) {
        onQueryDone(nodeId, res.tracking());
        U.error(log, "Failed to send query counter response [msg=" + msg + ", node=" + nodeId + ']', e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

MvccSnapshotResponse (org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Ignite (org.apache.ignite.Ignite)3 Transaction (org.apache.ignite.transactions.Transaction)3 CacheException (javax.cache.CacheException)2 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)2 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 Test (org.junit.Test)2