Instroduce Hazelcast

Post on 11-May-2015

4.281 views 0 download

Transcript of Instroduce Hazelcast

Hazelcast[ˈheizəlkɑ:st]

jushi@taobao.com

Hazelcast is an open source clustering and highly scalable data distribution platform for Java

-- www.hazelcast.com

从代码入手Get started from code example

Map.put(key, value) => partitions[hash&mod(key)]

.addEntry(key, value)

Map.put(key, value) => partitions[hash&mod(key)]

.getOwner()

.addEntry(key, value)

0 2701 2 …

Blocks (Partitions)

Hazelcast Instance (Node)

有了 MAP , 就有了一切Map is everything

Set.add(value) => Map.put(value, true)

Queue.offer(value) =>key = Master.genKeyBy(qName)index = Integer.MAX_VALUEMap.put(key, value)Master.add(key, index)

Queue.poll() =>key = Master.takeKeyBy(qName)Map.get(key)

逐出与存储Eviction & Persistence

enum EvictionPolicy {LRU, LFU, NONE

}

interface MapMaxSizePolicy {boolean overCapacity()

}

periodRun() => Records.foreach {

case isDirty(record) =>store(record)

case isEvictable(record) => evict(record)

case isPurgeable(record) =>purge(record)

}

interface MapStore<K, V>  {...}

???

集群Cluster

Member / Super ClientMap map = Hazelcast.getMap(“default”);

Java ClientMap map = HazelcastClient

.newHazelcastClient(“dev”, “pass”, ...)

.getMap(“default”);

Super Clients are members with no storage.

Node 1

<<Master>>

Node 2

<<Master>> <<Master>>

Split Brain

备份与迁移backup, migration

Node 1

<<Master>>

Node 3

Node 2

Node 4

(key, value)(key’, value’)

Node 1

<<Master>>

Node 2

总结Summary

应用模式Application

Hazelcast Client

Hazelcast Instance

Application Client

Application

Hazelcast Instance

优点 缺点• 接口丰富• 使用简单• 监控完善

• 无存储实现• 代码复杂• 测试覆盖较低

In-Memory Data Grid

Q&A

参考References

源码导读Code review guide

Hazelcast

Node

FactoryImpl

BaseManager

ConcurrentMapManager

BlockQueueManager

ClusterManager

ClusterService CMap

BQ

PartitionManager Joiner

EOF