Search in sources :

Example 1 with MvccSnapshotWithoutTxs

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

the class GridDhtTransactionalCacheAdapter method processDhtTxQueryEnlistRequest.

/**
 * @param primary Primary node.
 * @param req Message.
 * @param first Flag if this is a first request in current operation.
 */
private void processDhtTxQueryEnlistRequest(UUID primary, GridDhtTxQueryEnlistRequest req, boolean first) {
    try {
        assert req.version() != null && req.op() != null;
        GridDhtTxRemote tx = ctx.tm().tx(req.version());
        if (tx == null) {
            if (!first)
                throw new IgniteCheckedException("Can not find a transaction for version [version=" + req.version() + ']');
            GridDhtTxQueryFirstEnlistRequest req0 = (GridDhtTxQueryFirstEnlistRequest) req;
            tx = new GridDhtTxRemote(ctx.shared(), req0.nearNodeId(), req0.dhtFutureId(), primary, req0.nearXidVersion(), req0.topologyVersion(), req0.version(), null, ctx.systemTx(), ctx.ioPolicy(), PESSIMISTIC, REPEATABLE_READ, false, req0.timeout(), -1, securitySubjectId(ctx), req0.taskNameHash(), false, null);
            tx.mvccSnapshot(new MvccSnapshotWithoutTxs(req0.coordinatorVersion(), req0.counter(), MVCC_OP_COUNTER_NA, req0.cleanupVersion()));
            tx = ctx.tm().onCreated(null, tx);
            if (tx == null || !ctx.tm().onStarted(tx)) {
                throw new IgniteTxRollbackCheckedException("Failed to update backup " + "(transaction has been completed): " + req0.version());
            }
        }
        assert tx != null;
        MvccSnapshot s0 = tx.mvccSnapshot();
        MvccSnapshot snapshot = new MvccSnapshotWithoutTxs(s0.coordinatorVersion(), s0.counter(), req.operationCounter(), s0.cleanupVersion());
        ctx.tm().txHandler().mvccEnlistBatch(tx, ctx, req.op(), req.keys(), req.values(), snapshot, req.dhtFutureId(), req.batchId());
        GridDhtTxQueryEnlistResponse res = new GridDhtTxQueryEnlistResponse(req.cacheId(), req.dhtFutureId(), req.batchId(), null);
        try {
            ctx.io().send(primary, res, ctx.ioPolicy());
        } catch (IgniteCheckedException ioEx) {
            U.error(log, "Failed to send DHT enlist reply to primary node [node: " + primary + ", req=" + req + ']', ioEx);
        }
    } catch (Throwable e) {
        GridDhtTxQueryEnlistResponse res = new GridDhtTxQueryEnlistResponse(ctx.cacheId(), req.dhtFutureId(), req.batchId(), e);
        try {
            ctx.io().send(primary, res, ctx.ioPolicy());
        } catch (IgniteCheckedException ioEx) {
            U.error(log, "Failed to send DHT enlist reply to primary node " + "[node: " + primary + ", req=" + req + ']', ioEx);
        }
        if (e instanceof Error)
            throw (Error) e;
    }
}
Also used : MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccSnapshotWithoutTxs(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotWithoutTxs) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)

Example 2 with MvccSnapshotWithoutTxs

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

the class GridNearTxQueryResultsEnlistFuture method processBatchLocalBackupKeys.

/**
 * @param primaryId Primary node id.
 * @param rows Rows.
 * @param dhtVer Dht version assigned at primary node.
 * @param dhtFutId Dht future id assigned at primary node.
 */
private void processBatchLocalBackupKeys(UUID primaryId, List<Object> rows, GridCacheVersion dhtVer, IgniteUuid dhtFutId) {
    assert dhtVer != null;
    assert dhtFutId != null;
    EnlistOperation op = it.operation();
    assert op != EnlistOperation.LOCK;
    boolean keysOnly = op.isDeleteOrLock();
    final ArrayList<KeyCacheObject> keys = new ArrayList<>(rows.size());
    final ArrayList<Message> vals = keysOnly ? null : new ArrayList<>(rows.size());
    for (Object row : rows) {
        if (keysOnly)
            keys.add(cctx.toCacheKeyObject(row));
        else {
            keys.add(cctx.toCacheKeyObject(((IgniteBiTuple) row).getKey()));
            vals.add(cctx.toCacheObject(((IgniteBiTuple) row).getValue()));
        }
    }
    try {
        GridDhtTxRemote dhtTx = cctx.tm().tx(dhtVer);
        if (dhtTx == null) {
            dhtTx = new GridDhtTxRemote(cctx.shared(), cctx.localNodeId(), dhtFutId, primaryId, lockVer, topVer, dhtVer, null, cctx.systemTx(), cctx.ioPolicy(), PESSIMISTIC, REPEATABLE_READ, false, tx.remainingTime(), -1, SecurityUtils.securitySubjectId(cctx), tx.taskNameHash(), false, tx.label());
            dhtTx.mvccSnapshot(new MvccSnapshotWithoutTxs(mvccSnapshot.coordinatorVersion(), mvccSnapshot.counter(), MVCC_OP_COUNTER_NA, mvccSnapshot.cleanupVersion()));
            dhtTx = cctx.tm().onCreated(null, dhtTx);
            if (dhtTx == null || !cctx.tm().onStarted(dhtTx)) {
                throw new IgniteTxRollbackCheckedException("Failed to update backup " + "(transaction has been completed): " + dhtVer);
            }
        }
        cctx.tm().txHandler().mvccEnlistBatch(dhtTx, cctx, it.operation(), keys, vals, mvccSnapshot.withoutActiveTransactions(), null, -1);
    } catch (IgniteCheckedException e) {
        onDone(e);
        return;
    }
    sendNextBatches(primaryId);
}
Also used : GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) EnlistOperation(org.apache.ignite.internal.processors.query.EnlistOperation) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ArrayList(java.util.ArrayList) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccSnapshotWithoutTxs(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotWithoutTxs) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 3 with MvccSnapshotWithoutTxs

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

the class GridNearTxEnlistFuture method processBatchLocalBackupKeys.

/**
 * @param primaryId Primary node id.
 * @param rows Rows.
 * @param dhtVer Dht version assigned at primary node.
 * @param dhtFutId Dht future id assigned at primary node.
 */
private void processBatchLocalBackupKeys(UUID primaryId, List<Object> rows, GridCacheVersion dhtVer, IgniteUuid dhtFutId) {
    assert dhtVer != null;
    assert dhtFutId != null;
    EnlistOperation op = it.operation();
    assert op != EnlistOperation.LOCK;
    boolean keysOnly = op.isDeleteOrLock();
    final ArrayList<KeyCacheObject> keys = new ArrayList<>(rows.size());
    final ArrayList<Message> vals = keysOnly ? null : new ArrayList<>(rows.size());
    for (Object row : rows) {
        if (keysOnly)
            keys.add(cctx.toCacheKeyObject(row));
        else {
            keys.add(cctx.toCacheKeyObject(((IgniteBiTuple) row).getKey()));
            if (op.isInvoke())
                vals.add((Message) ((IgniteBiTuple) row).getValue());
            else
                vals.add(cctx.toCacheObject(((IgniteBiTuple) row).getValue()));
        }
    }
    try {
        GridDhtTxRemote dhtTx = cctx.tm().tx(dhtVer);
        if (dhtTx == null) {
            dhtTx = new GridDhtTxRemote(cctx.shared(), cctx.localNodeId(), dhtFutId, primaryId, lockVer, topVer, dhtVer, null, cctx.systemTx(), cctx.ioPolicy(), PESSIMISTIC, REPEATABLE_READ, false, tx.remainingTime(), -1, SecurityUtils.securitySubjectId(cctx), tx.taskNameHash(), false, null);
            dhtTx.mvccSnapshot(new MvccSnapshotWithoutTxs(mvccSnapshot.coordinatorVersion(), mvccSnapshot.counter(), MVCC_OP_COUNTER_NA, mvccSnapshot.cleanupVersion()));
            dhtTx = cctx.tm().onCreated(null, dhtTx);
            if (dhtTx == null || !cctx.tm().onStarted(dhtTx)) {
                throw new IgniteTxRollbackCheckedException("Failed to update backup " + "(transaction has been completed): " + dhtVer);
            }
        }
        cctx.tm().txHandler().mvccEnlistBatch(dhtTx, cctx, it.operation(), keys, vals, mvccSnapshot.withoutActiveTransactions(), null, -1);
    } catch (IgniteCheckedException e) {
        onDone(e);
        return;
    }
    sendNextBatches(primaryId);
}
Also used : GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) EnlistOperation(org.apache.ignite.internal.processors.query.EnlistOperation) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ArrayList(java.util.ArrayList) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccSnapshotWithoutTxs(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotWithoutTxs) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 MvccSnapshotWithoutTxs (org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotWithoutTxs)3 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)3 ArrayList (java.util.ArrayList)2 GridCacheMessage (org.apache.ignite.internal.processors.cache.GridCacheMessage)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 GridDhtTxRemote (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote)2 EnlistOperation (org.apache.ignite.internal.processors.query.EnlistOperation)2 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 MvccSnapshot (org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot)1