use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheMetricsManageTest method testJmxStatisticsEnable.
/**
* @param persistence Persistence.
*/
private void testJmxStatisticsEnable(boolean persistence) throws Exception {
this.persistence = persistence;
Ignite ig1 = startGrid(1);
Ignite ig2 = startGrid(2);
ig1.cluster().active(true);
CacheConfiguration<Object, Object> ccfg = ig1.cache(CACHE1).getConfiguration(CacheConfiguration.class);
CacheConfiguration<Object, Object> cacheCfg2 = new CacheConfiguration<>(ccfg);
cacheCfg2.setName(CACHE2);
cacheCfg2.setStatisticsEnabled(true);
ig2.getOrCreateCache(cacheCfg2);
CacheMetricsMXBean mxBeanCache1 = mxBean(2, CACHE1, CacheClusterMetricsMXBeanImpl.class);
CacheMetricsMXBean mxBeanCache2 = mxBean(2, CACHE2, CacheClusterMetricsMXBeanImpl.class);
CacheMetricsMXBean mxBeanCache1loc = mxBean(2, CACHE1, CacheLocalMetricsMXBeanImpl.class);
mxBeanCache1.enableStatistics();
mxBeanCache2.disableStatistics();
assertCachesStatisticsMode(true, false);
stopGrid(1);
startGrid(3);
assertCachesStatisticsMode(true, false);
mxBeanCache1loc.disableStatistics();
assertCachesStatisticsMode(false, false);
mxBeanCache1.enableStatistics();
mxBeanCache2.enableStatistics();
// Start node 1 again.
startGrid(1);
if (persistence)
ig2.resetLostPartitions(Arrays.asList(CACHE1, CACHE2));
assertCachesStatisticsMode(true, true);
int gridIdx = 0;
for (Ignite ignite : G.allGrids()) {
gridIdx++;
ignite.cache(CACHE1).put(gridIdx, gridIdx);
ignite.cache(CACHE2).put(gridIdx, gridIdx);
ignite.cache(CACHE1).get(gridIdx);
ignite.cache(CACHE2).get(gridIdx);
}
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
int cnt = G.allGrids().size();
for (Ignite ignite : G.allGrids()) {
CacheMetrics metrics1 = ignite.cache(CACHE1).metrics();
CacheMetrics metrics2 = ignite.cache(CACHE2).metrics();
if (metrics1.getCacheGets() < cnt || metrics2.getCacheGets() < cnt || metrics1.getCachePuts() < cnt || metrics2.getCachePuts() < cnt)
return false;
}
return true;
}
}, 10_000L));
stopAllGrids();
ig1 = startGrid(1);
ig1.cluster().active(true);
ig1.getOrCreateCache(cacheCfg2.setStatisticsEnabled(false));
if (persistence)
// Both caches restored from pds.
assertCachesStatisticsMode(true, true);
else
assertCachesStatisticsMode(false, false);
mxBeanCache1 = mxBean(1, CACHE1, CacheLocalMetricsMXBeanImpl.class);
mxBeanCache2 = mxBean(1, CACHE2, CacheLocalMetricsMXBeanImpl.class);
mxBeanCache1.enableStatistics();
mxBeanCache2.disableStatistics();
startGrid(2);
assertCachesStatisticsMode(true, false);
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheGroupMetricsTest method testCacheGroupMetrics.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheGroupMetrics() throws Exception {
pds = false;
startGrid(0);
startGrid(1);
startGrid(2);
awaitPartitionMapExchange(true, false, null);
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean1Grp1 = cacheGroupMetrics(1, "group1");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean2Grp1 = cacheGroupMetrics(2, "group1");
assertEquals("group1", mxBean0Grp1.get1().getGroupName());
assertEquals(null, mxBean0Grp3.get1().getGroupName());
assertEquals(3, mxBean0Grp1.get1().getBackups());
assertEquals(10, mxBean0Grp1.get1().getPartitions());
assertEquals(1, mxBean0Grp1.get2().<IntMetric>findMetric("MinimumNumberOfPartitionCopies").value());
assertEquals(3, mxBean0Grp1.get2().<IntMetric>findMetric("MaximumNumberOfPartitionCopies").value());
assertEquals(0, mxBean0Grp1.get1().getClusterMovingPartitionsCount());
assertEquals(19, mxBean0Grp1.get1().getClusterOwningPartitionsCount());
assertEquals(7, mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
assertEquals(6, mxBean1Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
assertEquals(6, mxBean2Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
assertEquals(F.asList("cache1"), mxBean0Grp1.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
assertEquals(F.asList("cache2", "cache3"), mxBean0Grp2.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
assertEquals(F.asList("cache4"), mxBean0Grp3.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
assertEquals(arrayToAssignmentMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("AffinityPartitionsAssignmentMap").value());
assertEquals(arrayToAllocationMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("OwningPartitionsAllocationMap").value());
ObjectMetric<Map<Integer, List<String>>> movingPartitionsAllocationMap = mxBean0Grp1.get2().findMetric("MovingPartitionsAllocationMap");
assertEquals(arrayToAllocationMap(new int[10][]), movingPartitionsAllocationMap.value());
try (IgniteDataStreamer<Integer, Integer> st = grid(0).dataStreamer("cache1")) {
for (int i = 0; i < 50_000; i++) st.addData(i, i);
}
// Pause rebalance to check instant partitions states.
grid(0).rebalanceEnabled(false);
grid(1).rebalanceEnabled(false);
stopGrid(2);
// Check moving partitions while rebalancing.
assertFalse(arrayToAllocationMap(new int[10][]).equals(movingPartitionsAllocationMap.value()));
int movingCnt = mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeMovingPartitionsCount").value();
assertTrue(movingCnt > 0);
assertTrue(mxBean0Grp1.get1().getClusterMovingPartitionsCount() > 0);
final CountDownLatch evictLatch = new CountDownLatch(1);
// Block all evicting threads to count total renting partitions.
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
try {
evictLatch.await();
} catch (InterruptedException e) {
log.error("Interrupted", e);
}
return true;
}
}, EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
grid(0).rebalanceEnabled(true);
grid(1).rebalanceEnabled(true);
startGrid(2);
try {
assertTrue("Renting partitions count when node returns not equals to moved partitions when node left", GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
IntMetric localNodeRentingPartitionsCount = mxBean0Grp1.get2().findMetric("LocalNodeRentingPartitionsCount");
log.info("Renting partitions count: " + localNodeRentingPartitionsCount.value());
log.info("Renting entries count: " + mxBean0Grp1.get2().findMetric("LocalNodeRentingEntriesCount").getAsString());
return localNodeRentingPartitionsCount.value() == movingCnt;
}
}, 10_000L));
assertTrue("Renting entries count is 0", mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeRentingPartitionsCount").value() > 0);
} finally {
evictLatch.countDown();
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheGroupsMetricsRebalanceTest method testRebalanceEstimateFinishTime.
/**
* @throws Exception If failed.
*/
@Test
public void testRebalanceEstimateFinishTime() throws Exception {
System.setProperty(IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL, String.valueOf(10_000));
Ignite ig1 = startGrid(1);
final int KEYS = 300_000;
try (IgniteDataStreamer<Integer, String> st = ig1.dataStreamer(CACHE1)) {
for (int i = 0; i < KEYS; i++) st.addData(i, CACHE1 + "-" + i);
}
final Ignite ig2 = startGrid(2);
boolean rebalancingStartTimeGot = waitForCondition(() -> ig2.cache(CACHE1).localMetrics().getRebalancingStartTime() != -1L, 5_000);
assertTrue("Unable to resolve rebalancing start time.", rebalancingStartTimeGot);
CacheMetrics metrics = ig2.cache(CACHE1).localMetrics();
long startTime = metrics.getRebalancingStartTime();
long currTime = U.currentTimeMillis();
assertTrue("Invalid start time [startTime=" + startTime + ", currTime=" + currTime + ']', startTime > 0L && (currTime - startTime) >= 0L && (currTime - startTime) <= 5000L);
final CountDownLatch latch = new CountDownLatch(1);
runAsync(() -> {
// Waiting 75% keys will be rebalanced.
int partKeys = KEYS / 2;
final long keysLine = (long) partKeys / 4L;
log.info("Wait until keys left will be less than: " + keysLine);
while (true) {
CacheMetrics m = ig2.cache(CACHE1).localMetrics();
long keyLeft = m.getKeysToRebalanceLeft();
if (keyLeft < keysLine) {
latch.countDown();
break;
}
log.info("Keys left: " + m.getKeysToRebalanceLeft());
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
log.warning("Interrupt thread", e);
Thread.currentThread().interrupt();
}
}
});
assertTrue(latch.await(getTestTimeout(), TimeUnit.MILLISECONDS));
boolean estimatedRebalancingFinishTimeGot = waitForCondition(new PA() {
@Override
public boolean apply() {
return ig2.cache(CACHE1).localMetrics().getEstimatedRebalancingFinishTime() != -1L;
}
}, 5_000L);
assertTrue("Unable to resolve estimated rebalancing finish time.", estimatedRebalancingFinishTimeGot);
long finishTime = ig2.cache(CACHE1).localMetrics().getEstimatedRebalancingFinishTime();
assertTrue("Not a positive estimation of rebalancing finish time: " + finishTime, finishTime > 0L);
currTime = U.currentTimeMillis();
long timePassed = currTime - startTime;
long timeLeft = finishTime - currTime;
// TODO: finishRebalanceLatch gets countdown much earlier because of ForceRebalanceExchangeTask triggered by cache with delay
// assertTrue("Got timeout while waiting for rebalancing. Estimated left time: " + timeLeft,
// finishRebalanceLatch.await(timeLeft + 10_000L, TimeUnit.MILLISECONDS));
boolean allKeysRebalanced = waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ig2.cache(CACHE1).localMetrics().getKeysToRebalanceLeft() == 0;
}
}, timeLeft + ACCEPTABLE_TIME_INACCURACY);
assertTrue("Some keys aren't rebalanced.", allKeysRebalanced);
log.info("[timePassed=" + timePassed + ", timeLeft=" + timeLeft + ", Time to rebalance=" + (finishTime - startTime) + ", startTime=" + startTime + ", finishTime=" + finishTime + ']');
System.clearProperty(IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL);
currTime = U.currentTimeMillis();
log.info("Rebalance time: " + (currTime - startTime));
long diff = finishTime - currTime;
assertTrue("Expected less than " + ACCEPTABLE_TIME_INACCURACY + ", but actual: " + diff, Math.abs(diff) < ACCEPTABLE_TIME_INACCURACY);
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheNearUpdateTopologyChangeAbstractTest method testNearUpdateTopologyChange.
/**
* @throws Exception If failed.
*/
@Test
public void testNearUpdateTopologyChange() throws Exception {
awaitPartitionMapExchange();
final Affinity<Integer> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
final Integer key = 9;
IgniteCache<Integer, Integer> primaryCache = primaryCache(key, DEFAULT_CACHE_NAME);
final Ignite primaryIgnite = primaryCache.unwrap(Ignite.class);
log.info("Primary node: " + primaryIgnite.name());
primaryCache.put(key, 1);
IgniteCache<Integer, Integer> nearCache = nearCache(key);
log.info("Near node: " + nearCache.unwrap(Ignite.class).name());
assertEquals((Object) 1, nearCache.get(key));
assertEquals((Object) 1, nearCache.localPeek(key, ONHEAP));
boolean gotNewPrimary = false;
List<Ignite> newNodes = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int idx = gridCount() + i;
log.info("Start new node: " + i);
Ignite ignite = startGrid(idx);
awaitPartitionMapExchange();
newNodes.add(ignite);
ClusterNode primaryNode = aff.mapKeyToNode(key);
Ignite primary = grid(primaryNode);
log.info("Primary node on new topology: " + primary.name());
if (!primaryNode.equals(primaryIgnite.cluster().localNode())) {
log.info("Update from new primary: " + primary.name());
primary = grid(primaryNode);
gotNewPrimary = true;
primary.cache(DEFAULT_CACHE_NAME).put(key, 2);
break;
} else
assertEquals((Object) 1, nearCache.localPeek(key, ONHEAP));
}
assertTrue(gotNewPrimary);
for (Ignite ignite : newNodes) {
log.info("Stop started node: " + ignite.name());
ignite.close();
}
awaitPartitionMapExchange();
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return aff.isPrimary(primaryIgnite.cluster().localNode(), key);
}
}, 10_000);
assertTrue(wait);
log.info("Primary node: " + primaryNode(key, DEFAULT_CACHE_NAME).name());
assertTrue(aff.isPrimary(primaryIgnite.cluster().localNode(), key));
assertFalse(aff.isPrimaryOrBackup(nearCache.unwrap(Ignite.class).cluster().localNode(), key));
assertEquals((Object) 2, nearCache.get(key));
assertEquals((Object) 2, nearCache.localPeek(key, ONHEAP));
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class SetTxTimeoutOnPartitionMapExchangeTest method waitForExchangeStarted.
/**
* Waits for srarting PME on grid.
*
* @param ig Ignite grid.
* @throws IgniteCheckedException If fails.
*/
private void waitForExchangeStarted(IgniteEx ig) throws IgniteCheckedException {
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (GridDhtPartitionsExchangeFuture fut : ig.context().cache().context().exchange().exchangeFutures()) {
if (!fut.isDone())
return true;
}
return false;
}
}, WAIT_CONDITION_TIMEOUT);
// Additional waiting to ensure that code really start waiting for partition release.
U.sleep(5_000L);
}
Aggregations