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);
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations