Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReplicatedMap not configured properly #8298

Closed
magiccrafter opened this issue Jun 2, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@magiccrafter
Copy link

commented Jun 2, 2016

ReplicatedMap is being miss-configured as IMap.
This can be easily verified after application startup in jmx client such as java mission control.
The section for ReplicatedMap is there and the map as well but after checking the MBean's attributes of the map it turns out that the "config" attribute contains the properties of an IMap one:

MapConfig{name='default'', inMemoryFormat=BINARY', backupCount=1, asyncBackupCount=0, timeToLiveSeconds=0, maxIdleSeconds=0, evictionPolicy='NONE', evictionPercentage=25, minEvictionCheckMillis=100, maxSizeConfig=MaxSizeConfig{maxSizePolicy='PER_NODE', size=2147483647}, readBackupData=false, hotRestart=HotRestartConfig{enabled=false, fsync=false}, nearCacheConfig=null, mapStoreConfig=MapStoreConfig{enabled=false, className='null', factoryClassName='null', writeDelaySeconds=0, writeBatchSize=1, implementation=null, factoryImplementation=null, properties={}, readOnly=null, initialLoadMode=LAZY, writeCoalescing=true}, mergePolicyConfig='com.hazelcast.map.merge.PutIfAbsentMapMergePolicy', wanReplicationRef=null, entryListenerConfigs=[], mapIndexConfigs=[], mapAttributeConfigs=[], quorumName=null, queryCacheConfigs=[], cacheDeserializedValues=INDEX_ONLY} String config -1 MapConfig

I believe this is the reason why when using declarative annotation-based caching (i.e. @Cacheable) in the Spring based application leads to creation of another IMap with same "default" name and the ReplicatedMap is never used.

Configuration (Spring Programmatic):

@Configuration
public class HazelcastInstanceConfig {

    /** Helper constants */
    private static final String HZ_MEMBERS_SEPARATOR = ",";

    /** Hazelcast Maps */
    public static final String REPL_MAP = "test";

    @Autowired
    private EntrySerializableFactory entrySerializableFactory;


    @Bean
    public CacheManager cacheManager() {
        return new HazelcastCacheManager(hazelcastInstance());
    }

    @Bean
    public HazelcastInstance hazelcastInstance() {
        Config config = new Config();

        //Cluster
        String clusterName = getClusterName();
        config.setInstanceName(clusterName);
        config.getGroupConfig().setName(clusterName);
        config.getGroupConfig().setPassword(hzProperties.getGroupPassword());

        //Network
        NetworkConfig network = config.getNetworkConfig();
        network.setPort(hzProperties.getHazelcastPort());
        network.setPortAutoIncrement(hzProperties.isPortAutoIncrement());
        JoinConfig join = network.getJoin();
        join.getMulticastConfig().setEnabled(false);
        TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
        tcpIpConfig.setEnabled(true);
        tcpIpConfig.setMembers(Arrays.asList(hzProperties.getMembers().split(HZ_MEMBERS_SEPARATOR)));

        //Maps
        config.addReplicatedMapConfig(new ReplicatedMapConfig().setName(REPL_MAP)
                .setInMemoryFormat(InMemoryFormat.OBJECT)
                .setStatisticsEnabled(true));

        //Serializers
        config.getSerializationConfig().addDataSerializableFactory(
                EntrySerializableFactory.FACTORY_ID, entrySerializableFactory);

        //Instance
        return Hazelcast.newHazelcastInstance(config);
    }

    protected String getClusterName() {
        return hzProperties.getGroupName();
    }
}
@magiccrafter

This comment has been minimized.

Copy link
Author

commented Jun 2, 2016

For clarity here is the picture that visualizes exactly how it looks like:
image

@jerrinot jerrinot added this to the 3.7 milestone Jun 2, 2016

@pveentjer pveentjer self-assigned this Jun 7, 2016

@pveentjer

This comment has been minimized.

Copy link
Member

commented Jun 7, 2016

The problem is in the ReplicatedMapMBean:

Errror

  @ManagedAnnotation("config")
    @ManagedDescription("MapConfig")
    public String getConfig() {
        return service.instance.getConfig().findMapConfig(managedObject.getName()).toString();
    }

Fix:


    @ManagedAnnotation("config")
    @ManagedDescription("ReplicatedMapConfig")
    public String getConfig() {
        return service.instance.getConfig().findReplicatedMapConfig(managedObject.getName()).toString();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.