model

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coon

type Coon struct {
	Srv            *Server // 服务对象
	Sock           Socket  // socket连接对象
	State          int     // 连接状态
	Type           int     // 连接类型
	Next           *Coon   // 链表下一条
	Use            *Tube   // 当前连接use的tube
	TickAt         int64
	TickPos        int
	InCoons        int
	SoonestJob     *Job // 快到期job
	Rw             byte // 连接类型('r':读 'w':写, '0':从epoll踢出)
	PendingTimeout int  // 连接阻塞超时时间
	HalfClosed     bool // 连接断开

	Cmd     []byte // cmd命令数据
	CmdLen  int    // cmd长度
	CmdRead int    // cmd当前读取长度

	Reply     []byte // 回复给客户端的数据
	ReplyLen  int64  // 数据长度
	ReplySent int64  // 已经发送的长度
	ReplyBuf  []byte

	InJobRead int64
	InJob     *Job

	OutJob     *Job
	OutJobSent int64

	Watch        *structure.Ms
	ReservedJobs *Job
}

Coon 连接对象

type File

type File struct {
	Next    *File
	Refs    uint
	Seq     int64
	IsWOpen bool
	F       *os.File
	Free    int64
	Resv    int64
	Path    string

	W       *Wal
	JobList Job
}

type Handle

type Handle func(interface{}, byte)

回调处理函数

type Job

type Job struct {
	// persistent fields; these get written to the wal
	R JobRec

	// bookeeping fields; these are in-memory only
	Pad [6]byte

	Tube        *Tube
	Prev, Next  *Job
	HtNext      *Job
	HeapIndex   int
	File        *File
	FPre, FNext *Job
	Reservoir   *Coon

	WalResv int64
	WalUsed int64

	Body []byte
}

type JobRec

type JobRec struct {
	ID       uint64
	Pri      uint32
	Delay    int64
	TTR      int64
	BodySize int64
	CreateAt int64

	// deadline_at is a timestamp, in nsec, that points to:
	// * time when job will become ready for delayed job,
	// * time when TTR is about to expire for reserved job,
	// * undefined otherwise.
	DeadlineAt int64

	ReserveCt uint32
	TimeoutCt uint32
	ReleaseCt uint32
	BuryCt    uint32
	KickCt    uint32
	State     byte
}

type JobRec5

type JobRec5 struct {
	ID         uint64
	Pri        uint32
	Delay      uint64
	TTR        uint64
	BodySize   int32
	CreatedAt  uint64
	DeadlineAt uint64
	ReserveCt  uint64
	TimeoutCt  uint32
	ReleaseCt  uint32
	BuryCt     uint32
	KickCt     uint32
	State      byte
	Pad        [1]byte
}

type Server

type Server struct {
	Options ServerOptions
	Wal     Wal

	Sock   *Socket
	Connes *structure.Heap
}

type ServerOption

type ServerOption func(*ServerOptions)

func WithAddr

func WithAddr(addr string) ServerOption

WithAddr 设置服务端监听ip

func WithPort

func WithPort(port int) ServerOption

WithPort 设置端口

func WithUser

func WithUser(user string) ServerOption

WithUser 运行用户

type ServerOptions

type ServerOptions struct {
	Port int // 服务端口
	Addr string
	User string
}

type Socket

type Socket struct {
	F           *os.File     // 打开文件
	Ln          net.Listener // 监听器
	H           Handle       // 处理函数
	X           interface{}  // 服务器对象|Conn
	Added       bool         // 是否已经添加到epoll
	AddedFilter int16        // 监听类型
}

Socket socket连接信息 以及listener接口

type State

type State struct {
	UrgentCt      uint64
	WaitingCt     uint64
	BuriedCt      uint64
	ReservedCt    uint64
	PauseCt       uint64
	TotalDeleteCt uint64
	TotalJobsCt   uint64
}

type Tube

type Tube struct {
	Name         string
	Ready        *structure.Heap
	Delay        *structure.Heap
	WaitingConns *structure.Ms // 等待在该tube上的客户端连接
	Stat         State         // job各个状态统计
	UsingCt      int           // tube正在被多少coon监听
	WatchingCt   int           // tube上watching的coon

	Pause     int64 // 暂停时间,单位nsec,pause-tube 命令设置
	UnpauseAt int64 // 暂停结束时间的时间戳

	Buried *Job // 休眠状态job链表
}

type Wal

type Wal struct {
	FileSize int64
	Use      bool
	Dir      string
	Head     *File
	Cur      *File
	Tail     *File
	NFile    int64
	Next     int64
	Resv     int64
	Alive    int64
	Nmig     int64
	Nrec     int64
	WantSync bool
	SyncRate int64
	LastSync int64
}

Jump to

Keyboard shortcuts

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