1
votes

I am using hazelcast 3.9 with spring boot as a caching backend, and using multiple distributed maps as the datastructure for caching. Most config parameters for the maps are common, like backup count, eviction policy etc, but some can be different, like time to live.

Is there away using which I can have a common map configuration that I can use as reference in configs of different maps?

I found some people using <map name="default"> in some open source repos, and it looked like they expect this config to be overridden by other map configs, but it is not working for me.

This is the config I am using currently:

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast
        xsi:schemaLocation="http://www.hazelcast.com/schema/config https://hazelcast.com/schema/config/hazelcast-config-3.9.xsd"
        xmlns="http://www.hazelcast.com/schema/config"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <group>
        <name>something</name>
        <password>something</password>
    </group>

    <properties>
        <property name="hazelcast.partition.count">83</property>
    </properties>

    <management-center enabled="true" update-interval="3">http://localhost:8081/mancenter</management-center>
    <network>
        <join>
            <multicast enabled="true"/>
        </join>
    </network>

    <map name="map1">
        <!--<max-size policy="PER_NODE">273</max-size>-->
        <max-size policy="USED_HEAP_PERCENTAGE">20</max-size>
        <eviction-policy>LFU</eviction-policy>
        <statistics-enabled>true</statistics-enabled>
        <backup-count>0</backup-count>
        <async-backup-count>1</async-backup-count>
        <read-backup-data>true</read-backup-data>

        <time-to-live-seconds>10800</time-to-live-seconds>  <!--3 hours-->
    </map>

    <map name="map2">
        <!--<max-size policy="PER_NODE">273</max-size>-->
        <max-size policy="USED_HEAP_PERCENTAGE">20</max-size>
        <eviction-policy>LFU</eviction-policy>
        <statistics-enabled>true</statistics-enabled>
        <backup-count>0</backup-count>
        <async-backup-count>1</async-backup-count>
        <read-backup-data>true</read-backup-data>

        <time-to-live-seconds>86400</time-to-live-seconds>  <!--24 hours-->
    </map>


</hazelcast>

I am not very familiar with using xmls, but I tried to find some way to refer xml elements in other xml elements, but that doesn't seem to be working either. Looks like DOCTYPE attribute isn't allowed in hazelcast config schema.

I also want to avoid hazelcast configuration through code.

1

1 Answers

4
votes

Hazelcast supports wildcard configuration for most of the data structures that are configured in the cluster. Using an asterisk (*) character in the name, different instances of maps, queues, topics, semaphores, etc. can be configured by a single configuration. See the example below:

<map name="map*">
    <max-size policy="USED_HEAP_PERCENTAGE">20</max-size>
    <eviction-policy>LFU</eviction-policy>
    <statistics-enabled>true</statistics-enabled>
    <backup-count>0</backup-count>
    <async-backup-count>1</async-backup-count>
    <read-backup-data>true</read-backup-data>
</map>

By using this configuration, both map1 and map2 will have the exact same configuration. But you need to use programmatic configuration if you want to add more configuration elements (such as time-to-live-seconds) by using a base config.