Search in sources :

Example 1 with GridCacheInternal

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

the class GridCacheQueryManager method remove.

/**
     * @param key Key.
     * @param partId Partition.
     * @param val Value.
     * @param ver Version.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
@SuppressWarnings("SimplifiableIfStatement")
public void remove(KeyCacheObject key, int partId, CacheObject val, GridCacheVersion ver) throws IgniteCheckedException {
    assert key != null;
    if (!QueryUtils.isEnabled(cctx.config()) && !(key instanceof GridCacheInternal))
        // No-op.
        return;
    if (!enterBusy())
        // Ignore index update when node is stopping.
        return;
    try {
        if (isIndexingSpiEnabled()) {
            Object key0 = unwrapIfNeeded(key, cctx.cacheObjectContext());
            cctx.kernalContext().indexing().remove(cacheName, key0);
        }
        // val may be null if we have no previous value. We should not call processor in this case.
        if (qryProcEnabled && val != null)
            qryProc.remove(cacheName, key, partId, val, ver);
    } finally {
        invalidateResultCache();
        leaveBusy();
    }
}
Also used : GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 2 with GridCacheInternal

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

the class DataStructuresProcessor method onActivate.

/** {@inheritDoc} */
@Override
public void onActivate(GridKernalContext ctx) throws IgniteCheckedException {
    if (log.isDebugEnabled())
        log.debug("Activate data structure processor [nodeId=" + ctx.localNodeId() + " topVer=" + ctx.discovery().topologyVersionEx() + " ]");
    this.initFailed = false;
    this.initLatch = new CountDownLatch(1);
    this.qryId = null;
    ctx.event().addLocalEventListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED);
    onKernalStart0(true);
    for (Map.Entry<GridCacheInternal, GridCacheRemovable> e : dsMap.entrySet()) {
        GridCacheRemovable v = e.getValue();
        if (v instanceof IgniteChangeGlobalStateSupport)
            ((IgniteChangeGlobalStateSupport) v).onActivate(ctx);
    }
}
Also used : GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) IgniteChangeGlobalStateSupport(org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 3 with GridCacheInternal

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

the class DataStructuresProcessor method removeCountDownLatch.

/**
     * Removes count down latch from cache.
     *
     * @param name Name of the latch.
     * @throws IgniteCheckedException If operation failed.
     */
public void removeCountDownLatch(final String name) throws IgniteCheckedException {
    assert name != null;
    assert dsCacheCtx != null;
    awaitInitialization();
    removeDataStructure(new IgniteOutClosureX<Void>() {

        @Override
        public Void applyx() throws IgniteCheckedException {
            GridCacheInternal key = new GridCacheInternalKeyImpl(name);
            dsCacheCtx.gate().enter();
            try (GridNearTxLocal tx = CU.txStartInternal(dsCacheCtx, dsView, PESSIMISTIC, REPEATABLE_READ)) {
                // Check correctness type of removable object.
                GridCacheCountDownLatchValue val = cast(dsView.get(key), GridCacheCountDownLatchValue.class);
                if (val != null) {
                    if (val.get() > 0) {
                        throw new IgniteCheckedException("Failed to remove count down latch " + "with non-zero count: " + val.get());
                    }
                    dsView.remove(key);
                    tx.commit();
                } else
                    tx.setRollbackOnly();
                return null;
            } finally {
                dsCacheCtx.gate().leave();
            }
        }
    }, name, COUNT_DOWN_LATCH, null);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)

Example 4 with GridCacheInternal

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

the class GridCacheStoreManagerAdapter method put.

/**
 * {@inheritDoc}
 */
@Override
public final boolean put(@Nullable IgniteInternalTx tx, KeyCacheObject key, CacheObject val, GridCacheVersion ver) throws IgniteCheckedException {
    if (store != null) {
        // Never persist internal keys.
        if (key instanceof GridCacheInternal)
            return true;
        Object key0 = cctx.unwrapBinaryIfNeeded(key, !convertBinary(), null);
        Object val0 = cctx.unwrapBinaryIfNeeded(val, !convertBinary(), null);
        if (log.isDebugEnabled()) {
            log.debug(S.toString("Storing value in cache store", "key", key0, true, "val", val0, true));
        }
        sessionInit0(tx, StoreOperation.WRITE, false);
        boolean threwEx = true;
        try {
            store.write(new CacheEntryImpl<>(key0, locStore ? F.t(val0, ver) : val0));
            threwEx = false;
        } catch (ClassCastException e) {
            handleClassCastException(e);
        } catch (CacheWriterException e) {
            throw new IgniteCheckedException(e);
        } catch (Exception e) {
            throw new IgniteCheckedException(new CacheWriterException(e));
        } finally {
            sessionEnd0(tx, threwEx);
        }
        if (log.isDebugEnabled()) {
            log.debug(S.toString("Stored value in cache store", "key", key0, true, "val", val0, true));
        }
        return true;
    }
    return false;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 5 with GridCacheInternal

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

the class GridCacheQueryManager method store.

/**
     * Writes key-value pair to index.
     *
     * @param key Key.
     * @param partId Partition.
     * @param prevVal Previous value.
     * @param prevVer Previous version.
     * @param val Value.
     * @param ver Cache entry version.
     * @param expirationTime Expiration time or 0 if never expires.
     * @param link Link.
     * @throws IgniteCheckedException In case of error.
     */
public void store(KeyCacheObject key, int partId, @Nullable CacheObject prevVal, @Nullable GridCacheVersion prevVer, CacheObject val, GridCacheVersion ver, long expirationTime, long link) throws IgniteCheckedException {
    assert key != null;
    assert val != null;
    assert enabled();
    if (key instanceof GridCacheInternal)
        // No-op.
        return;
    if (!enterBusy())
        throw new NodeStoppingException("Operation has been cancelled (node is stopping).");
    try {
        if (isIndexingSpiEnabled()) {
            CacheObjectContext coctx = cctx.cacheObjectContext();
            Object key0 = unwrapIfNeeded(key, coctx);
            Object val0 = unwrapIfNeeded(val, coctx);
            cctx.kernalContext().indexing().store(cacheName, key0, val0, expirationTime);
        }
        if (qryProcEnabled)
            qryProc.store(cacheName, key, partId, prevVal, prevVer, val, ver, expirationTime, link);
    } finally {
        invalidateResultCache();
        leaveBusy();
    }
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Aggregations

GridCacheInternal (org.apache.ignite.internal.processors.cache.GridCacheInternal)6 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)4 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 NoSuchElementException (java.util.NoSuchElementException)2 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 CacheWriterException (javax.cache.integration.CacheWriterException)2 IgniteException (org.apache.ignite.IgniteException)2 CacheStorePartialUpdateException (org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 IgniteChangeGlobalStateSupport (org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport)1