dister

package
v0.0.0-...-07370e6 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

封装API常用方法

数据同步需要注意的是: leader只有在通知完所有follower更新完数据之后,自身才会进行数据更新 因此leader

数据同步需要注意的是,必须在节点完成election选举之后才能进行数据通信。 也就是说repl通信需要建立在raft成功作为前提

数据同步需要注意的是: leader只有在通知完所有follower更新完数据之后,自身才会进行数据更新 因此leader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Receive

func Receive(conn net.Conn) []byte

获取数据

func Send

func Send(conn net.Conn, data []byte) error

发送数据

Types

type LogEntry

type LogEntry struct {
	Id    int64 // 唯一ID
	Act   int
	Items interface{} // map[string]string或[]string
}

日志记录项

type Msg

type Msg struct {
	Head int
	Body []byte
	Info NodeInfo
}

消息

type Node

type Node struct {
	Group string // 集群名称
	Id    string // 节点ID(根据算法自动生成的集群唯一名称)
	Name  string // 节点主机名称
	Ip    string // 主机节点的ip,由通信的时候进行填充,
	// 一个节点可能会有多个IP,这里保存最近通信的那个,节点唯一性识别使用的是Name字段
	CfgFilePath      string                   // 配置文件绝对路径
	CfgReplicated    bool                     // 本地配置对象是否已同步到leader(配置同步需要注意覆盖问题)
	Peers            *gmap.StringInterfaceMap // 集群所有的节点信息(ip->节点信息),不包含自身
	Role             int32                    // 集群角色
	RaftRole         int32                    // RAFT角色
	Leader           *NodeInfo                // Leader节点信息
	MinNode          int32                    // 最小节点数
	Score            int64                    // 选举比分
	ScoreCount       int32                    // 选举比分的节点数
	ElectionDeadline int64                    // 选举超时时间点
	AutoScan         bool                     // 启动时自动扫描局域网,添加dister节点

	LogIdIndex       int64                    // 用于生成LogId的参考字段
	LastLogId        int64                    // 最后一次保存log的id,用以数据一致性判断
	LastServiceLogId int64                    // 最后一次保存的service id号,用以识别本地Service数据是否已更新,不做Leader与Follower的同步数据
	LogList          *glist.SafeList          // 日志列表,用以存储临时的消息日志,以便快速进行数据同步到其他节点,仅在Leader节点存储
	ServiceList      *glist.SafeList          // Service同步事件列表,用以Service同步
	SavePath         string                   // 物理存储的本地数据*目录*绝对路径
	Service          *gmap.StringInterfaceMap // 存储的服务配置表
	DataMap          *gmap.StringStringMap    // 存储的K-V哈希表
	// contains filtered or unexported fields
}

服务器节点信息

func NewServer

func NewServer() *Node

绑定本地IP并创建一个服务节点

func (*Node) Run

func (n *Node) Run()

运行节点

func (*Node) SendToLeader

func (n *Node) SendToLeader(head int, port int, body []byte) ([]byte, error)

向leader发送操作请求,并返回执行结果

func (*Node) SetSavePath

func (n *Node) SetSavePath(path string)

设置数据保存目录路径

type NodeApiBalance

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

用于Service 负载均衡API接口的对象

func (*NodeApiBalance) Get

负载均衡查询

type NodeApiKv

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

用于KV API接口的对象

func (*NodeApiKv) Delete

func (this *NodeApiKv) Delete(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse)

K-V 删除

func (*NodeApiKv) Get

K-V 查询

func (*NodeApiKv) Post

func (this *NodeApiKv) Post(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse)

K-V 新增/修改

type NodeApiNode

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

用于Node API接口的对象

func (*NodeApiNode) Delete

func (this *NodeApiNode) Delete(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse)

删除Peer

func (*NodeApiNode) Get

查询Peers

func (*NodeApiNode) Post

新增/修改Peer

type NodeApiService

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

用于Service API接口的对象

func (*NodeApiService) Delete

Service 删除

func (*NodeApiService) Get

Service 查询

func (*NodeApiService) Post

Service 新增/修改

type NodeInfo

type NodeInfo struct {
	Name             string `json:"name"`
	Group            string `json:"group"`
	Id               string `json:"id"`
	Ip               string `json:"ip"`
	Status           int32  `json:"status"`
	Role             int32  `json:"role"`
	RaftRole         int32  `json:"raft"`
	LastLogId        int64  `json:"logid"`
	LastServiceLogId int64  `json:"serviceid"`
	Version          string `json:"version"`
}

节点信息

type PriorityNode

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

用于负载均衡计算的结构体

type Service

type Service struct {
	Type string                 `json:"type"`
	Node map[string]interface{} `json:"node"`
}

服务节点对象(用于程序更新及检索结构)

type ServiceConfig

type ServiceConfig struct {
	Name string                   `json:"name"`
	Type string                   `json:"type"`
	Node []map[string]interface{} `json:"node"`
}

服务信息配置对象(用于配置结构)

Directories

Path Synopsis
dister日志模块 顶部索引域:随机数(14bit,固定4位正整数)数据开始位置(43bit,8TB) 数据长度(23bit,8MB) 底部数据域:[消息数据](变长)
dister日志模块 顶部索引域:随机数(14bit,固定4位正整数)数据开始位置(43bit,8TB) 数据长度(23bit,8MB) 底部数据域:[消息数据](变长)

Jump to

Keyboard shortcuts

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