Search in sources :

Example 1 with MvccQuerySnapshotRequest

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

the class MvccProcessorImpl method requestSnapshotAsync.

/**
 */
private void requestSnapshotAsync(MvccCoordinator crd, MvccSnapshotResponseListener lsnr, boolean forRead) {
    if (crd.disconnected()) {
        lsnr.onError(noCoordinatorError());
        return;
    }
    if (!busyLock.enterBusy()) {
        lsnr.onError(new NodeStoppingException("Failed to request snapshot (Node is stopping)."));
        return;
    }
    try {
        if (ctx.localNodeId().equals(crd.nodeId())) {
            if (!initFut.isDone()) {
                // Wait for the local coordinator init.
                initFut.listen(new IgniteInClosure<IgniteInternalFuture>() {

                    @Override
                    public void apply(IgniteInternalFuture fut) {
                        if (forRead)
                            lsnr.onResponse(activeQueries.assignQueryCounter(ctx.localNodeId(), 0L));
                        else
                            lsnr.onResponse(assignTxSnapshot(0L, ctx.localNodeId(), false));
                    }
                });
            } else if (forRead)
                lsnr.onResponse(activeQueries.assignQueryCounter(ctx.localNodeId(), 0L));
            else
                lsnr.onResponse(assignTxSnapshot(0L, ctx.localNodeId(), false));
            return;
        }
        // Send request to the remote coordinator.
        UUID nodeId = crd.nodeId();
        long id = futIdCntr.incrementAndGet();
        Map<Long, MvccSnapshotResponseListener> map = snapLsnrs.get(nodeId), map0;
        if (map == null && (map0 = snapLsnrs.putIfAbsent(nodeId, map = new ConcurrentHashMap<>())) != null)
            map = map0;
        map.put(id, lsnr);
        try {
            sendMessage(nodeId, forRead ? new MvccQuerySnapshotRequest(id) : new MvccTxSnapshotRequest(id));
        } catch (IgniteCheckedException e) {
            if (map.remove(id) != null)
                lsnr.onError(e);
        }
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) MvccQuerySnapshotRequest(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccQuerySnapshotRequest) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MvccTxSnapshotRequest(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccTxSnapshotRequest)

Aggregations

UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 MvccQuerySnapshotRequest (org.apache.ignite.internal.processors.cache.mvcc.msg.MvccQuerySnapshotRequest)1 MvccTxSnapshotRequest (org.apache.ignite.internal.processors.cache.mvcc.msg.MvccTxSnapshotRequest)1 GridAtomicLong (org.apache.ignite.internal.util.GridAtomicLong)1