use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class IgniteDataStorageMetricsSelfTest method testWalTotalSizeWithArchiveTurnedOff.
/**
* Check whether Wal is reporting correct usage when WAL Archive is turned off.
*
* @throws Exception If failed.
*/
@Test
public void testWalTotalSizeWithArchiveTurnedOff() throws Exception {
IgniteEx n = startGrid(0, (Consumer<IgniteConfiguration>) cfg -> cfg.getDataStorageConfiguration().setWalArchivePath(cfg.getDataStorageConfiguration().getWalPath()).setWalSegmentSize((int) (2 * U.MB)));
n.cluster().state(ACTIVE);
populateCache(n);
disableWal(n, true);
checkWalArchiveAndTotalSize(n, false);
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class IgniteDataStorageMetricsSelfTest method testWalWrittenBytes.
/**
* Checking that the metrics of the total logged bytes are working correctly.
*
* @throws Exception If failed.
*/
@Test
public void testWalWrittenBytes() throws Exception {
IgniteEx n = startGrid(0, (UnaryOperator<IgniteConfiguration>) cfg -> {
cfg.getDataStorageConfiguration().setWalSegmentSize((int) (2 * U.MB));
return cfg;
});
n.cluster().state(ACTIVE);
awaitPartitionMapExchange();
for (int i = 0; i < 10; i++) n.cache("cache").put(ThreadLocalRandom.current().nextLong(), new byte[(int) (32 * U.KB)]);
WALDisableContext walDisableCtx = n.context().cache().context().walState().walDisableContext();
assertNotNull(walDisableCtx);
setFieldValue(walDisableCtx, "disableWal", true);
assertTrue(walDisableCtx.check());
assertNull(walMgr(n).log(new DataRecord(emptyList())));
assertEquals(-1, walMgr(n).lastArchivedSegment());
long exp = walMgr(n).lastWritePointer().fileOffset() - HEADER_RECORD_SIZE;
assertEquals(exp, dbMgr(n).persistentStoreMetrics().getWalWrittenBytes());
assertEquals(exp, dsMetricsMXBean(n).getWalWrittenBytes());
assertEquals(exp, ((LongAdderMetric) dsMetricRegistry(n).findMetric("WalWrittenBytes")).value());
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class IgniteDataStorageMetricsSelfTest method testWalCompressedBytes.
/**
* Checking that the metrics of the total size compressed segment are working correctly.
*
* @throws Exception If failed.
*/
@Test
public void testWalCompressedBytes() throws Exception {
IgniteEx n0 = startGrid(0, (UnaryOperator<IgniteConfiguration>) cfg -> {
cfg.getDataStorageConfiguration().setWalCompactionEnabled(true).setWalSegmentSize((int) (2 * U.MB));
return cfg;
});
n0.cluster().state(ACTIVE);
awaitPartitionMapExchange();
while (walMgr(n0).lastArchivedSegment() < 3) n0.cache("cache").put(ThreadLocalRandom.current().nextLong(), new byte[(int) (32 * U.KB)]);
waitForCondition(() -> walMgr(n0).lastArchivedSegment() == walMgr(n0).lastCompactedSegment(), getTestTimeout());
assertCorrectWalCompressedBytesMetrics(n0);
stopAllGrids();
IgniteEx n1 = startGrid(0, (UnaryOperator<IgniteConfiguration>) cfg -> {
cfg.getDataStorageConfiguration().setWalCompactionEnabled(true);
return cfg;
});
n1.cluster().state(ACTIVE);
awaitPartitionMapExchange();
assertCorrectWalCompressedBytesMetrics(n1);
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class DurableBackgroundTasksProcessorSelfTest method testDontDeleteTaskIfItsRestart.
/**
* Check that the task will not be deleted from the MetaStorage if it was restarted.
*
* @throws Exception If failed.
*/
@Test
public void testDontDeleteTaskIfItsRestart() throws Exception {
IgniteEx n = startGrid(0);
ObservingCheckpointListener observingCpLsnr = new ObservingCheckpointListener();
dbMgr(n).addCheckpointListener(observingCpLsnr);
n.cluster().state(ACTIVE);
CheckpointWorkflow cpWorkflow = checkpointWorkflow(n);
List<CheckpointListener> cpLs = cpWorkflow.getRelevantCheckpointListeners(dbMgr(n).checkpointedDataRegions());
assertTrue(cpLs.contains(observingCpLsnr));
assertTrue(cpLs.contains(durableBackgroundTask(n)));
assertTrue(cpLs.indexOf(observingCpLsnr) < cpLs.indexOf(durableBackgroundTask(n)));
SimpleTask simpleTask0 = new SimpleTask("t");
IgniteInternalFuture<Void> taskFut = durableBackgroundTask(n).executeAsync(simpleTask0, true);
simpleTask0.onExecFut.get(getTestTimeout());
forceCheckpoint();
dbMgr(n).enableCheckpoints(false).get(getTestTimeout());
simpleTask0.taskFut.onDone(DurableBackgroundTaskResult.complete(null));
taskFut.get(getTestTimeout());
SimpleTask simpleTask1 = new SimpleTask("t");
AtomicReference<IgniteInternalFuture<Void>> taskFutRef = new AtomicReference<>();
observingCpLsnr.afterCheckpointEndConsumer = ctx -> taskFutRef.set(durableBackgroundTask(n).executeAsync(simpleTask1, true));
dbMgr(n).enableCheckpoints(true).get(getTestTimeout());
forceCheckpoint();
assertNotNull(metaStorageOperation(n, ms -> ms.read(metaStorageKey(simpleTask0))));
simpleTask1.onExecFut.get(getTestTimeout());
simpleTask1.taskFut.onDone(DurableBackgroundTaskResult.complete(null));
taskFutRef.get().get(getTestTimeout());
forceCheckpoint();
assertNull(metaStorageOperation(n, ms -> ms.read(metaStorageKey(simpleTask1))));
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class ClusterReadOnlyModeSelfTest method testEnableReadOnlyModeInsideTransaction.
/**
*/
@Test
public void testEnableReadOnlyModeInsideTransaction() throws Exception {
IgniteEx grid = startGrids(SERVER_NODES_COUNT);
grid.cluster().state(ACTIVE);
CacheConfiguration cfg = Stream.of(grid.configuration().getCacheConfiguration()).filter(c -> c.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL).filter(c -> !CU.isSystemCache(c.getName())).findAny().get();
final int key = 1;
IgniteCache<Integer, Integer> cache = grid.cache(cfg.getName());
cache.put(key, 0);
CountDownLatch startTxLatch = new CountDownLatch(1);
CountDownLatch clusterReadOnlyLatch = new CountDownLatch(1);
Thread t = new Thread(() -> {
try {
startTxLatch.await();
grid(1).cluster().state(ACTIVE_READ_ONLY);
assertEquals(ACTIVE_READ_ONLY, grid(1).cluster().state());
clusterReadOnlyLatch.countDown();
} catch (InterruptedException e) {
log.error("Thread interrupted", e);
fail("Thread interrupted");
}
});
t.start();
Transaction tx = grid(0).transactions().txStart();
try {
cache.put(key, 1);
startTxLatch.countDown();
tx.commit();
} catch (Exception e) {
log.error("TX Failed", e);
tx.rollback();
}
assertEquals(1, (int) cache.get(key));
t.join();
}
Aggregations