Search in sources :

Example 46 with GridCacheAdapter

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

the class EvictionPolicyFailureHandlerTest method testFailureHandlerShouldNotCallOnRuntimeException.

/**
 */
@Test
public void testFailureHandlerShouldNotCallOnRuntimeException() throws Exception {
    IgniteEx node1 = startGrid(0);
    IgniteEx node2 = startGrid(1);
    GridCacheAdapter<Object, Object> cache = ((IgniteKernal) node2).internalCache(DEFAULT_CACHE_NAME);
    Affinity<Object> affinity = cache.affinity();
    for (int i = 0; i < 1000; i++) {
        if (affinity.isPrimary(node1.localNode(), i))
            cache.put(i, 1);
    }
    for (int i = 0; i < 1000; i++) {
        if (affinity.isPrimary(node1.localNode(), (double) i))
            cache.put((double) i, 1);
    }
    assertFalse(cache.map().entrySet(cache.context().cacheId()).stream().anyMatch(e -> e.key().value(null, false) instanceof Double));
    assertFalse(nodeFailure.get());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Affinity(org.apache.ignite.cache.affinity.Affinity) Transaction(org.apache.ignite.transactions.Transaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) Factory(javax.cache.configuration.Factory) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CachePeekMode(org.apache.ignite.cache.CachePeekMode) FailureHandler(org.apache.ignite.failure.FailureHandler) Test(org.junit.Test) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) SortedEvictionPolicy(org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicy) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) SortedEvictionPolicyFactory(org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicyFactory) CountDownLatch(java.util.concurrent.CountDownLatch) EvictionPolicy(org.apache.ignite.cache.eviction.EvictionPolicy) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IgniteTransactions(org.apache.ignite.IgniteTransactions) EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 47 with GridCacheAdapter

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

the class GridCacheRebalancingSyncSelfTest method checkSupplyContextMapIsEmpty.

/**
 * @throws Exception If failed.
 */
protected void checkSupplyContextMapIsEmpty() throws Exception {
    for (Ignite g : G.allGrids()) {
        for (GridCacheAdapter c : ((IgniteEx) g).context().cache().internalCaches()) {
            Object supplier = U.field(c.preloader(), "supplier");
            final Map map = U.field(supplier, "scMap");
            GridTestUtils.waitForCondition(new PA() {

                @Override
                public boolean apply() {
                    synchronized (map) {
                        return map.isEmpty();
                    }
                }
            }, 15_000);
            synchronized (map) {
                assertTrue("Map is not empty [cache=" + c.name() + ", node=" + g.name() + ", map=" + map + ']', map.isEmpty());
            }
        }
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Map(java.util.Map) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 48 with GridCacheAdapter

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

the class CheckpointFreeListTest method cacheOffheapManager.

/**
 * Extract GridCacheOffheapManager for default cache.
 *
 * @return GridCacheOffheapManager.
 */
private GridCacheOffheapManager cacheOffheapManager() {
    GridCacheAdapter<Object, Object> cacheInternal = ((IgniteKernal) ignite(0)).internalCache(CACHE_NAME);
    GridCacheAdapter cache0 = (GridCacheAdapter) cacheInternal.cache();
    return (GridCacheOffheapManager) cache0.context().group().offheap();
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager)

Example 49 with GridCacheAdapter

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

the class GridCacheNearEvictionSelfTest method testNearEnabledThreeNodes.

/**
 * @throws Exception If failed.
 */
@Test
public void testNearEnabledThreeNodes() throws Exception {
    gridCnt = 3;
    startGridsMultiThreaded(gridCnt);
    try {
        final int cnt = 100;
        grid(0).compute().broadcast(new IgniteCallable<Object>() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public Object call() throws Exception {
                IgniteCache<Integer, String> c = ignite.cache(DEFAULT_CACHE_NAME);
                for (int i = 0; i < cnt; i++) c.put(i, Integer.toString(i));
                return true;
            }
        });
        for (int i = 0; i < gridCnt; i++) {
            final GridCacheAdapter cache = internalCache(i);
            final GridCacheAdapter near = near(i);
            // Repeatedly check cache sizes because of concurrent cache updates.
            assertTrue(GridTestUtils.waitForCondition(new PA() {

                @Override
                public boolean apply() {
                    // Every node contains either near, backup, or primary.
                    return cnt == cache.size() + near.nearSize();
                }
            }, getTestTimeout()));
            int keySize = near(i).nearSize();
            assert keySize < cnt : "Key size is not less than count [cnt=" + cnt + ", size=" + keySize + ']';
        }
    } finally {
        stopAllGrids();
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with GridCacheAdapter

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

the class InconsistentNodeApplication method run.

/**
 * {@inheritDoc}
 */
@Override
protected void run(JsonNode jsonNode) throws Exception {
    String cacheName = jsonNode.get("cacheName").asText();
    int amount = jsonNode.get("amount").asInt();
    int parts = jsonNode.get("parts").asInt();
    boolean tx = jsonNode.get("tx").asBoolean();
    markInitialized();
    waitForActivation();
    CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(cacheName);
    cfg.setAtomicityMode(tx ? TRANSACTIONAL : ATOMIC);
    cfg.setCacheMode(CacheMode.REPLICATED);
    cfg.setAffinity(new RendezvousAffinityFunction().setPartitions(parts));
    ignite.getOrCreateCache(cfg);
    GridCacheVersionManager mgr = ((GridCacheAdapter) ((IgniteEx) ignite).cachex(cacheName).cache()).context().shared().versions();
    int cnt = 0;
    for (int key = 0; key < amount; key += ThreadLocalRandom.current().nextInt(1, 3)) {
        // Random shift.
        IgniteInternalCache<?, ?> cache = ((IgniteEx) ignite).cachex(cacheName);
        GridCacheAdapter<?, ?> adapter = (GridCacheAdapter) cache.cache();
        GridCacheEntryEx entry = adapter.entryEx(key);
        boolean init = entry.initialValue(// Incremental value.
        new CacheObjectImpl(cnt, null), // Incremental version.
        mgr.next(entry.context().kernalContext().discovery().topologyVersion()), 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
        assert init : "iterableKey " + key + " already inited";
        if (cnt % 1_000 == 0)
            log.info("APPLICATION_STREAMED [entries=" + cnt + "]");
        cnt++;
    }
    log.info("APPLICATION_STREAMING_FINISHED [entries=" + cnt + "]");
    while (!terminated()) // Keeping node alive.
    U.sleep(100);
    markFinished();
}
Also used : CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)50 IgniteEx (org.apache.ignite.internal.IgniteEx)18 Map (java.util.Map)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)12 IgniteException (org.apache.ignite.IgniteException)12 IgniteKernal (org.apache.ignite.internal.IgniteKernal)12 ArrayList (java.util.ArrayList)11 UUID (java.util.UUID)11 Test (org.junit.Test)11 IgniteCache (org.apache.ignite.IgniteCache)10 HashMap (java.util.HashMap)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 HashSet (java.util.HashSet)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)7