Search in sources :

Example 31 with IgniteInternalTx

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());
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)

Example 32 with IgniteInternalTx

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);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)

Example 33 with IgniteInternalTx

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 34 with IgniteInternalTx

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);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheExplicitLockSpan(org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext)

Aggregations

IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)34 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)10 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)5 IgniteException (org.apache.ignite.IgniteException)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)4 IgfsPath (org.apache.ignite.igfs.IgfsPath)3 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 TransactionProxyImpl (org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 Nullable (org.jetbrains.annotations.Nullable)3 HashMap (java.util.HashMap)2 NoSuchElementException (java.util.NoSuchElementException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2