Search in sources :

Example 51 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 52 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 53 with IgfsPath

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

the class IgfsProcessorSelfTest method checkCreateAppendLongData.

/**
 * @param chunkSize Chunk size.
 * @param bufSize Buffer size.
 * @param cnt Count.
 * @throws Exception If failed.
 */
private void checkCreateAppendLongData(int chunkSize, int bufSize, int cnt) throws Exception {
    IgfsPath path = new IgfsPath("/someFile");
    byte[] buf = new byte[chunkSize];
    for (int i = 0; i < buf.length; i++) buf[i] = (byte) (i * i);
    IgfsOutputStream os = igfs.create(path, bufSize, true, null, 0, 1024, null);
    try {
        for (int i = 0; i < cnt; i++) os.write(buf);
        os.flush();
    } finally {
        os.close();
    }
    os = igfs.append(path, chunkSize, false, null);
    try {
        for (int i = 0; i < cnt; i++) os.write(buf);
        os.flush();
    } finally {
        os.close();
    }
    byte[] readBuf = new byte[chunkSize];
    try (IgfsInputStream in = igfs.open(path)) {
        long pos = 0;
        for (int k = 0; k < 2 * cnt; k++) {
            in.readFully(pos, readBuf);
            for (int i = 0; i < readBuf.length; i++) assertEquals(buf[i], readBuf[i]);
            pos += readBuf.length;
        }
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 54 with IgfsPath

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

the class IgniteHadoopFileSystemClientSelfTest method testOutputStreamDeferredException.

/**
 * Test output stream deferred exception (GG-4440).
 *
 * @throws Exception If failed.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testOutputStreamDeferredException() throws Exception {
    final byte[] data = "test".getBytes();
    try {
        switchHandlerErrorFlag(true);
        HadoopIgfs client = new HadoopIgfsOutProc("127.0.0.1", 10500, "igfs", LOG, null);
        client.handshake(null);
        IgfsPath path = new IgfsPath("/test1.file");
        HadoopIgfsStreamDelegate delegate = client.create(path, true, false, 1, 1024, null);
        final HadoopIgfsOutputStream igfsOut = new HadoopIgfsOutputStream(delegate, LOG, IgfsLogger.disabledLogger(), 0);
        // This call should return fine as exception is thrown for the first time.
        igfsOut.write(data);
        U.sleep(500);
        // This call should throw an IO exception.
        GridTestUtils.assertThrows(null, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                igfsOut.write(data);
                return null;
            }
        }, IOException.class, "Failed to write data to server (test).");
    } finally {
        switchHandlerErrorFlag(false);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IOException(java.io.IOException)

Example 55 with IgfsPath

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

the class HadoopIgfs20FileSystemAbstractSelfTest method testZeroReplicationFactor.

/**
 * @throws Exception If failed.
 */
public void testZeroReplicationFactor() throws Exception {
    // This test doesn't make sense for any mode except of PRIMARY.
    if (mode == PRIMARY) {
        Path igfsHome = new Path(primaryFsUri);
        Path file = new Path(igfsHome, "someFile");
        try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()), Options.CreateOpts.repFac((short) 1))) {
            out.write(new byte[1024 * 1024]);
        }
        IgniteFileSystem igfs = grid(0).fileSystem("igfs");
        IgfsPath filePath = new IgfsPath("/someFile");
        IgfsFile fileInfo = igfs.info(filePath);
        Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length());
        assertEquals(1, locations.size());
        IgfsBlockLocation location = F.first(locations);
        assertEquals(1, location.nodeIds().size());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) IgfsPath(org.apache.ignite.igfs.IgfsPath) CreateFlag(org.apache.hadoop.fs.CreateFlag) IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) IgfsFile(org.apache.ignite.igfs.IgfsFile)

Aggregations

IgfsPath (org.apache.ignite.igfs.IgfsPath)161 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)24 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 Map (java.util.Map)9 Path (org.apache.hadoop.fs.Path)9 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)9 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)8 FileNotFoundException (java.io.FileNotFoundException)6 OutputStream (java.io.OutputStream)6 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)6 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)6