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(""));
}
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());
}
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);
}
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());
}
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());
}
Aggregations