use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccTxSnapshotRequest 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();
}
}
Aggregations