Search in sources :

Example 11 with IgniteCacheProxy

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

the class PlatformProcessorImpl method createCacheFromConfig.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy createCacheFromConfig(long memPtr) throws IgniteCheckedException {
    BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
    CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
    IgniteCacheProxy cache = reader.readBoolean() ? (IgniteCacheProxy) ctx.grid().createCache(cfg, PlatformConfigurationUtils.readNearConfiguration(reader)) : (IgniteCacheProxy) ctx.grid().createCache(cfg);
    return createPlatformCache(cache);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 12 with IgniteCacheProxy

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

the class IgniteDrDataStreamerCacheUpdater method receive.

/** {@inheritDoc} */
@Override
public void receive(IgniteCache<KeyCacheObject, CacheObject> cache0, Collection<Map.Entry<KeyCacheObject, CacheObject>> col) {
    try {
        String cacheName = cache0.getConfiguration(CacheConfiguration.class).getName();
        GridKernalContext ctx = ((IgniteKernal) cache0.unwrap(Ignite.class)).context();
        IgniteLogger log = ctx.log(IgniteDrDataStreamerCacheUpdater.class);
        GridCacheAdapter internalCache = ctx.cache().internalCache(cacheName);
        CacheOperationContext opCtx = ((IgniteCacheProxy) cache0).operationContext();
        IgniteInternalCache cache = opCtx != null ? new GridCacheProxyImpl(internalCache.context(), internalCache, opCtx) : internalCache;
        assert !F.isEmpty(col);
        if (log.isDebugEnabled())
            log.debug("Running DR put job [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
        CacheObjectContext cacheObjCtx = cache.context().cacheObjectContext();
        for (Map.Entry<KeyCacheObject, CacheObject> entry0 : col) {
            GridCacheRawVersionedEntry entry = (GridCacheRawVersionedEntry) entry0;
            entry.unmarshal(cacheObjCtx, ctx.config().getMarshaller());
            KeyCacheObject key = entry.getKey();
            // Ensure that receiver to not receive special-purpose values for TTL and expire time.
            assert entry.ttl() != CU.TTL_NOT_CHANGED && entry.ttl() != CU.TTL_ZERO && entry.ttl() >= 0;
            assert entry.expireTime() != CU.EXPIRE_TIME_CALCULATE && entry.expireTime() >= 0;
            CacheObject cacheVal = entry.getValue();
            GridCacheDrInfo val = cacheVal != null ? entry.ttl() != CU.TTL_ETERNAL ? new GridCacheDrExpirationInfo(cacheVal, entry.version(), entry.ttl(), entry.expireTime()) : new GridCacheDrInfo(cacheVal, entry.version()) : null;
            if (val == null)
                cache.removeAllConflict(Collections.singletonMap(key, entry.version()));
            else
                cache.putAllConflict(Collections.singletonMap(key, val));
        }
        if (log.isDebugEnabled())
            log.debug("DR put job finished [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCacheProxyImpl(org.apache.ignite.internal.processors.cache.GridCacheProxyImpl) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDrExpirationInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteLogger(org.apache.ignite.IgniteLogger) GridCacheRawVersionedEntry(org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry) Map(java.util.Map) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 13 with IgniteCacheProxy

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

the class GridQueryProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    super.start(activeOnStart);
    if (idx != null) {
        ctx.resource().injectGeneric(idx);
        idx.start(ctx, busyLock);
    }
    ctx.io().addMessageListener(TOPIC_SCHEMA, ioLsnr);
    // Schedule queries detail metrics eviction.
    qryDetailMetricsEvictTask = ctx.timeout().schedule(new Runnable() {

        @Override
        public void run() {
            for (IgniteCacheProxy cache : ctx.cache().jcaches()) cache.context().queries().evictDetailMetrics();
        }
    }, QRY_DETAIL_METRICS_EVICTION_FREQ, QRY_DETAIL_METRICS_EVICTION_FREQ);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy)

Example 14 with IgniteCacheProxy

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

the class GridCacheBinaryObjectsAbstractSelfTest method testIterator.

/**
     * @throws Exception If failed.
     */
public void testIterator() throws Exception {
    IgniteCache<Integer, TestObject> c = jcache(0);
    Map<Integer, TestObject> entries = new HashMap<>();
    for (int i = 0; i < ENTRY_CNT; i++) {
        TestObject val = new TestObject(i);
        c.put(i, val);
        entries.put(i, val);
    }
    IgniteCache<Integer, BinaryObject> prj = ((IgniteCacheProxy) c).keepBinary();
    Iterator<Cache.Entry<Integer, BinaryObject>> it = prj.iterator();
    assertTrue(it.hasNext());
    while (it.hasNext()) {
        Cache.Entry<Integer, BinaryObject> entry = it.next();
        assertTrue(entries.containsKey(entry.getKey()));
        TestObject o = entries.get(entry.getKey());
        BinaryObject po = entry.getValue();
        assertEquals(o.val, (int) po.field("val"));
        entries.remove(entry.getKey());
    }
    assertEquals(0, entries.size());
}
Also used : HashMap(java.util.HashMap) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) MutableEntry(javax.cache.processor.MutableEntry) BinaryObject(org.apache.ignite.binary.BinaryObject) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 15 with IgniteCacheProxy

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

the class GridDataStreamerImplSelfTest method testAddBinaryDataFromMap.

/**
     * Data streamer should correctly load binary entries from HashMap in case of grids with more than one node
     *  and with GridOptimizedMarshaller that requires serializable.
     *
     * @throws Exception If failed.
     */
public void testAddBinaryDataFromMap() throws Exception {
    try {
        binaries = true;
        startGrids(2);
        awaitPartitionMapExchange();
        Ignite g0 = grid(0);
        IgniteDataStreamer<Integer, TestObject> dataLdr = g0.dataStreamer(DEFAULT_CACHE_NAME);
        Map<Integer, TestObject> map = U.newHashMap(KEYS_COUNT);
        for (int i = 0; i < KEYS_COUNT; i++) map.put(i, new TestObject(i));
        dataLdr.addData(map);
        dataLdr.close(false);
        checkDistribution(grid(0));
        checkDistribution(grid(1));
        // Read random keys. Take values as TestObject.
        Random rnd = new Random();
        IgniteCache<Integer, TestObject> c = g0.cache(DEFAULT_CACHE_NAME);
        for (int i = 0; i < 100; i++) {
            Integer k = rnd.nextInt(KEYS_COUNT);
            TestObject v = c.get(k);
            assertEquals(k, v.val());
        }
        // Read random keys. Take values as BinaryObject.
        IgniteCache<Integer, BinaryObject> c2 = ((IgniteCacheProxy) c).keepBinary();
        for (int i = 0; i < 100; i++) {
            Integer k = rnd.nextInt(KEYS_COUNT);
            BinaryObject v = c2.get(k);
            assertEquals(k, v.field("val"));
        }
    } finally {
        G.stopAll(true);
    }
}
Also used : Random(java.util.Random) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy)

Aggregations

IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)17 Ignite (org.apache.ignite.Ignite)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 IgniteKernal (org.apache.ignite.internal.IgniteKernal)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1