Search in sources :

Example 91 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class IgfsFileMapSelfTest method testRangeUpdate2.

/**
 * @throws Exception If failed.
 */
public void testRangeUpdate2() throws Exception {
    IgfsFileMap map = new IgfsFileMap();
    IgniteUuid affKey = IgniteUuid.randomUuid();
    for (int i = 0; i < 4; i++) map.addRange(new IgfsFileAffinityRange(i * 20 + 10, i * 20 + 19, affKey));
    // Middle, first, last.
    map.updateRangeStatus(new IgfsFileAffinityRange(30, 35, affKey), RANGE_STATUS_MOVING);
    map.updateRangeStatus(new IgfsFileAffinityRange(10, 15, affKey), RANGE_STATUS_MOVING);
    map.updateRangeStatus(new IgfsFileAffinityRange(70, 75, affKey), RANGE_STATUS_MOVING);
    List<IgfsFileAffinityRange> ranges = map.ranges();
    assertEquals(7, ranges.size());
    int idx = 0;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(10, 15, affKey)));
    assertEquals(RANGE_STATUS_MOVING, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(16, 19, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(30, 35, affKey)));
    assertEquals(RANGE_STATUS_MOVING, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(36, 39, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(50, 59, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(70, 75, affKey)));
    assertEquals(RANGE_STATUS_MOVING, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(76, 79, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    // Middle, first, last.
    map.updateRangeStatus(new IgfsFileAffinityRange(30, 35, affKey), RANGE_STATUS_MOVED);
    map.updateRangeStatus(new IgfsFileAffinityRange(10, 15, affKey), RANGE_STATUS_MOVED);
    map.updateRangeStatus(new IgfsFileAffinityRange(70, 75, affKey), RANGE_STATUS_MOVED);
    idx = 0;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(10, 15, affKey)));
    assertEquals(RANGE_STATUS_MOVED, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(16, 19, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(30, 35, affKey)));
    assertEquals(RANGE_STATUS_MOVED, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(36, 39, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(50, 59, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(70, 75, affKey)));
    assertEquals(RANGE_STATUS_MOVED, ranges.get(idx).status());
    idx++;
    assertTrue(ranges.get(idx).regionEqual(new IgfsFileAffinityRange(76, 79, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
    // Middle, first, last.
    map.deleteRange(new IgfsFileAffinityRange(30, 35, affKey));
    map.deleteRange(new IgfsFileAffinityRange(10, 15, affKey));
    map.deleteRange(new IgfsFileAffinityRange(70, 75, affKey));
    ranges = map.ranges();
    assertEquals(4, ranges.size());
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(0).status());
    assertTrue(ranges.get(0).regionEqual(new IgfsFileAffinityRange(16, 19, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(1).status());
    assertTrue(ranges.get(1).regionEqual(new IgfsFileAffinityRange(36, 39, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(2).status());
    assertTrue(ranges.get(2).regionEqual(new IgfsFileAffinityRange(50, 59, affKey)));
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(3).status());
    assertTrue(ranges.get(3).regionEqual(new IgfsFileAffinityRange(76, 79, affKey)));
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 92 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class IgfsAbstractBaseSelfTest method clear.

/**
 * Clear particular IGFS.
 *
 * @param igfs IGFS.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
public static void clear(IgniteFileSystem igfs) throws Exception {
    Field workerMapFld = IgfsImpl.class.getDeclaredField("workerMap");
    workerMapFld.setAccessible(true);
    // Wait for all workers to finish.
    Map<IgfsPath, IgfsFileWorkerBatch> workerMap = (Map<IgfsPath, IgfsFileWorkerBatch>) workerMapFld.get(igfs);
    for (Map.Entry<IgfsPath, IgfsFileWorkerBatch> entry : workerMap.entrySet()) {
        entry.getValue().cancel();
        try {
            entry.getValue().await();
        } catch (IgniteCheckedException e) {
            if (!(e instanceof IgfsFileWorkerBatchCancelledException))
                throw e;
        }
    }
    // Clear igfs.
    igfs.clear();
    // Previous different size.
    int prevDifferentSize = Integer.MAX_VALUE;
    int constCnt = 0, totalCnt = 0;
    final int constThreshold = 20;
    final long sleepPeriod = 500L;
    final long totalThreshold = CACHE_EMPTY_TIMEOUT / sleepPeriod;
    while (true) {
        int metaSize = 0;
        for (IgniteUuid metaId : getMetaCache(igfs).keySet()) {
            if (!IgfsUtils.isRootOrTrashId(metaId))
                metaSize++;
        }
        int dataSize = getDataCache(igfs).size();
        int size = metaSize + dataSize;
        if (size <= 2)
            // Caches are cleared, we're done. (2 because ROOT & TRASH always exist).
            return;
        X.println("Sum size: " + size);
        if (size > prevDifferentSize) {
            X.println("Summary cache size has grown unexpectedly: size=" + size + ", prevSize=" + prevDifferentSize);
            break;
        }
        if (totalCnt > totalThreshold) {
            X.println("Timeout exceeded.");
            break;
        }
        if (size == prevDifferentSize) {
            constCnt++;
            if (constCnt == constThreshold) {
                X.println("Summary cache size stays unchanged for too long: size=" + size);
                break;
            }
        } else {
            constCnt = 0;
            // renew;
            prevDifferentSize = size;
        }
        Thread.sleep(sleepPeriod);
        totalCnt++;
    }
    dumpCache("MetaCache", getMetaCache(igfs));
    dumpCache("DataCache", getDataCache(igfs));
    fail("Caches are not empty.");
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) Field(java.lang.reflect.Field) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) HashMap(java.util.HashMap) Map(java.util.Map)

Example 93 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class IgfsAbstractSelfTest method testAppendDeleteNoClose.

/**
 * Test delete on the file when it was opened for write(append) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testAppendDeleteNoClose() 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);
            boolean del = igfs.delete(FILE, false);
            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 94 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class IgfsAbstractSelfTest method testCreateDeleteNoClose.

/**
 * Test delete on the file when it was opened for write(create) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testCreateDeleteNoClose() throws Exception {
    if (mode != PRIMARY)
        return;
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = null;
    IgniteUuid id = null;
    try {
        os = igfs.create(FILE, false);
        id = igfs.context().meta().fileId(FILE);
        assert id != null;
        boolean del = igfs.delete(FILE, false);
        assertTrue(del);
        assertFalse(igfs.exists(FILE));
        // The id still exists in meta cache since
        // it is locked for writing and just moved to TRASH.
        // Delete worker cannot delete it for that reason:
        assertTrue(igfs.context().meta().exists(id));
        os.write(chunk);
        os.close();
    } finally {
        U.closeQuiet(os);
    }
    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 95 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class IgfsAbstractSelfTest method testCreateDeleteParentNoClose.

/**
 * Test delete on the file parent when it was opened for write(create) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testCreateDeleteParentNoClose() throws Exception {
    if (mode != PRIMARY)
        return;
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = null;
    IgniteUuid id = null;
    try {
        os = igfs.create(FILE, false);
        id = igfs.context().meta().fileId(FILE);
        assert id != null;
        boolean del = igfs.delete(SUBDIR, true);
        assertTrue(del);
        assertFalse(igfs.exists(FILE));
        // The id still exists in meta cache since
        // it is locked for writing and just moved to TRASH.
        // Delete worker cannot delete it for that reason:
        assertTrue(igfs.context().meta().exists(id));
        os.write(chunk);
        os.close();
    } finally {
        U.closeQuiet(os);
    }
    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)

Aggregations

IgniteUuid (org.apache.ignite.lang.IgniteUuid)107 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)25 UUID (java.util.UUID)23 IgniteException (org.apache.ignite.IgniteException)17 HashMap (java.util.HashMap)15 Map (java.util.Map)13 IgfsPath (org.apache.ignite.igfs.IgfsPath)11 ArrayList (java.util.ArrayList)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Nullable (org.jetbrains.annotations.Nullable)9 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)7 HashSet (java.util.HashSet)6 TreeSet (java.util.TreeSet)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Ignite (org.apache.ignite.Ignite)6 IgfsException (org.apache.ignite.igfs.IgfsException)6 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5