Documentation
¶
Index ¶
- Variables
- func CountInJointState(peers ...metapb.Peer) int
- func IsInJointState(peers ...metapb.Peer) bool
- func IsLearner(peer metapb.Peer) bool
- func IsLearnerOrDemotingVoter(peer metapb.Peer) bool
- func IsVoterOrIncomingVoter(peer metapb.Peer) bool
- type Adapter
- type Container
- type Resource
- type RoleChangeHandler
- type TestContainer
- func (c *TestContainer) ActionOnJoinCluster() metapb.Action
- func (c *TestContainer) Addr() string
- func (c *TestContainer) Clone() Container
- func (c *TestContainer) DeployPath() string
- func (c *TestContainer) ID() uint64
- func (c *TestContainer) Labels() []metapb.Pair
- func (c *TestContainer) LastHeartbeat() int64
- func (c *TestContainer) Marshal() ([]byte, error)
- func (c *TestContainer) SetAddrs(addr, shardAddr string)
- func (c *TestContainer) SetDeployPath(value string)
- func (c *TestContainer) SetID(id uint64)
- func (c *TestContainer) SetLabels(labels []metapb.Pair)
- func (c *TestContainer) SetLastHeartbeat(value int64)
- func (c *TestContainer) SetStartTimestamp(startTS int64)
- func (c *TestContainer) SetState(state metapb.ContainerState)
- func (c *TestContainer) SetVersion(version string, githash string)
- func (c *TestContainer) ShardAddr() string
- func (c *TestContainer) StartTimestamp() int64
- func (c *TestContainer) State() metapb.ContainerState
- func (c *TestContainer) Unmarshal(data []byte) error
- func (c *TestContainer) Version() (string, string)
- type TestResource
- func (res *TestResource) Changed(other Resource) bool
- func (res *TestResource) Clone() Resource
- func (res *TestResource) Epoch() metapb.ResourceEpoch
- func (res *TestResource) ID() uint64
- func (res *TestResource) Labels() []metapb.Pair
- func (res *TestResource) Marshal() ([]byte, error)
- func (res *TestResource) Peers() []metapb.Peer
- func (res *TestResource) Range() ([]byte, []byte)
- func (res *TestResource) ScaleCompleted(uint64) bool
- func (res *TestResource) SetEndKey(value []byte)
- func (res *TestResource) SetEpoch(value metapb.ResourceEpoch)
- func (res *TestResource) SetID(id uint64)
- func (res *TestResource) SetPeers(peers []metapb.Peer)
- func (res *TestResource) SetStartKey(value []byte)
- func (res *TestResource) Stale(other Resource) bool
- func (res *TestResource) SupportRebalance() bool
- func (res *TestResource) SupportTransferLeader() bool
- func (res *TestResource) Unmarshal(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // TestResourceFactory test factory TestResourceFactory = func() Resource { return &TestResource{} } )
Functions ¶
func CountInJointState ¶
CountInJointState count the peers are in joint state.
func IsInJointState ¶
IsInJointState judges whether the Peer is in joint state.
func IsLearnerOrDemotingVoter ¶
IsLearnerOrDemotingVoter judges whether peer role will become Learner. The peer is not nil and the role is equal to DemotingVoter or Learner.
func IsVoterOrIncomingVoter ¶
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
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 (*TestContainer) ActionOnJoinCluster ¶
func (c *TestContainer) ActionOnJoinCluster() metapb.Action
ActionOnJoinCluster mock
func (*TestContainer) DeployPath ¶
func (c *TestContainer) DeployPath() string
DeployPath returns the container deploy path
func (*TestContainer) LastHeartbeat ¶
func (c *TestContainer) LastHeartbeat() int64
LastHeartbeat 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) 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) StartTimestamp ¶
func (c *TestContainer) StartTimestamp() int64
StartTimestamp 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) ScaleCompleted ¶
func (res *TestResource) ScaleCompleted(uint64) bool
ScaleCompleted mock
func (*TestResource) SetEpoch ¶
func (res *TestResource) SetEpoch(value metapb.ResourceEpoch)
SetEpoch 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) 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