Search in sources :

Example 1 with DefragmentationMXBean

use of org.apache.ignite.mxbean.DefragmentationMXBean in project ignite by apache.

the class DefragmentationMXBeanTest method testDefragmentationSchedule.

/**
 * Test that defragmentation won't be scheduled second time, if previously scheduled via maintenance registry.
 * Description:
 * 1. Start two nodes.
 * 2. Register defragmentation maintenance task on the first node.
 * 3. Restart node.
 * 3. Scheduling of the defragmentation on the first node via JMX bean should fail.
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationSchedule() throws Exception {
    Ignite ignite = startGrids(2);
    ignite.cluster().state(ACTIVE);
    DefragmentationMXBean mxBean = defragmentationMXBean(ignite.name());
    assertTrue(mxBean.schedule(""));
    MaintenanceTask mntcTask = DefragmentationParameters.toStore(Collections.emptyList());
    assertNotNull(grid(0).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
    assertNull(grid(1).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
    stopGrid(0);
    startGrid(0);
    // node is already in defragmentation mode, hence scheduling is not possible
    assertFalse(mxBean.schedule(""));
}
Also used : DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) Ignite(org.apache.ignite.Ignite) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with DefragmentationMXBean

use of org.apache.ignite.mxbean.DefragmentationMXBean in project ignite by apache.

the class DefragmentationMXBeanTest method testDefragmentationCancelInProgress.

/**
 * Test that ongong defragmentation can be stopped via JMX bean.
 * Description:
 * 1. Start one node.
 * 2. Put a load of a data on it.
 * 3. Schedule defragmentation.
 * 4. Make IO factory slow down after 128 partitions are processed, so we have time to stop the defragmentation.
 * 5. Stop the defragmentation.
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationCancelInProgress() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 1024; i++) cache.put(i, i);
    forceCheckpoint(ig);
    DefragmentationMXBean mxBean = defragmentationMXBean(ig.name());
    mxBean.schedule("");
    stopGrid(0);
    blockCdl = new CountDownLatch(128);
    UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
        DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
        FileIOFactory delegate = dsCfg.getFileIOFactory();
        dsCfg.setFileIOFactory((file, modes) -> {
            if (file.getName().contains("dfrg")) {
                if (blockCdl.getCount() == 0) {
                    try {
                        // Slow down defragmentation process.
                        // This'll be enough for the test since we have, like, 900 partitions left.
                        Thread.sleep(100);
                    } catch (InterruptedException ignore) {
                    // No-op.
                    }
                } else
                    blockCdl.countDown();
            }
            return delegate.create(file, modes);
        });
        return cfg;
    };
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
        try {
            startGrid(0, cfgOp);
        } catch (Exception e) {
            // No-op.
            throw new RuntimeException(e);
        }
    });
    blockCdl.await();
    mxBean = defragmentationMXBean(ig.name());
    assertTrue(mxBean.cancel());
    fut.get();
    assertTrue(mxBean.cancel());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) IgnitionEx(org.apache.ignite.internal.IgnitionEx) DefragmentationParameters(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) ClusterState(org.apache.ignite.cluster.ClusterState) UnaryOperator(java.util.function.UnaryOperator) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) CountDownLatch(java.util.concurrent.CountDownLatch) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with DefragmentationMXBean

use of org.apache.ignite.mxbean.DefragmentationMXBean in project ignite by apache.

the class IgniteMBeansManager method registerMBeansAfterNodeStarted.

/**
 * Registers kernal MBeans (for kernal, metrics, thread pools) after node start.
 *
 * @throws IgniteCheckedException if fails to register any of the MBeans.
 */
public void registerMBeansAfterNodeStarted() throws IgniteCheckedException {
    if (U.IGNITE_MBEANS_DISABLED)
        return;
    // Kernal
    IgniteMXBean kernalMXBean = new IgniteMXBeanImpl(kernal);
    registerMBean("Kernal", IgniteKernal.class.getSimpleName(), kernalMXBean, IgniteMXBean.class);
    // Metrics
    ClusterMetricsMXBean locMetricsBean = new ClusterLocalNodeMetricsMXBeanImpl(ctx.discovery());
    registerMBean("Kernal", locMetricsBean.getClass().getSimpleName(), locMetricsBean, ClusterMetricsMXBean.class);
    ClusterMetricsMXBean metricsBean = new ClusterMetricsMXBeanImpl(kernal.cluster(), ctx);
    registerMBean("Kernal", metricsBean.getClass().getSimpleName(), metricsBean, ClusterMetricsMXBean.class);
    // Transaction metrics
    TransactionMetricsMxBean txMetricsMXBean = new TransactionMetricsMxBeanImpl(ctx.cache().transactions().metrics());
    registerMBean("TransactionMetrics", txMetricsMXBean.getClass().getSimpleName(), txMetricsMXBean, TransactionMetricsMxBean.class);
    // Transactions
    TransactionsMXBean txMXBean = new TransactionsMXBeanImpl(ctx);
    registerMBean("Transactions", txMXBean.getClass().getSimpleName(), txMXBean, TransactionsMXBean.class);
    // Queries management
    QueryMXBean qryMXBean = new QueryMXBeanImpl(ctx);
    registerMBean("Query", qryMXBean.getClass().getSimpleName(), qryMXBean, QueryMXBean.class);
    // Compute task management
    ComputeMXBean computeMXBean = new ComputeMXBeanImpl(ctx);
    registerMBean("Compute", computeMXBean.getClass().getSimpleName(), computeMXBean, ComputeMXBean.class);
    // Service management
    ServiceMXBean serviceMXBean = new ServiceMXBeanImpl(ctx);
    registerMBean("Service", serviceMXBean.getClass().getSimpleName(), serviceMXBean, ServiceMXBean.class);
    // Data storage
    DataStorageMXBean dataStorageMXBean = new DataStorageMXBeanImpl(ctx);
    registerMBean("DataStorage", dataStorageMXBean.getClass().getSimpleName(), dataStorageMXBean, DataStorageMXBean.class);
    // Baseline configuration
    BaselineAutoAdjustMXBean baselineAutoAdjustMXBean = new BaselineAutoAdjustMXBeanImpl(ctx);
    registerMBean("Baseline", baselineAutoAdjustMXBean.getClass().getSimpleName(), baselineAutoAdjustMXBean, BaselineAutoAdjustMXBean.class);
    // Encryption
    EncryptionMXBean encryptionMXBean = new EncryptionMXBeanImpl(ctx);
    registerMBean("Encryption", encryptionMXBean.getClass().getSimpleName(), encryptionMXBean, EncryptionMXBean.class);
    // Snapshot.
    SnapshotMXBean snpMXBean = new SnapshotMXBeanImpl(ctx);
    registerMBean("Snapshot", snpMXBean.getClass().getSimpleName(), snpMXBean, SnapshotMXBean.class);
    // Defragmentation.
    DefragmentationMXBean defragMXBean = new DefragmentationMXBeanImpl(ctx);
    registerMBean("Defragmentation", defragMXBean.getClass().getSimpleName(), defragMXBean, DefragmentationMXBean.class);
    // Metrics configuration
    MetricsMxBean metricsMxBean = new MetricsMxBeanImpl(ctx.metric(), log);
    registerMBean("Metrics", metricsMxBean.getClass().getSimpleName(), metricsMxBean, MetricsMxBean.class);
    ctx.pools().registerMxBeans(this);
    if (U.IGNITE_TEST_FEATURES_ENABLED) {
        WorkersControlMXBean workerCtrlMXBean = new WorkersControlMXBeanImpl(ctx.workersRegistry());
        registerMBean("Kernal", workerCtrlMXBean.getClass().getSimpleName(), workerCtrlMXBean, WorkersControlMXBean.class);
    }
    FailureHandlingMxBean blockOpCtrlMXBean = new FailureHandlingMxBeanImpl(ctx.workersRegistry(), ctx.cache().context().database());
    registerMBean("Kernal", blockOpCtrlMXBean.getClass().getSimpleName(), blockOpCtrlMXBean, FailureHandlingMxBean.class);
    if (ctx.query().moduleEnabled())
        ctx.query().getIndexing().registerMxBeans(this);
    PerformanceStatisticsMBeanImpl performanceStatMbean = new PerformanceStatisticsMBeanImpl(ctx);
    registerMBean("PerformanceStatistics", performanceStatMbean.getClass().getSimpleName(), performanceStatMbean, PerformanceStatisticsMBean.class);
}
Also used : QueryMXBean(org.apache.ignite.mxbean.QueryMXBean) TransactionMetricsMxBeanImpl(org.apache.ignite.internal.TransactionMetricsMxBeanImpl) QueryMXBeanImpl(org.apache.ignite.internal.QueryMXBeanImpl) ComputeMXBean(org.apache.ignite.mxbean.ComputeMXBean) ClusterLocalNodeMetricsMXBeanImpl(org.apache.ignite.internal.ClusterLocalNodeMetricsMXBeanImpl) EncryptionMXBeanImpl(org.apache.ignite.internal.managers.encryption.EncryptionMXBeanImpl) ServiceMXBean(org.apache.ignite.mxbean.ServiceMXBean) BaselineAutoAdjustMXBean(org.apache.ignite.mxbean.BaselineAutoAdjustMXBean) WorkersControlMXBeanImpl(org.apache.ignite.internal.worker.WorkersControlMXBeanImpl) SnapshotMXBeanImpl(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotMXBeanImpl) DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) DataStorageMXBeanImpl(org.apache.ignite.internal.processors.cache.persistence.DataStorageMXBeanImpl) EncryptionMXBean(org.apache.ignite.mxbean.EncryptionMXBean) IgniteKernal(org.apache.ignite.internal.IgniteKernal) TransactionsMXBeanImpl(org.apache.ignite.internal.TransactionsMXBeanImpl) ClusterMetricsMXBeanImpl(org.apache.ignite.internal.ClusterMetricsMXBeanImpl) ServiceMXBeanImpl(org.apache.ignite.internal.ServiceMXBeanImpl) IgniteMXBean(org.apache.ignite.mxbean.IgniteMXBean) DataStorageMXBean(org.apache.ignite.mxbean.DataStorageMXBean) PerformanceStatisticsMBeanImpl(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsMBeanImpl) ComputeMXBeanImpl(org.apache.ignite.internal.ComputeMXBeanImpl) ClusterMetricsMXBean(org.apache.ignite.mxbean.ClusterMetricsMXBean) TransactionMetricsMxBean(org.apache.ignite.mxbean.TransactionMetricsMxBean) SnapshotMXBean(org.apache.ignite.mxbean.SnapshotMXBean) TransactionsMXBean(org.apache.ignite.mxbean.TransactionsMXBean) BaselineAutoAdjustMXBeanImpl(org.apache.ignite.internal.processors.cluster.BaselineAutoAdjustMXBeanImpl) WorkersControlMXBean(org.apache.ignite.mxbean.WorkersControlMXBean) FailureHandlingMxBean(org.apache.ignite.mxbean.FailureHandlingMxBean) TransactionMetricsMxBean(org.apache.ignite.mxbean.TransactionMetricsMxBean) MetricsMxBean(org.apache.ignite.mxbean.MetricsMxBean) TransactionMetricsMxBeanImpl(org.apache.ignite.internal.TransactionMetricsMxBeanImpl) MetricsMxBeanImpl(org.apache.ignite.internal.processors.metric.MetricsMxBeanImpl) DefragmentationMXBeanImpl(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationMXBeanImpl) IgniteMXBeanImpl(org.apache.ignite.internal.IgniteMXBeanImpl) FailureHandlingMxBeanImpl(org.apache.ignite.internal.worker.FailureHandlingMxBeanImpl)

Example 4 with DefragmentationMXBean

use of org.apache.ignite.mxbean.DefragmentationMXBean in project ignite by apache.

the class DefragmentationMXBeanTest method testDefragmentationCancel.

/**
 * Test that defragmentation can be successfuly cancelled via JMX bean.
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationCancel() throws Exception {
    Ignite ignite = startGrids(2);
    ignite.cluster().state(ACTIVE);
    DefragmentationMXBean mxBean = defragmentationMXBean(ignite.name());
    mxBean.schedule("");
    assertTrue(mxBean.cancel());
    // subsequent cancel call should be successful
    assertTrue(mxBean.cancel());
}
Also used : DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with DefragmentationMXBean

use of org.apache.ignite.mxbean.DefragmentationMXBean in project ignite by apache.

the class DefragmentationMXBeanTest method testDefragmentationStatus.

/**
 * Test that JMX bean provides correct defragmentation status.
 * Description:
 * 1. Start one node,
 * 2. Put a load of data on it.
 * 3. Schedule defragmentation.
 * 4. Completely stop defragmentation when 128 partitions processed.
 * 5. Check defragmentation status.
 * 6. Continue defragmentation and wait for it to end.
 * 7. Check defragmentation finished.
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationStatus() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    ig.getOrCreateCache(DEFAULT_CACHE_NAME + "1");
    IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME + "2");
    ig.getOrCreateCache(DEFAULT_CACHE_NAME + "3");
    for (int i = 0; i < 1024; i++) cache.put(i, i);
    forceCheckpoint(ig);
    DefragmentationMXBean mxBean = defragmentationMXBean(ig.name());
    mxBean.schedule("");
    stopGrid(0);
    blockCdl = new CountDownLatch(128);
    waitCdl = new CountDownLatch(1);
    UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
        DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
        FileIOFactory delegate = dsCfg.getFileIOFactory();
        dsCfg.setFileIOFactory((file, modes) -> {
            if (file.getName().contains("dfrg")) {
                if (blockCdl.getCount() == 0) {
                    try {
                        waitCdl.await();
                    } catch (InterruptedException ignore) {
                    // No-op.
                    }
                } else
                    blockCdl.countDown();
            }
            return delegate.create(file, modes);
        });
        return cfg;
    };
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
        try {
            startGrid(0, cfgOp);
        } catch (Exception e) {
            // No-op.
            throw new RuntimeException(e);
        }
    });
    blockCdl.await();
    mxBean = defragmentationMXBean(ig.name());
    final IgniteKernal gridx = IgnitionEx.gridx(ig.name());
    final IgniteDefragmentation defragmentation = gridx.context().defragmentation();
    final IgniteDefragmentation.DefragmentationStatus status1 = defragmentation.status();
    assertEquals(status1.getStartTs(), mxBean.startTime());
    assertTrue(mxBean.inProgress());
    final int totalPartitions = status1.getTotalPartitions();
    assertEquals(totalPartitions, mxBean.totalPartitions());
    waitCdl.countDown();
    fut.get();
    ((GridCacheDatabaseSharedManager) grid(0).context().cache().context().database()).defragmentationManager().completionFuture().get();
    assertFalse(mxBean.inProgress());
    assertEquals(totalPartitions, mxBean.processedPartitions());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) IgnitionEx(org.apache.ignite.internal.IgnitionEx) DefragmentationParameters(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) ClusterState(org.apache.ignite.cluster.ClusterState) UnaryOperator(java.util.function.UnaryOperator) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CountDownLatch(java.util.concurrent.CountDownLatch) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) DefragmentationMXBean(org.apache.ignite.mxbean.DefragmentationMXBean) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DefragmentationMXBean (org.apache.ignite.mxbean.DefragmentationMXBean)5 Ignite (org.apache.ignite.Ignite)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 MaintenanceTask (org.apache.ignite.maintenance.MaintenanceTask)3 Collections (java.util.Collections)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 UnaryOperator (java.util.function.UnaryOperator)2 IgniteCache (org.apache.ignite.IgniteCache)2 ClusterState (org.apache.ignite.cluster.ClusterState)2 ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)2 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)2 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 IgnitionEx (org.apache.ignite.internal.IgnitionEx)2 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)2 DefragmentationParameters (org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters)2