Search in sources :

Example 41 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridTimeoutProcessorSelfTest method testTimeoutSameEndTime.

/**
 * @throws Exception If test failed.
 */
public void testTimeoutSameEndTime() throws Exception {
    final CountDownLatch latch = new CountDownLatch(2);
    final long endTime0 = System.currentTimeMillis() + 1000;
    ctx.timeout().addTimeoutObject(new GridTimeoutObject() {

        /**
         * Timeout ID.
         */
        private final IgniteUuid id = IgniteUuid.randomUuid();

        /**
         * End time.
         */
        private final long endTime = endTime0;

        /**
         * {@inheritDoc}
         */
        @Override
        public IgniteUuid timeoutId() {
            return id;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public long endTime() {
            return endTime;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onTimeout() {
            info("Received timeout callback: " + this);
            latch.countDown();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "Timeout test object [endTime=" + endTime + ", id=" + id + ']';
        }
    });
    ctx.timeout().addTimeoutObject(new GridTimeoutObject() {

        /**
         * Timeout ID.
         */
        private final IgniteUuid id = IgniteUuid.randomUuid();

        /**
         * End time.
         */
        private final long endTime = endTime0;

        /**
         * {@inheritDoc}
         */
        @Override
        public IgniteUuid timeoutId() {
            return id;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public long endTime() {
            return endTime;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onTimeout() {
            info("Received timeout callback: " + this);
            latch.countDown();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "Timeout test object [endTime=" + endTime + ", id=" + id + ']';
        }
    });
    assert latch.await(3000, MILLISECONDS);
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 42 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridTimeoutProcessorSelfTest method testTimeouts.

/**
 * Tests timeouts.
 *
 * @throws Exception If test failed.
 */
public void testTimeouts() throws Exception {
    int max = 100;
    final CountDownLatch latch = new CountDownLatch(max);
    final Collection<GridTimeoutObject> timeObjs = new ConcurrentLinkedQueue<>();
    for (int i = 0; i < max; i++) {
        final int idx = i;
        ctx.timeout().addTimeoutObject(new GridTimeoutObject() {

            /**
             * Timeout ID.
             */
            private final IgniteUuid id = IgniteUuid.randomUuid();

            /**
             * End time.
             */
            private final long endTime = System.currentTimeMillis() + RAND.nextInt(1000);

            /**
             * {@inheritDoc}
             */
            @Override
            public IgniteUuid timeoutId() {
                return id;
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public long endTime() {
                return endTime;
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public void onTimeout() {
                info("Received timeout callback: " + this);
                long now = System.currentTimeMillis();
                if (now < endTime) {
                    fail("Timeout event happened prematurely [endTime=" + endTime + ", now=" + now + ", obj=" + this + ']');
                }
                synchronized (timeObjs) {
                    timeObjs.add(this);
                }
                latch.countDown();
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public String toString() {
                return "Timeout test object [idx=" + idx + ", endTime=" + endTime + ", id=" + id + ']';
            }
        });
    }
    latch.await();
    assert timeObjs.size() == max;
    // Ensure proper timeout sequence.
    long endTime = 0;
    for (GridTimeoutObject obj : timeObjs) {
        assert endTime <= obj.endTime();
        endTime = obj.endTime();
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 43 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridIoManagerBenchmark0 method testLatency.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
public void testLatency() throws Exception {
    final IgniteKernal sndKernal = (IgniteKernal) grid(0);
    final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
    final ClusterNode sndNode = sndKernal.localNode();
    final ClusterNode rcvNode = rcvKernal.localNode();
    final GridIoManager snd = sndKernal.context().io();
    final GridIoManager rcv = rcvKernal.context().io();
    final LongAdder msgCntr = new LongAdder();
    final Integer topic = 1;
    final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap<>();
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            try {
                rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
            } catch (IgniteCheckedException e) {
                error("Failed to send message.", e);
            }
        }
    });
    snd.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            map.get(((GridTestMessage) msg).id()).countDown();
        }
    });
    Timer t = new Timer("results-reporter");
    t.schedule(new TimerTask() {

        private long ts = System.currentTimeMillis();

        @Override
        public void run() {
            long newTs = System.currentTimeMillis();
            long qrys = msgCntr.sumThenReset();
            long time = newTs - ts;
            X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
            ts = newTs;
        }
    }, 10000, 10000);
    final AtomicBoolean finish = new AtomicBoolean();
    IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                IgniteUuid msgId = IgniteUuid.randomUuid();
                while (!finish.get()) {
                    CountDownLatch latch = new CountDownLatch(1);
                    map.put(msgId, latch);
                    snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                    latch.await();
                    msgCntr.increment();
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            } catch (InterruptedException ignored) {
            // No-op.
            }
            return null;
        }
    }, 1, "send-thread");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    t.cancel();
    f.get();
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TimerTask(java.util.TimerTask) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) Timer(java.util.Timer) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager)

Example 44 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class CacheDataStructuresManager method onReconnected.

/**
 * @param clusterRestarted Cluster restarted flag.
 * @throws IgniteCheckedException If failed.
 */
public void onReconnected(boolean clusterRestarted) throws IgniteCheckedException {
    for (Map.Entry<IgniteUuid, GridCacheSetProxy> e : setsMap.entrySet()) {
        GridCacheSetProxy set = e.getValue();
        if (clusterRestarted) {
            set.blockOnRemove();
            setsMap.remove(e.getKey(), set);
        } else
            set.needCheckNotRemoved();
    }
    for (Map.Entry<IgniteUuid, GridCacheQueueProxy> e : queuesMap.entrySet()) {
        GridCacheQueueProxy queue = e.getValue();
        if (clusterRestarted) {
            queue.delegate().onRemoved(false);
            queuesMap.remove(e.getKey(), queue);
        }
    }
}
Also used : GridCacheSetProxy(org.apache.ignite.internal.processors.datastructures.GridCacheSetProxy) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheQueueProxy(org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 45 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridDeploymentPerVersionStore method getDeployment.

/**
 * {@inheritDoc}
 */
@Override
@Nullable
public GridDeployment getDeployment(GridDeploymentMetadata meta) {
    assert meta != null;
    assert ctx.config().isPeerClassLoadingEnabled();
    // Validate metadata.
    assert meta.classLoaderId() != null;
    assert meta.senderNodeId() != null;
    assert meta.sequenceNumber() >= -1;
    assert meta.parentLoader() == null;
    if (log.isDebugEnabled())
        log.debug("Starting to peer-load class based on deployment metadata: " + meta);
    if (meta.participants() == null && !checkLoadRemoteClass(meta.className(), meta)) {
        if (log.isDebugEnabled())
            log.debug("Skipping deployment check as remote node does not have required class: " + meta);
        return null;
    }
    while (true) {
        List<SharedDeployment> depsToCheck = null;
        SharedDeployment dep = null;
        synchronized (mux) {
            // Check obsolete request.
            if (isDeadClassLoader(meta))
                return null;
            if (meta.participants() != null && !meta.participants().isEmpty()) {
                Map<UUID, IgniteUuid> participants = new LinkedHashMap<>();
                for (Map.Entry<UUID, IgniteUuid> e : meta.participants().entrySet()) {
                    // Warn if local node is in participants.
                    if (ctx.localNodeId().equals(e.getKey())) {
                        // Warn only if mode is not CONTINUOUS.
                        if (meta.deploymentMode() != CONTINUOUS)
                            LT.warn(log, "Local node is in participants (most probably, " + "IgniteConfiguration.getPeerClassLoadingLocalClassPathExclude() " + "is not used properly " + "[locNodeId=" + ctx.localNodeId() + ", meta=" + meta + ']');
                        continue;
                    }
                    // Skip left nodes.
                    if (ctx.discovery().node(e.getKey()) != null)
                        participants.put(e.getKey(), e.getValue());
                }
                if (!participants.isEmpty()) {
                    // Set new participants.
                    meta = new GridDeploymentMetadata(meta);
                    meta.participants(participants);
                    if (log.isDebugEnabled())
                        log.debug("Created new meta with updated participants: " + meta);
                } else {
                    if (log.isDebugEnabled())
                        log.debug("All participants has gone: " + meta);
                    // can have this classes deployed.
                    if (meta.deploymentMode() != CONTINUOUS)
                        return null;
                }
            } else if (ctx.discovery().node(meta.senderNodeId()) == null) {
                if (log.isDebugEnabled())
                    log.debug("Sender node has gone: " + meta);
                return null;
            }
            List<SharedDeployment> deps = cache.get(meta.userVersion());
            if (deps != null) {
                assert !deps.isEmpty();
                for (SharedDeployment d : deps) {
                    if (d.hasParticipant(meta.senderNodeId(), meta.classLoaderId()) || meta.senderNodeId().equals(ctx.localNodeId())) {
                        // Done.
                        dep = d;
                        break;
                    }
                }
                if (dep == null) {
                    checkRedeploy(meta);
                    // whether they should be reused for this request.
                    if (ctx.config().getDeploymentMode() == CONTINUOUS) {
                        for (SharedDeployment d : deps) {
                            if (!d.pendingUndeploy() && !d.undeployed()) {
                                Map<UUID, IgniteUuid> parties = d.participants();
                                if (parties != null) {
                                    IgniteUuid ldrId = parties.get(meta.senderNodeId());
                                    if (ldrId != null) {
                                        assert !ldrId.equals(meta.classLoaderId());
                                        if (log.isDebugEnabled())
                                            log.debug("Skipping deployment (loaders on remote node are different) " + "[dep=" + d + ", meta=" + meta + ']');
                                        continue;
                                    }
                                }
                                if (depsToCheck == null)
                                    depsToCheck = new LinkedList<>();
                                if (log.isDebugEnabled())
                                    log.debug("Adding deployment to check: " + d);
                                depsToCheck.add(d);
                            }
                        }
                    }
                    // If no deployment can be reused, create a new one.
                    if (depsToCheck == null) {
                        dep = createNewDeployment(meta, false);
                        deps.add(dep);
                    }
                }
            } else {
                checkRedeploy(meta);
                // Create peer class loader.
                dep = createNewDeployment(meta, true);
            }
        }
        if (dep != null) {
            if (log.isDebugEnabled())
                log.debug("Found SHARED or CONTINUOUS deployment after first check: " + dep);
            // Cache the deployed class.
            Class<?> cls = dep.deployedClass(meta.className(), meta.alias());
            if (cls == null) {
                U.warn(log, "Failed to load peer class (ignore if class got undeployed during preloading) [alias=" + meta.alias() + ", dep=" + dep + ']');
                return null;
            }
            return dep;
        }
        assert meta.parentLoader() == null;
        assert depsToCheck != null;
        assert !depsToCheck.isEmpty();
        // In most cases this loop will find something.
        for (SharedDeployment d : depsToCheck) {
            // Load class. Note, that remote node will not load this class.
            // The class will only be loaded on this node.
            Class<?> cls = d.deployedClass(meta.className(), meta.alias());
            if (cls != null) {
                synchronized (mux) {
                    if (!d.undeployed() && !d.pendingUndeploy()) {
                        if (!addParticipant(d, meta))
                            return null;
                        if (log.isDebugEnabled())
                            log.debug("Acquired deployment after verifying it's availability on " + "existing nodes [depCls=" + cls + ", dep=" + d + ", meta=" + meta + ']');
                        return d;
                    }
                }
            } else if (log.isDebugEnabled()) {
                log.debug("Deployment cannot be reused (class does not exist on participating nodes) [dep=" + d + ", meta=" + meta + ']');
            }
        }
        // or the class indeed should have a separate deployment.
        for (SharedDeployment d : depsToCheck) {
            // deployment.
            if (meta.participants() != null || checkLoadRemoteClass(d.sampleClassName(), meta)) {
                synchronized (mux) {
                    if (d.undeployed() || d.pendingUndeploy())
                        continue;
                    // to load the class from the latest node.
                    if (!addParticipant(d, meta)) {
                        if (log.isDebugEnabled())
                            log.debug("Failed to add participant to deployment " + "[meta=" + meta + ", dep=" + dep + ']');
                        return null;
                    }
                }
                Class<?> depCls = d.deployedClass(meta.className(), meta.alias());
                if (depCls == null) {
                    U.error(log, "Failed to peer load class after loading it as a resource [alias=" + meta.alias() + ", dep=" + dep + ']');
                    return null;
                }
                if (log.isDebugEnabled())
                    log.debug("Acquired deployment class after verifying other class " + "availability on sender node [depCls=" + depCls + ", rndCls=" + d.sampleClassName() + ", sampleClsName=" + d.sampleClassName() + ", meta=" + meta + ']');
                return d;
            } else if (log.isDebugEnabled())
                log.debug("Deployment cannot be reused (random class could not be loaded from sender node) [dep=" + d + ", meta=" + meta + ']');
        }
        synchronized (mux) {
            if (log.isDebugEnabled())
                log.debug("None of the existing class-loaders fits (will try to create a new one): " + meta);
            // Check obsolete request.
            if (isDeadClassLoader(meta))
                return null;
            // Check that deployment picture has not changed.
            List<SharedDeployment> deps = cache.get(meta.userVersion());
            if (deps != null) {
                assert !deps.isEmpty();
                boolean retry = false;
                for (SharedDeployment d : deps) {
                    // Double check if sender was already added.
                    if (d.hasParticipant(meta.senderNodeId(), meta.classLoaderId())) {
                        dep = d;
                        retry = false;
                        break;
                    }
                    // Need to recheck it again.
                    if (!d.pendingUndeploy() && !d.undeployed() && !depsToCheck.contains(d)) {
                        Map<UUID, IgniteUuid> parties = d.participants();
                        if (parties == null || parties.get(meta.senderNodeId()) == null)
                            retry = true;
                    }
                }
                if (retry) {
                    if (log.isDebugEnabled())
                        log.debug("Retrying due to concurrency issues: " + meta);
                    // Outer while loop.
                    continue;
                }
                if (dep == null) {
                    // No new deployments were added, so we can safely add ours.
                    dep = createNewDeployment(meta, false);
                    deps.add(dep);
                    if (log.isDebugEnabled())
                        log.debug("Adding new deployment within second check [dep=" + dep + ", meta=" + meta + ']');
                }
            } else {
                dep = createNewDeployment(meta, true);
                if (log.isDebugEnabled())
                    log.debug("Created new deployment within second check [dep=" + dep + ", meta=" + meta + ']');
            }
        }
        if (dep != null) {
            // Cache the deployed class.
            Class<?> cls = dep.deployedClass(meta.className(), meta.alias());
            if (cls == null) {
                U.warn(log, "Failed to load peer class (ignore if class got undeployed during preloading) [alias=" + meta.alias() + ", dep=" + dep + ']');
                return null;
            }
        }
        return dep;
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteUuid (org.apache.ignite.lang.IgniteUuid)107 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)25 UUID (java.util.UUID)23 IgniteException (org.apache.ignite.IgniteException)17 HashMap (java.util.HashMap)15 Map (java.util.Map)13 IgfsPath (org.apache.ignite.igfs.IgfsPath)11 ArrayList (java.util.ArrayList)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Nullable (org.jetbrains.annotations.Nullable)9 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)7 HashSet (java.util.HashSet)6 TreeSet (java.util.TreeSet)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Ignite (org.apache.ignite.Ignite)6 IgfsException (org.apache.ignite.igfs.IgfsException)6 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5