-
Notifications
You must be signed in to change notification settings - Fork 352
raft
bobohume edited this page Feb 19, 2021
·
2 revisions
raft同步参考
raft中文参考
raft采用hashicorp/raft,配合服发现集群,只需要实现raft状态机即可,可以mmo战斗raft同步,配合a,b版本就可以实现热更新战斗
fsm基本状态机
shardingfsm分片状态机,可以通过64uid+hashring分片确定分部在那一台机器,分布式缓存,不需要关注,集群内存分部,实现起来,具体参考
func (this *RaftManager) Add(Id int64){
if !this.IsLeader(){
return
}
_, clusterId := this.GetHashRing(Id)
info := raft.ShardingInfo{Op:"add", Id:Id, ClusterId:clusterId}
this.Apply(info.ToByte(), 10*time.Microsecond)
}
func (this *RaftManager) Del(Id int64){
if !this.IsLeader(){
return
}
info := raft.ShardingInfo{Op:"del", Id:Id, ClusterId:0}
this.Apply(info.ToByte(), 10*time.Microsecond)
}
func (this *RaftManager) IsSharding(Id int64) bool{
clusterId := this.m_Fsm.Get(Id)
if this.Id() == clusterId{
return true
}
return false
}
add添加分片到raft集群,del删除分片到raft集群,issharding是否为缓存分片,缓存可以不用内存同步,每台分片服务器彼此独立,分片idraft同步,类似mogodb