use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalHistoryReservationsTest method testNodeLeftDuringExchange.
/**
* @throws Exception If failed.
*/
public void testNodeLeftDuringExchange() throws Exception {
System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0");
final int entryCnt = 10_000;
final int initGridCnt = 4;
final Ignite ig0 = startGrids(initGridCnt);
ig0.active(true);
IgniteCache<Object, Object> cache = ig0.cache("cache1");
for (int k = 0; k < entryCnt; k++) cache.put(k, k);
forceCheckpoint();
Lock lock = cache.lock(0);
lock.lock();
try {
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
try {
startGrid(initGridCnt);
} catch (Exception e) {
fail(e.getMessage());
}
}
});
boolean reserved = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int g = 0; g < initGridCnt; g++) {
IgniteEx ig = grid(g);
FileWriteAheadLogManager wal = (FileWriteAheadLogManager) ig.context().cache().context().wal();
Object reservationStorage = GridTestUtils.getFieldValue(wal, "reservationStorage");
synchronized (reservationStorage) {
Map reserved = GridTestUtils.getFieldValue(reservationStorage, "reserved");
if (reserved.isEmpty())
return false;
}
}
return true;
}
}, 10_000);
assert reserved;
stopGrid(Integer.toString(initGridCnt - 1), true, false);
} finally {
lock.unlock();
}
boolean released = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int g = 0; g < initGridCnt - 1; g++) {
IgniteEx ig = grid(g);
FileWriteAheadLogManager wal = (FileWriteAheadLogManager) ig.context().cache().context().wal();
Object reservationStorage = GridTestUtils.getFieldValue(wal, "reservationStorage");
synchronized (reservationStorage) {
Map reserved = GridTestUtils.getFieldValue(reservationStorage, "reserved");
if (!reserved.isEmpty())
return false;
}
}
return true;
}
}, 10_000);
assert released;
awaitPartitionMapExchange();
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryPPCTest method testDynamicallyStartedNonPersistentCache.
/**
*/
public void testDynamicallyStartedNonPersistentCache() throws Exception {
try {
IgniteEx ignite = startGrid(1);
ignite.active(true);
IgniteCache<Integer, Object> dynamicPersistent = ignite.getOrCreateCache(new CacheConfiguration<Integer, Object>().setAtomicityMode(CacheAtomicityMode.ATOMIC).setRebalanceMode(CacheRebalanceMode.SYNC).setName("dynamicPersistent").setAffinity(new RendezvousAffinityFunction(false, 32)));
IgniteCache<Integer, Object> dynamicVolatile = ignite.getOrCreateCache(new CacheConfiguration<Integer, Object>().setAtomicityMode(CacheAtomicityMode.ATOMIC).setRebalanceMode(CacheRebalanceMode.SYNC).setDataRegionName(MEM_PLC_NO_PDS).setName("dynamicVolatile").setAffinity(new RendezvousAffinityFunction(false, 32)));
for (int i = 0; i < 10_000; i++) {
dynamicPersistent.put(i, new IndexedObject(i));
dynamicVolatile.put(i, new IndexedObject(i + 1));
}
stopGrid(1);
ignite = startGrid(1);
ignite.active(true);
dynamicPersistent = ignite.cache("dynamicPersistent");
dynamicVolatile = ignite.cache("dynamicVolatile");
for (int i = 0; i < 10_000; i++) assertEquals(new IndexedObject(i), dynamicPersistent.get(i));
assertNull(dynamicVolatile);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoverySeveralRestartsTest method testWalRecoverySeveralRestarts.
/**
* @throws Exception if failed.
*/
public void testWalRecoverySeveralRestarts() throws Exception {
try {
IgniteEx ignite = startGrid(1);
ignite.active(true);
Random locRandom = ThreadLocalRandom.current();
try (IgniteDataStreamer<Integer, IndexedObject> dataLdr = ignite.dataStreamer(cacheName)) {
for (int i = 0; i < KEYS_COUNT; ++i) {
if (i % (KEYS_COUNT / 100) == 0)
info("Loading " + i * 100 / KEYS_COUNT + "%");
dataLdr.addData(i, new IndexedObject(i));
}
}
int size = ignite.cache(cacheName).size();
for (int restartCnt = 0; restartCnt < 5; ++restartCnt) {
stopGrid(1, true);
info("Restart #" + restartCnt);
U.sleep(500);
ignite = startGrid(1);
ignite.active(true);
IgniteCache<Integer, IndexedObject> cache = ignite.cache(cacheName);
assertEquals(size, cache.size());
info("Restart #" + restartCnt);
for (int i = 0; i < KEYS_COUNT / 100; ++i) {
assertNotNull(cache.get(locRandom.nextInt(KEYS_COUNT / 100)));
cache.put(locRandom.nextInt(KEYS_COUNT / 100), new IndexedObject(locRandom.nextInt(KEYS_COUNT / 100)));
}
cache.put(KEYS_COUNT + restartCnt, new IndexedObject(KEYS_COUNT + restartCnt));
// Check recovery for partition meta pages.
size = cache.size();
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testMetastorageLargeArray.
/**
* @throws Exception If fail.
*/
public void testMetastorageLargeArray() throws Exception {
try {
int cnt = 5000;
int arraySize = 32_768;
IgniteEx ignite = (IgniteEx) startGrid("node1");
ignite.active(true);
GridCacheSharedContext<Object, Object> sharedCtx = ignite.context().cache().context();
MetaStorage storage = sharedCtx.database().metaStorage();
for (int i = 0; i < cnt; i++) {
byte[] b1 = new byte[arraySize];
for (int k = 0; k < arraySize; k++) {
b1[k] = (byte) (k % 100);
}
sharedCtx.database().checkpointReadLock();
try {
storage.putData(String.valueOf(i), b1);
} finally {
sharedCtx.database().checkpointReadUnlock();
}
}
for (int i = 0; i < cnt; i++) {
byte[] d2 = storage.getData(String.valueOf(i));
assertEquals(arraySize, d2.length);
for (int k = 0; k < arraySize; k++) {
assertEquals((byte) (k % 100), d2[k]);
}
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testSwitchClassLoader.
/**
* @throws Exception If fail.
*/
public void testSwitchClassLoader() throws Exception {
try {
final IgniteEx igniteEx = startGrid(1);
// CustomDiscoveryMessage will trigger service tasks
startGrid(2);
igniteEx.active(true);
IgniteCache<Integer, EnumVal> cache = igniteEx.cache("partitioned");
// Creates LoadCacheJobV2
// cache.loadCache(null);
final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
final ClassLoader newCl = getExternalClassLoader();
Thread.currentThread().setContextClassLoader(newCl);
for (int i = 0; i < 10; i++) cache.put(i, i % 2 == 0 ? EnumVal.VAL1 : EnumVal.VAL2);
for (int i = 0; i < 10; i++) assert cache.containsKey(i);
// Invokes ClearTask with new class loader
cache.clear();
Thread.currentThread().setContextClassLoader(oldCl);
for (int i = 0; i < 10; i++) cache.put(i, i % 2 == 0 ? EnumVal.VAL1 : EnumVal.VAL2);
for (int i = 0; i < 10; i++) assert cache.containsKey(i);
} finally {
stopAllGrids();
}
}
Aggregations