use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class IgfsDataManagerSelfTest method testDataStoringFlush.
/**
* @throws Exception If failed.
*/
public void testDataStoringFlush() throws Exception {
final int blockSize = IGFS_BLOCK_SIZE;
final int writesCnt = 64;
for (int i = 0; i < 10; i++) {
IgfsPath path = IgfsPath.ROOT;
long t = System.currentTimeMillis();
IgfsEntryInfo info = IgfsUtils.createFile(IgniteUuid.randomUuid(), blockSize, 0L, null, IgfsUtils.DELETE_LOCK_ID, false, null, t, t);
IgfsFileAffinityRange range = new IgfsFileAffinityRange();
assertNull(mgr.dataBlock(info, path, 0, null).get());
int chunkSize = blockSize / 4;
byte[] data = new byte[chunkSize];
info = info.length(info.length() + data.length * writesCnt);
IgniteInternalFuture<Boolean> fut = mgr.writeStart(info.id());
for (int j = 0; j < 64; j++) {
Arrays.fill(data, (byte) (j / 4));
byte[] left = mgr.storeDataBlocks(info, (j + 1) * chunkSize, null, 0, ByteBuffer.wrap(data), true, range, null);
assert left == null : "No remainder should be returned if flush is true: " + Arrays.toString(left);
}
mgr.writeClose(info.id());
assertTrue(range.regionEqual(new IgfsFileAffinityRange(0, writesCnt * chunkSize - 1, null)));
fut.get(3000);
for (int j = 0; j < NODES_CNT; j++) {
GridCacheContext<Object, Object> ctx = GridTestUtils.getFieldValue(grid(j).cachex(grid(j).igfsx("igfs").configuration().getDataCacheConfiguration().getName()), "ctx");
Collection<IgniteInternalTx> txs = ctx.tm().txs();
assert txs.isEmpty() : "Incomplete transactions: " + txs;
}
// Validate data stored in cache.
for (int pos = 0, block = 0; pos < info.length(); block++) {
byte[] stored = mgr.dataBlock(info, path, block, null).get();
assertNotNull("Expects data exist [block=" + block + ']', stored);
for (byte b : stored) assertEquals(b, (byte) block);
pos += stored.length;
}
IgniteInternalFuture<Object> delFut = mgr.delete(info);
delFut.get();
for (long block = 0; block < info.blocksCount(); block++) assertNull(mgr.dataBlock(info, path, block, null).get());
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class IgfsDataManagerSelfTest method testDataStoring.
/**
* Test file system structure in meta-cache.
*
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
public void testDataStoring() throws Exception {
for (int i = 0; i < 10; i++) {
IgfsPath path = IgfsPath.ROOT;
long t = System.currentTimeMillis();
IgfsEntryInfo info = IgfsUtils.createFile(IgniteUuid.randomUuid(), 200, 0L, null, IgfsUtils.DELETE_LOCK_ID, false, null, t, t);
assertNull(mgr.dataBlock(info, path, 0, null).get());
byte[] data = new byte[rnd.nextInt(20000) + 5];
rnd.nextBytes(data);
IgniteInternalFuture<Boolean> fut = mgr.writeStart(info.id());
expectsStoreFail(info, data, "Not enough space reserved to store data");
info = info.length(info.length() + data.length - 3);
expectsStoreFail(info, data, "Not enough space reserved to store data");
info = info.length(info.length() + 3);
IgfsFileAffinityRange range = new IgfsFileAffinityRange();
byte[] remainder = mgr.storeDataBlocks(info, info.length(), null, 0, ByteBuffer.wrap(data), true, range, null);
assert remainder == null;
mgr.writeClose(info.id());
fut.get(3000);
for (int j = 0; j < NODES_CNT; j++) {
GridCacheContext<Object, Object> ctx = GridTestUtils.getFieldValue(grid(j).cachex(grid(j).igfsx("igfs").configuration().getDataCacheConfiguration().getName()), "ctx");
Collection<IgniteInternalTx> txs = ctx.tm().txs();
assert txs.isEmpty() : "Incomplete transactions: " + txs;
}
// Validate data stored in cache.
for (int pos = 0, block = 0; pos < info.length(); block++) {
byte[] stored = mgr.dataBlock(info, path, block, null).get();
assertNotNull("Expects data exist [data.length=" + data.length + ", block=" + block + ']', stored);
for (int j = 0; j < stored.length; j++) assertEquals(stored[j], data[pos + j]);
pos += stored.length;
}
mgr.delete(info);
long nIters = getTestTimeout() / BUSY_WAIT_SLEEP_INTERVAL;
assert nIters < Integer.MAX_VALUE;
boolean rmvBlocks = false;
// Wait for all blocks to be removed.
for (int j = 0; j < nIters && !rmvBlocks; j = sleepAndIncrement(BUSY_WAIT_SLEEP_INTERVAL, j)) {
boolean b = true;
for (long block = 0; block < info.blocksCount(); block++) b &= mgr.dataBlock(info, path, block, null).get() == null;
rmvBlocks = b;
}
assertTrue("All blocks should be removed from cache.", rmvBlocks);
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridNearTxLocal method chainFinishFuture.
/**
* @param fut Already started finish future.
* @param commit Commit flag.
* @return Finish future.
*/
private IgniteInternalFuture<IgniteInternalTx> chainFinishFuture(final NearTxFinishFuture fut, final boolean commit) {
assert fut != null;
if (fut.commit() != commit) {
final GridNearTxLocal tx = this;
if (!commit) {
final GridNearTxFinishFuture rollbackFut = new GridNearTxFinishFuture<>(cctx, this, false);
fut.listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {
@Override
public void apply(IgniteInternalFuture<IgniteInternalTx> fut0) {
if (FINISH_FUT_UPD.compareAndSet(tx, fut, rollbackFut)) {
if (tx.state() == COMMITTED) {
if (log.isDebugEnabled())
log.debug("Failed to rollback, transaction is already committed: " + tx);
rollbackFut.forceFinish();
assert rollbackFut.isDone() : rollbackFut;
} else {
if (!cctx.mvcc().addFuture(rollbackFut, rollbackFut.futureId()))
return;
rollbackFut.finish(false, true);
}
}
}
});
return rollbackFut;
} else {
final GridFutureAdapter<IgniteInternalTx> fut0 = new GridFutureAdapter<>();
fut.listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {
@Override
public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
if (timedOut())
fut0.onDone(new IgniteTxTimeoutCheckedException("Failed to commit transaction, " + "transaction is concurrently rolled back on timeout: " + tx));
else
fut0.onDone(new IgniteCheckedException("Failed to commit transaction, " + "transaction is concurrently rolled back: " + tx));
}
});
return fut0;
}
}
return fut;
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridCommonAbstractTest method dumpCacheDebugInfo.
/**
* @param ignite Node.
*/
public void dumpCacheDebugInfo(Ignite ignite) {
GridKernalContext ctx = ((IgniteKernal) ignite).context();
log.error("Cache information update [node=" + ignite.name() + ", client=" + ignite.configuration().isClientMode() + ']');
GridCacheSharedContext cctx = ctx.cache().context();
log.error("Pending transactions:");
for (IgniteInternalTx tx : cctx.tm().activeTransactions()) log.error(">>> " + tx);
log.error("Pending explicit locks:");
for (GridCacheExplicitLockSpan lockSpan : cctx.mvcc().activeExplicitLocks()) log.error(">>> " + lockSpan);
log.error("Pending cache futures:");
for (GridCacheFuture<?> fut : cctx.mvcc().activeFutures()) log.error(">>> " + fut);
log.error("Pending atomic cache futures:");
for (GridCacheFuture<?> fut : cctx.mvcc().atomicFutures()) log.error(">>> " + fut);
}
Aggregations