Search in sources :

Example 1 with IgfsOutputStream

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

the class DefaultIgfsSecondaryFileSystemTestAdapter method openOutputStream.

/**
 * {@inheritDoc}
 */
@Override
public OutputStream openOutputStream(String path, boolean append) throws IOException {
    IgfsPath igfsPath = new IgfsPath(path);
    final IgfsOutputStream igfsOutputStream;
    if (append)
        igfsOutputStream = igfsEx.append(igfsPath, true);
    else
        igfsOutputStream = igfsEx.create(igfsPath, true);
    return igfsOutputStream;
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 2 with IgfsOutputStream

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

the class IgfsAbstractBaseSelfTest method appendFile.

/**
 * Append to the file in the given IGFS provided data chunks.
 *
 * @param igfs IGFS.
 * @param file File.
 * @param chunks Data chunks.
 * @throws Exception If failed.
 */
protected static void appendFile(IgfsImpl igfs, IgfsPath file, @Nullable byte[]... chunks) throws Exception {
    IgfsOutputStream os = null;
    try {
        os = igfs.append(file, false);
        writeFileChunks(os, chunks);
    } finally {
        U.closeQuiet(os);
        awaitFileClose(igfs, file);
    }
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 3 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testAppendUpdateNoClose.

/**
 * Test update on the file when it was opened for write(create) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testAppendUpdateNoClose() throws Exception {
    if (dual)
        return;
    if (appendSupported()) {
        Map<String, String> props = properties("owner", "group", "0555");
        create(igfs, paths(DIR, SUBDIR), null);
        createFile(igfs, FILE, false);
        IgfsOutputStream os = null;
        try {
            os = igfs.append(FILE, false);
            if (permissionsSupported())
                igfs.update(FILE, props);
            os.close();
        } finally {
            U.closeQuiet(os);
        }
    }
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 4 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testAppendDeleteParentNoClose.

/**
 * Test delete on the file parent when it was opened for write(append) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testAppendDeleteParentNoClose() throws Exception {
    if (mode != PRIMARY)
        return;
    if (appendSupported()) {
        create(igfs, paths(DIR, SUBDIR), null);
        createFile(igfs, FILE, false);
        IgfsOutputStream os = null;
        IgniteUuid id = null;
        try {
            id = igfs.context().meta().fileId(FILE);
            os = igfs.append(FILE, false);
            // Since GG-4911 we allow deletes in this case.
            boolean del = igfs.delete(SUBDIR, true);
            assertTrue(del);
            assertFalse(igfs.exists(FILE));
            // id still exists in meta cache since
            assertTrue(igfs.context().meta().exists(id));
            // it is locked for writing and just moved to TRASH.
            // Delete worker cannot delete it for that reason.
            os.write(chunk);
            os.close();
        } finally {
            U.closeQuiet(os);
        }
        assert id != null;
        final IgniteUuid id0 = id;
        // Delete worker should delete the file once its output stream is finally closed:
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                try {
                    return !igfs.context().meta().exists(id0);
                } catch (IgniteCheckedException ice) {
                    throw new IgniteException(ice);
                }
            }
        }, 5_000L);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 5 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream 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)

Aggregations

IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)47 IgfsPath (org.apache.ignite.igfs.IgfsPath)25 IOException (java.io.IOException)14 IgniteException (org.apache.ignite.IgniteException)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)8 IgniteUuid (org.apache.ignite.lang.IgniteUuid)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)4 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgfsException (org.apache.ignite.igfs.IgfsException)3 IgfsMetrics (org.apache.ignite.igfs.IgfsMetrics)3 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)3 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2