Search in sources :

Example 21 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method startDeafClient.

/**
 * Starts client node that skips <b>MetadataUpdateProposedMessage</b> and <b>MetadataUpdateAcceptedMessage</b>
 * messages.
 *
 * @param clientName name of client node.
 */
private Ignite startDeafClient(String clientName) throws Exception {
    applyDiscoveryHook = true;
    discoveryHook = new DiscoveryHook() {

        @Override
        public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
            if (customMsg instanceof MetadataUpdateProposedMessage) {
                if (((MetadataUpdateProposedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                    GridTestUtils.setFieldValue(customMsg, "typeId", 1);
            } else if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                    GridTestUtils.setFieldValue(customMsg, "typeId", 1);
            }
        }
    };
    Ignite client = startClientGrid(clientName);
    applyDiscoveryHook = false;
    return client;
}
Also used : Ignite(org.apache.ignite.Ignite) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 22 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method testReadRequestBlockedOnUpdatingMetadata.

/**
 * Verifies that if thread tries to read metadata with ongoing update it gets blocked
 * until acknowledge message arrives.
 */
@Test
public void testReadRequestBlockedOnUpdatingMetadata() throws Exception {
    final CyclicBarrier barrier = new CyclicBarrier(2);
    applyDiscoveryHook = false;
    final Ignite ignite0 = startGrid(0);
    final Ignite ignite1 = startGrid(1);
    final GridFutureAdapter finishFut = new GridFutureAdapter();
    applyDiscoveryHook = true;
    discoveryHook = new DiscoveryHook() {

        private volatile IgniteEx ignite;

        @Override
        public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
            if (finishFut.isDone())
                return;
            if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                MetadataUpdateAcceptedMessage acceptedMsg = (MetadataUpdateAcceptedMessage) customMsg;
                if (acceptedMsg.typeId() == BINARY_TYPE_ID && acceptedMsg.acceptedVersion() == 2) {
                    Object binaryProc = U.field(ignite.context(), "cacheObjProc");
                    Object transport = U.field(binaryProc, "transport");
                    try {
                        barrier.await(MAX_AWAIT, TimeUnit.MILLISECONDS);
                        Map syncMap = U.field(transport, "syncMap");
                        GridTestUtils.waitForCondition(new PA() {

                            @Override
                            public boolean apply() {
                                return syncMap.size() == 1;
                            }
                        }, MAX_AWAIT);
                        assertEquals("unexpected size of syncMap: ", 1, syncMap.size());
                        Object syncKey = syncMap.keySet().iterator().next();
                        int typeId = U.field(syncKey, "typeId");
                        assertEquals("unexpected typeId: ", BINARY_TYPE_ID, typeId);
                        int ver = U.field(syncKey, "ver");
                        assertEquals("unexpected pendingVersion: ", 2, ver);
                        finishFut.onDone();
                    } catch (Throwable t) {
                        finishFut.onDone(t);
                    }
                }
            }
        }

        @Override
        public void ignite(IgniteEx ignite) {
            this.ignite = ignite;
        }
    };
    final IgniteEx ignite2 = startGrid(2);
    discoveryHook.ignite(ignite2);
    // Unfinished PME may affect max await timeout.
    awaitPartitionMapExchange();
    // Update metadata (version 1).
    ignite0.executorService(ignite0.cluster().forLocal()).submit(new Runnable() {

        @Override
        public void run() {
            addIntField(ignite0, "f1", 101, 1);
        }
    }).get();
    // Update metadata (version 2).
    ignite1.executorService(ignite1.cluster().forLocal()).submit(new Runnable() {

        @Override
        public void run() {
            addStringField(ignite1, "f2", "str", 2);
        }
    });
    // Read metadata.
    IgniteFuture readFut = ignite2.compute(ignite2.cluster().forLocal()).callAsync(new IgniteCallable<Object>() {

        @Override
        public Object call() throws Exception {
            barrier.await(MAX_AWAIT, TimeUnit.MILLISECONDS);
            return ((BinaryObject) ignite2.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(1)).field("f1");
        }
    });
    finishFut.get(MAX_AWAIT);
    assertEquals(101, readFut.get(MAX_AWAIT));
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) CyclicBarrier(java.util.concurrent.CyclicBarrier) PA(org.apache.ignite.internal.util.typedef.PA) IgniteEx(org.apache.ignite.internal.IgniteEx) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) Map(java.util.Map) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class AbstractBinaryMetadataRegistrationTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TestTcpDiscoverySpi) cfg.getDiscoverySpi()).discoveryHook(new DiscoveryHook() {

        @Override
        public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
            if (customMsg instanceof MetadataUpdateProposedMessage)
                proposeMsgNum.incrementAndGet();
        }
    });
    cfg.setCacheConfiguration(cacheConfiguration());
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 24 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class DiscoverySpiTestListener method beforeSendCustomEvent.

/**
 * {@inheritDoc}
 */
@Override
public boolean beforeSendCustomEvent(DiscoverySpi spi, IgniteLogger log, DiscoverySpiCustomMessage msg) {
    this.spi = spi;
    this.log = log;
    synchronized (mux) {
        if (blockCustomEvtCls != null) {
            DiscoveryCustomMessage msg0 = GridTestUtils.getFieldValue(msg, "delegate");
            if (blockCustomEvtCls.contains(msg0.getClass())) {
                log.info("Block custom message: " + msg0);
                blockedMsgs.add(msg);
                mux.notifyAll();
                return false;
            }
        }
    }
    return true;
}
Also used : DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)

Example 25 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class CacheBlockOnReadAbstractTest method testUpdateBaselineTopologyTransactionalReplicated.

/**
 * @throws Exception If failed.
 */
@Params(timeout = 5000L, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED)
@Test
public void testUpdateBaselineTopologyTransactionalReplicated() throws Exception {
    doTest(asMessagePredicate(discoEvt -> {
        if (discoEvt instanceof DiscoveryCustomEvent) {
            DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
            DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
            return customMsg instanceof ChangeGlobalStateMessage;
        }
        return false;
    }), () -> {
        startNodesInClientMode(false);
        IgniteEx ignite = startGrid(UUID.randomUUID().toString());
        baseline.get(0).cluster().setBaselineTopology(baseline.get(0).context().discovery().topologyVersion());
        baseline.add(ignite);
    });
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Arrays(java.util.Arrays) TcpDiscoveryNodeAddFinishedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddFinishedMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) X(org.apache.ignite.internal.util.typedef.X) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) TcpDiscoveryNodeLeftMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Predicate(java.util.function.Predicate) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) UUID(java.util.UUID) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) NotNull(org.jetbrains.annotations.NotNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TcpDiscoveryIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) U(org.apache.ignite.internal.util.typedef.internal.U) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) BiConsumer(java.util.function.BiConsumer) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheActionData(org.apache.ignite.internal.processors.cache.ExchangeActions.CacheActionData) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Target(java.lang.annotation.Target) Test(org.junit.Test) ElementType(java.lang.annotation.ElementType) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) RetentionPolicy(java.lang.annotation.RetentionPolicy) CacheMode(org.apache.ignite.cache.CacheMode) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) IgniteEx(org.apache.ignite.internal.IgniteEx) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)29 DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)10 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)9 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)8 DiscoveryHook (org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteException (org.apache.ignite.IgniteException)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)6 Test (org.junit.Test)6 UUID (java.util.UUID)5 TestTcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi)5 Ignite (org.apache.ignite.Ignite)4 Collection (java.util.Collection)3 List (java.util.List)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3