pd: github.com/tikv/pd/client Index | Files

package pd

import "github.com/tikv/pd/client"


Package Files

base_client.go client.go metrics.go

type Client Uses

type Client interface {
    // GetClusterID gets the cluster ID from PD.
    GetClusterID(ctx context.Context) uint64
    // GetAllMembers gets the members Info from PD
    GetAllMembers(ctx context.Context) ([]*pdpb.Member, error)
    // GetLeaderAddr returns current leader's address. It returns "" before
    // syncing leader from server.
    GetLeaderAddr() string
    // GetTS gets a timestamp from PD.
    GetTS(ctx context.Context) (int64, int64, error)
    // GetTSAsync gets a timestamp from PD, without block the caller.
    GetTSAsync(ctx context.Context) TSFuture
    // GetRegion gets a region and its leader Peer from PD by key.
    // The region may expire after split. Caller is responsible for caching and
    // taking care of region change.
    // Also it may return nil if PD finds no Region for the key temporarily,
    // client should retry later.
    GetRegion(ctx context.Context, key []byte) (*Region, error)
    // GetRegionFromMember gets a region from certain members.
    GetRegionFromMember(ctx context.Context, key []byte, memberURLs []string) (*Region, error)
    // GetPrevRegion gets the previous region and its leader Peer of the region where the key is located.
    GetPrevRegion(ctx context.Context, key []byte) (*Region, error)
    // GetRegionByID gets a region and its leader Peer from PD by id.
    GetRegionByID(ctx context.Context, regionID uint64) (*Region, error)
    // ScanRegion gets a list of regions, starts from the region that contains key.
    // Limit limits the maximum number of regions returned.
    // If a region has no leader, corresponding leader will be placed by a peer
    // with empty value (PeerID is 0).
    ScanRegions(ctx context.Context, key, endKey []byte, limit int) ([]*Region, error)
    // GetStore gets a store from PD by store id.
    // The store may expire later. Caller is responsible for caching and taking care
    // of store change.
    GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error)
    // GetAllStores gets all stores from pd.
    // The store may expire later. Caller is responsible for caching and taking care
    // of store change.
    GetAllStores(ctx context.Context, opts ...GetStoreOption) ([]*metapb.Store, error)
    // Update GC safe point. TiKV will check it and do GC themselves if necessary.
    // If the given safePoint is less than the current one, it will not be updated.
    // Returns the new safePoint after updating.
    UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint64, error)

    // UpdateServiceGCSafePoint updates the safepoint for specific service and
    // returns the minimum safepoint across all services, this value is used to
    // determine the safepoint for multiple services, it does not trigger a GC
    // job. Use UpdateGCSafePoint to trigger the GC job if needed.
    UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error)
    // ScatterRegion scatters the specified region. Should use it for a batch of regions,
    // and the distribution of these regions will be dispersed.
    ScatterRegion(ctx context.Context, regionID uint64) error
    // ScatterRegionWithOption scatters the specified region with the given options, should use it
    // for a batch of regions.
    ScatterRegionWithOption(ctx context.Context, regionID uint64, opts ...ScatterRegionOption) error
    // GetOperator gets the status of operator of the specified region.
    GetOperator(ctx context.Context, regionID uint64) (*pdpb.GetOperatorResponse, error)
    // Close closes the client.

Client is a PD (Placement Driver) client. It should not be used after calling Close().

func NewClient Uses

func NewClient(pdAddrs []string, security SecurityOption, opts ...ClientOption) (Client, error)

NewClient creates a PD client.

func NewClientWithContext Uses

func NewClientWithContext(ctx context.Context, pdAddrs []string, security SecurityOption, opts ...ClientOption) (Client, error)

NewClientWithContext creates a PD client with context.

type ClientOption Uses

type ClientOption func(c *baseClient)

ClientOption configures client.

func WithCustomTimeoutOption Uses

func WithCustomTimeoutOption(timeout time.Duration) ClientOption

WithCustomTimeoutOption configures the client with timeout option.

func WithGRPCDialOptions Uses

func WithGRPCDialOptions(opts ...grpc.DialOption) ClientOption

WithGRPCDialOptions configures the client with gRPC dial options.

type GetStoreOp Uses

type GetStoreOp struct {
    // contains filtered or unexported fields

GetStoreOp represents available options when getting stores.

type GetStoreOption Uses

type GetStoreOption func(*GetStoreOp)

GetStoreOption configures GetStoreOp.

func WithExcludeTombstone Uses

func WithExcludeTombstone() GetStoreOption

WithExcludeTombstone excludes tombstone stores from the result.

type Region Uses

type Region struct {
    Meta         *metapb.Region
    Leader       *metapb.Peer
    DownPeers    []*metapb.Peer
    PendingPeers []*metapb.Peer

Region contains information of a region's meta and its peers.

type ScatterRegionOp Uses

type ScatterRegionOp struct {
    // contains filtered or unexported fields

ScatterRegionOp represents available options when scatter regions

type ScatterRegionOption Uses

type ScatterRegionOption func(op *ScatterRegionOp)

ScatterRegionOption configures ScatterRegionOp

func WithGroup Uses

func WithGroup(group string) ScatterRegionOption

WithGroup specify the group during ScatterRegion

type SecurityOption Uses

type SecurityOption struct {
    CAPath   string
    CertPath string
    KeyPath  string

SecurityOption records options about tls

type TSFuture Uses

type TSFuture interface {
    // Wait gets the physical and logical time, it would block caller if data is not available yet.
    Wait() (int64, int64, error)

TSFuture is a future which promises to return a TSO.

Package pd imports 17 packages (graph) and is imported by 25 packages. Updated 2020-10-27. Refresh now. Tools for package owners.