Search in sources :

Example 6 with GridNearAtomicCache

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache in project ignite by apache.

the class GridDhtAtomicCache method processDhtAtomicUpdateRequest.

/**
 * @param nodeId Sender node ID.
 * @param req Dht atomic update request.
 */
private void processDhtAtomicUpdateRequest(UUID nodeId, GridDhtAtomicAbstractUpdateRequest req) {
    assert Thread.currentThread().getName().startsWith("sys-stripe-") : Thread.currentThread().getName();
    if (msgLog.isDebugEnabled()) {
        msgLog.debug("Received DHT atomic update request [futId=" + req.futureId() + ", writeVer=" + req.writeVersion() + ", node=" + nodeId + ']');
    }
    assert req.partition() >= 0 : req;
    GridCacheVersion ver = req.writeVersion();
    ctx.versions().onReceived(nodeId, ver);
    GridDhtAtomicNearResponse nearRes = null;
    if (req.nearNodeId() != null) {
        nearRes = new GridDhtAtomicNearResponse(ctx.cacheId(), req.partition(), req.nearFutureId(), nodeId, req.flags());
    }
    boolean replicate = ctx.isDrEnabled();
    boolean intercept = req.forceTransformBackups() && ctx.config().getInterceptor() != null;
    boolean needTaskName = ctx.events().isRecordable(EVT_CACHE_OBJECT_READ) || ctx.events().isRecordable(EVT_CACHE_OBJECT_PUT) || ctx.events().isRecordable(EVT_CACHE_OBJECT_REMOVED);
    String taskName = needTaskName ? ctx.kernalContext().task().resolveTaskName(req.taskNameHash()) : null;
    ctx.shared().database().checkpointReadLock();
    try {
        for (int i = 0; i < req.size(); i++) {
            KeyCacheObject key = req.key(i);
            try {
                while (true) {
                    GridDhtCacheEntry entry = null;
                    try {
                        entry = entryExx(key);
                        CacheObject val = req.value(i);
                        CacheObject prevVal = req.previousValue(i);
                        EntryProcessor<Object, Object, Object> entryProcessor = req.entryProcessor(i);
                        Long updateIdx = req.updateCounter(i);
                        GridCacheOperation op = entryProcessor != null ? TRANSFORM : (val != null) ? UPDATE : DELETE;
                        long ttl = req.ttl(i);
                        long expireTime = req.conflictExpireTime(i);
                        GridCacheUpdateAtomicResult updRes = entry.innerUpdate(ver, nodeId, nodeId, op, op == TRANSFORM ? entryProcessor : val, op == TRANSFORM ? req.invokeArguments() : null, /*write-through*/
                        (ctx.store().isLocal() && !ctx.shared().localStorePrimaryOnly()) && writeThrough() && !req.skipStore(), /*read-through*/
                        false, /*retval*/
                        false, req.keepBinary(), /*expiry policy*/
                        null, /*event*/
                        true, /*metrics*/
                        true, /*primary*/
                        false, /*check version*/
                        !req.forceTransformBackups(), req.topologyVersion(), CU.empty0(), replicate ? DR_BACKUP : DR_NONE, ttl, expireTime, req.conflictVersion(i), false, intercept, taskName, prevVal, updateIdx, null, req.transformOperation());
                        if (updRes.removeVersion() != null)
                            ctx.onDeferredDelete(entry, updRes.removeVersion());
                        entry.onUnlock();
                        // While.
                        break;
                    } catch (GridCacheEntryRemovedException ignored) {
                        if (log.isDebugEnabled())
                            log.debug("Got removed entry while updating backup value (will retry): " + key);
                        entry = null;
                    } finally {
                        if (entry != null)
                            entry.touch();
                    }
                }
            } catch (NodeStoppingException e) {
                U.warn(log, "Failed to update key on backup (local node is stopping): " + key);
                return;
            } catch (GridDhtInvalidPartitionException ignored) {
            // Ignore.
            } catch (IgniteCheckedException | RuntimeException e) {
                if (e instanceof RuntimeException && !X.hasCause(e, IgniteOutOfMemoryException.class))
                    throw (RuntimeException) e;
                IgniteCheckedException err = new IgniteCheckedException("Failed to update key on backup node: " + key, e);
                if (nearRes != null)
                    nearRes.addFailedKey(key, err);
                U.error(log, "Failed to update key on backup node: " + key, e);
            }
        }
    } finally {
        ctx.shared().database().checkpointReadUnlock();
    }
    GridDhtAtomicUpdateResponse dhtRes = null;
    if (req.nearSize() > 0 || req.obsoleteNearKeysSize() > 0) {
        List<KeyCacheObject> nearEvicted = null;
        if (isNearEnabled(ctx))
            nearEvicted = ((GridNearAtomicCache<K, V>) near()).processDhtAtomicUpdateRequest(nodeId, req, nearRes);
        else if (req.nearSize() > 0) {
            nearEvicted = new ArrayList<>(req.nearSize());
            for (int i = 0; i < req.nearSize(); i++) nearEvicted.add(req.nearKey(i));
        }
        if (nearEvicted != null) {
            dhtRes = new GridDhtAtomicUpdateResponse(ctx.cacheId(), req.partition(), req.futureId(), ctx.deploymentEnabled());
            dhtRes.nearEvicted(nearEvicted);
        }
    }
    try {
        // TODO fire events only after successful fsync
        if (ctx.shared().wal() != null)
            ctx.shared().wal().flush(null, false);
    } catch (StorageException e) {
        if (dhtRes != null)
            dhtRes.onError(new IgniteCheckedException(e));
        if (nearRes != null)
            nearRes.onClassError(e);
    } catch (IgniteCheckedException e) {
        if (dhtRes != null)
            dhtRes.onError(e);
        if (nearRes != null)
            nearRes.onClassError(e);
    }
    if (nearRes != null)
        sendDhtNearResponse(req, nearRes);
    if (dhtRes == null && req.replyWithoutDelay()) {
        dhtRes = new GridDhtAtomicUpdateResponse(ctx.cacheId(), req.partition(), req.futureId(), ctx.deploymentEnabled());
    }
    if (dhtRes != null)
        sendDhtPrimaryResponse(nodeId, req, dhtRes);
    else
        sendDeferredUpdateResponse(req.partition(), nodeId, req.futureId());
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ArrayList(java.util.ArrayList) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearAtomicCache(org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) GridCacheUpdateAtomicResult(org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException)

Aggregations

GridNearAtomicCache (org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache)6 ArrayList (java.util.ArrayList)4 CacheStore (org.apache.ignite.cache.store.CacheStore)3 CacheDataStructuresManager (org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager)3 GridDhtCache (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache)3 GridDhtCacheAdapter (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter)3 GridDhtAtomicCache (org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache)3 GridDhtColocatedCache (org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache)3 GridNearTransactionalCache (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTransactionalCache)3 GridCacheDrManager (org.apache.ignite.internal.processors.cache.dr.GridCacheDrManager)3 GridLocalCache (org.apache.ignite.internal.processors.cache.local.GridLocalCache)3 GridLocalAtomicCache (org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache)3 GridCacheQueryManager (org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager)3 CacheContinuousQueryManager (org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager)3 CacheStoreManager (org.apache.ignite.internal.processors.cache.store.CacheStoreManager)3 CachePluginManager (org.apache.ignite.internal.processors.plugin.CachePluginManager)3 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 IgniteOutOfMemoryException (org.apache.ignite.internal.mem.IgniteOutOfMemoryException)1