Search in sources :

Example 1 with MetadataUpdateProposedMessage

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

the class CacheRegisterMetadataLocallyTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            if (msg instanceof CustomMessageWrapper) {
                DiscoveryCustomMessage realMsg = ((CustomMessageWrapper) msg).delegate();
                if (realMsg instanceof MetadataUpdateProposedMessage || realMsg instanceof MetadataUpdateAcceptedMessage)
                    customMessages.add(realMsg);
            }
            super.sendCustomEvent(msg);
        }
    });
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
            if (msg instanceof GridIoMessage)
                communicationMessages.add(((GridIoMessage) msg).message());
            super.sendMessage(node, msg, ackC);
        }

        @Override
        public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
            if (msg instanceof GridIoMessage)
                communicationMessages.add(((GridIoMessage) msg).message());
            super.sendMessage(node, msg);
        }
    });
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
    cfg.setCacheConfiguration(cacheConfiguration(STATIC_CACHE_NAME, StaticKey.class, StaticValue.class));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) MetadataRequestMessage(org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) MetadataResponseMessage(org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 2 with MetadataUpdateProposedMessage

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

the class BinaryMetadataConcurrentUpdateWithIndexesTest method testMissingSchemaUpdate.

/**
 */
@Test
public void testMissingSchemaUpdate() throws Exception {
    // Start order is important.
    Ignite node0 = startGrid("node0");
    Ignite node1 = startGrid("node1");
    IgniteEx client0 = startClientGrid("client0");
    CacheObjectBinaryProcessorImpl.TestBinaryContext clientCtx = (CacheObjectBinaryProcessorImpl.TestBinaryContext) ((CacheObjectBinaryProcessorImpl) client0.context().cacheObjects()).binaryContext();
    clientCtx.addListener(new CacheObjectBinaryProcessorImpl.TestBinaryContext.TestBinaryContextListener() {

        @Override
        public void onAfterMetadataRequest(int typeId, BinaryType type) {
            if (syncMeta) {
                try {
                    initMetaReq.countDown();
                    initMetaReq.await();
                } catch (Exception e) {
                    throw new BinaryObjectException(e);
                }
            }
        }

        @Override
        public void onBeforeMetadataUpdate(int typeId, BinaryMetadata metadata) {
            // Delay one of updates until schema is locally updated on propose message.
            if (delayMetadataUpdateThreadLoc.get() != null)
                await(localMetaUpdatedLatch, 5000);
        }
    });
    Ignite node2 = startGrid("node2");
    Ignite node3 = startGrid("node3");
    startGrid("node4");
    node0.cluster().active(true);
    awaitPartitionMapExchange();
    syncMeta = true;
    CountDownLatch clientProposeMsgBlockedLatch = new CountDownLatch(1);
    AtomicBoolean clientWait = new AtomicBoolean();
    final Object clientMux = new Object();
    AtomicBoolean srvWait = new AtomicBoolean();
    final Object srvMux = new Object();
    ((BlockTcpDiscoverySpi) node1.configuration().getDiscoverySpi()).setClosure((snd, msg) -> {
        if (msg instanceof MetadataUpdateProposedMessage) {
            if (Thread.currentThread().getName().contains("client")) {
                log.info("Block custom message to client0: [locNode=" + snd + ", msg=" + msg + ']');
                clientProposeMsgBlockedLatch.countDown();
                // Message to client
                synchronized (clientMux) {
                    while (!clientWait.get()) try {
                        clientMux.wait();
                    } catch (InterruptedException e) {
                        fail();
                    }
                }
            }
        }
        return null;
    });
    ((BlockTcpDiscoverySpi) node2.configuration().getDiscoverySpi()).setClosure((snd, msg) -> {
        if (msg instanceof MetadataUpdateProposedMessage) {
            MetadataUpdateProposedMessage msg0 = (MetadataUpdateProposedMessage) msg;
            int pendingVer = U.field(msg0, "pendingVer");
            // Should not block propose messages until they reach coordinator.
            if (pendingVer == 0)
                return null;
            log.info("Block custom message to next server: [locNode=" + snd + ", msg=" + msg + ']');
            // Message to client
            synchronized (srvMux) {
                while (!srvWait.get()) try {
                    srvMux.wait();
                } catch (InterruptedException e) {
                    fail();
                }
            }
        }
        return null;
    });
    Integer key = primaryKey(node3.cache(DEFAULT_CACHE_NAME));
    IgniteInternalFuture fut0 = runAsync(() -> {
        try (Transaction tx = client0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            client0.cache(DEFAULT_CACHE_NAME).put(key, build(client0, "val", 0));
            tx.commit();
        } catch (Throwable t) {
            log.error("err", t);
        }
    });
    // Implements test logic.
    IgniteInternalFuture fut1 = runAsync(() -> {
        // Wait for initial metadata received. It should be initial version: pending=0, accepted=0
        await(initMetaReq, 5000);
        // Wait for blocking proposal message to client node.
        await(clientProposeMsgBlockedLatch, 5000);
        // Unblock proposal message to client.
        clientWait.set(true);
        synchronized (clientMux) {
            clientMux.notify();
        }
        // Give some time to apply update.
        doSleep(3000);
        // Unblock second metadata update.
        localMetaUpdatedLatch.countDown();
        // Give some time for tx to complete (success or fail). fut2 will throw an error if tx has failed on commit.
        doSleep(3000);
        // Unblock metadata message and allow for correct version acceptance.
        srvWait.set(true);
        synchronized (srvMux) {
            srvMux.notify();
        }
    });
    IgniteInternalFuture fut2 = runAsync(() -> {
        delayMetadataUpdateThreadLoc.set(true);
        try (Transaction tx = client0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 1)) {
            client0.cache(DEFAULT_CACHE_NAME).put(key, build(client0, "val", 0));
            tx.commit();
        }
    });
    fut0.get();
    fut1.get();
    fut2.get();
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.apache.ignite.transactions.Transaction) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) BlockTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.BlockTcpDiscoverySpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with MetadataUpdateProposedMessage

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

the class BinaryTypeRegistrationTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            if (msg instanceof CustomMessageWrapper && ((CustomMessageWrapper) msg).delegate() instanceof MetadataUpdateProposedMessage)
                metadataUpdateProposedMessages.add(((CustomMessageWrapper) msg).delegate());
            super.sendCustomEvent(msg);
        }
    });
    return cfg;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) IgniteException(org.apache.ignite.IgniteException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

MetadataUpdateProposedMessage (org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage)3 IgniteException (org.apache.ignite.IgniteException)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 CustomMessageWrapper (org.apache.ignite.internal.managers.discovery.CustomMessageWrapper)2 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)2 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)1 BinaryType (org.apache.ignite.binary.BinaryType)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)1 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)1 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)1 CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)1 MetadataRequestMessage (org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage)1