use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class IgnitePdsDefragmentationTest method defragmentAndValidateSizesDecreasedAfterDefragmentation.
/**
* Start node, wait for defragmentation and validate that sizes of caches are less than those before the defragmentation.
* @param gridId Idx of ignite grid.
* @param groups Cache groups to check.
* @throws Exception If failed.
*/
protected void defragmentAndValidateSizesDecreasedAfterDefragmentation(int gridId, CacheGroupContext... groups) throws Exception {
for (CacheGroupContext grp : groups) {
final long[] oldPartLen = partitionSizes(grp);
startGrid(0);
waitForDefragmentation(0);
stopGrid(0);
final long[] newPartLen = partitionSizes(grp);
boolean atLeastOneSmaller = false;
for (int p = 0; p < oldPartLen.length; p++) {
assertTrue(newPartLen[p] <= oldPartLen[p]);
if (newPartLen[p] < oldPartLen[p])
atLeastOneSmaller = true;
}
assertTrue(atLeastOneSmaller);
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class PendingTreeCorruptionTest method testCorruptionWhileLoadingData.
/**
*/
@Test
public void testCorruptionWhileLoadingData() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
String expireCacheName = "cacheWithExpire";
String regularCacheName = "cacheWithoutExpire";
String grpName = "cacheGroup";
IgniteCache<Object, Object> expireCache = ig.getOrCreateCache(new CacheConfiguration<>(expireCacheName).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(MINUTES, 10))).setGroupName(grpName));
IgniteCache<Object, Object> regularCache = ig.getOrCreateCache(new CacheConfiguration<>(regularCacheName).setGroupName(grpName));
// This will initialize partition and cache structures.
expireCache.put(0, 0);
expireCache.remove(0);
int expireCacheId = CU.cacheGroupId(expireCacheName, grpName);
CacheGroupContext grp = ig.context().cache().cacheGroup(CU.cacheId(grpName));
IgniteCacheOffheapManager.CacheDataStore store = grp.topology().localPartition(0).dataStore();
assertNotNull(store);
// Get pending tree of expire cache.
PendingEntriesTree pendingTree = store.pendingTree();
long year = TimeUnit.DAYS.toMillis(365);
long expiration = System.currentTimeMillis() + year;
ig.context().cache().context().database().checkpointReadLock();
try {
// Carefully calculated number. Just enough for the first split to happen, but not more.
for (int i = 0; i < 202; i++) // link != 0
pendingTree.putx(new PendingRow(expireCacheId, expiration, expiration + i));
// Open cursor, it'll cache first leaf of the tree.
GridCursor<PendingRow> cur = pendingTree.find(null, new PendingRow(expireCacheId, expiration + year, 0), PendingEntriesTree.WITHOUT_KEY);
// Required for "do" loop to work.
assertTrue(cur.next());
int cnt = 0;
// Emulate real expiry loop but with a more precise control.
do {
PendingRow row = cur.get();
pendingTree.removex(row);
// with its sibling, meaning that cached "nextPageId" points to empty page from reuse list.
if (row.link - row.expireTime == 100) {
// Put into another cache will take a page from reuse list first. This means that cached
// "nextPageId" points to a data page.
regularCache.put(0, 0);
}
cnt++;
} while (cur.next());
assertEquals(202, cnt);
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class LocalWalModeChangeDuringRebalancingSelfTest method doTestSimple.
/**
* @throws Exception If failed.
*/
private void doTestSimple() throws Exception {
Ignite ignite = startGrids(3);
ignite.cluster().baselineAutoAdjustEnabled(false);
ignite.cluster().state(ACTIVE);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Integer> cache2 = ignite.cache(REPL_CACHE);
int keysCnt = getKeysCount();
for (int k = 0; k < keysCnt; k++) {
cache.put(k, k);
// Empty cache causes skipped checkpoint.
cache2.put(k, k);
}
IgniteEx newIgnite = startGrid(3);
final CheckpointHistory cpHist = ((GridCacheDatabaseSharedManager) newIgnite.context().cache().context().database()).checkpointHistory();
waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return !cpHist.checkpoints().isEmpty();
}
}, 10_000);
// To ensure timestamp granularity.
U.sleep(10);
long newIgniteStartedTimestamp = System.currentTimeMillis();
newIgnite.cluster().setBaselineTopology(4);
awaitExchange(newIgnite);
CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
assertEquals(!disableWalDuringRebalancing, grpCtx.walEnabled());
// To ensure timestamp granularity.
U.sleep(10);
long rebalanceStartedTimestamp = System.currentTimeMillis();
for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
awaitPartitionMapExchange();
assertTrue(grpCtx.walEnabled());
// To ensure timestamp granularity.
U.sleep(10);
long rebalanceFinishedTimestamp = System.currentTimeMillis();
for (Integer k = 0; k < keysCnt; k++) assertEquals("k=" + k, k, cache.get(k));
int checkpointsBeforeNodeStarted = 0;
int checkpointsBeforeRebalance = 0;
int checkpointsAfterRebalance = 0;
for (Long timestamp : cpHist.checkpoints()) {
if (timestamp < newIgniteStartedTimestamp)
checkpointsBeforeNodeStarted++;
else if (timestamp >= newIgniteStartedTimestamp && timestamp < rebalanceStartedTimestamp)
checkpointsBeforeRebalance++;
else if (timestamp >= rebalanceStartedTimestamp && timestamp <= rebalanceFinishedTimestamp)
checkpointsAfterRebalance++;
}
// checkpoint on start
assertEquals(1, checkpointsBeforeNodeStarted);
assertEquals(0, checkpointsBeforeRebalance);
// Expecting a checkpoint for each group.
assertEquals(disableWalDuringRebalancing ? newIgnite.context().cache().cacheGroups().size() : 0, // checkpoint if WAL was re-activated
checkpointsAfterRebalance);
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class LocalWalModeChangeDuringRebalancingSelfTest method doTestParallelExchange.
/**
* @throws Exception If failed.
*/
private void doTestParallelExchange(AtomicReference<CountDownLatch> latchRef) throws Exception {
Ignite ignite = startGrids(3);
ignite.cluster().baselineAutoAdjustEnabled(false);
ignite.cluster().state(ACTIVE);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
for (int k = 0; k < getKeysCount(); k++) cache.put(k, k);
IgniteEx newIgnite = startGrid(3);
CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
CountDownLatch latch = new CountDownLatch(1);
latchRef.set(latch);
ignite.cluster().setBaselineTopology(ignite.cluster().nodes());
// Await fully exchange complete.
awaitExchange(newIgnite);
assertFalse(grpCtx.walEnabled());
// TODO : test with client node as well
// Trigger exchange
startGrid(4);
assertFalse(grpCtx.walEnabled());
latch.countDown();
assertFalse(grpCtx.walEnabled());
for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
awaitPartitionMapExchange();
assertTrue(waitForCondition(grpCtx::walEnabled, 2_000));
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class LocalWalModeChangeDuringRebalancingSelfTest method testWalNotDisabledAfterShrinkingBaselineTopology.
/**
* @throws Exception If failed.
*/
@Test
public void testWalNotDisabledAfterShrinkingBaselineTopology() throws Exception {
Ignite ignite = startGrids(4);
ignite.cluster().baselineAutoAdjustEnabled(false);
ignite.cluster().state(ACTIVE);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
int keysCnt = getKeysCount();
for (int k = 0; k < keysCnt; k++) cache.put(k, k);
for (Ignite g : G.allGrids()) {
CacheGroupContext grpCtx = ((IgniteEx) g).cachex(DEFAULT_CACHE_NAME).context().group();
assertTrue(grpCtx.walEnabled());
}
stopGrid(2);
ignite.cluster().setBaselineTopology(5);
ignite.resetLostPartitions(Collections.singleton(DEFAULT_CACHE_NAME));
// Await fully exchange complete.
awaitExchange((IgniteEx) ignite);
for (Ignite g : G.allGrids()) {
CacheGroupContext grpCtx = ((IgniteEx) g).cachex(DEFAULT_CACHE_NAME).context().group();
assertTrue(grpCtx.walEnabled());
g.cache(DEFAULT_CACHE_NAME).rebalance();
}
awaitPartitionMapExchange();
for (Ignite g : G.allGrids()) {
CacheGroupContext grpCtx = ((IgniteEx) g).cachex(DEFAULT_CACHE_NAME).context().group();
assertTrue(grpCtx.walEnabled());
}
}
Aggregations