Search in sources :

Example 96 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class IgfsAbstractSelfTest method testFormat.

/**
     * Ensure that formatting is not propagated to the secondary file system.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings("ConstantConditions")
public void testFormat() throws Exception {
    if (mode == PROXY)
        return;
    final GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = getDataCache(igfs);
    assert dataCache != null;
    int size0 = dataCache.size(new CachePeekMode[] { CachePeekMode.ALL });
    assert size0 == 0 : "Initial data cache size = " + size0;
    if (dual)
        create(igfsSecondary, paths(DIR, SUBDIR, DIR_NEW, SUBDIR_NEW), paths(FILE, FILE_NEW));
    create(igfs, paths(DIR, SUBDIR), paths(FILE));
    try (IgfsOutputStream os = igfs.create(FILE, true)) {
        os.write(new byte[10 * 1024 * 1024]);
    }
    awaitFileClose(igfs, FILE);
    if (dual)
        checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
    checkExist(igfs, DIR, SUBDIR, FILE);
    assertEquals(10 * 1024 * 1024, igfs.info(FILE).length());
    assert dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) > 0;
    igfs.clear();
    // Ensure format is not propagated to the secondary file system.
    if (dual) {
        checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
        igfsSecondary.format();
    }
    // Ensure entries deletion in the primary file system.
    checkNotExist(igfs, DIR, SUBDIR, FILE);
    if (!GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                return dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) == 0;
            } catch (IgniteCheckedException ice) {
                throw new IgniteException(ice);
            }
        }
    }, 10_000)) {
        Iterable<? extends GridCacheEntryEx> entries = dataCache.allEntries();
        for (GridCacheEntryEx e : entries) {
            X.println("deleted = " + e.deleted());
            X.println("detached = " + e.detached());
            X.println("info = " + e.info());
            X.println("k = " + e.key() + ", v = " + e.valueBytes());
        }
        assert false;
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CachePeekMode(org.apache.ignite.cache.CachePeekMode) IgniteException(org.apache.ignite.IgniteException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 97 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class IgfsAbstractSelfTest method testConcurrentRenameDeleteSource.

/**
     * Ensure that in case we rename the folder A and delete it at the same time, only one of these requests succeed.
     *
     * @throws Exception If failed.
     */
public void testConcurrentRenameDeleteSource() throws Exception {
    for (int i = 0; i < REPEAT_CNT; i++) {
        final CyclicBarrier barrier = new CyclicBarrier(2);
        create(igfs, paths(DIR, SUBDIR, DIR_NEW), paths());
        IgniteInternalFuture<Boolean> res1 = execute(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                U.awaitQuiet(barrier);
                try {
                    igfs.rename(SUBDIR, SUBDIR_NEW);
                    return true;
                } catch (IgniteException ignored) {
                    return false;
                }
            }
        });
        IgniteInternalFuture<Boolean> res2 = execute(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                U.awaitQuiet(barrier);
                try {
                    return igfs.delete(SUBDIR, true);
                } catch (IgniteException ignored) {
                    return false;
                }
            }
        });
        res1.get();
        res2.get();
        if (res1.get()) {
            // Rename succeeded, so delete must fail.
            assert !res2.get();
            checkExist(igfs, igfsSecondary, DIR, DIR_NEW, SUBDIR_NEW);
            checkNotExist(igfs, igfsSecondary, SUBDIR);
        } else {
            // Rename failed because delete succeeded.
            assert res2.get();
            // DIR_NEW should not be synchronized with he primary IGFS.
            checkExist(igfs, DIR);
            if (dual)
                checkExist(igfsSecondary, DIR, DIR_NEW);
            checkNotExist(igfs, igfsSecondary, SUBDIR, SUBDIR_NEW);
        }
        clear(igfs, igfsSecondary);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) IgfsDirectoryNotEmptyException(org.apache.ignite.igfs.IgfsDirectoryNotEmptyException) IgfsException(org.apache.ignite.igfs.IgfsException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 98 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class IgfsAbstractSelfTest method testCreateConsistencyMultithreaded.

/**
     * Ensure create consistency when multiple threads writes to the same file.
     *
     * @throws Exception If failed.
     */
public void testCreateConsistencyMultithreaded() throws Exception {
    final AtomicBoolean stop = new AtomicBoolean();
    // How many times the file was re-created.
    final AtomicInteger createCtr = new AtomicInteger();
    final AtomicReference<Exception> err = new AtomicReference<>();
    igfs.create(FILE, false).close();
    int threadCnt = 50;
    IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

        @SuppressWarnings("ThrowFromFinallyBlock")
        @Override
        public void run() {
            while (!stop.get() && err.get() == null) {
                IgfsOutputStream os = null;
                try {
                    os = igfs.create(FILE, true);
                    os.write(chunk);
                    os.close();
                    createCtr.incrementAndGet();
                } catch (IgniteException ignored) {
                // No-op.
                } catch (IOException e) {
                    err.compareAndSet(null, e);
                    Throwable[] chain = X.getThrowables(e);
                    Throwable cause = chain[chain.length - 1];
                    System.out.println("Failed due to IOException exception. Cause:");
                    cause.printStackTrace(System.out);
                } finally {
                    if (os != null)
                        try {
                            os.close();
                        } catch (IOException ioe) {
                            throw new IgniteException(ioe);
                        }
                }
            }
        }
    }, threadCnt);
    long startTime = U.currentTimeMillis();
    while (err.get() == null && createCtr.get() < 500 && U.currentTimeMillis() - startTime < 60 * 1000) U.sleep(100);
    stop.set(true);
    fut.get();
    awaitFileClose(igfs.asSecondary(), FILE);
    if (err.get() != null) {
        X.println("Test failed: rethrowing first error: " + err.get());
        throw err.get();
    }
    checkFileContent(igfs, FILE, chunk);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) IgfsDirectoryNotEmptyException(org.apache.ignite.igfs.IgfsDirectoryNotEmptyException) IgfsException(org.apache.ignite.igfs.IgfsException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException)

Example 99 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class IgfsAbstractSelfTest method testConcurrentRenameDeleteDestination.

/**
     * Ensure that in case we rename the folder A to B and delete B at the same time, FS consistency is not
     * compromised.
     *
     * @throws Exception If failed.
     */
public void testConcurrentRenameDeleteDestination() throws Exception {
    for (int i = 0; i < REPEAT_CNT; i++) {
        final CyclicBarrier barrier = new CyclicBarrier(2);
        create(igfs, paths(DIR, SUBDIR, DIR_NEW), paths());
        IgniteInternalFuture<Boolean> res1 = execute(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                U.awaitQuiet(barrier);
                try {
                    igfs.rename(SUBDIR, SUBDIR_NEW);
                    return true;
                } catch (IgniteException ignored) {
                    return false;
                }
            }
        });
        IgniteInternalFuture<Boolean> res2 = execute(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                U.awaitQuiet(barrier);
                try {
                    return igfs.delete(SUBDIR_NEW, true);
                } catch (IgniteException ignored) {
                    return false;
                }
            }
        });
        assert res1.get();
        if (res2.get()) {
            // Delete after rename.
            checkExist(igfs, igfsSecondary, DIR, DIR_NEW);
            checkNotExist(igfs, igfsSecondary, SUBDIR, SUBDIR_NEW);
        } else {
            // Delete before rename.
            checkExist(igfs, igfsSecondary, DIR, DIR_NEW, SUBDIR_NEW);
            checkNotExist(igfs, igfsSecondary, SUBDIR);
        }
        clear(igfs, igfsSecondary);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) IgfsDirectoryNotEmptyException(org.apache.ignite.igfs.IgfsDirectoryNotEmptyException) IgfsException(org.apache.ignite.igfs.IgfsException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 100 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class GridSharedFsCheckpointSpiMultipleDirectoriesSelfTest method testMultipleSharedDirectories.

/**
     * @throws Exception If failed.
     */
public void testMultipleSharedDirectories() throws Exception {
    String data = "Test check point data.";
    GridCheckpointTestState state = new GridCheckpointTestState(data);
    getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    info("Saved check point [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
    String curSpiPath1 = getSpi().getCurrentDirectoryPath();
    File folder1 = U.resolveWorkDirectory(U.defaultWorkDirectory(), curSpiPath1, false);
    assert folder1.exists() : "Checkpoint folder doesn't exist.";
    boolean rewritten = getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    assert rewritten : "Check point was not rewritten.";
    info("Rewrite check point [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
    String curSpiPath2 = getSpi().getCurrentDirectoryPath();
    File folder2 = U.resolveWorkDirectory(U.defaultWorkDirectory(), curSpiPath2, false);
    assert folder2.exists() : "Check point folder doesn't exist.";
    assert folder1.getAbsoluteFile().equals(folder2.getAbsoluteFile()) : "folder1 should be equal folder2.";
    U.delete(folder2);
    getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    info("Saved check point to other folder [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
    String newCurSpiPath = getSpi().getCurrentDirectoryPath();
    File changedFolder = U.resolveWorkDirectory(U.defaultWorkDirectory(), newCurSpiPath, false);
    assert changedFolder.exists() : "Check point folder doesn't exist.";
    assert !folder2.getAbsolutePath().equals(changedFolder.getAbsolutePath()) : "Directories should not be equal.";
    U.delete(changedFolder);
    boolean error = false;
    // Try save after delete all directories.
    try {
        getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    } catch (IgniteException ignored) {
        error = true;
    }
    assert error : "Check point should not be saved.";
}
Also used : GridCheckpointTestState(org.apache.ignite.spi.checkpoint.GridCheckpointTestState) IgniteException(org.apache.ignite.IgniteException) File(java.io.File)

Aggregations

IgniteException (org.apache.ignite.IgniteException)414 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)82 ClusterNode (org.apache.ignite.cluster.ClusterNode)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ArrayList (java.util.ArrayList)40 UUID (java.util.UUID)40 CountDownLatch (java.util.concurrent.CountDownLatch)40 IOException (java.io.IOException)32 HashMap (java.util.HashMap)32 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 CacheException (javax.cache.CacheException)31 Transaction (org.apache.ignite.transactions.Transaction)28 CyclicBarrier (java.util.concurrent.CyclicBarrier)21 Map (java.util.Map)20 IgniteCache (org.apache.ignite.IgniteCache)19 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)18 Nullable (org.jetbrains.annotations.Nullable)18 List (java.util.List)17 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)16