use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheQueryJdbcMetadataTask method map.
/**
* {@inheritDoc}
*/
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable String cacheName) {
Map<JdbcDriverMetadataJob, ClusterNode> map = new HashMap<>();
IgniteKernal kernal = (IgniteKernal) ignite;
GridDiscoveryManager discoMgr = kernal.context().discovery();
for (ClusterNode n : subgrid) if (discoMgr.cacheAffinityNode(n, cacheName)) {
map.put(new JdbcDriverMetadataJob(cacheName), n);
break;
}
return map;
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteClientCacheStartFailoverTest method testRebalanceStateConcurrentStart.
/**
* @throws Exception If failed.
*/
public void testRebalanceStateConcurrentStart() throws Exception {
final int SRVS1 = 3;
final int CLIENTS = 5;
final int SRVS2 = 5;
startGrids(SRVS1);
Ignite srv0 = ignite(0);
final int KEYS = 1000;
final List<String> cacheNames = startCaches(srv0, KEYS);
client = true;
final List<Ignite> clients = new ArrayList<>();
for (int i = 0; i < CLIENTS; i++) clients.add(startGrid(SRVS1 + i));
client = false;
final CyclicBarrier barrier = new CyclicBarrier(clients.size() + SRVS2);
final AtomicInteger clientIdx = new AtomicInteger();
final Set<Integer> keys = new HashSet<>();
for (int i = 0; i < KEYS; i++) keys.add(i);
IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
Ignite client = clients.get(clientIdx.getAndIncrement());
for (String cacheName : cacheNames) client.cache(cacheName);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 10; i++) {
for (String cacheName : cacheNames) {
IgniteCache<Object, Object> cache = client.cache(cacheName);
Map<Object, Object> map0 = cache.getAll(keys);
assertEquals(KEYS, map0.size());
cache.put(rnd.nextInt(KEYS), i);
}
}
return null;
}
}, clients.size(), "client-cache-start");
final AtomicInteger srvIdx = new AtomicInteger(SRVS1 + CLIENTS);
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
startGrid(srvIdx.incrementAndGet());
return null;
}
}, SRVS2, "node-start");
fut1.get();
fut2.get();
final AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS1 + SRVS2 + CLIENTS, 1);
for (Ignite client : clients) {
for (String cacheName : cacheNames) {
final GridDhtPartitionTopology top = ((IgniteKernal) client).context().cache().internalCache(cacheName).context().topology();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return top.rebalanceFinished(topVer);
}
}, 5000);
assertTrue(top.rebalanceFinished(topVer));
}
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method testStartStopCacheAddNode.
/**
* @throws Exception If failed.
*/
public void testStartStopCacheAddNode() throws Exception {
final IgniteEx kernal = grid(0);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(CacheMode.REPLICATED);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setName(DYNAMIC_CACHE_NAME);
kernal.createCache(ccfg);
info(">>>>>>> Deployed dynamic cache");
startGrid(nodeCount());
try {
// Check that cache got deployed on new node.
IgniteCache<Object, Object> cache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);
cache.put("1", "1");
for (int g = 0; g < nodeCount() + 1; g++) {
assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));
Collection<ClusterNode> nodes = grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(0);
assertEquals(nodeCount() + 1, nodes.size());
}
// Undeploy cache.
kernal.destroyCache(DYNAMIC_CACHE_NAME);
startGrid(nodeCount() + 1);
awaitPartitionMapExchange();
// Check that cache is not deployed on new node after undeploy.
for (int g = 0; g < nodeCount() + 2; g++) {
final IgniteKernal kernal0 = (IgniteKernal) grid(g);
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
}
} finally {
stopGrid(nodeCount() + 1);
stopGrid(nodeCount());
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method testStartFromClientNode.
/**
* @throws Exception If failed.
*/
public void testStartFromClientNode() throws Exception {
try {
testAttribute = false;
startGrid(nodeCount());
final IgniteEx kernal = grid(0);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setName(DYNAMIC_CACHE_NAME);
ccfg.setNodeFilter(NODE_FILTER);
final IgniteKernal started = (IgniteKernal) grid(nodeCount());
started.createCache(ccfg);
GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME);
assertNotNull(cache);
assertFalse(cache.context().affinityNode());
// Should obtain client cache on new node.
IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);
clientCache.put("1", "1");
for (int g = 0; g < nodeCount() + 1; g++) assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));
kernal.destroyCache(DYNAMIC_CACHE_NAME);
} finally {
stopGrid(nodeCount());
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method checkStartStopCacheSimple.
/**
* @param mode Cache atomicity mode.
* @throws Exception If failed.
*/
private void checkStartStopCacheSimple(CacheAtomicityMode mode) throws Exception {
final IgniteEx kernal = grid(0);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setAtomicityMode(mode);
ccfg.setName(DYNAMIC_CACHE_NAME);
kernal.createCache(ccfg);
for (int g = 0; g < nodeCount(); g++) {
IgniteEx kernal0 = grid(g);
info("Getting cache for node: " + g);
assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME));
}
grid(0).cache(DYNAMIC_CACHE_NAME).put("1", "1");
for (int g = 0; g < nodeCount(); g++) assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));
// Grab caches before stop.
final IgniteCache[] caches = new IgniteCache[nodeCount()];
for (int g = 0; g < nodeCount(); g++) caches[g] = grid(g).cache(DYNAMIC_CACHE_NAME);
kernal.destroyCache(DYNAMIC_CACHE_NAME);
awaitPartitionMapExchange();
for (int g = 0; g < nodeCount(); g++) {
final IgniteKernal kernal0 = (IgniteKernal) grid(g);
final int idx = g;
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return caches[idx].get("1");
}
}, IllegalStateException.class, null);
}
}
Aggregations