metadata

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TestResourceFactory test factory
	TestResourceFactory = func() Resource {
		return &TestResource{}
	}
)

Functions

func CountInJointState

func CountInJointState(peers ...metapb.Peer) int

CountInJointState count the peers are in joint state.

func IsInJointState

func IsInJointState(peers ...metapb.Peer) bool

IsInJointState judges whether the Peer is in joint state.

func IsLearner

func IsLearner(peer metapb.Peer) bool

IsLearner judges whether the Peer's Role is Learner.

func IsLearnerOrDemotingVoter

func IsLearnerOrDemotingVoter(peer metapb.Peer) bool

IsLearnerOrDemotingVoter judges whether peer role will become Learner. The peer is not nil and the role is equal to DemotingVoter or Learner.

func IsVoterOrIncomingVoter

func IsVoterOrIncomingVoter(peer metapb.Peer) bool

IsVoterOrIncomingVoter judges whether peer role will become Voter. The peer is not nil and the role is equal to IncomingVoter or Voter.

Types

type Adapter

type Adapter interface {
	// NewResource return a new resource
	NewResource() Resource
	// NewContainer return a new container
	NewContainer() Container
}

Adapter metadata adapter

func NewTestAdapter

func NewTestAdapter() Adapter

NewTestAdapter create test adapter

type Container

type Container interface {
	// SetAddrs set addrs
	SetAddrs(addr, shardAddr string)
	// Addr returns address that used for client request
	Addr() string
	// ShardAddr returns address that used for communication between the resource replications
	ShardAddr() string
	// SetID update the container id
	SetID(id uint64)
	// ID returns the container id
	ID() uint64
	// Labels returns the lable tag of the container
	Labels() []metapb.Pair
	// SetLabels set labels
	SetLabels(labels []metapb.Pair)
	// The start timestamp of the current container
	StartTimestamp() int64
	// SetStartTimestamp set the start timestamp of the current container
	SetStartTimestamp(int64)
	// Version returns version and githash
	Version() (string, string)
	// SetVersion set version
	SetVersion(version string, githash string)
	// DeployPath returns the container deploy path
	DeployPath() string
	// SetDeployPath set deploy path
	SetDeployPath(string)
	// State returns the state of the container
	State() metapb.ContainerState
	// SetState set state
	SetState(metapb.ContainerState)
	// The last heartbeat timestamp of the container.
	LastHeartbeat() int64
	//SetLastHeartbeat set the last heartbeat timestamp of the container.
	SetLastHeartbeat(int64)

	// Clone returns the cloned value
	Clone() Container
	// ActionOnJoinCluster returns the cluster will do what when a new container join the cluster
	ActionOnJoinCluster() metapb.Action

	// Marshal returns error if marshal failed
	Marshal() ([]byte, error)
	// Unmarshal returns error if unmarshal failed
	Unmarshal(data []byte) error
}

Container is an abstraction of the node in a distributed system. Usually a container has many resoruces

type Resource

type Resource interface {
	// SetID update the resource id
	SetID(id uint64)
	// ID returns the resource id
	ID() uint64
	// Peers returns the repication peers
	Peers() []metapb.Peer
	// SetPeers update the repication peers
	SetPeers(peers []metapb.Peer)
	// Range resource range
	Range() ([]byte, []byte)
	// SetStartKey set startKey
	SetStartKey([]byte)
	// SetEndKey set startKey
	SetEndKey([]byte)
	// Epoch returns resource epoch
	Epoch() metapb.ResourceEpoch
	// SetEpoch set epoch
	SetEpoch(metapb.ResourceEpoch)
	// Stale returns true if the other resource is older than current resource
	Stale(other Resource) bool
	// Changed returns true if the other resource is newer than current resource
	Changed(other Resource) bool
	// Labels returns the label pairs that determine which the resources will be scheduled to which nodes
	Labels() []metapb.Pair
	// Clone returns the cloned value
	Clone() Resource

	// ScaleCompleted returns true if the current resource has been successfully scaled according to the specified container
	ScaleCompleted(uint64) bool

	// Marshal returns error if marshal failed
	Marshal() ([]byte, error)
	// Unmarshal returns error if unmarshal failed
	Unmarshal(data []byte) error

	// SupportRebalance support rebalance the resource
	SupportRebalance() bool
	// SupportTransferLeader support transfer leader
	SupportTransferLeader() bool
}

Resource is an abstraction of data shard in a distributed system. Each Resource has multiple replication and is distributed on different nodes.

type RoleChangeHandler

type RoleChangeHandler interface {
	ProphetBecomeLeader()
	ProphetBecomeFollower()
}

RoleChangeHandler prophet role change handler

func NewTestRoleHandler

func NewTestRoleHandler(leaderCB, followerCB func()) RoleChangeHandler

NewTestRoleHandler create test adapter

type TestContainer

type TestContainer struct {
	CID            uint64        `json:"cid"`
	CAddr          string        `json:"addr"`
	CShardAddr     string        `json:"shardAddr"`
	CLabels        []metapb.Pair `json:"labels"`
	StartTS        int64         `json:"startTS"`
	CLastHeartbeat int64         `json:"lastHeartbeat"`
	CVerion        string        `json:"version"`
	CGitHash       string        `json:"gitHash"`
	CDeployPath    string        `json:"deployPath"`

	CState  metapb.ContainerState `json:"state"`
	CAction metapb.Action         `json:"action"`
}

TestContainer mock

func NewTestContainer

func NewTestContainer(id uint64) *TestContainer

NewTestContainer mock

func (*TestContainer) ActionOnJoinCluster

func (c *TestContainer) ActionOnJoinCluster() metapb.Action

ActionOnJoinCluster mock

func (*TestContainer) Addr

func (c *TestContainer) Addr() string

Addr mock

func (*TestContainer) Clone

func (c *TestContainer) Clone() Container

Clone mock

func (*TestContainer) DeployPath

func (c *TestContainer) DeployPath() string

DeployPath returns the container deploy path

func (*TestContainer) ID

func (c *TestContainer) ID() uint64

ID mock

func (*TestContainer) Labels

func (c *TestContainer) Labels() []metapb.Pair

Labels mock

func (*TestContainer) LastHeartbeat

func (c *TestContainer) LastHeartbeat() int64

LastHeartbeat mock

func (*TestContainer) Marshal

func (c *TestContainer) Marshal() ([]byte, error)

Marshal mock

func (*TestContainer) SetAddrs

func (c *TestContainer) SetAddrs(addr, shardAddr string)

SetAddrs mock

func (*TestContainer) SetDeployPath

func (c *TestContainer) SetDeployPath(value string)

SetDeployPath set deploy path

func (*TestContainer) SetID

func (c *TestContainer) SetID(id uint64)

SetID mock

func (*TestContainer) SetLabels

func (c *TestContainer) SetLabels(labels []metapb.Pair)

SetLabels mock

func (*TestContainer) SetLastHeartbeat

func (c *TestContainer) SetLastHeartbeat(value int64)

SetLastHeartbeat mock.

func (*TestContainer) SetStartTimestamp

func (c *TestContainer) SetStartTimestamp(startTS int64)

SetStartTimestamp mock

func (*TestContainer) SetState

func (c *TestContainer) SetState(state metapb.ContainerState)

SetState mock

func (*TestContainer) SetVersion

func (c *TestContainer) SetVersion(version string, githash string)

SetVersion set version

func (*TestContainer) ShardAddr

func (c *TestContainer) ShardAddr() string

ShardAddr mock

func (*TestContainer) StartTimestamp

func (c *TestContainer) StartTimestamp() int64

StartTimestamp mock

func (*TestContainer) State

func (c *TestContainer) State() metapb.ContainerState

State mock

func (*TestContainer) Unmarshal

func (c *TestContainer) Unmarshal(data []byte) error

Unmarshal mock

func (*TestContainer) Version

func (c *TestContainer) Version() (string, string)

Version returns version and githash

type TestResource

type TestResource struct {
	ResID     uint64               `json:"id"`
	Version   uint64               `json:"version"`
	ResPeers  []metapb.Peer        `json:"peers"`
	ResLabels []metapb.Pair        `json:"labels"`
	Start     []byte               `json:"start"`
	End       []byte               `json:"end"`
	ResEpoch  metapb.ResourceEpoch `json:"epoch"`
	Err       bool                 `json:"-"`
}

TestResource test resource

func NewTestResource

func NewTestResource(id uint64) *TestResource

NewTestResource create test resource

func (*TestResource) Changed

func (res *TestResource) Changed(other Resource) bool

Changed mock

func (*TestResource) Clone

func (res *TestResource) Clone() Resource

Clone mock

func (*TestResource) Epoch

func (res *TestResource) Epoch() metapb.ResourceEpoch

Epoch mock

func (*TestResource) ID

func (res *TestResource) ID() uint64

ID mock

func (*TestResource) Labels

func (res *TestResource) Labels() []metapb.Pair

Labels mock

func (*TestResource) Marshal

func (res *TestResource) Marshal() ([]byte, error)

Marshal mock

func (*TestResource) Peers

func (res *TestResource) Peers() []metapb.Peer

Peers mock

func (*TestResource) Range

func (res *TestResource) Range() ([]byte, []byte)

Range mock

func (*TestResource) ScaleCompleted

func (res *TestResource) ScaleCompleted(uint64) bool

ScaleCompleted mock

func (*TestResource) SetEndKey

func (res *TestResource) SetEndKey(value []byte)

SetEndKey mock

func (*TestResource) SetEpoch

func (res *TestResource) SetEpoch(value metapb.ResourceEpoch)

SetEpoch mock

func (*TestResource) SetID

func (res *TestResource) SetID(id uint64)

SetID mock

func (*TestResource) SetPeers

func (res *TestResource) SetPeers(peers []metapb.Peer)

SetPeers mock

func (*TestResource) SetStartKey

func (res *TestResource) SetStartKey(value []byte)

SetStartKey mock

func (*TestResource) Stale

func (res *TestResource) Stale(other Resource) bool

Stale mock

func (*TestResource) SupportRebalance

func (res *TestResource) SupportRebalance() bool

SupportRebalance mock

func (*TestResource) SupportTransferLeader

func (res *TestResource) SupportTransferLeader() bool

SupportTransferLeader mock

func (*TestResource) Unmarshal

func (res *TestResource) Unmarshal(data []byte) error

Unmarshal mock

Jump to

Keyboard shortcuts

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