Hazelcast MapStoreConfig被忽略 [英] Hazelcast MapStoreConfig ignored

查看:159
本文介绍了Hazelcast MapStoreConfig被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用地图存储将hazelcast分布式地图保存在数据库中.

I'm using a map store to persist my hazelcast distributed map in a database.

在我的测试案例中,我启动了三个hazelcast实例,每个实例的配置方式相同:

In my test case, I start three hazelcast instances, each configured the same way:

Config cfg = new Config();
cfg.setInstanceName("name");
hazelcast = Hazelcast.newHazelcastInstance(cfg);    
MapConfig mapConfig = new MapConfig("myMapName");
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setClassName(MyMapStore.class.getName());
mapStoreConfig.setWriteDelaySeconds(0);
mapStoreConfig.setEnabled(true);
mapConfig.setMapStoreConfig(mapStoreConfig);
mapConfig.setBackupCount(2);
hazelcast.getConfig().addMapConfig(mapConfig);
IMap myMap = hazelcast.getMap("myMapName");

但是,当我向地图添加值时,只有第一个Cluster成员写入数据库时​​,MapStoreConfig才在每个其他节点上都设置为Default values. 但是,如果我将代码更改为以下代码,那么它将起作用:

However, when I add values to the map, only the first Cluster member writes into the database, the MapStoreConfig is just set to Default values on each other node. But, if I change the code to the following, it works:

Config cfg = new Config();
cfg.setInstanceName("name");
MapConfig mapConfig = new MapConfig("myMapName");
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setClassName(MyMapStore.class.getName());
mapStoreConfig.setWriteDelaySeconds(0);
mapStoreConfig.setEnabled(true);
mapConfig.setMapStoreConfig(mapStoreConfig);
mapConfig.setBackupCount(2);
cfg.addMapConfig(mapConfig);
hazelcast = Hazelcast.newHazelcastInstance(cfg);
IMap myMap = hazelcast.getMap("myMapName");

似乎忽略了行hazelcast.getConfig().addMapConfig(mapConfig);. 经过hazelcast v3.1.5的测试.

Seems like the line hazelcast.getConfig().addMapConfig(mapConfig); is ignored. Tested with hazelcast v3.1.5.

推荐答案

据我了解,Config实例应仅被视为一种模板",用于创建一个实例,但此后可能无法用于修改.尽管根据快速的网络搜索和对文档的了解,并没有明确说明,但是

To my understanding, the Config instance should be considered only as a sort of "template", which is used to create one instance, but may not be used to afterwards modify this instance. Although, according to a quick websearch and a look at the documentation, this is not stated explicitly, but

  1. 到目前为止,我所看到的所有示例都遵循FIRST创建和完整Config的模式,然后再创建相应的实例,
  2. addMapConfig方法(在 https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/config/Config.java )不涉及任何通知机制.因此,至少必须有某种机制可以通知Hazelcast实例有关已更改的配置,但是我认为这样的机制不存在.
  1. all examples that I have seen so far follow the pattern of FIRST creating and the complete Config, and THEN creating the corresponding instance and
  2. the addMapConfig method (in https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/config/Config.java ) does not involve any notification mechanism. So there would at least have to be some mechanism to inform the Hazelcast instance about the changed config, but I think that such a mechanism does not exist.

根据我在源代码中所读的内容(例如,在 https://github.com /hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/instance/HazelcastInstanceImpl.java ),该配置文件在构造时仅 read ,并且创建Hazelcast实例后,似乎不可能在 后更改配置.

From what I have read in the source code ( e.g. in https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/instance/Node.java and https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/instance/HazelcastInstanceImpl.java ), the Config is only read at construction time, and it does not seem to be possible to change the configuration after the Hazelcast instance has been created.

这篇关于Hazelcast MapStoreConfig被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆