Search in sources :

Example 1 with DataStreamerImpl

use of org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl in project ignite by apache.

the class PlatformProcessorImpl method dataStreamer.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy dataStreamer(@Nullable String cacheName, boolean keepBinary) throws IgniteCheckedException {
    IgniteDataStreamer ldr = ctx.dataStream().dataStreamer(cacheName);
    ldr.keepBinary(true);
    return proxy(new PlatformDataStreamer(platformCtx, cacheName, (DataStreamerImpl) ldr, keepBinary));
}
Also used : PlatformDataStreamer(org.apache.ignite.internal.processors.platform.datastreamer.PlatformDataStreamer) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl)

Example 2 with DataStreamerImpl

use of org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl in project ignite by apache.

the class CacheLoadingConcurrentGridStartSelfTest method loadCacheWithDataStreamerSequential.

/**
 * @throws Exception if failed
 */
private void loadCacheWithDataStreamerSequential() throws Exception {
    startGrid(1);
    Ignite g0 = startGrid(0);
    IgniteInternalFuture<Object> restartFut = runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (restarts) {
                stopGrid(1);
                startGrid(1);
                U.sleep(100);
            }
            return null;
        }
    });
    CountDownLatch startNodesLatch = new CountDownLatch(1);
    IgniteInternalFuture<Object> fut = runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            startNodesLatch.await();
            for (int i = 2; i < GRIDS_CNT; i++) startGrid(i);
            return null;
        }
    });
    final HashSet<IgniteFuture> set = new HashSet<>();
    boolean stop = false;
    int insertedKeys = 0;
    startNodesLatch.countDown();
    try (IgniteDataStreamer<Integer, String> dataStreamer = g0.dataStreamer(DEFAULT_CACHE_NAME)) {
        dataStreamer.allowOverwrite(allowOverwrite);
        ((DataStreamerImpl) dataStreamer).maxRemapCount(Integer.MAX_VALUE);
        long startingEndTs = -1L;
        while (!stop) {
            set.add(dataStreamer.addData(insertedKeys, "Data"));
            insertedKeys = insertedKeys + 1;
            if (insertedKeys % 100000 == 0)
                log.info("Streaming " + insertedKeys + "'th entry.");
            // When all nodes started we continue restart nodes during 1 second and stop it after this timeout.
            if (fut.isDone() && startingEndTs == -1)
                startingEndTs = System.currentTimeMillis();
            if (// Nodes starting was ended and we check restarts duration after it.
            startingEndTs != -1)
                restarts = (System.currentTimeMillis() - startingEndTs) < 1000;
            // Stop test when all keys were inserted or restarts timeout was exceeded.
            stop = insertedKeys >= KEYS_CNT || (fut.isDone() && !restarts);
        }
    }
    log.info("Data loaded.");
    restarts = false;
    fut.get();
    restartFut.get();
    for (IgniteFuture res : set) assertNull(res.get());
    IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    long size = cache.size(CachePeekMode.PRIMARY);
    if (size != insertedKeys) {
        Set<Integer> failedKeys = new LinkedHashSet<>();
        for (int i = 0; i < insertedKeys; i++) if (!cache.containsKey(i)) {
            log.info("Actual cache size: " + size);
            for (Ignite ignite : G.allGrids()) {
                IgniteEx igniteEx = (IgniteEx) ignite;
                log.info("Missed key info:" + igniteEx.localNode().id() + " primary=" + ignite.affinity(DEFAULT_CACHE_NAME).isPrimary(igniteEx.localNode(), i) + " backup=" + ignite.affinity(DEFAULT_CACHE_NAME).isBackup(igniteEx.localNode(), i) + " local peek=" + ignite.cache(DEFAULT_CACHE_NAME).localPeek(i, CachePeekMode.ONHEAP));
            }
            for (int j = i; j < i + 10000; j++) {
                if (!cache.containsKey(j))
                    failedKeys.add(j);
            }
            break;
        }
        assert failedKeys.isEmpty() : "Some failed keys: " + failedKeys.toString();
    }
    assertCacheSize(insertedKeys);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CountDownLatch(java.util.concurrent.CountDownLatch) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheWriterException(javax.cache.integration.CacheWriterException) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with DataStreamerImpl

use of org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl in project ignite by apache.

the class IgniteDataStreamerTest method testStreamerIgniteUuid.

/**
 * @throws Exception If failed.
 */
@Test
public void testStreamerIgniteUuid() throws Exception {
    Ignite client = grid("client");
    IgniteCache<IgniteUuid, Integer> cache = client.createCache(cacheConfiguration(IgniteUuid.class, Integer.class));
    try (IgniteDataStreamer<IgniteUuid, Integer> streamer = client.dataStreamer(CACHE_NAME)) {
        assertTrue("Expecting " + DataStreamerImpl.class.getName(), streamer instanceof DataStreamerImpl);
        ((DataStreamerImpl<IgniteUuid, Integer>) streamer).maxRemapCount(0);
        List<IgniteFuture> futs = new ArrayList<>();
        for (int i = 0; i < DATA_SIZE; i++) {
            IgniteFuture<?> fut = streamer.addData(IgniteUuid.randomUuid(), i);
            futs.add(fut);
        }
        streamer.flush();
        for (IgniteFuture fut : futs) {
            // This should not throw any exception.
            Object res = fut.get(WAIT_TIMEOUT);
            if (log.isDebugEnabled()) {
                // Printing future result to log to prevent jvm optimization
                log.debug(String.valueOf(res));
            }
        }
        assertTrue(cache.size(ALL) == DATA_SIZE);
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl) ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with DataStreamerImpl

use of org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl in project ignite by apache.

the class GridCacheAdapter method localLoadCache.

/**
 * {@inheritDoc}
 */
@Override
public void localLoadCache(final IgniteBiPredicate<K, V> p, Object[] args) throws IgniteCheckedException {
    // TODO IGNITE-7954
    MvccUtils.verifyMvccOperationSupport(ctx, "Load");
    final boolean replicate = ctx.isDrEnabled();
    final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    ExpiryPolicy plc0 = opCtx != null ? opCtx.expiry() : null;
    final ExpiryPolicy plc = plc0 != null ? plc0 : ctx.expiry();
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    if (p != null)
        ctx.kernalContext().resource().injectGeneric(p);
    try {
        if (ctx.store().isLocal()) {
            DataStreamerImpl ldr = ctx.kernalContext().dataStream().dataStreamer(ctx.name());
            try {
                ldr.skipStore(true);
                ldr.receiver(new IgniteDrDataStreamerCacheUpdater());
                ldr.keepBinary(keepBinary);
                LocalStoreLoadClosure c = new LocalStoreLoadClosure(p, ldr, plc);
                ctx.store().loadCache(c, args);
                c.onDone();
            } finally {
                ldr.closeEx(false);
            }
        } else {
            // Version for all loaded entries.
            final GridCacheVersion ver0 = ctx.versions().nextForLoad();
            ctx.store().loadCache(new CIX3<KeyCacheObject, Object, GridCacheVersion>() {

                @Override
                public void applyx(KeyCacheObject key, Object val, @Nullable GridCacheVersion ver) throws IgniteException {
                    assert ver == null;
                    long ttl = CU.ttlForLoad(plc);
                    if (ttl == CU.TTL_ZERO)
                        return;
                    loadEntry(key, val, ver0, (IgniteBiPredicate<Object, Object>) p, topVer, replicate, ttl);
                }
            }, args);
        }
    } finally {
        if (p instanceof PlatformCacheEntryFilter)
            ((PlatformCacheEntryFilter) p).onClose();
    }
}
Also used : IgniteDrDataStreamerCacheUpdater(org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl) PlatformCacheEntryFilter(org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteException(org.apache.ignite.IgniteException) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy)

Example 5 with DataStreamerImpl

use of org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl in project ignite by apache.

the class GridCacheAdapter method localLoad.

/**
 * @param keys Keys to load.
 * @param plc Optional expiry policy.
 * @throws IgniteCheckedException If failed.
 */
public void localLoad(Collection<? extends K> keys, @Nullable ExpiryPolicy plc, final boolean keepBinary) throws IgniteCheckedException {
    // TODO IGNITE-7954
    MvccUtils.verifyMvccOperationSupport(ctx, "Load");
    final boolean replicate = ctx.isDrEnabled();
    final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    final ExpiryPolicy plc0 = plc != null ? plc : ctx.expiry();
    Collection<KeyCacheObject> keys0 = ctx.cacheKeysView(keys);
    if (ctx.store().isLocal()) {
        DataStreamerImpl ldr = ctx.kernalContext().dataStream().dataStreamer(ctx.name());
        try {
            ldr.skipStore(true);
            ldr.keepBinary(keepBinary);
            ldr.receiver(new IgniteDrDataStreamerCacheUpdater());
            LocalStoreLoadClosure c = new LocalStoreLoadClosure(null, ldr, plc0);
            ctx.store().localStoreLoadAll(null, keys0, c);
            c.onDone();
        } finally {
            ldr.closeEx(false);
        }
    } else {
        // Version for all loaded entries.
        final GridCacheVersion ver0 = ctx.versions().nextForLoad();
        ctx.store().loadAll(null, keys0, new CI2<KeyCacheObject, Object>() {

            @Override
            public void apply(KeyCacheObject key, Object val) {
                long ttl = CU.ttlForLoad(plc0);
                if (ttl == CU.TTL_ZERO)
                    return;
                loadEntry(key, val, ver0, null, topVer, replicate, ttl);
            }
        });
    }
}
Also used : IgniteDrDataStreamerCacheUpdater(org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl)

Aggregations

DataStreamerImpl (org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl)6 Ignite (org.apache.ignite.Ignite)3 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 IgniteExternalizableExpiryPolicy (org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 IgniteDrDataStreamerCacheUpdater (org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheException (javax.cache.CacheException)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 PlatformCacheEntryFilter (org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter)1