Documentation ¶
Index ¶
- Variables
- func CountInJointState(peers ...metapb.Replica) int
- func IsInJointState(peers ...metapb.Replica) bool
- func IsLearner(peer metapb.Replica) bool
- func IsLearnerOrDemotingVoter(peer metapb.Replica) bool
- func IsVoterOrIncomingVoter(peer metapb.Replica) bool
- type Adapter
- type Container
- type Resource
- type RoleChangeHandler
- type TestContainer
- 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) PhysicallyDestroyed() bool
- 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) SetPhysicallyDestroyed(v bool)
- 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) Clone() Resource
- func (res *TestResource) Data() []byte
- func (res *TestResource) Epoch() metapb.ResourceEpoch
- func (res *TestResource) Group() uint64
- func (res *TestResource) ID() uint64
- func (res *TestResource) Labels() []metapb.Pair
- func (res *TestResource) Marshal() ([]byte, error)
- func (res *TestResource) Peers() []metapb.Replica
- func (res *TestResource) Range() ([]byte, []byte)
- func (res *TestResource) RuleGroups() []string
- func (res *TestResource) ScaleCompleted(uint64) bool
- func (res *TestResource) SetData(data []byte)
- func (res *TestResource) SetEndKey(value []byte)
- func (res *TestResource) SetEpoch(value metapb.ResourceEpoch)
- func (res *TestResource) SetGroup(group uint64)
- func (res *TestResource) SetID(id uint64)
- func (res *TestResource) SetLabels(labels []metapb.Pair)
- func (res *TestResource) SetPeers(peers []metapb.Replica)
- func (res *TestResource) SetRuleGroups(ruleGroups ...string)
- func (res *TestResource) SetStartKey(value []byte)
- func (res *TestResource) SetState(state metapb.ResourceState)
- func (res *TestResource) SetUnique(value string)
- func (res *TestResource) State() metapb.ResourceState
- func (res *TestResource) SupportRebalance() bool
- func (res *TestResource) SupportTransferLeader() bool
- func (res *TestResource) Unique() string
- 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) // PhysicallyDestroyed return true if the contianer is physically destroyed, // which means it can never up again PhysicallyDestroyed() bool // SetPhysicallyDestroyed set physicallyDestroyed SetPhysicallyDestroyed(bool) // Clone returns the cloned value Clone() Container // 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 { // ID returns the resource id ID() uint64 // SetID update the resource id SetID(id uint64) // Group resource group Group() uint64 // SetGroup set raft group SetGroup(uint64) // Peers returns the repication peers Peers() []metapb.Replica // SetPeers update the repication peers SetPeers(peers []metapb.Replica) // 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) // State resource state State() metapb.ResourceState // SetState set resource state SetState(metapb.ResourceState) // Unique is identifier of the resources, used for dynamic create resources. Unique() string // SetUnique set Unique SetUnique(string) // Data resource data Data() []byte // SetData set resource data SetData([]byte) // RuleGroups used for placement rule engine to use, all rule group will used if nil returned. RuleGroups() []string // SetRuleGroups set rule groups SetRuleGroups(...string) // Labels returns the lable tag of the resource Labels() []metapb.Pair // SetLabels set labels SetLabels(labels []metapb.Pair) // Clone returns the cloned value Clone() Resource // Marshal returns error if marshal failed Marshal() ([]byte, error) // Unmarshal returns error if unmarshal failed Unmarshal(data []byte) error }
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"` CPhysicallyDestroyed bool `json:"physicallyDestroyed"` CState metapb.ContainerState `json:"state"` CAction metapb.Action `json:"action"` }
TestContainer 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) PhysicallyDestroyed ¶
func (c *TestContainer) PhysicallyDestroyed() bool
PhysicallyDestroyed 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) SetPhysicallyDestroyed ¶
func (c *TestContainer) SetPhysicallyDestroyed(v bool)
SetPhysicallyDestroyed 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"` ResGroup uint64 `json:"group"` Version uint64 `json:"version"` ResPeers []metapb.Replica `json:"peers"` ResLabels []metapb.Pair `json:"labels"` Start []byte `json:"start"` End []byte `json:"end"` ResEpoch metapb.ResourceEpoch `json:"epoch"` ResState metapb.ResourceState `json:"state"` ResUnique string `json:"unique"` ResData []byte `json:"data"` ResRuleGroups []string `json:"rule-groups"` Err bool `json:"-"` }
func NewTestResource ¶
func NewTestResource(id uint64) *TestResource
func (*TestResource) Group ¶
func (res *TestResource) Group() uint64
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) SetGroup ¶
func (res *TestResource) SetGroup(group uint64)
SetGroup set raft group
func (*TestResource) SetLabels ¶ added in v0.2.0
func (res *TestResource) SetLabels(labels []metapb.Pair)
SetLabels mock
func (*TestResource) SetPeers ¶
func (res *TestResource) SetPeers(peers []metapb.Replica)
SetPeers mock
func (*TestResource) SetRuleGroups ¶
func (res *TestResource) SetRuleGroups(ruleGroups ...string)
SetRuleGroups mock
func (*TestResource) SetStartKey ¶
func (res *TestResource) SetStartKey(value []byte)
SetStartKey mock
func (*TestResource) SetState ¶
func (res *TestResource) SetState(state metapb.ResourceState)
func (*TestResource) State ¶
func (res *TestResource) State() metapb.ResourceState
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