Search in sources :

Example 21 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class WalRolloverTypesTest method checkNextSegmentTypeWithCacheActivity.

/**
 * Under load, ensures the record gets into very beginning of the segment in {@code NEXT_SEGMENT} log mode.
 */
private void checkNextSegmentTypeWithCacheActivity(WALMode mode, boolean disableArch) throws Exception {
    walMode = mode;
    disableWALArchiving = disableArch;
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    IgniteCache<Integer, Integer> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
    final long testDuration = 30_000;
    long startTime = U.currentTimeMillis();
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(() -> {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        while (U.currentTimeMillis() - startTime < testDuration) cache.put(random.nextInt(100), random.nextInt(100_000));
    }, 8, "cache-put-thread");
    IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
    IgniteCacheDatabaseSharedManager dbMgr = ig.context().cache().context().database();
    AdHocWALRecord markerRecord = new AdHocWALRecord();
    WALPointer ptr0;
    WALPointer ptr1;
    do {
        try {
            U.sleep(1000);
            ptr0 = walMgr.log(markerRecord);
            dbMgr.checkpointReadLock();
            try {
                ptr1 = walMgr.log(markerRecord, NEXT_SEGMENT);
            } finally {
                dbMgr.checkpointReadUnlock();
            }
            assertTrue(ptr0.index() < ptr1.index());
            assertEquals(HEADER_RECORD_SIZE, ptr1.fileOffset());
        } catch (IgniteCheckedException e) {
            log.error(e.getMessage(), e);
        }
    } while (U.currentTimeMillis() - startTime < testDuration);
    fut.get();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 22 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class WalRolloverRecordLoggingTest method testAvoidInfinityWaitingOnRolloverOfSegment.

/**
 */
@Test
public void testAvoidInfinityWaitingOnRolloverOfSegment() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    IgniteCache<Integer, Integer> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
    long startTime = U.currentTimeMillis();
    long duration = 5_000;
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(() -> {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        while (U.currentTimeMillis() - startTime < duration) cache.put(random.nextInt(100_000), random.nextInt(100_000));
    }, 8, "cache-put-thread");
    Thread t = new Thread(() -> {
        do {
            try {
                U.sleep(100);
            } catch (IgniteInterruptedCheckedException e) {
            // No-op.
            }
            ig.context().cache().context().database().wakeupForCheckpoint("test");
        } while (U.currentTimeMillis() - startTime < duration);
    });
    t.start();
    IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
    IgniteCacheDatabaseSharedManager dbMgr = ig.context().cache().context().database();
    RolloverRecord rec = new RolloverRecord();
    do {
        try {
            dbMgr.checkpointReadLock();
            try {
                walMgr.log(rec, RolloverType.NEXT_SEGMENT);
            } finally {
                dbMgr.checkpointReadUnlock();
            }
        } catch (IgniteCheckedException e) {
            log.error(e.getMessage(), e);
        }
    } while (U.currentTimeMillis() - startTime < duration);
    fut.get();
    t.join();
}
Also used : IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class DurableBackgroundTasksProcessor method metaStorageOperation.

/**
 * Performing an operation on a {@link MetaStorage}.
 * Guarded by {@link #metaStorageMux}.
 *
 * @param consumer MetaStorage operation, argument can be {@code null}.
 * @throws IgniteException If an exception is thrown from the {@code consumer}.
 */
private void metaStorageOperation(IgniteThrowableConsumer<MetaStorage> consumer) throws IgniteException {
    synchronized (metaStorageMux) {
        IgniteCacheDatabaseSharedManager dbMgr = ctx.cache().context().database();
        dbMgr.checkpointReadLock();
        try {
            MetaStorage metaStorage = dbMgr.metaStorage();
            consumer.accept(metaStorage);
        } catch (IgniteCheckedException e) {
            throw new IgniteException(e);
        } finally {
            dbMgr.checkpointReadUnlock();
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteException(org.apache.ignite.IgniteException) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 24 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class IgniteDefragmentationImpl method getStatus.

/**
 * Get defragmentation status.
 * @return Defragmentation status or {@code null} if there is no ongoing defragmentation.
 */
private Status getStatus() {
    final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
    if (!maintenanceRegistry.isMaintenanceMode())
        return null;
    IgniteCacheDatabaseSharedManager dbMgr = ctx.cache().context().database();
    assert dbMgr instanceof GridCacheDatabaseSharedManager;
    CachePartitionDefragmentationManager defrgMgr = ((GridCacheDatabaseSharedManager) dbMgr).defragmentationManager();
    if (defrgMgr == null)
        return null;
    return defrgMgr.status();
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 25 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class IndexBuildStatusStorage method metaStorageOperation.

/**
 * Performing an operation on a {@link MetaStorage}.
 * Guarded by {@link #metaStorageMux}.
 *
 * @param consumer MetaStorage operation, argument can be {@code null}.
 * @throws IgniteException If an exception is thrown from the {@code consumer}.
 */
private void metaStorageOperation(IgniteThrowableConsumer<MetaStorage> consumer) {
    synchronized (metaStorageMux) {
        IgniteCacheDatabaseSharedManager db = ctx.cache().context().database();
        db.checkpointReadLock();
        try {
            consumer.accept(db.metaStorage());
        } catch (IgniteCheckedException e) {
            throw new IgniteException(e);
        } finally {
            db.checkpointReadUnlock();
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Aggregations

IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)58 Test (org.junit.Test)27 IgniteEx (org.apache.ignite.internal.IgniteEx)24 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)10 GridInternalSubscriptionProcessor (org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor)9 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)8 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)7 GridSystemViewManager (org.apache.ignite.internal.managers.systemview.GridSystemViewManager)7 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)7 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)7 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)7 IgnitePluginProcessor (org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 HashMap (java.util.HashMap)5 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)5 JmxSystemViewExporterSpi (org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi)5