点燃远程群集[无法映射缓存键(所有分区节点都离开网格)]

时间:2018-08-20 03:09:31

标签: java ignite

我在远程Ignite群集上创建缓存K,V对时遇到一些问题。我的Ignite节点建立在Java8的Maven项目上,通过多播配置进行集群,并具有分区缓存。这里面临的问题是,当集群中只有1个节点时,ignite只能通过SqlFieldQuery或NoSQL成功创建和检索缓存。当我将其缩放到大于1(在本例中为2)时,我会遇到远程服务器抛出的错误。

Caused by: org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException: Failed to map keys for cache (all partition nodes left the grid) [topVer=AffinityTopologyVersion [topVer=5, minorTopVer=3], cache=Transactions]
at org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.serverNotFoundError(GridPartitionedSingleGetFuture.java:711) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.mapKeyToNode(GridPartitionedSingleGetFuture.java:332) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.map(GridPartitionedSingleGetFuture.java:216) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.init(GridPartitionedSingleGetFuture.java:208) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache.getAsync(GridDhtColocatedCache.java:246) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.GridCacheAdapter.get0(GridCacheAdapter.java:4556) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:4537) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:1350) ~[ignite-core-2.6.0.jar:2.6.0]
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.get(IgniteCacheProxyImpl.java:907) ~[ignite-core-2.6.0.jar:2.6.0]

这是我的服务器设置:

public class App 
{
    protected static IgniteConfiguration config;
    protected static String igniteID = UUID.randomUUID().toString();

    public static void main( String[] args )
    {
        System.out.println( "Starting instance of Ignite..." );
        config = new IgniteConfiguration();
        config.setIgniteInstanceName("ignite-node-"+igniteID);
        config.setClientMode(false);
        setupDiscoveryConfig();
        setupDataConfig();
        //cacheConfig();
        config.setPeerClassLoadingEnabled(false);
        config.setDeploymentMode(DeploymentMode.CONTINUOUS);
        config.setPeerClassLoadingMissedResourcesCacheSize(0);
        config.setFailureDetectionTimeout(10000);
        config.setClientFailureDetectionTimeout(10000);
        config.setNetworkTimeout(10000);
        Ignite ignite = Ignition.start(config);
        loadAndRemove(ignite);

    }

    private static void loadAndRemove(Ignite ignite) {
        ignite.cluster().active();
        IgniteCache<String, TransactionRecord> cache = ignite.getOrCreateCache("Transactions");
    }

    private static void cacheConfig(){
        CacheConfiguration cacheConfig = new CacheConfiguration("Transactions");
        cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        cacheConfig.setCacheMode(CacheMode.PARTITIONED);
        config.setCacheConfiguration(cacheConfig);
    }


    private static void setupDataConfig(){
        DataStorageConfiguration storageConfiguration = new DataStorageConfiguration();
        storageConfiguration.getDefaultDataRegionConfiguration()
                .setPersistenceEnabled(true);
        config.setDataStorageConfiguration(storageConfiguration);
    }

    private static void setupDiscoveryConfig(){
        TcpDiscoverySpi spi = new TcpDiscoverySpi();
        TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
        ((TcpDiscoveryMulticastIpFinder) ipFinder).setMulticastGroup("228.10.10.157");
        ipFinder.setAddresses(Arrays.asList("127.0.0.1"));
        spi.setIpFinder(ipFinder);
        config.setDiscoverySpi(spi);
    }
}

客户端配置如下所示:

@Bean
    public Ignite igniteInstance(){
        IgniteConfiguration config = new IgniteConfiguration();
        config.setIgniteInstanceName("cluster-client");
        config.setClientMode(true);
        config.setPeerClassLoadingEnabled(false);
        config.setDeploymentMode(DeploymentMode.CONTINUOUS);
        config.setPeerClassLoadingMissedResourcesCacheSize(0);
        config.setFailureDetectionTimeout(10000);
        config.setClientFailureDetectionTimeout(10000);
        config.setNetworkTimeout(10000);
        TcpDiscoverySpi spi = new TcpDiscoverySpi();
        TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
        ipFinder.setMulticastGroup("228.10.10.157");
        ipFinder.setAddresses(Arrays.asList("127.0.0.1"));
        spi.setIpFinder(ipFinder);
        config.setDiscoverySpi(spi);
        return Ignition.getOrStart(config);
    }

数据插入使用简单的cache.put命令。感谢有人可以帮我解决这个问题。

2 个答案:

答案 0 :(得分:2)

很可能您的群集只有一个基准节点,这意味着所有数据仅存储在该节点上。当它离开集群时,所有缓存操作都将引发此异常,因为没有剩余的亲和力节点。

为避免这种情况,仅应在所有服务器节点启动后才激活集群。如果拓扑发生更改,则应该带回出现故障的节点,或者重置为基准拓扑以触发分区的重新分配和重新平衡。

这里是如何通过代码设置基线拓扑:

Collection<ClusterNode> nodes = ignite.cluster().forServers().nodes();
ignite.cluster().setBaselineTopology(nodes);

有关基线拓扑功能的文档:https://apacheignite.readme.io/docs/baseline-topology

答案 1 :(得分:0)

停用集群

停用会在所有群集节点上取消分配所有内存资源,包括您的应用程序数据,并禁用公共群集API。如果您的内存高速缓存未由持久性存储备份,则将丢失数据,并且必须重新填充这些高速缓存。 要停用群集,请使用以下方法之一:

// Connect to the cluster.
Ignite ignite = Ignition.start();

// Deactivate the cluster. 
ignite.cluster().active(false);

根据代码设置拓扑

如上所述,当您手动激活集群时,基线拓扑会自动初始化。使用IgniteCluster.activate()方法从代码激活集群。然后,您可以使用IgniteCluster.setBaseLineTopogy()方法来调整现有的基线拓扑。请注意,必须激活集群才能调用该方法。

设置基准拓扑节点 将群集拓扑设置为基准拓扑

 // Connect to the cluster.
Ignite ignite = Ignition.start();

// Activate the cluster.
// This is required only if the cluster is still inactive.
ignite.cluster().active(true);

// Get all server nodes that are already up and running.
Collection<ClusterNode> nodes = ignite.cluster().forServers().nodes();

// Set the baseline topology that is represented by these nodes.
ignite.cluster().setBaselineTopology(nodes);

如果稍后更新基准拓扑,例如,通过向其添加新节点,则Ignite将在所有基准节点之间自动重新平衡数据。