Search in sources :

Example 16 with IgniteInternalCache

use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.

the class IgniteCacheClientNodePartitionsExchangeTest method waitForTopologyUpdate.

/**
 * @param expNodes Expected number of nodes.
 * @param topVer Expected topology version.
 * @throws Exception If failed.
 */
private void waitForTopologyUpdate(int expNodes, final AffinityTopologyVersion topVer) throws Exception {
    List<Ignite> nodes = G.allGrids();
    assertEquals(expNodes, nodes.size());
    for (Ignite ignite : nodes) {
        final IgniteKernal kernal = (IgniteKernal) ignite;
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return topVer.equals(kernal.context().cache().context().exchange().readyAffinityVersion());
            }
        }, 10_000);
        assertEquals("Unexpected affinity version for " + ignite.name(), topVer, kernal.context().cache().context().exchange().readyAffinityVersion());
    }
    Iterator<Ignite> it = nodes.iterator();
    Ignite ignite0 = it.next();
    Affinity<Integer> aff0 = ignite0.affinity(DEFAULT_CACHE_NAME);
    while (it.hasNext()) {
        Ignite ignite = it.next();
        Affinity<Integer> aff = ignite.affinity(DEFAULT_CACHE_NAME);
        assertEquals(aff0.partitions(), aff.partitions());
        for (int part = 0; part < aff.partitions(); part++) assertEquals(aff0.mapPartitionToPrimaryAndBackups(part), aff.mapPartitionToPrimaryAndBackups(part));
    }
    for (Ignite ignite : nodes) {
        final IgniteKernal kernal = (IgniteKernal) ignite;
        for (IgniteInternalCache cache : kernal.context().cache().caches()) {
            GridDhtPartitionTopology top = cache.context().topology();
            waitForReadyTopology(top, topVer);
            assertEquals("Unexpected topology version [node=" + ignite.name() + ", cache=" + cache.name() + ']', topVer, top.readyTopologyVersion());
        }
    }
    awaitPartitionMapExchange();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) Ignite(org.apache.ignite.Ignite)

Example 17 with IgniteInternalCache

use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.

the class PartitionEvictionOrderTest method testSyncCachesEvictedAtFirst.

/**
 * Tests that {@link CacheRebalanceMode#SYNC} caches are evicted at first.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_EVICTION_PERMITS, value = "1")
@WithSystemProperty(key = IGNITE_PDS_WAL_REBALANCE_THRESHOLD, value = "500_000")
public void testSyncCachesEvictedAtFirst() throws Exception {
    IgniteEx node0 = startGrid(0);
    node0.cluster().state(ACTIVE);
    IgniteEx node1 = startGrid(1);
    node0.cluster().setBaselineTopology(node1.cluster().topologyVersion());
    GridCacheAdapter<Object, Object> utilCache0 = grid(0).context().cache().internalCache(CU.UTILITY_CACHE_NAME);
    IgniteCache<Object, Object> cache = node0.getOrCreateCache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 1000; i++) {
        utilCache0.put(i, i);
        cache.put(i, i);
    }
    awaitPartitionMapExchange();
    stopGrid(0);
    GridCacheAdapter<Object, Object> utilCache1 = grid(1).context().cache().internalCache(CU.UTILITY_CACHE_NAME);
    IgniteInternalCache<Object, Object> cache2 = grid(1).context().cache().cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 2000; i++) {
        try {
            cache2.put(i, i + 1);
            utilCache1.put(i, i + 1);
        } catch (IgniteCheckedException e) {
            e.printStackTrace();
        }
    }
    List<T2<Integer, Integer>> evictionOrder = Collections.synchronizedList(new ArrayList<>());
    TestDependencyResolver rslvr = new TestDependencyResolver(new DependencyResolver() {

        @Override
        public <T> T resolve(T instance) {
            if (instance instanceof GridDhtPartitionTopologyImpl) {
                GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) instance;
                top.partitionFactory((ctx, grp, id, recovery) -> new GridDhtLocalPartition(ctx, grp, id, recovery) {

                    @Override
                    public long clearAll(EvictionContext evictionCtx) throws NodeStoppingException {
                        evictionOrder.add(new T2<>(grp.groupId(), id));
                        return super.clearAll(evictionCtx);
                    }
                });
            }
            return instance;
        }
    });
    startGrid(0, rslvr);
    awaitPartitionMapExchange(true, true, null);
    assertEquals(utilCache0.affinity().partitions() + grid(0).cachex(DEFAULT_CACHE_NAME).affinity().partitions(), evictionOrder.size());
    for (int i = 0; i < utilCache0.affinity().partitions(); i++) assertEquals(CU.UTILITY_CACHE_GROUP_ID, evictionOrder.get(i).get1().intValue());
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) ArrayList(java.util.ArrayList) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) Test(org.junit.Test) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) IgniteCache(org.apache.ignite.IgniteCache) T2(org.apache.ignite.internal.util.typedef.T2) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 18 with IgniteInternalCache

use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.

the class WaitMapExchangeFinishCallable method call.

/**
 * {@inheritDoc}
 */
@Override
public Void call() throws Exception {
    Collection<IgniteInternalCache<?, ?>> cachesx = ((IgniteKernal) ignite).cachesx(null);
    for (IgniteInternalCache<?, ?> cache : cachesx) {
        try {
            GridDhtPartitionTopology top = cache.context().isNear() ? cache.context().near().dht().topology() : cache.context().dht().topology();
            BenchmarkUtils.println("Validating cache: " + cache.name());
            for (; ; ) {
                boolean success = true;
                if (top.readyTopologyVersion().topologyVersion() == ignite.cluster().topologyVersion()) {
                    for (Map.Entry<UUID, GridDhtPartitionMap> e : top.partitionMap(true).entrySet()) {
                        for (Map.Entry<Integer, GridDhtPartitionState> p : e.getValue().entrySet()) {
                            if (p.getValue() != GridDhtPartitionState.OWNING) {
                                BenchmarkUtils.println("Not owning partition [part=" + p.getKey() + ", state=" + p.getValue() + ']');
                                success = false;
                                break;
                            }
                        }
                        if (!success)
                            break;
                    }
                } else {
                    BenchmarkUtils.println("Topology version is different [cache=" + top.readyTopologyVersion() + ", cluster=" + ignite.cluster().topologyVersion() + ']');
                    success = false;
                }
                if (!success)
                    Thread.sleep(1000);
                else {
                    BenchmarkUtils.println("Cache state is fine: " + cache.name());
                    break;
                }
            }
        } catch (RuntimeException e1) {
            BenchmarkUtils.println("Ignored exception: " + e1);
        }
    }
    return null;
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) UUID(java.util.UUID) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) Map(java.util.Map)

Example 19 with IgniteInternalCache

use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.

the class CacheDataPageScanQueryTest method testDataPageScanWithRestart.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("ConstantConditions")
@Test
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11998")
public void testDataPageScanWithRestart() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    IgniteInternalCache<Long, String> cache = ignite.cachex(CACHE);
    CacheGroupMetricsImpl metrics = cache.context().group().metrics();
    DataRegionMetricsImpl rmx = cache.context().dataRegion().metrics();
    long maxKey = 10_000;
    Map<Long, String> map = new ConcurrentHashMap<>();
    int threads = 16;
    AtomicInteger threadShift = new AtomicInteger();
    multithreaded((Callable<Void>) () -> {
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int shift = threadShift.getAndIncrement();
        for (int i = shift; i < maxKey; i += threads) {
            Long k = (long) i;
            // Bigger than single page.
            String v = GridTestUtils.randomString(rnd, 6 * 1024);
            cache.put(k, v);
            map.put(k, v);
        }
        return null;
    }, threads);
    assertEquals(map.size(), cache.size());
    info("Page mem  : " + rmx.getPhysicalMemorySize());
    info("Alloc size: " + metrics.getTotalAllocatedSize());
    info("Store size: " + metrics.getStorageSize());
    HashMap<Long, String> map2 = new HashMap<>(map);
    IgniteCache<Long, String> c = ignite.cache(CACHE);
    for (Cache.Entry<Long, String> e : c.query(new ScanQuery<Long, String>()).getAll()) assertEquals(e.getValue(), map.remove(e.getKey()));
    assertTrue(map.isEmpty());
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());
    stopAllGrids(true);
    ignite = startGrid(0);
    ignite.cluster().active(true);
    c = ignite.cache(CACHE);
    for (Cache.Entry<Long, String> e : c.query(new ScanQuery<Long, String>()).getAll()) assertEquals(e.getValue(), map2.remove(e.getKey()));
    assertTrue(map2.isEmpty());
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ScanQuery(org.apache.ignite.cache.query.ScanQuery) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) CacheGroupMetricsImpl(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Cache(javax.cache.Cache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) IgniteCache(org.apache.ignite.IgniteCache) Ignore(org.junit.Ignore) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 20 with IgniteInternalCache

use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.

the class H2DynamicTableSelfTest method testQueryLocalWithRecreate.

/**
 * @throws Exception If test failed.
 */
@Test
public void testQueryLocalWithRecreate() throws Exception {
    execute("CREATE TABLE A(id int primary key, name varchar, surname varchar) WITH \"cache_name=cache," + "template=replicated\"");
    // In order for local queries to work, let's use non client node.
    IgniteInternalCache cache = grid(0).cachex("cache");
    assertNotNull(cache);
    executeLocal(cache.context(), "INSERT INTO A(id, name, surname) values (1, 'X', 'Y')");
    assertEqualsCollections(Collections.singletonList(Arrays.asList(1, "X", "Y")), executeLocal(cache.context(), "SELECT id, name, surname FROM A"));
    execute("DROP TABLE A");
    execute("CREATE TABLE A(id int primary key, name varchar, surname varchar) WITH \"cache_name=cache\"");
    cache = grid(0).cachex("cache");
    assertNotNull(cache);
    try {
        executeLocal(cache.context(), "INSERT INTO A(id, name, surname) values (1, 'X', 'Y')");
    } finally {
        execute("DROP TABLE A");
    }
}
Also used : IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) Test(org.junit.Test)

Aggregations

IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)32 IgniteEx (org.apache.ignite.internal.IgniteEx)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 Test (org.junit.Test)8 Ignite (org.apache.ignite.Ignite)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteKernal (org.apache.ignite.internal.IgniteKernal)6 ArrayList (java.util.ArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 File (java.io.File)4 Cache (javax.cache.Cache)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 List (java.util.List)3 GridKernalContext (org.apache.ignite.internal.GridKernalContext)3 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)3 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)3 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)3