Search in sources :

Example 36 with IgfsPath

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

the class IgfsDualAbstractSelfTest method testMoveFileSourceParentRootDestinationMissing.

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

Example 37 with IgfsPath

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

the class IgfsDualAbstractSelfTest method testMoveRenameDirectoryDestinationRootSourceMissingPartially.

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

Example 38 with IgfsPath

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

the class IgfsMetaManagerSelfTest method testUpdateProperties.

/**
 * Test properties management in meta-cache.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings("NullableProblems")
public void testUpdateProperties() throws Exception {
    assertEmpty(mgr.directoryListing(ROOT_ID));
    assertTrue(mgr.mkdirs(new IgfsPath("/dir"), IgfsImpl.DFLT_DIR_META));
    assertNotNull(mgr.create(new IgfsPath("/file"), null, false, 400, null, false, null, null));
    IgfsListingEntry dirEntry = mgr.directoryListing(ROOT_ID).get("dir");
    assertNotNull(dirEntry);
    assertTrue(dirEntry.isDirectory());
    IgfsEntryInfo dir = mgr.info(dirEntry.fileId());
    IgfsListingEntry fileEntry = mgr.directoryListing(ROOT_ID).get("file");
    assertNotNull(fileEntry);
    assertTrue(!fileEntry.isDirectory());
    IgfsEntryInfo file = mgr.info(fileEntry.fileId());
    assertEquals(2, mgr.directoryListing(ROOT_ID).size());
    for (IgniteBiTuple<IgniteUuid, String> tup : Arrays.asList(F.t(dir.id(), "dir"), F.t(file.id(), "file"))) {
        IgniteUuid fileId = tup.get1();
        for (Map<String, String> props : Arrays.asList(null, Collections.<String, String>emptyMap())) expectsUpdatePropertiesFail(fileId, props, AssertionError.class, "Expects not-empty file's properties");
        String key1 = UUID.randomUUID().toString();
        String key2 = UUID.randomUUID().toString();
        IgfsEntryInfo info = mgr.info(fileId);
        assertNull("Unexpected stored properties: " + info, info.properties().get(key1));
        assertNull("Unexpected stored properties: " + info, info.properties().get(key2));
        info = mgr.updateProperties(fileId, F.asMap(key1, "1"));
        assertEquals("Unexpected stored properties: " + info, "1", info.properties().get(key1));
        info = mgr.updateProperties(fileId, F.asMap(key2, "2"));
        // assertEquals("Unexpected stored properties: " + info, F.asMap(key1, "1", key2, "2"), info.properties());
        assertEquals("Unexpected stored properties: " + info, "1", info.properties().get(key1));
        assertEquals("Unexpected stored properties: " + info, "2", info.properties().get(key2));
        info = mgr.updateProperties(fileId, F.<String, String>asMap(key1, null));
        assertEquals("Unexpected stored properties: " + info, "2", info.properties().get(key2));
        info = mgr.updateProperties(fileId, F.<String, String>asMap(key2, null));
        assertNull("Unexpected stored properties: " + info, info.properties().get(key1));
        assertNull("Unexpected stored properties: " + info, info.properties().get(key2));
    }
    mgr.softDelete(new IgfsPath("/dir"), true, null);
    mgr.softDelete(new IgfsPath("/file"), false, null);
    assertNull(mgr.updateProperties(dir.id(), F.asMap("p", "7")));
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 39 with IgfsPath

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

the class IgfsMetricsSelfTest method testBlockMetrics.

/**
 * Test block metrics.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "ResultOfMethodCallIgnored", "ConstantConditions" })
public void testBlockMetrics() throws Exception {
    IgfsEx igfs = (IgfsEx) igfsPrimary[0];
    IgfsPath fileRemote = new IgfsPath("/fileRemote");
    IgfsPath file1 = new IgfsPath("/primary/file1");
    IgfsPath file2 = new IgfsPath("/primary/file2");
    // Create remote file and write some data to it.
    IgfsOutputStream out = igfsSecondary.create(fileRemote, 256, true, null, 1, 256, null);
    int rmtBlockSize = igfsSecondary.info(fileRemote).blockSize();
    out.write(new byte[rmtBlockSize]);
    out.close();
    // Start metrics measuring.
    IgfsMetrics initMetrics = igfs.metrics();
    // Create empty file.
    igfs.create(file1, 256, true, null, 1, 256, null).close();
    int blockSize = igfs.info(file1).blockSize();
    checkBlockMetrics(initMetrics, igfs.metrics(), 0, 0, 0, 0, 0, 0);
    // Write two blocks to the file.
    IgfsOutputStream os = igfs.append(file1, false);
    os.write(new byte[blockSize * 2]);
    os.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 0, 0, 0, 2, 0, blockSize * 2);
    // Write one more file (one block).
    os = igfs.create(file2, 256, true, null, 1, 256, null);
    os.write(new byte[blockSize]);
    os.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 0, 0, 0, 3, 0, blockSize * 3);
    // Read data from the first file.
    IgfsInputStream is = igfs.open(file1);
    is.readFully(0, new byte[blockSize * 2]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 2, 0, blockSize * 2, 3, 0, blockSize * 3);
    // Read data from the second file with hits.
    is = igfs.open(file2);
    is.read(new byte[blockSize]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 3, 0, blockSize * 3, 3, 0, blockSize * 3);
    // Clear the first file.
    igfs.create(file1, true).close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 3, 0, blockSize * 3, 3, 0, blockSize * 3);
    // Delete the second file.
    igfs.delete(file2, false);
    checkBlockMetrics(initMetrics, igfs.metrics(), 3, 0, blockSize * 3, 3, 0, blockSize * 3);
    // Read remote file.
    is = igfs.open(fileRemote);
    is.read(new byte[rmtBlockSize]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 4, 1, blockSize * 3 + rmtBlockSize, 3, 0, blockSize * 3);
    // Lets wait for blocks will be placed to cache
    U.sleep(300);
    // Read remote file again.
    is = igfs.open(fileRemote);
    is.read(new byte[rmtBlockSize]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 5, 1, blockSize * 3 + rmtBlockSize * 2, 3, 0, blockSize * 3);
    IgfsMetrics metrics = igfs.metrics();
    assert metrics.secondarySpaceSize() == rmtBlockSize;
    // Write some data to the file working in DUAL mode.
    os = igfs.append(fileRemote, false);
    os.write(new byte[rmtBlockSize]);
    os.close();
    // Additional block read here due to file ending synchronization.
    checkBlockMetrics(initMetrics, igfs.metrics(), 5, 1, blockSize * 3 + rmtBlockSize * 2, 4, 1, blockSize * 3 + rmtBlockSize);
    metrics = igfs.metrics();
    assert metrics.secondarySpaceSize() == rmtBlockSize * 2;
    igfs.delete(fileRemote, false);
    U.sleep(300);
    assert igfs.metrics().secondarySpaceSize() == 0;
    // Write partial block to the first file.
    os = igfs.append(file1, false);
    os.write(new byte[blockSize / 2]);
    os.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 5, 1, blockSize * 3 + rmtBlockSize * 2, 5, 1, blockSize * 7 / 2 + rmtBlockSize);
    igfs.resetMetrics();
    metrics = igfs.metrics();
    assert metrics.blocksReadTotal() == 0;
    assert metrics.blocksReadRemote() == 0;
    assert metrics.blocksWrittenTotal() == 0;
    assert metrics.blocksWrittenRemote() == 0;
    assert metrics.bytesRead() == 0;
    assert metrics.bytesReadTime() == 0;
    assert metrics.bytesWritten() == 0;
    assert metrics.bytesWriteTime() == 0;
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsMetrics(org.apache.ignite.igfs.IgfsMetrics) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 40 with IgfsPath

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

the class IgfsModeResolverSelfTest method testModesValidation.

/**
 * @throws Exception If failed.
 */
public void testModesValidation() throws Exception {
    // Another mode inside PRIMARY directory:
    try {
        IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/"), PRIMARY), new T2<>(new IgfsPath("/a/b/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
        fail("IgniteCheckedException expected");
    } catch (IgniteCheckedException ignored) {
    // No-op.
    }
    // PRIMARY default mode and non-primary subfolder:
    for (IgfsMode m : IgfsMode.values()) {
        if (m != IgfsMode.PRIMARY) {
            try {
                IgfsUtils.preparePathModes(PRIMARY, Arrays.asList(new T2<>(new IgfsPath("/a/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
                fail("IgniteCheckedException expected");
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
        }
    }
    // Duplicated sub-folders should be ignored:
    List<T2<IgfsPath, IgfsMode>> modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a"), PRIMARY), new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/c/d/e/f"), PRIMARY)), new HashSet<IgfsPath>());
    assertNotNull(modes);
    assertEquals(2, modes.size());
    assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/a"), PRIMARY)));
    // Non-duplicated sub-folders should not be ignored:
    modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC)), new HashSet<IgfsPath>());
    assertNotNull(modes);
    assertEquals(modes.size(), 3);
    assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC)));
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsMode(org.apache.ignite.igfs.IgfsMode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) T2(org.apache.ignite.internal.util.typedef.T2) HashSet(java.util.HashSet)

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