Search in sources :

Example 26 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgfsAbstractSelfTest method testAppendParentRoot.

/**
     * Test create when parent is the root.
     *
     * @throws Exception If failed.
     */
public void testAppendParentRoot() throws Exception {
    if (appendSupported()) {
        IgfsPath file = new IgfsPath("/" + FILE.name());
        createFile(igfs, file, true, BLOCK_SIZE, chunk);
        appendFile(igfs, file, chunk);
        checkFile(igfs, igfsSecondary, file, chunk, chunk);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath)

Example 27 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgfsBackupFailoverSelfTest method testReadFailoverAfterStopMultipleNodes.

/**
     * Checks correct data read *after* N-1 nodes are stopped.
     *
     * @throws Exception On error.
     */
public void testReadFailoverAfterStopMultipleNodes() throws Exception {
    final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
    clear(igfs0);
    IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
    // Create files through the 0th node:
    for (int f = 0; f < files; f++) {
        final byte[] data = createChunk(fileSize, f);
        createFile(igfs0, filePath(f), true, -1, /*block size unused*/
        data);
    }
    // Check files:
    for (int f = 0; f < files; f++) {
        IgfsPath path = filePath(f);
        byte[] data = createChunk(fileSize, f);
        // Check through 0th node:
        checkExist(igfs0, path);
        checkFileContent(igfs0, path, data);
        // Check the same file through other nodes:
        for (int n = 1; n < numIgfsNodes; n++) {
            checkExist(nodeDatas[n].igfsImpl, path);
            checkFileContent(nodeDatas[n].igfsImpl, path, data);
        }
    }
    // Now stop all the nodes but the 1st:
    for (int n = 1; n < numIgfsNodes; n++) stopGrid(n);
    // Check files again:
    for (int f = 0; f < files; f++) {
        IgfsPath path = filePath(f);
        byte[] data = createChunk(fileSize, f);
        // Check through 0th node:
        checkExist(igfs0, path);
        checkFileContent(igfs0, path, data);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath)

Example 28 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgfsBackupFailoverSelfTest method testReadFailoverWhileStoppingMultipleNodes.

/**
     * Checks correct data read *while* N-1 nodes are being concurrently stopped.
     *
     * @throws Exception On error.
     */
public void testReadFailoverWhileStoppingMultipleNodes() throws Exception {
    final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
    clear(igfs0);
    IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
    // Create files:
    for (int f = 0; f < files; f++) {
        final byte[] data = createChunk(fileSize, f);
        createFile(igfs0, filePath(f), true, -1, /*block size unused*/
        data);
    }
    // Check files:
    for (int f = 0; f < files; f++) {
        IgfsPath path = filePath(f);
        byte[] data = createChunk(fileSize, f);
        // Check through 1st node:
        checkExist(igfs0, path);
        checkFileContent(igfs0, path, data);
        // Check the same file through other nodes:
        for (int n = 1; n < numIgfsNodes; n++) {
            checkExist(nodeDatas[n].igfsImpl, path);
            checkFileContent(nodeDatas[n].igfsImpl, path, data);
        }
    }
    final AtomicBoolean stop = new AtomicBoolean();
    GridTestUtils.runMultiThreadedAsync(new Callable() {

        @Override
        public Object call() throws Exception {
            // Some delay to ensure read is in progress.
            Thread.sleep(1_000);
            // Now stop all the nodes but the 1st:
            for (int n = 1; n < numIgfsNodes; n++) {
                stopGrid(n);
                X.println("grid " + n + " stopped.");
            }
            Thread.sleep(1_000);
            stop.set(true);
            return null;
        }
    }, 1, "igfs-node-stopper");
    // Read the files repeatedly, while the nodes are being stopped:
    while (!stop.get()) {
        // Check files while the nodes are being stopped:
        for (int f = 0; f < files; f++) {
            IgfsPath path = filePath(f);
            byte[] data = createChunk(fileSize, f);
            // Check through 1st node:
            checkExist(igfs0, path);
            checkFileContent(igfs0, path, data);
        }
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) IOException(java.io.IOException)

Example 29 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgfsBackupFailoverSelfTest method testWriteFailoverWhileStoppingMultipleNodes.

/**
     *
     * @throws Exception
     */
public void testWriteFailoverWhileStoppingMultipleNodes() throws Exception {
    final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
    clear(igfs0);
    IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
    final IgfsOutputStream[] outStreams = new IgfsOutputStream[files];
    // Create files:
    for (int f = 0; f < files; f++) {
        final byte[] data = createChunk(fileSize, f);
        IgfsOutputStream os = null;
        try {
            os = igfs0.create(filePath(f), 256, true, null, 0, -1, null);
            assert os != null;
            writeFileChunks(os, data);
        } finally {
            if (os != null)
                os.flush();
        }
        outStreams[f] = os;
        X.println("write #1 completed: " + f);
    }
    final AtomicBoolean stop = new AtomicBoolean();
    GridTestUtils.runMultiThreadedAsync(new Callable() {

        @Override
        public Object call() throws Exception {
            // Some delay to ensure read is in progress.
            Thread.sleep(10_000);
            // Now stop all the nodes but the 1st:
            for (int n = 1; n < numIgfsNodes; n++) {
                stopGrid(n);
                X.println("#### grid " + n + " stopped.");
            }
            //Thread.sleep(10_000);
            stop.set(true);
            return null;
        }
    }, 1, "igfs-node-stopper");
    // Write #2:
    for (int f0 = 0; f0 < files; f0++) {
        final IgfsOutputStream os = outStreams[f0];
        assert os != null;
        final int f = f0;
        int att = doWithRetries(1, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                IgfsOutputStream ios = os;
                try {
                    writeChunks0(igfs0, ios, f);
                } catch (IOException ioe) {
                    log().warning("Attempt to append the data to existing stream failed: ", ioe);
                    ios = igfs0.append(filePath(f), false);
                    assert ios != null;
                    writeChunks0(igfs0, ios, f);
                }
                return null;
            }
        });
        assert att == 1;
        X.println("write #2 completed: " + f0 + " in " + att + " attempts.");
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return stop.get();
        }
    }, 25_000);
    // Check files:
    for (int f = 0; f < files; f++) {
        IgfsPath path = filePath(f);
        byte[] data = createChunk(fileSize, f);
        // Check through 1st node:
        checkExist(igfs0, path);
        assertEquals("File length mismatch.", data.length * 2, igfs0.size(path));
        checkFileContent(igfs0, path, data, data);
        X.println("Read test completed: " + f);
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IOException(java.io.IOException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) Callable(java.util.concurrent.Callable) IOException(java.io.IOException) IgfsPath(org.apache.ignite.igfs.IgfsPath) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 30 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgfsAbstractSelfTest method testMoveDirectorySourceParentRoot.

/**
     * Test directory move when source parent is the root.
     *
     * @throws Exception If failed.
     */
public void testMoveDirectorySourceParentRoot() throws Exception {
    IgfsPath dir = new IgfsPath("/" + SUBSUBDIR.name());
    create(igfs, paths(DIR_NEW, SUBDIR_NEW, dir), null);
    igfs.rename(dir, SUBDIR_NEW);
    checkExist(igfs, igfsSecondary, new IgfsPath(SUBDIR_NEW, SUBSUBDIR.name()));
    checkNotExist(igfs, igfsSecondary, dir);
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath)

Aggregations

IgfsPath (org.apache.ignite.igfs.IgfsPath)161 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 HashMap (java.util.HashMap)13 IgniteException (org.apache.ignite.IgniteException)13 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)13 IgfsFile (org.apache.ignite.igfs.IgfsFile)13 IgfsException (org.apache.ignite.igfs.IgfsException)12 IgniteUuid (org.apache.ignite.lang.IgniteUuid)11 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)10 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)10 Map (java.util.Map)9 Path (org.apache.hadoop.fs.Path)9 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)6 OutputStream (java.io.OutputStream)6 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)6 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)6