store

package
v0.0.0-...-133fc75 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package store 存储发号进度

Index

Examples

Constants

View Source
const (

	// DefaultConnectTimeout is the default timeout to establish a connection to
	// a ZooKeeper node.
	DefaultConnectTimeout = 2 * time.Second
	// DefaultSessionTimeout is the default timeout to keep the current
	// ZooKeeper session alive during a temporary disconnect.
	DefaultSessionTimeout = 5 * time.Second
)

Variables

View Source
var (
	// ErrEtcdFail 从etcd中Range出错
	ErrEtcdFail = errors.New("etcd save error")
	// ErrEtcdNotFound 从etcd中获取单个key出错
	ErrEtcdNotFound = errors.New("etcd key not found")
)
View Source
var (
	DefaultACL            = zk.WorldACL(zk.PermAll)
	ErrInvalidCredentials = errors.New("invalid credentials provided")
	ErrZKFail             = errors.New("zk save error")
)

DefaultACL is the default ACL to use for creating znodes.

View Source
var (
	ErrDBNotExists = errors.New("zk: db does not exist")
)

Functions

This section is empty.

Types

type Etcd

type Etcd struct {
	KV v3.KV
	// contains filtered or unexported fields
}

A Etcd 使用etcd 存储发号元数据

func NewEtcd

func NewEtcd(clientURI string, logger *logrus.Entry) Etcd

NewEtcd 获取redis实例

Example
log := logrus.NewEntry(logrus.New())
db := NewEtcd(testURI, log)

ctx, cancel := context.WithTimeout(context.Background(), timeout)
err := db.Ping(ctx)
cancel()
if err != nil {
	log.Fatal(err)
}
Output:

func (Etcd) BlockDB

func (p Etcd) BlockDB(dataCenter uint8, db string) bool

func (Etcd) Init

func (p Etcd) Init(dataCenter uint8) error

Init 这里可以完成初始化方法,保证服务的可用

func (Etcd) Ping

func (p Etcd) Ping(ctx context.Context) error

Ping 测试连接状态

func (Etcd) Range

func (p Etcd) Range(ctx context.Context, dataCenter uint8, db, table string, size int64) (int64, error)

Range 分片分配进度, 返回v 表示可用范围[v, v+size)

type Option

type Option func(*zkConfig) error

Option functions enable friendly APIs.

func ConnectTimeout

func ConnectTimeout(t time.Duration) Option

ConnectTimeout returns an Option specifying a non-default connection timeout when we try to establish a connection to a ZooKeeper server.

func Credentials

func Credentials(user, pass string) Option

Credentials returns an Option specifying a user/password combination which the client will use to authenticate itself with.

func EventHandler

func EventHandler(handler func(zk.Event)) Option

EventHandler returns an Option specifying a callback function to handle incoming zk.Event payloads (ZooKeeper connection events).

func Payload

func Payload(payload [][]byte) Option

Payload returns an Option specifying non-default data values for each znode created by CreateParentNodes.

func SessionTimeout

func SessionTimeout(t time.Duration) Option

SessionTimeout returns an Option specifying a non-default session timeout.

type Redis

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

A Redis 使用redis作存储

func NewRedis

func NewRedis(redisAddr string, logger *logrus.Entry) Redis

NewRedis 获取redis实例

Example
log := logrus.NewEntry(logrus.New())
db := NewRedis(testRedis, log)
err := db.Ping(context.TODO())
if err != nil {
	log.Fatal(err)
}
Output:

func (Redis) BlockDB

func (p Redis) BlockDB(dataCenter uint8, db string) bool

func (Redis) Init

func (p Redis) Init(dataCenter uint8) error

Init 这里可以完成初始化方法,保证服务的可用

func (Redis) Ping

func (p Redis) Ping(_ context.Context) error

Ping 测试连接状态

func (Redis) Range

func (p Redis) Range(_ context.Context, dataCenter uint8, db, table string, size int64) (int64, error)

Range 分片分配进度, 返回v 表示可用范围[v, v+size)

type Store

type Store interface {
	// Range 获取数据,传入数据中心ID,业务唯一ID和获取连续的区间大小,得到连续的最大ID和错误[id-size, id)
	Range(ctx context.Context, dataCenter uint8, db, table string, size int64) (id int64, err error)
	// Init 这里可以完成初始化方法,保证服务的可用
	Init(dataCenter uint8) error

	BlockDB(dataCenter uint8, db string) bool
	// Ping 检查连接
	Ping(ctx context.Context) error
}

A Store 存储接口

func NewStore

func NewStore(storeType, uri string, dataCenter uint8, logger *logrus.Entry) Store

type ZK

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

A ZK 使用zookeeper做存储

func NewZK

func NewZK(clientURI string, logger *logrus.Entry, options ...Option) ZK

NewZK 获取redis实例

func (ZK) BlockDB

func (p ZK) BlockDB(dataCenter uint8, db string) bool

func (ZK) Init

func (p ZK) Init(dataCenter uint8) error

Init 这里可以完成初始化方法,保证服务的可用

func (ZK) Ping

func (p ZK) Ping(_ context.Context) error

Ping 测试连接状态

func (ZK) Range

func (p ZK) Range(_ context.Context, dataCenter uint8, db, table string, size int64) (int64, error)

Range 分片分配进度, 返回v 表示可用范围[v, v+size)

func (*ZK) Stop

func (p *ZK) Stop()

Stop implements the ZooKeeper Client interface.

Jump to

Keyboard shortcuts

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