Search in sources :

Example 36 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class GridCacheIoManager method addHandler.

/**
 * @param hndId Message handler ID.
 * @param type Type of message.
 * @param c Handler.
 * @param msgHandlers Message handlers.
 */
@SuppressWarnings({ "unchecked" })
private void addHandler(int hndId, Class<? extends GridCacheMessage> type, IgniteBiInClosure<UUID, ? extends GridCacheMessage> c, MessageHandlers msgHandlers) {
    int msgIdx = messageIndex(type);
    if (msgIdx != -1) {
        Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = msgHandlers.idxClsHandlers;
        IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(hndId);
        if (cacheClsHandlers == null) {
            cacheClsHandlers = new IgniteBiInClosure[GridCacheMessage.MAX_CACHE_MSG_LOOKUP_INDEX];
            idxClsHandlers0.put(hndId, cacheClsHandlers);
        }
        if (cacheClsHandlers[msgIdx] != null)
            throw new IgniteException("Duplicate cache message ID found [hndId=" + hndId + ", type=" + type + ']');
        cacheClsHandlers[msgIdx] = c;
        msgHandlers.idxClsHandlers = idxClsHandlers0;
        return;
    } else {
        ListenerKey key = new ListenerKey(hndId, type);
        if (msgHandlers.clsHandlers.putIfAbsent(key, (IgniteBiInClosure<UUID, GridCacheMessage>) c) != null)
            assert false : "Handler for class already registered [hndId=" + hndId + ", cls=" + type + ", old=" + msgHandlers.clsHandlers.get(key) + ", new=" + c + ']';
    }
    IgniteLogger log0 = log;
    if (log0 != null && log0.isTraceEnabled())
        log0.trace("Registered cache communication handler [hndId=" + hndId + ", type=" + type + ", msgIdx=" + msgIdx + ", handler=" + c + ']');
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 37 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class CacheContinuousQueryHandler method sendBackupAcknowledge.

/**
 * @param t Acknowledge information.
 * @param routineId Routine ID.
 * @param ctx Context.
 */
private void sendBackupAcknowledge(final IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>> t, final UUID routineId, final GridKernalContext ctx) {
    if (t != null) {
        ctx.closure().runLocalSafe(new Runnable() {

            @Override
            public void run() {
                GridCacheContext<K, V> cctx = cacheContext(ctx);
                CacheContinuousQueryBatchAck msg = new CacheContinuousQueryBatchAck(cctx.cacheId(), routineId, t.get1());
                for (AffinityTopologyVersion topVer : t.get2()) {
                    for (ClusterNode node : ctx.discovery().cacheGroupAffinityNodes(cctx.groupId(), topVer)) {
                        if (!node.isLocal()) {
                            try {
                                cctx.io().send(node, msg, GridIoPolicy.SYSTEM_POOL);
                            } catch (ClusterTopologyCheckedException ignored) {
                                IgniteLogger log = ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY);
                                if (log.isDebugEnabled())
                                    log.debug("Failed to send acknowledge message, node left " + "[msg=" + msg + ", node=" + node + ']');
                            } catch (IgniteCheckedException e) {
                                IgniteLogger log = ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY);
                                U.error(log, "Failed to send acknowledge message " + "[msg=" + msg + ", node=" + node + ']', e);
                            }
                        }
                    }
                }
            }
        });
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteLogger(org.apache.ignite.IgniteLogger) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 38 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class GridDhtAssignmentFetchFuture method requestFromNextNode.

/**
 * Requests affinity from next node in the list.
 */
private void requestFromNextNode() {
    boolean complete;
    // Avoid 'protected field is accessed in synchronized context' warning.
    IgniteLogger log0 = log;
    synchronized (this) {
        while (!availableNodes.isEmpty()) {
            ClusterNode node = availableNodes.poll();
            try {
                if (log0.isDebugEnabled())
                    log0.debug("Sending affinity fetch request to remote node [locNodeId=" + ctx.localNodeId() + ", node=" + node + ']');
                ctx.io().send(node, new GridDhtAffinityAssignmentRequest(id, grpId, topVer, needPartState), AFFINITY_POOL);
                // Close window for listener notification.
                if (ctx.discovery().node(node.id()) == null) {
                    U.warn(log0, "Failed to request affinity assignment from remote node (node left grid, will " + "continue to another node): " + node);
                    continue;
                }
                pendingNode = node;
                break;
            } catch (ClusterTopologyCheckedException ignored) {
                U.warn(log0, "Failed to request affinity assignment from remote node (node left grid, will " + "continue to another node): " + node);
            } catch (IgniteCheckedException e) {
                if (ctx.discovery().reconnectSupported() && X.hasCause(e, IOException.class)) {
                    onDone(new IgniteNeedReconnectException(ctx.localNode(), e));
                    return;
                }
                U.warn(log0, "Failed to request affinity assignment from remote node (will " + "continue to another node): " + node);
            }
        }
        complete = pendingNode == null;
    }
    // Affinity should be calculated from scratch.
    if (complete)
        onDone((GridDhtAffinityAssignmentResponse) null);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 39 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class IgniteDrDataStreamerCacheUpdater method receive.

/**
 * {@inheritDoc}
 */
@Override
public void receive(IgniteCache<KeyCacheObject, CacheObject> cache0, Collection<Map.Entry<KeyCacheObject, CacheObject>> col) {
    try {
        String cacheName = cache0.getConfiguration(CacheConfiguration.class).getName();
        GridKernalContext ctx = ((IgniteKernal) cache0.unwrap(Ignite.class)).context();
        IgniteLogger log = ctx.log(IgniteDrDataStreamerCacheUpdater.class);
        GridCacheAdapter internalCache = ctx.cache().internalCache(cacheName);
        CacheOperationContext opCtx = ((IgniteCacheProxy) cache0).context().operationContextPerCall();
        IgniteInternalCache cache = opCtx != null ? new GridCacheProxyImpl(internalCache.context(), internalCache, opCtx) : internalCache;
        assert !F.isEmpty(col);
        if (log.isDebugEnabled())
            log.debug("Running DR put job [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
        CacheObjectContext cacheObjCtx = cache.context().cacheObjectContext();
        for (Map.Entry<KeyCacheObject, CacheObject> entry0 : col) {
            GridCacheRawVersionedEntry entry = (GridCacheRawVersionedEntry) entry0;
            entry.unmarshal(cacheObjCtx, ctx.config().getMarshaller());
            KeyCacheObject key = entry.getKey();
            // Ensure that receiver to not receive special-purpose values for TTL and expire time.
            assert entry.ttl() != CU.TTL_NOT_CHANGED && entry.ttl() != CU.TTL_ZERO && entry.ttl() >= 0;
            assert entry.expireTime() != CU.EXPIRE_TIME_CALCULATE && entry.expireTime() >= 0;
            CacheObject cacheVal = entry.getValue();
            GridCacheDrInfo val = cacheVal != null ? entry.ttl() != CU.TTL_ETERNAL ? new GridCacheDrExpirationInfo(cacheVal, entry.version(), entry.ttl(), entry.expireTime()) : new GridCacheDrInfo(cacheVal, entry.version()) : null;
            if (val == null)
                cache.removeAllConflict(Collections.singletonMap(key, entry.version()));
            else
                cache.putAllConflict(Collections.singletonMap(key, val));
        }
        if (log.isDebugEnabled())
            log.debug("DR put job finished [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCacheProxyImpl(org.apache.ignite.internal.processors.cache.GridCacheProxyImpl) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDrExpirationInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteLogger(org.apache.ignite.IgniteLogger) GridCacheRawVersionedEntry(org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry) Map(java.util.Map) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 40 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class CacheContinuousWithTransformerFailoverTest method testTransformerException.

/**
 * @throws Exception If failed.
 */
public void testTransformerException() throws Exception {
    try {
        startGrids(1);
        Ignite ignite = ignite(0);
        IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
        final CountDownLatch latch = new CountDownLatch(10);
        ContinuousQueryWithTransformer<Integer, Integer, Integer> qry = new ContinuousQueryWithTransformer<>();
        qry.setLocalListener(new EventListener<Integer>() {

            /**
             */
            @LoggerResource
            private IgniteLogger log;

            @Override
            public void onUpdated(Iterable<? extends Integer> evts) throws CacheEntryListenerException {
                for (Integer evt : evts) {
                    log.debug("" + evt);
                }
            }
        });
        qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Integer>, Integer>() {

            @Override
            public Integer apply(CacheEntryEvent<? extends Integer, ? extends Integer> evt) {
                latch.countDown();
                throw new RuntimeException("Test error.");
            }
        }));
        qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, Integer>() {

            @Override
            public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Integer> evt) {
                return true;
            }
        }));
        try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) {
            for (int i = 0; i < 10; i++) cache.put(i, i);
            assertTrue(latch.await(10, SECONDS));
        }
    } finally {
        stopAllGrids();
    }
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) IgniteClosure(org.apache.ignite.lang.IgniteClosure) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger)

Aggregations

IgniteLogger (org.apache.ignite.IgniteLogger)60 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 Ignite (org.apache.ignite.Ignite)12 IOException (java.io.IOException)10 LoggerResource (org.apache.ignite.resources.LoggerResource)10 IgniteException (org.apache.ignite.IgniteException)8 Map (java.util.Map)6 UUID (java.util.UUID)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)6 HashMap (java.util.HashMap)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 IgniteBiInClosure (org.apache.ignite.lang.IgniteBiInClosure)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 URL (java.net.URL)3 Callable (java.util.concurrent.Callable)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3