Connect

package
v0.0.0-...-e11b555 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Listener_error
)

Variables

View Source
var ClientListeners []ClientListener
View Source
var ServerListeners []ServerListener

Functions

func ParserFileName

func ParserFileName(pathname string) bool

* @brief: 解析从json提取出的文件名 * @return: 正确返回true;否则false,这里不区分各种错误类型 * @notes: 一下根据机器不同可以配置,Golang我没有找到接口可以直接获得以下值,所以手动配置 * Linux下使用getconf PATH_MAX /usr 获取路径长度限制;4096 * getconf NAME_MAX /usr 获取文件名称长度限制;255 * 还有一点是我个人的要求,后缀必须是hdb,就是这么傲娇 * 文件名的限制 : https://en.wikipedia.org/wiki/Filename * 目前搜到的文件名限制就是不允许采用"/"和" ",且"-"不能是第一个字符

func ParserIP

func ParserIP(address string) bool

* @brief: 解析从json提取出的ip地址项 * @return: 正确返回true;否则false * @notes: net包的ip解析函数有点蛋疼,没办法解析"ip:port",只能解析"ip/port",或者"ip"

func RegisterRestClientListener

func RegisterRestClientListener(l ClientListener)

func RegisterRestServerListener

func RegisterRestServerListener(l ServerListener)

func ReturnInterval

func ReturnInterval(n int) int
  • @brief: 李浩帮忙推出的服务器连接时间间隔函数

  • @return: 毫秒,调用方不用转换

  • @notes: TODO 目前看起来并不符合预期;后面可以再改,

  • @example: 0 695 893 1005 1083 // 可以看出前几次重试斜率还是太陡峭,后面太过平缓 1142 1190 1230 1265 1295 1322 1347 1369 1389 1408 1426 1442 1457 1472 1485

func Sbyte2str

func Sbyte2str(b []byte) string

[]byte转string

func Str2sbyte

func Str2sbyte(s string) (b []byte)

string转ytes

Types

type ClientConfig

type ClientConfig struct {
	ServersAddress []string `json:"client_address"` // 从配置文件中读取服务器的地址
	Maxreries      int      `json:"maxreries"`      // 超时重连最大数
	// contains filtered or unexported fields
}

func CreateClient

func CreateClient() *ClientConfig

func (*ClientConfig) Acquire

func (cfg *ClientConfig) Acquire(fd *BaseServer.FileDescriptor, LockType int, Timeout uint32) (bool, uint64)

func (*ClientConfig) Append

func (cfg *ClientConfig) Append(key string, value string)

func (*ClientConfig) CheckToken

func (cfg *ClientConfig) CheckToken(AbsolutePath string, token uint64) bool

* @param: 给出文件名和手中持有的token,返回**此时刻**token是否有效 * @brief: 可以传入绝对路径和相对路径,也不能叫相对路径

func (*ClientConfig) CheckTokenAt

func (cfg *ClientConfig) CheckTokenAt(pathname string, filename string, token uint64) bool

func (*ClientConfig) CompareAndSwap

func (cfg *ClientConfig) CompareAndSwap(Key string, Old int, New int, Flag int) bool

* @brief: 提供一个更为灵活的CAS操作,具体的定义见compareSwap.go文件首部

func (*ClientConfig) Create

func (cfg *ClientConfig) Create(fd *BaseServer.FileDescriptor, fileType int, filename string) (bool, *BaseServer.FileDescriptor)

func (*ClientConfig) Delete

func (cfg *ClientConfig) Delete(fd *BaseServer.FileDescriptor, opType int) bool

func (*ClientConfig) FastGet

func (cfg *ClientConfig) FastGet(key string) string

* @brief: FastGet不提供任何一致性保证,适用于读极多写极少的情况,此时讲并发map的策略改为syncmap更优,性能可以提升百分之二十到三十

func (*ClientConfig) Get

func (cfg *ClientConfig) Get(key string) string

func (*ClientConfig) GetUniqueFlake

func (cfg *ClientConfig) GetUniqueFlake() uint64

func (*ClientConfig) Open

func (cfg *ClientConfig) Open(pathname string) (bool, *BaseServer.FileDescriptor)

func (*ClientConfig) Put

func (cfg *ClientConfig) Put(key string, value string)

func (*ClientConfig) Release

func (cfg *ClientConfig) Release(fd *BaseServer.FileDescriptor, token uint64) bool

func (*ClientConfig) SetUniqueFlake

func (cfg *ClientConfig) SetUniqueFlake(value uint64)

func (*ClientConfig) StartClient

func (cfg *ClientConfig) StartClient() error

* @brief: 再调用这个函数的时候开始服务, * @return: 三种返回类型:路径解析错误;connectAll连接出现问题;成功

type ClientListener

type ClientListener func(filename string, cfg *ClientConfig) bool

type Empty

type Empty interface{}

type ErrorInConnectAll

type ErrorInConnectAll int8 // 特用于connectAll的返回值 因为有三种错误 无法用bool表示

func (ErrorInConnectAll) Error

func (err ErrorInConnectAll) Error() string

type ErrorInParserConfig

type ErrorInParserConfig int8

func (ErrorInParserConfig) Error

func (err ErrorInParserConfig) Error() string

type ErrorInStartServer

type ErrorInStartServer int8 // 特用于StartServer与StartClient的返回值 因为有四种错误 无法用bool表示

func (ErrorInStartServer) Error

func (err ErrorInStartServer) Error() string

type Semaphore

type Semaphore chan Empty

func (Semaphore) P

func (s Semaphore) P(n int)

acquire n resources

func (Semaphore) V

func (s Semaphore) V(n int)

release n resources

type ServerConfig

type ServerConfig struct {

	// 不设置成大写没办法从配置文件中读出来
	MaxRaftState   int      `json:"maxraftstate"`    // raft层日志压缩上限
	Maxreries      int      `json:"maxreries"`       // 超时重连最大数
	ServersAddress []string `json:"servers_address"` // 读取配置文件中的其他服务器地址
	MyPort         string   `json:"myport"`          // 自己的端口号
	TimeOutEntry   int      `json:"timeout_entry"`   // connectAll中定义的重传超时间隔 单位为毫秒
	// 这三个要在解析完以后传给persister
	// 后缀hdb全称为 "Honeycomb Database Backup file" 蜂巢数据备份文件
	SnapshotFileName    string `json:"snapshotfilename"`    // 快照的持久化文件名
	RaftstateFileName   string `json:"raftstatefilename"`   // raft状态的持久化名
	PersistenceStrategy string `json:"persistencestrategy"` // 对应着三条策略 见persister.go 注意配置文件中不能拼写错误
	ChubbyGoMapStrategy string `json:"chubbygomapstrategy"` // 对应两条策略:syncmap,concurrentmap;详细见chubbygomap.go
	// contains filtered or unexported fields
}

func CreatServer

func CreatServer(nservers int) *ServerConfig

* @brief: 返回一个Config结构体,用于开始一个服务 * @param: nservers这个集群需要的机器数,包括本身,而且每个服务器初始化的时候必须配置正确

func (*ServerConfig) StartServer

func (cfg *ServerConfig) StartServer() error

* @brief: 再调用这个函数的时候开始服务, * @return: 三种返回类型:路径解析错误;connectAll连接出现问题;成功

type ServerListener

type ServerListener func(filename string, cfg *ServerConfig) bool

Jump to

Keyboard shortcuts

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