Search in sources :

Example 1 with PlatformCacheEntryFilter

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

the class GridCacheQueryManager method scanIterator.

/**
 * @param qry Query.
 * @param transformer Transformer.
 * @param locNode Local node.
 * @return Full-scan row iterator.
 * @throws IgniteCheckedException If failed to get iterator.
 */
@SuppressWarnings({ "unchecked" })
private GridCloseableIterator scanIterator(final GridCacheQueryAdapter<?> qry, IgniteClosure transformer, boolean locNode) throws IgniteCheckedException {
    assert !cctx.mvccEnabled() || qry.mvccSnapshot() != null;
    final IgniteBiPredicate<K, V> keyValFilter = qry.scanFilter();
    final InternalScanFilter<K, V> intFilter = keyValFilter != null ? new InternalScanFilter<>(keyValFilter) : null;
    try {
        if (keyValFilter instanceof PlatformCacheEntryFilter)
            ((PlatformCacheEntryFilter) keyValFilter).cacheContext(cctx);
        else
            injectResources(keyValFilter);
        Integer part = cctx.isLocal() ? null : qry.partition();
        if (part != null && (part < 0 || part >= cctx.affinity().partitions()))
            return new GridEmptyCloseableIterator() {

                @Override
                public void close() throws IgniteCheckedException {
                    if (intFilter != null)
                        intFilter.close();
                    super.close();
                }
            };
        AffinityTopologyVersion topVer = GridQueryProcessor.getRequestAffinityTopologyVersion();
        if (topVer == null)
            topVer = cctx.affinity().affinityTopologyVersion();
        final boolean backups = qry.includeBackups() || cctx.isReplicated();
        final GridDhtLocalPartition locPart;
        final GridIterator<CacheDataRow> it;
        if (part != null) {
            final GridDhtCacheAdapter dht = cctx.isNear() ? cctx.near().dht() : cctx.dht();
            GridDhtLocalPartition locPart0 = dht.topology().localPartition(part, topVer, false);
            if (locPart0 == null || locPart0.state() != OWNING || !locPart0.reserve()) {
                throw locPart0 != null && locPart0.state() == LOST ? new CacheInvalidStateException("Failed to execute scan query because cache partition has been " + "lost [cacheName=" + cctx.name() + ", part=" + part + "]") : new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(), "Partition can not be reserved");
            }
            locPart = locPart0;
            it = cctx.offheap().cachePartitionIterator(cctx.cacheId(), part, qry.mvccSnapshot(), qry.isDataPageScanEnabled());
        } else {
            locPart = null;
            if (!cctx.isLocal()) {
                final GridDhtCacheAdapter dht = cctx.isNear() ? cctx.near().dht() : cctx.dht();
                Set<Integer> lostParts = dht.topology().lostPartitions();
                if (!lostParts.isEmpty()) {
                    throw new CacheInvalidStateException("Failed to execute scan query because cache partition " + "has been lost [cacheName=" + cctx.name() + ", part=" + lostParts.iterator().next() + "]");
                }
            }
            it = cctx.offheap().cacheIterator(cctx.cacheId(), true, backups, topVer, qry.mvccSnapshot(), qry.isDataPageScanEnabled());
        }
        ScanQueryIterator iter = new ScanQueryIterator(it, qry, topVer, locPart, SecurityUtils.sandboxedProxy(cctx.kernalContext(), IgniteBiPredicate.class, keyValFilter), SecurityUtils.sandboxedProxy(cctx.kernalContext(), IgniteClosure.class, transformer), locNode, locNode ? locIters : null, cctx, log);
        if (locNode) {
            ScanQueryIterator old = locIters.addx(iter);
            assert old == null;
        }
        return iter;
    } catch (IgniteCheckedException | RuntimeException e) {
        if (intFilter != null)
            intFilter.close();
        throw e;
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) IgniteClosure(org.apache.ignite.lang.IgniteClosure) GridDhtUnreservedPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridEmptyCloseableIterator(org.apache.ignite.internal.util.GridEmptyCloseableIterator) PlatformCacheEntryFilter(org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException)

Example 2 with PlatformCacheEntryFilter

use of org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter 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 3 with PlatformCacheEntryFilter

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

the class GridDhtCacheAdapter method localLoadCache.

/**
 * {@inheritDoc}
 */
@Override
public void localLoadCache(final IgniteBiPredicate<K, V> p, Object[] args) throws IgniteCheckedException {
    if (ctx.store().isLocal()) {
        super.localLoadCache(p, args);
        return;
    }
    // TODO IGNITE-7954
    MvccUtils.verifyMvccOperationSupport(ctx, "Load");
    final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    // Version for all loaded entries.
    final GridCacheVersion ver0 = ctx.shared().versions().nextForLoad(topVer.topologyVersion());
    final boolean replicate = ctx.isDrEnabled();
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    ExpiryPolicy plc0 = opCtx != null ? opCtx.expiry() : null;
    final ExpiryPolicy plc = plc0 != null ? plc0 : ctx.expiry();
    final IgniteBiPredicate<K, V> pred;
    if (p != null) {
        ctx.kernalContext().resource().injectGeneric(p);
        pred = SecurityUtils.sandboxedProxy(ctx.kernalContext(), IgniteBiPredicate.class, p);
    } else
        pred = null;
    try {
        ctx.store().loadCache(new CI3<KeyCacheObject, Object, GridCacheVersion>() {

            @Override
            public void apply(KeyCacheObject key, Object val, @Nullable GridCacheVersion ver) {
                assert ver == null;
                loadEntry(key, val, ver0, pred, topVer, replicate, plc);
            }
        }, args);
    } finally {
        if (p instanceof PlatformCacheEntryFilter)
            ((PlatformCacheEntryFilter) p).onClose();
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) PlatformCacheEntryFilter(org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 PlatformCacheEntryFilter (org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter)3 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)3 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheInvalidStateException (org.apache.ignite.internal.processors.cache.CacheInvalidStateException)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)1 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 IgniteExternalizableExpiryPolicy (org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy)1 GridDhtCacheAdapter (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter)1 GridDhtUnreservedPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException)1 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 DataStreamerImpl (org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl)1 IgniteDrDataStreamerCacheUpdater (org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater)1 GridEmptyCloseableIterator (org.apache.ignite.internal.util.GridEmptyCloseableIterator)1