cache

package
v0.0.0-...-a32e77c Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnableWriteTrue  = int32(1)
	EnableWriteFalse = int32(0)
)

Variables

This section is empty.

Functions

func JoinRaftCluster

func JoinRaftCluster(opts *Options) error

JoinRaftCluster 加入raft集群

func NewCacheManager

func NewCacheManager() *cacheManager

Types

type FSM

type FSM struct {
	Ctx *StCachedContext
	Log *log.Logger
}

FSM : finite state machine,有限状态机

func (*FSM) Apply

func (f *FSM) Apply(logEntry *raft.Log) interface{}

Apply applies a Raft log entry to the key-value store.

func (*FSM) Restore

func (f *FSM) Restore(serialized io.ReadCloser) error

Restore stores the key-value store to a previous state. 服务重启的时候,会先读取本地的快照来恢复数据,在FSM里面定义的Restore函数会被调用

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a latest snapshot 生成一个快照结构

type HttpServer

type HttpServer struct {
	Mux *http.ServeMux
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(ctx *StCachedContext, log *log.Logger) *HttpServer

func (*HttpServer) SetWriteFlag

func (h *HttpServer) SetWriteFlag(flag bool)

type LogEntryData

type LogEntryData struct {
	Key   string
	Value string
}

type Options

type Options struct {
	HttpAddress    string // http server address
	RaftTCPAddress string // construct Raft Address

	JoinAddress string // peer address to join
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions() *Options

type RaftNodeInfo

type RaftNodeInfo struct {
	Raft *raft.Raft

	LeaderNotifyCh chan bool
	// contains filtered or unexported fields
}

func NewRaftNode

func NewRaftNode(opts *Options, ctx *StCachedContext) (*RaftNodeInfo, error)

type Snapshot

type Snapshot struct {
	Cm *cacheManager
}

func (*Snapshot) Persist

func (s *Snapshot) Persist(sink raft.SnapshotSink) error

Persist saves the FSM Snapshot out to the given sink. 在Persist里面,自己把缓存里面的数据用json格式化的方式来生成快照,sink.Write就是把快照写入snapStore,我们刚才定义的是FileSnapshotStore,所以会把数据写入文件。

func (*Snapshot) Release

func (f *Snapshot) Release()

type StCached

type StCached struct {
	Hs   *HttpServer
	Opts *Options
	Log  *log.Logger
	Cm   *cacheManager
	Raft *RaftNodeInfo
}

type StCachedContext

type StCachedContext struct {
	St *StCached
}

Jump to

Keyboard shortcuts

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