hazelcast map 备份策略

来源:互联网 发布:mysql平均数 编辑:程序博客网 时间:2024/05/01 03:47

Backups

Hazelcast will distribute map entries onto multiple JVMs (cluster members). Each JVM holds some portion of the data but we don't want to lose data when a member JVM crashes. To provide data-safety, Hazelcast allows you to specify the number of backup copies you want to have. That way data on a JVM will be synchronously copied onto other JVM(s). By default, Hazelcast will have one backup copy. Backup operations aresynchronous. When a map.put(key,value) call returns, it means entry is updated on the both owner and backup JVMs. If backup count >= 1, then each member will carry both owned entries and backup copies of other member(s). So for the map.get(key)call, it is possible that calling member has backup copy of that key but by default, map.get(key) will always read the value from the actual owner of the key for consistency. It is possible to enable backup reads by changing the configuration. Enabling backup reads will give you greater performance.

<hazelcast>    ...    <map name="default">        <!--            Number of backups. If 1 is set as the backup-count for example,            then all entries of the map will be copied to another JVM for            fail-safety. Valid numbers are 0 (no backup), 1, 2, 3.        -->        <backup-count>1</backup-count>        <!--            Can we read the local backup entries? Default value is false for            strong consistency. Being able to read backup data will give you            greater performance.        -->        <read-backup-data>false</read-backup-data>        ...    </map></hazelcast>

Q. If I have only one backup-copy then, will I always lose data if two JVMs crash at the same time?

Not always. Cluster member list is the same on each member. Hazelcast will backup each member's data onto next members in the member list. Let say you have a cluster with members A, B, C, D, E, F, G and the backup-count is 1, then Hazelcast will copy A's data onto B, B's data onto C... and G's data onto A. If A and B crashes at the same time then you will lose data because B was the backup of A. But A and C crashes at the same time, you won't lose any data because B was the backup of A and D was the backup of C. So you will only lose that ifsequential-JVM-crash-count > backup-count.

原创粉丝点击