use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class CacheTxFastFinishTest method checkFastTxFinish.
/**
* @param tx Transaction.
* @param commit Commit flag.
*/
private void checkFastTxFinish(Transaction tx, boolean commit) {
if (commit)
tx.commit();
else
tx.rollback();
IgniteInternalTx tx0 = ((TransactionProxyImpl) tx).tx();
assertNull(fieldValue(tx0, "prepFut"));
assertNull(fieldValue(tx0, "commitFut"));
assertNull(fieldValue(tx0, "rollbackFut"));
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridHashMapLoadTest method testMapEntry.
/**
* @throws Exception If failed.
*/
public void testMapEntry() throws Exception {
Map<Integer, GridCacheMapEntry> map = new HashMap<>(5 * 1024 * 1024);
int i = 0;
GridCacheTestContext<Integer, Integer> ctx = new GridCacheTestContext<>(new GridTestKernalContext(new GridTestLog4jLogger()));
while (true) {
Integer key = i++;
map.put(key, new GridCacheMapEntry(ctx, ctx.toCacheKeyObject(key)) {
@Override
public boolean tmLock(IgniteInternalTx tx, long timeout, @Nullable GridCacheVersion serOrder, GridCacheVersion serReadVer, boolean read) {
return false;
}
@Override
protected void checkThreadChain(GridCacheMvccCandidate owner) {
// No-op.
}
@Override
public void txUnlock(IgniteInternalTx tx) {
// No-op.
}
@Override
public boolean removeLock(GridCacheVersion ver) {
return false;
}
});
if (i % 100000 == 0)
info("Inserted objects: " + i / 2);
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridCacheNearTxMultiNodeSelfTest method checkTm.
/**
* @param g Grid.
* @param tm Transaction manager.
*/
@SuppressWarnings({ "unchecked" })
private void checkTm(Ignite g, IgniteTxManager tm) {
Collection<IgniteInternalTx> txs = tm.txs();
info(">>> Number of transactions in the set [size=" + txs.size() + ", nodeId=" + g.cluster().localNode().id() + ']');
for (IgniteInternalTx tx : txs) assert tx.done() : "Transaction is not finished: " + tx;
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridDhtCacheEntry method addReader.
/**
* @param nodeId Reader to add.
* @param msgId Message ID.
* @param topVer Topology version.
* @return Future for all relevant transactions that were active at the time of adding reader,
* or {@code null} if reader was added
* @throws GridCacheEntryRemovedException If entry was removed.
*/
@SuppressWarnings("unchecked")
@Nullable
public IgniteInternalFuture<Boolean> addReader(UUID nodeId, long msgId, AffinityTopologyVersion topVer) throws GridCacheEntryRemovedException {
// Don't add local node as reader.
if (cctx.nodeId().equals(nodeId))
return null;
ClusterNode node = cctx.discovery().node(nodeId);
if (node == null) {
if (log.isDebugEnabled())
log.debug("Ignoring near reader because node left the grid: " + nodeId);
return null;
}
// If remote node has no near cache, don't add it.
if (!cctx.discovery().cacheNearNode(node, cacheName())) {
if (log.isDebugEnabled())
log.debug("Ignoring near reader because near cache is disabled: " + nodeId);
return null;
}
// If remote node is (primary?) or back up, don't add it as a reader.
if (cctx.affinity().partitionBelongs(node, partition(), topVer)) {
if (log.isDebugEnabled())
log.debug("Ignoring near reader because remote node is affinity node [locNodeId=" + cctx.localNodeId() + ", rmtNodeId=" + nodeId + ", key=" + key + ']');
return null;
}
boolean ret = false;
GridCacheMultiTxFuture txFut = null;
Collection<GridCacheMvccCandidate> cands = null;
ReaderId reader;
synchronized (this) {
checkObsolete();
reader = readerId(nodeId);
if (reader == null) {
reader = new ReaderId(nodeId, msgId);
ReaderId[] rdrs = Arrays.copyOf(this.rdrs, this.rdrs.length + 1);
rdrs[rdrs.length - 1] = reader;
// Seal.
this.rdrs = rdrs;
// No transactions in ATOMIC cache.
if (!cctx.atomic()) {
txFut = reader.getOrCreateTxFuture(cctx);
cands = localCandidates();
ret = true;
}
} else {
txFut = reader.txFuture();
long id = reader.messageId();
if (id < msgId)
reader.messageId(msgId);
}
}
if (ret) {
assert txFut != null;
if (!F.isEmpty(cands)) {
for (GridCacheMvccCandidate c : cands) {
IgniteInternalTx tx = cctx.tm().tx(c.version());
if (tx != null && tx.local())
txFut.addTx(tx);
}
}
txFut.init();
if (!txFut.isDone()) {
final ReaderId reader0 = reader;
txFut.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> f) {
cctx.kernalContext().closure().runLocalSafe(new GridPlainRunnable() {
@Override
public void run() {
synchronized (this) {
// Release memory.
reader0.resetTxFuture();
}
}
});
}
});
} else {
synchronized (this) {
// Release memory.
reader.resetTxFuture();
}
txFut = null;
}
}
return txFut;
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridCachePartitionExchangeManager method dumpLongRunningOperations.
/**
* @param timeout Operation timeout.
*/
public void dumpLongRunningOperations(long timeout) {
try {
GridDhtPartitionsExchangeFuture lastFut = lastInitializedFut;
// If exchange is in progress it will dump all hanging operations if any.
if (lastFut != null && !lastFut.isDone())
return;
long curTime = U.currentTimeMillis();
boolean found = false;
IgniteTxManager tm = cctx.tm();
if (tm != null) {
for (IgniteInternalTx tx : tm.activeTransactions()) {
if (curTime - tx.startTime() > timeout) {
found = true;
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
U.warn(log, "Found long running transaction [startTime=" + formatTime(tx.startTime()) + ", curTime=" + formatTime(curTime) + ", tx=" + tx + ']');
} else
break;
}
}
}
GridCacheMvccManager mvcc = cctx.mvcc();
if (mvcc != null) {
for (GridCacheFuture<?> fut : mvcc.activeFutures()) {
if (curTime - fut.startTime() > timeout) {
found = true;
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
U.warn(log, "Found long running cache future [startTime=" + formatTime(fut.startTime()) + ", curTime=" + formatTime(curTime) + ", fut=" + fut + ']');
} else
break;
}
}
for (GridCacheFuture<?> fut : mvcc.atomicFutures()) {
if (curTime - fut.startTime() > timeout) {
found = true;
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
U.warn(log, "Found long running cache future [startTime=" + formatTime(fut.startTime()) + ", curTime=" + formatTime(curTime) + ", fut=" + fut + ']');
} else
break;
}
}
}
if (found) {
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
longRunningOpsDumpCnt++;
if (IgniteSystemProperties.getBoolean(IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT, false)) {
U.warn(log, "Found long running cache operations, dump threads.");
U.dumpThreads(log);
}
U.warn(log, "Found long running cache operations, dump IO statistics.");
// Dump IO manager statistics.
cctx.gridIO().dumpStats();
}
} else
longRunningOpsDumpCnt = 0;
} catch (Exception e) {
U.error(log, "Failed to dump debug information: " + e, e);
}
}
Aggregations