Java Code Examples for org.apache.ignite.configuration.IgniteConfiguration#getCommunicationSpi()

The following examples show how to use org.apache.ignite.configuration.IgniteConfiguration#getCommunicationSpi() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridDiscoveryManager.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cfg Configuration.
 * @throws IgniteCheckedException If configuration is not valid.
 */
public static void initCommunicationErrorResolveConfiguration(IgniteConfiguration cfg) throws IgniteCheckedException {
    CommunicationFailureResolver rslvr = cfg.getCommunicationFailureResolver();
    CommunicationSpi commSpi = cfg.getCommunicationSpi();
    DiscoverySpi discoverySpi = cfg.getDiscoverySpi();

    if (rslvr != null) {
        if (!supportsCommunicationErrorResolve(commSpi))
            throw new IgniteCheckedException("CommunicationFailureResolver is configured, but CommunicationSpi does not support communication" +
                "problem resolve: " + commSpi.getClass().getName());

        if (!supportsCommunicationErrorResolve(discoverySpi))
            throw new IgniteCheckedException("CommunicationFailureResolver is configured, but DiscoverySpi does not support communication" +
                "problem resolve: " + discoverySpi.getClass().getName());
    }
    else {
        if (supportsCommunicationErrorResolve(commSpi) && supportsCommunicationErrorResolve(discoverySpi))
            cfg.setCommunicationFailureResolver(new DefaultCommunicationFailureResolver());
    }
}
 
Example 2
Source File: IgniteCommunicationBalanceTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpCommunicationSpi commSpi = ((TcpCommunicationSpi)cfg.getCommunicationSpi());

    commSpi.setSharedMemoryPort(-1);
    commSpi.setConnectionsPerNode(connectionsPerNode());
    commSpi.setUsePairedConnections(usePairedConnections());

    if (selectors > 0)
        commSpi.setSelectorsCount(selectors);

    if (sslEnabled())
        cfg.setSslContextFactory(GridTestUtils.sslFactory());

    return cfg;
}
 
Example 3
Source File: RebalanceCompleteDuringExchangeTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Starts node and blocks exchange on it.
 *
 * @param nodeNum Number of node.
 * @return Test communication spi.
 * @throws Exception If failed.
 */
public TestRecordingCommunicationSpi startNodeAndBlockExchange(int nodeNum) throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(nodeNum)));

    TestRecordingCommunicationSpi commSpi = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    commSpi.blockMessages(GridDhtPartitionsSingleMessage.class, getTestIgniteInstanceName(0));

    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        try {
            IgniteEx ignite2 = startGrid(cfg);
        }
        catch (Exception e) {
            log.error("Start clustr exception " + e.getMessage(), e);
        }
    });

    return commSpi;
}
 
Example 4
Source File: TcpCommunicationSpiHalfOpenedConnectionTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    if (igniteInstanceName.contains("client"))
        clientSpi = (TcpCommunicationSpi)cfg.getCommunicationSpi();

    ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setUsePairedConnections(pairedConnections);

    return cfg;
}
 
Example 5
Source File: GridTcpCommunicationSpiConfigSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Checking local host on node.
 *
 * @param node Node.
 * @param emptyLocHost Check whether {@link
 *      IgniteConfiguration#getLocalHost} is empty.
 * @param emptyHostNamesAttr Check whether {@link
 *      TcpCommunicationSpi#ATTR_HOST_NAMES} attribute is empty.
 */
private void checkHostNamesAttr(IgniteEx node, boolean emptyLocHost, boolean emptyHostNamesAttr) {
    requireNonNull(node);

    IgniteConfiguration cfg = node.configuration();
    assertEquals(emptyLocHost, isNull(cfg.getLocalHost()));

    TcpCommunicationSpi spi = (TcpCommunicationSpi)cfg.getCommunicationSpi();
    assertEquals(
        emptyHostNamesAttr,
        ((Collection<String>)node.localNode().attribute(spiAttribute(spi, ATTR_HOST_NAMES))).isEmpty()
    );
}
 
Example 6
Source File: IgniteWalRebalanceTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0"); //to make all rebalance wal-based

    IgniteConfiguration cfg = super.getConfiguration(gridName);

    cfg.setConsistentId(gridName);

    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(CACHE_NAME)
        .setAtomicityMode(CacheAtomicityMode.ATOMIC)
        .setRebalanceMode(CacheRebalanceMode.ASYNC)
        .setCacheMode(CacheMode.PARTITIONED)
        .setBackups(backups)
        .setAffinity(new RendezvousAffinityFunction(false, PARTS_CNT));

    cfg.setCacheConfiguration(ccfg);

    DataStorageConfiguration dbCfg = new DataStorageConfiguration()
        .setWalSegmentSize(4 * 1024 * 1024)
        .setWalHistorySize(Integer.MAX_VALUE)
        .setWalMode(WALMode.LOG_ONLY)
        .setCheckpointFrequency(15 * 60 * 1000)
        .setDefaultDataRegionConfiguration(
            new DataRegionConfiguration()
                .setPersistenceEnabled(true)
                .setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE)
        );

    cfg.setDataStorageConfiguration(dbCfg);

    cfg.setCommunicationSpi(new WalRebalanceCheckingCommunicationSpi());

    if (blockMessagePredicate != null) {
        TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) cfg.getCommunicationSpi();

        spi.blockMessages(blockMessagePredicate);
    }

    return cfg;
}
 
Example 7
Source File: NotOptimizedRebalanceTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Starts node with name <code>name</code> and blocks demand message for custom caches.
 *
 * @param name Node instance name.
 * @return Test communication SPI.
 * @throws Exception If failed.
 */
private TestRecordingCommunicationSpi startNodeWithBlockingRebalance(String name) throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration(name));

    TestRecordingCommunicationSpi communicationSpi = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    communicationSpi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage demandMessage = (GridDhtPartitionDemandMessage)msg;

            if (CU.cacheId(DEFAULT_CACHE_NAME) != demandMessage.groupId())
                return false;

            info("Message was caught: " + msg.getClass().getSimpleName()
                + " rebalanceId = " + U.field(demandMessage, "rebalanceId")
                + " to: " + node.consistentId()
                + " by cache id: " + demandMessage.groupId());

            return true;
        }

        return false;
    });

    startGrid(cfg);

    return communicationSpi;
}
 
Example 8
Source File: RebalanceCancellationTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Starts node with name <code>name</code> and blocks demand message for custom caches.
 *
 * @param name Node instance name.
 * @return Test communication SPI.
 * @throws Exception If failed.
 */
private TestRecordingCommunicationSpi startNodeWithBlockingRebalance(String name) throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration(name));

    TestRecordingCommunicationSpi communicationSpi = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    communicationSpi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage demandMessage = (GridDhtPartitionDemandMessage)msg;

            if (CU.cacheId(DEFAULT_CACHE_NAME) != demandMessage.groupId()
                && CU.cacheId(MEM_REGOIN_CACHE) != demandMessage.groupId())
                return false;

            info("Message was caught: " + msg.getClass().getSimpleName()
                + " rebalanceId = " + U.field(demandMessage, "rebalanceId")
                + " to: " + node.consistentId()
                + " by cache id: " + demandMessage.groupId());

            return true;
        }

        return false;
    });

    startGrid(cfg);

    return communicationSpi;
}
 
Example 9
Source File: IgnitionEx.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize default SPI implementations.
 *
 * @param cfg Ignite configuration.
 */
private void initializeDefaultSpi(IgniteConfiguration cfg) {
    if (cfg.getDiscoverySpi() == null)
        cfg.setDiscoverySpi(new TcpDiscoverySpi());

    if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) {
        TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)cfg.getDiscoverySpi();

        if (tcpDisco.getIpFinder() == null)
            tcpDisco.setIpFinder(new TcpDiscoveryMulticastIpFinder());
    }

    if (cfg.getCommunicationSpi() == null)
        cfg.setCommunicationSpi(new TcpCommunicationSpi());

    if (cfg.getDeploymentSpi() == null)
        cfg.setDeploymentSpi(new LocalDeploymentSpi());

    if (cfg.getEventStorageSpi() == null)
        cfg.setEventStorageSpi(new NoopEventStorageSpi());

    if (cfg.getCheckpointSpi() == null)
        cfg.setCheckpointSpi(new NoopCheckpointSpi());

    if (cfg.getCollisionSpi() == null)
        cfg.setCollisionSpi(new NoopCollisionSpi());

    if (cfg.getFailoverSpi() == null)
        cfg.setFailoverSpi(new AlwaysFailoverSpi());

    if (cfg.getLoadBalancingSpi() == null)
        cfg.setLoadBalancingSpi(new RoundRobinLoadBalancingSpi());
    else {
        Collection<LoadBalancingSpi> spis = new ArrayList<>();

        boolean dfltLoadBalancingSpi = false;

        for (LoadBalancingSpi spi : cfg.getLoadBalancingSpi()) {
            spis.add(spi);

            if (!dfltLoadBalancingSpi && spi instanceof RoundRobinLoadBalancingSpi)
                dfltLoadBalancingSpi = true;
        }

        // Add default load balancing SPI for internal tasks.
        if (!dfltLoadBalancingSpi)
            spis.add(new RoundRobinLoadBalancingSpi());

        cfg.setLoadBalancingSpi(spis.toArray(new LoadBalancingSpi[spis.size()]));
    }

    if (cfg.getIndexingSpi() == null)
        cfg.setIndexingSpi(new NoopIndexingSpi());

    if (cfg.getEncryptionSpi() == null)
        cfg.setEncryptionSpi(new NoopEncryptionSpi());

    if (F.isEmpty(cfg.getMetricExporterSpi()))
        cfg.setMetricExporterSpi(new NoopMetricExporterSpi());

    if (F.isEmpty(cfg.getSystemViewExporterSpi())) {
        if (IgniteComponentType.INDEXING.inClassPath()) {
            try {
                cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi(),
                    U.newInstance(SYSTEM_VIEW_SQL_SPI));
            }
            catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }

        }
        else
            cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());
    }
}
 
Example 10
Source File: ClusterRebalancedMetricTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Starts node with blocked ability to demand {@link GridAbstractTest#DEFAULT_CACHE_NAME} partitions
 * from other nodes.
 *
 * @param idx Index of the node to be started.
 * @return Communication SPI instance of the node that was started.
 */
private TestRecordingCommunicationSpi startGridWithRebalanceBlocked(int idx) throws Exception {
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx));

    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) cfg.getCommunicationSpi();

    spi.blockMessages((node, msg) -> {
        if (!(msg instanceof GridDhtPartitionDemandMessage))
            return false;

        GridDhtPartitionDemandMessage demandMsg = (GridDhtPartitionDemandMessage) msg;

        return CU.cacheId(DEFAULT_CACHE_NAME) == demandMsg.groupId();
    });

    startGrid(cfg);

    return spi;
}
 
Example 11
Source File: TxPartitionCounterStateConsistencyTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param idx Starting node index.
 * @return Ignite.
 * @throws Exception If failed.
 */
private Ignite startNodeWithBlockingSupplying(int idx) throws Exception {
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx));

    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    spi.blockMessages(GridDhtPartitionSupplyMessage.class, getTestIgniteInstanceName(1));

    return startGrid(optimize(cfg));
}
 
Example 12
Source File: IgniteCacheAtomicMessageRecoveryPairedConnectionsTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpCommunicationSpi commSpi = (TcpCommunicationSpi)cfg.getCommunicationSpi();

    assertFalse(commSpi.isUsePairedConnections());

    commSpi.setUsePairedConnections(true);

    return cfg;
}
 
Example 13
Source File: HistoricalReservationTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Execute some action before historical rebalance.
 *
 * @param someAction Some action, executing before rebalance.
 * @throws Exception If faild.
 */
public void historicalRebalance(IgniteRunnable someAction) throws Exception {
    String rebalancedNodeName = getTestIgniteInstanceName(CLUSTER_NODES) + "_rebalance";

    IgniteEx ignite0 = startGrids(CLUSTER_NODES);
    IgniteEx rebalancedNode = startGrid(rebalancedNodeName);

    ignite0.cluster().active(true);

    preloadData(ignite0, 0, 100);

    forceCheckpoint();

    awaitPartitionMapExchange();

    rebalancedNode.close();

    preloadData(ignite0, 100, 200);

    awaitPartitionMapExchange();

    someAction.run();

    AtomicBoolean hasFullRebalance = new AtomicBoolean();

    IgniteConfiguration cfg = getConfiguration(rebalancedNodeName);

    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    spi.record((node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage demandMsg = (GridDhtPartitionDemandMessage)msg;

            if (!F.isEmpty(demandMsg.partitions().fullSet()))
                hasFullRebalance.compareAndSet(false, true);
        }

        return false;
    });

    rebalancedNode = startGrid(cfg);

    rebalancedNode.cluster().active(true);

    awaitPartitionMapExchange();

    assertFalse("Full rebalance appeared where only the  historical one was expected.", hasFullRebalance.get());

    assertPartitionsSame(idleVerify(rebalancedNode, DEFAULT_CACHE_NAME));
}
 
Example 14
Source File: CachePartitionLostAfterSupplierHasLeftTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 *
 */
@Test
public void testPartitionConsistencyOnSupplierRestart() throws Exception {
    lossPlc = PartitionLossPolicy.READ_ONLY_SAFE;
    persistence = true;

    int entryCnt = PARTS_CNT * 200;

    IgniteEx crd = (IgniteEx)startGridsMultiThreaded(2);

    crd.cluster().active(true);

    IgniteCache<Integer, String> cache0 = crd.cache(DEFAULT_CACHE_NAME);

    for (int i = 0; i < entryCnt / 2; i++)
        cache0.put(i, String.valueOf(i));

    forceCheckpoint();

    stopGrid(1);

    for (int i = entryCnt / 2; i < entryCnt; i++)
        cache0.put(i, String.valueOf(i));

    final IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(1));

    final TestRecordingCommunicationSpi spi1 = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    spi1.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
        @Override public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtPartitionDemandMessage) {
                GridDhtPartitionDemandMessage msg0 = (GridDhtPartitionDemandMessage)msg;

                return msg0.groupId() == CU.cacheId(DEFAULT_CACHE_NAME);
            }

            return false;
        }
    });

    startGrid(cfg);

    spi1.waitForBlocked(1);

    // Will cause a cancellation of rebalancing because a supplier has left.
    stopGrid(0);

    awaitPartitionMapExchange();

    final Collection<Integer> lostParts = grid(1).cache(DEFAULT_CACHE_NAME).lostPartitions();

    assertEquals(PARTS_CNT, lostParts.size());

    final IgniteEx g0 = startGrid(0);

    final Collection<Integer> lostParts2 = g0.cache(DEFAULT_CACHE_NAME).lostPartitions();

    assertEquals(PARTS_CNT, lostParts2.size());

    spi1.stopBlock();

    g0.resetLostPartitions(Collections.singletonList(DEFAULT_CACHE_NAME));

    awaitPartitionMapExchange();

    assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
}