raft_service

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandInit     = "init"
	SystemNamespace = "__system"

	EventReset    = "reset"
	EventComplete = "complete"
)

Variables

View Source
var (
	ErrInvalidNamespace     = errors.New("invalid namespace")
	ErrInvalidCommitHandler = errors.New("invalid commit handler")
	ErrInvalidCommand       = errors.New("invalid command")
)

Functions

This section is empty.

Types

type Commend added in v0.1.0

type Commend struct {
	Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
	Cmd       string `protobuf:"bytes,2,opt,name=cmd,proto3" json:"cmd,omitempty"`
	Body      []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`
	// contains filtered or unexported fields
}

func (*Commend) Descriptor deprecated added in v0.1.0

func (*Commend) Descriptor() ([]byte, []int)

Deprecated: Use Commend.ProtoReflect.Descriptor instead.

func (*Commend) GetBody added in v0.1.0

func (x *Commend) GetBody() []byte

func (*Commend) GetCmd added in v0.1.0

func (x *Commend) GetCmd() string

func (*Commend) GetNamespace added in v0.1.0

func (x *Commend) GetNamespace() string

func (*Commend) ProtoMessage added in v0.1.0

func (*Commend) ProtoMessage()

func (*Commend) ProtoReflect added in v0.1.0

func (x *Commend) ProtoReflect() protoreflect.Message

func (*Commend) Reset added in v0.1.0

func (x *Commend) Reset()

func (*Commend) String added in v0.1.0

func (x *Commend) String() string

type ICommitEventHandler added in v0.3.0

type ICommitEventHandler func(namespace, cmd string)

type ICreateHandler added in v0.1.0

type ICreateHandler interface {
	Namespace() string
	Handler() IRaftServiceHandler
}

func NewCreateHandler added in v0.1.0

func NewCreateHandler(namespace string, handler IRaftServiceHandler) ICreateHandler

type IRaftEventHandler added in v0.3.0

type IRaftEventHandler func(event string)

type IRaftServiceHandler added in v0.1.0

type IRaftServiceHandler interface {
	// ResetHandler  初始化snapshot
	ResetHandler(data []byte) error
	// Append 追加需要初始化的日志
	Append(cmd string, data []byte) error
	// Complete 初始化完成
	Complete() error

	// CommitHandler 节点commit信息前的处理
	CommitHandler(cmd string, data []byte) error
	// Snapshot 获取快照
	Snapshot() []byte
	// ProcessHandler leader 节点propose信息前的处理
	ProcessHandler(cmd string, body []byte) ([]byte, interface{}, error)
}

type IService added in v0.1.0

type IService interface {
	Send(namespace, cmd string, body []byte) (interface{}, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService() *Service

func (*Service) AddCommitEventHandler added in v0.3.0

func (s *Service) AddCommitEventHandler(h ICommitEventHandler)

func (*Service) AddEventHandler added in v0.3.0

func (s *Service) AddEventHandler(h IRaftEventHandler)

func (*Service) Append added in v0.3.0

func (s *Service) Append(cmd string, data []byte) error

func (*Service) Commit added in v0.3.0

func (s *Service) Commit(data []byte) error

func (*Service) CommitHandler

func (s *Service) CommitHandler(cmd string, data []byte) error

func (*Service) Complete added in v0.3.0

func (s *Service) Complete() error

func (*Service) GetInit

func (s *Service) GetInit() ([]byte, error)

func (*Service) GetSnapshot

func (s *Service) GetSnapshot() ([]byte, error)

func (*Service) PreProcessData added in v0.3.0

func (s *Service) PreProcessData(inBody []byte) (object interface{}, data []byte, err error)

func (*Service) ProcessHandler

func (s *Service) ProcessHandler(cmd string, body []byte) ([]byte, interface{}, error)

func (*Service) ResetHandler added in v0.3.0

func (s *Service) ResetHandler(data []byte) error

func (*Service) ResetSnap

func (s *Service) ResetSnap(data []byte) error

func (*Service) Send added in v0.1.0

func (s *Service) Send(namespace, cmd string, body []byte) (interface{}, error)

func (*Service) SetHandler added in v0.1.0

func (s *Service) SetHandler(namespace string, handler IRaftServiceHandler)

func (*Service) SetHandlers added in v0.1.0

func (s *Service) SetHandlers(handlers ...ICreateHandler)

func (*Service) SetRaft added in v0.1.0

func (s *Service) SetRaft(raft raft.IRaftSender)

func (*Service) Snapshot added in v0.3.0

func (s *Service) Snapshot() []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL