Search in sources :

Example 1 with IgniteDrDataStreamerCacheUpdater

use of org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater 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 2 with IgniteDrDataStreamerCacheUpdater

use of org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater 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

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 DataStreamerImpl (org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl)2 IgniteDrDataStreamerCacheUpdater (org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater)2 IgniteException (org.apache.ignite.IgniteException)1 PlatformCacheEntryFilter (org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter)1 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)1