Search in sources :

Example 61 with IgniteKernal

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) HashMap(java.util.HashMap)

Example 62 with IgniteKernal

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));
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 63 with IgniteKernal

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());
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 64 with IgniteKernal

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());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 65 with IgniteKernal

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);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheExistsException(org.apache.ignite.cache.CacheExistsException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Aggregations

IgniteKernal (org.apache.ignite.internal.IgniteKernal)181 Ignite (org.apache.ignite.Ignite)78 ClusterNode (org.apache.ignite.cluster.ClusterNode)35 ArrayList (java.util.ArrayList)34 Map (java.util.Map)30 Transaction (org.apache.ignite.transactions.Transaction)30 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)27 IgniteCache (org.apache.ignite.IgniteCache)26 UUID (java.util.UUID)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)22 IgniteException (org.apache.ignite.IgniteException)21 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)20 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)19 IgniteEx (org.apache.ignite.internal.IgniteEx)15 HashMap (java.util.HashMap)14 List (java.util.List)14 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13