dkron的fsm是怎样的
发表于:2026-11-04 作者:千家信息网编辑
千家信息网最后更新 2026年11月04日,今天就跟大家聊聊有关dkron的fsm是怎样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。MessageType// MessageType
千家信息网最后更新 2026年11月04日dkron的fsm是怎样的
今天就跟大家聊聊有关dkron的fsm是怎样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
MessageType
// MessageType is the type to encode FSM commands.type MessageType uint8const ( // SetJobType is the command used to store a job in the store. SetJobType MessageType = iota // DeleteJobType is the command used to delete a Job from the store. DeleteJobType // SetExecutionType is the command used to store an Execution to the store. SetExecutionType // DeleteExecutionsType is the command used to delete executions from the store. DeleteExecutionsType // ExecutionDoneType is the command to perform the logic needed once an exeuction // is done. ExecutionDoneType)
MessageType可以分为SetJobType、DeleteJobType、SetExecutionType、DeleteExecutionsType、ExecutionDoneType
dkronFSM
type dkronFSM struct { store Storage // proAppliers holds the set of pro only LogAppliers proAppliers LogAppliers}// NewFSM is used to construct a new FSM with a blank statefunc newFSM(store Storage, logAppliers LogAppliers) *dkronFSM { return &dkronFSM{ store: store, proAppliers: logAppliers, }}// Apply applies a Raft log entry to the key-value store.func (d *dkronFSM) Apply(l *raft.Log) interface{} { buf := l.Data msgType := MessageType(buf[0]) log.WithField("command", msgType).Debug("fsm: received command") switch msgType { case SetJobType: return d.applySetJob(buf[1:]) case DeleteJobType: return d.applyDeleteJob(buf[1:]) case ExecutionDoneType: return d.applyExecutionDone(buf[1:]) case SetExecutionType: return d.applySetExecution(buf[1:]) } // Check enterprise only message types. if applier, ok := d.proAppliers[msgType]; ok { return applier(buf[1:], l.Index) } return nil}func (d *dkronFSM) applySetJob(buf []byte) interface{} { var pj dkronpb.Job if err := proto.Unmarshal(buf, &pj); err != nil { return err } job := NewJobFromProto(&pj) if err := d.store.SetJob(job, false); err != nil { return err } return nil}func (d *dkronFSM) applyDeleteJob(buf []byte) interface{} { var djr dkronpb.DeleteJobRequest if err := proto.Unmarshal(buf, &djr); err != nil { return err } job, err := d.store.DeleteJob(djr.GetJobName()) if err != nil { return err } return job}func (d *dkronFSM) applyExecutionDone(buf []byte) interface{} { var execDoneReq dkronpb.ExecutionDoneRequest if err := proto.Unmarshal(buf, &execDoneReq); err != nil { return err } execution := NewExecutionFromProto(execDoneReq.Execution) log.WithField("execution", execution.Key()). WithField("output", string(execution.Output)). Debug("fsm: Setting execution") _, err := d.store.SetExecutionDone(execution) return err}func (d *dkronFSM) applySetExecution(buf []byte) interface{} { var pbex dkronpb.Execution if err := proto.Unmarshal(buf, &pbex); err != nil { return err } execution := NewExecutionFromProto(&pbex) key, err := d.store.SetExecution(execution) if err != nil { return err } return key}// Snapshot returns a snapshot of the key-value store. We wrap// the things we need in dkronSnapshot and then send that over to Persist.// Persist encodes the needed data from dkronSnapshot and transport it to// Restore where the necessary data is replicated into the finite state machine.// This allows the consensus algorithm to truncate the replicated log.func (d *dkronFSM) Snapshot() (raft.FSMSnapshot, error) { return &dkronSnapshot{store: d.store}, nil}// Restore stores the key-value store to a previous state.func (d *dkronFSM) Restore(r io.ReadCloser) error { defer r.Close() return d.store.Restore(r)}// LogApplier is the definition of a function that can apply a Raft logtype LogApplier func(buf []byte, index uint64) interface{}dkronFSM定义了store、proAppliers属性;Apply方法将raft的log保存到KV存储中,具体分不同msgType做不同处理;最后根据msgType查找LogAppliers
小结
dkron的FSM根据不同msgType做不同处理,具体有applySetJob、applyDeleteJob、applyExecutionDone、applySetExecution方法。
看完上述内容,你们对dkron的fsm是怎样的有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。
不同
内容
方法
处理
小结
属性
更多
知识
篇文章
行业
资讯
资讯频道
频道
进一
存储
支持
有关
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
华服互联网科技靠谱吗
广州万易互联网科技有限公司
北京互联网科技有限公司
互联网科技视频
卓越科技(互联网 )
亿策互联网科技
善班互联网科技有限公司
易通互联网络科技有限公司
米客互联网科技
融贸通互联网科技
互联网科技有限公司 翻译
华中科技有哪些互联网大佬
开启互联网科技时代小说
中国的互联网科技企业的崛起
昭通互联网科技选哪家
电子科技大学互联网创业大赛
科技赋能视角下互联网保险发展
21世纪互联网科技成就
半导体是互联网高科技吗
郑州欣桑互联网科技有限公司
互联网科技会
互联网科技集团
碳银互联网科技
掌上梦互联网科技
恒银科技与互联网金融
顶级互联网科技成果有哪些
彤创互联网科技有限公司
搜狐科技互联网
世界互联网领先科技成果获奖
互联网金融科技名词解释