简体   繁体   English

如何设置 Apache 点燃缓存?

[英]How to set Apache Ignite Cache?

Here is my current Apache Ignite settings:这是我当前的 Apache Ignite 设置:

public class IgniteCacheConfig {

    @Bean
    public Ignite applicationIgnite() {
        Ignite ignite = Ignition.start(igniteConfiguration());
        ignite.cluster().active(true);
        return ignite;
    }

    @Bean
    public CacheConfiguration<String, AppRequest> applicationCacheConfig() {
        CacheConfiguration<String, AppRequest> cfg = new CacheConfiguration<>();
        int isPartitionMode = 0;
        int backups = 0;
        CacheMode cacheMode = CacheMode.PARTITIONED;
        if (0 == isPartitionMode) {
            cacheMode = CacheMode.REPLICATED;
        }
        cfg.setName("appCache");
        cfg.setCacheMode(cacheMode);
        cfg.setBackups(backups);
        cfg.setPartitionLossPolicy(PartitionLossPolicy.IGNORE);
        cfg.setDataRegionName("DA-1");
        cfg.setDefaultLockTimeout(0L);
        cfg.setExpiryPolicyFactory(CreatedExpiryPolicy
                .factoryOf(new Duration(SECONDS, 3600)));
        cfg.setOnheapCacheEnabled(false);
        cfg.setStatisticsEnabled(true);
        return cfg;
    }

    private IgniteConfiguration igniteConfiguration() {
        IgniteConfiguration cacheConfig = new IgniteConfiguration();
        cacheConfig.setClientMode(false);
        TransactionConfiguration transactionConfig = new TransactionConfiguration();
        transactionConfig.setDefaultTxTimeout(0L);
        cacheConfig.setTransactionConfiguration(transactionConfig);
        cacheConfig.setFailureDetectionTimeout(10000L);
        cacheConfig.setIgniteInstanceName("appListener");
        DataStorageConfiguration dsCfg = new DataStorageConfiguration();
        dsCfg.setConcurrencyLevel(32);
        DataRegionConfiguration defaultRegionConf = new DataRegionConfiguration();
        defaultRegionConf.setName("DA-1");
        defaultRegionConf.setInitialSize(1024 * 1024 * 100);
        defaultRegionConf.setMaxSize(1024 * 1024 * 500);
        defaultRegionConf.setEmptyPagesPoolSize(256);
        defaultRegionConf.setEvictionThreshold(0.8);
        defaultRegionConf.setPageEvictionMode(DataPageEvictionMode.RANDOM_2_LRU);
        defaultRegionConf.setPersistenceEnabled(true);
        dsCfg.setDefaultDataRegionConfiguration(defaultRegionConf);
        cacheConfig.setDataStorageConfiguration(dsCfg);

        TcpDiscoverySpi tcpDiscovery = new TcpDiscoverySpi();
        tcpDiscovery.setLocalPort(47500);
        tcpDiscovery.setAckTimeout(5000L);
        tcpDiscovery.setSocketTimeout(5000L);
        tcpDiscovery.setNetworkTimeout(5000L);
        tcpDiscovery.setStatisticsPrintFrequency(1000 * 60 * 15);

        final Set<String> mcastAddCol = Collections.singleton("127.0.0.1:47500..47509");

        final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder()
                .setAddresses(mcastAddCol);

        tcpDiscovery.setIpFinder(ipFinder);
        cacheConfig.setDiscoverySpi(tcpDiscovery);
        TcpCommunicationSpi communicationSpi = new TcpCommunicationSpi();
        communicationSpi.setSocketWriteTimeout(5000L);
        communicationSpi.setConnectTimeout(5000L);
        cacheConfig.setCommunicationSpi(communicationSpi);
        return cacheConfig;
    }
}

Here is my task For cache (in-memory distributed) Apache Ignite version 2.7 will be used, the cluster will be deployed separately.这是我的任务对于缓存(内存中分布式)Apache 将使用 Ignite 2.7 版本,集群将单独部署。 It is necessary to implement a connection to the cluster, reconnecting in the background during failures in working with Ignite.有必要实现与集群的连接,在使用 Ignite 失败时在后台重新连接。 If for some reason the cluster is unavailable, output to the log, assume that nothing was found in the cache.如果由于某种原因集群不可用,output 到日志中,假设在缓存中没有找到任何东西。

Now I'm getting an error:现在我收到一个错误:

Caused by: class org.apache.ignite.IgniteException: Failed to activate cluster

Can you suggest me any solution of starting the cluster and realizing my task about reconnecting because of a failure?您能否建议我启动集群并实现我因失败而重新连接的任务的任何解决方案?

I think there was a bug when you tried to activate the cluster on every node's start-up.我认为当您尝试在每个节点启动时激活集群时存在错误。 Maybe it's IGNITE-10417也许是IGNITE-10417

Please remember you only need to activate the cluster once, when all nodes are ready, as opposed to calling active() every time just in case.请记住,当所有节点都准备好时,您只需要激活一次集群,而不是每次都调用 active() 以防万一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM