pd

package
v0.0.0-...-f0aa2c5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ZeroID use for check
	ZeroID uint64 = 0
)

Variables

View Source
var (
	// EventInit event init
	EventInit = uint32(1 << 1)
	// EventCellCreated event cell created
	EventCellCreated = uint32(1 << 2)
	// EventCellLeaderChanged event cell created
	EventCellLeaderChanged = uint32(1 << 3)
	// EventCellRangeChaned event cell range changed
	EventCellRangeChaned = uint32(1 << 4)
	// EventCellPeersChaned event cell peer changed
	EventCellPeersChaned = uint32(1 << 5)
	// EventStoreUp event store status was up
	EventStoreUp = uint32(1 << 6)
	// EventStoreDown event store status was down
	EventStoreDown = uint32(1 << 7)
	// EventStoreTombstone event store status was tombstone
	EventStoreTombstone = uint32(1 << 8)

	// EventFlagCell all cell event
	EventFlagCell = uint32(EventCellCreated | EventCellLeaderChanged | EventCellRangeChaned | EventCellPeersChaned)
	// EventFlagStore all store event
	EventFlagStore = uint32(EventStoreUp | EventStoreDown | EventStoreTombstone)
	// EventFlagAll all event
	EventFlagAll = uint32(0xffffffff)
)
View Source
var (

	// ErrNotLeader pd is not leader
	ErrNotLeader = errors.New("PD Server Not Leader")
)
View Source
var (
	// ErrWatcherStopped watcher is stopped
	ErrWatcherStopped = errors.New("watcher is stopped")
)

Functions

func MatchEvent

func MatchEvent(event, flag uint32) bool

MatchEvent returns the flag has the target event

Types

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Client pd client

func NewClient

func NewClient(name string, initAddrs ...string) (*Client, error)

NewClient create a pd client use init pd pdAddrs

func (*Client) AllocID

func (c *Client) AllocID(ctx context.Context, req *pdpb.AllocIDReq) (*pdpb.AllocIDRsp, error)

AllocID returns a uniq id

func (*Client) AskSplit

func (c *Client) AskSplit(ctx context.Context, req *pdpb.AskSplitReq) (*pdpb.AskSplitRsp, error)

AskSplit returns ask split response

func (*Client) BootstrapCluster

func (c *Client) BootstrapCluster(ctx context.Context, req *pdpb.BootstrapClusterReq) (*pdpb.BootstrapClusterRsp, error)

BootstrapCluster returns bootstrap cluster response

func (*Client) CellHeartbeat

func (c *Client) CellHeartbeat(ctx context.Context, req *pdpb.CellHeartbeatReq) (*pdpb.CellHeartbeatRsp, error)

CellHeartbeat returns cell heartbeat response

func (*Client) Close

func (c *Client) Close() error

Close close conn

func (*Client) GetClusterID

func (c *Client) GetClusterID(ctx context.Context, req *pdpb.GetClusterIDReq) (*pdpb.GetClusterIDRsp, error)

GetClusterID returns cluster id

func (*Client) GetInitParams

func (c *Client) GetInitParams(ctx context.Context, req *pdpb.GetInitParamsReq) (*pdpb.GetInitParamsRsp, error)

GetInitParams returns cluster init params

func (*Client) GetLastPD

func (c *Client) GetLastPD() string

GetLastPD returns last pd server

func (*Client) GetLastRanges

func (c *Client) GetLastRanges(ctx context.Context, req *pdpb.GetLastRangesReq) (*pdpb.GetLastRangesRsp, error)

GetLastRanges returns lastest key ranges

func (*Client) GetLeader

func (c *Client) GetLeader(ctx context.Context, req *pdpb.LeaderReq) (*pdpb.LeaderRsp, error)

GetLeader returns current leader

func (*Client) GetStore

func (c *Client) GetStore(ctx context.Context, req *pdpb.GetStoreReq) (*pdpb.GetStoreRsp, error)

GetStore returns get store response

func (*Client) IsClusterBootstrapped

func (c *Client) IsClusterBootstrapped(ctx context.Context, req *pdpb.IsClusterBootstrapReq) (*pdpb.IsClusterBootstrapRsp, error)

IsClusterBootstrapped returns cluster is bootstrapped response

func (*Client) ListStore

func (c *Client) ListStore(ctx context.Context, req *pdpb.ListStoreReq) (*pdpb.ListStoreRsp, error)

ListStore returns list store response

func (*Client) PutStore

func (c *Client) PutStore(ctx context.Context, req *pdpb.PutStoreReq) (*pdpb.PutStoreRsp, error)

PutStore returns put store response

func (*Client) RegisterWatcher

func (c *Client) RegisterWatcher(ctx context.Context, req *pdpb.RegisterWatcherReq) (*pdpb.RegisterWatcherRsp, error)

RegisterWatcher register a watcher for newest cell info notify

func (*Client) ReportSplit

func (c *Client) ReportSplit(ctx context.Context, req *pdpb.ReportSplitReq) (*pdpb.ReportSplitRsp, error)

ReportSplit returns report split response

func (*Client) SetName

func (c *Client) SetName(name string)

SetName set name of client

func (*Client) StoreHeartbeat

func (c *Client) StoreHeartbeat(ctx context.Context, req *pdpb.StoreHeartbeatReq) (*pdpb.StoreHeartbeatRsp, error)

StoreHeartbeat returns store heartbeat response

func (*Client) WatcherHeartbeat

func (c *Client) WatcherHeartbeat(ctx context.Context, req *pdpb.WatcherHeartbeatReq) (*pdpb.WatcherHeartbeatRsp, error)

WatcherHeartbeat update the watcher lastest alive time

type Watcher

type Watcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Watcher is watch pd event

func NewWatcher

func NewWatcher(client *Client, addr string, eventFlag uint32, heartbeat time.Duration) *Watcher

NewWatcher returns a watcher. The watcher will listen form pd at the addr parameter

func (*Watcher) Ready

func (w *Watcher) Ready() (*pdpb.WatchEvent, error)

Ready returns the event return a error if watcher was stopped

func (*Watcher) Start

func (w *Watcher) Start() error

Start start the watch If watcher was started, use Ready method in a loop to receive the newest notify

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stop the watcher

Jump to

Keyboard shortcuts

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