metadata

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 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.Replica) int

CountInJointState count the peers are in joint state.

func IsInJointState

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

IsInJointState judges whether the Peer is in joint state.

func IsLearner

func IsLearner(peer metapb.Replica) bool

IsLearner judges whether the Peer's Role is Learner.

func IsLearnerOrDemotingVoter

func IsLearnerOrDemotingVoter(peer metapb.Replica) 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.Replica) 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)
	// 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 NewTestContainer

func NewTestContainer(id uint64) *TestContainer

NewTestContainer 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) 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) 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) 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) 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"`
	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) Clone

func (res *TestResource) Clone() Resource

Clone mock

func (*TestResource) Data

func (res *TestResource) Data() []byte

Data mock

func (*TestResource) Epoch

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

Epoch mock

func (*TestResource) Group

func (res *TestResource) Group() uint64

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.Replica

Peers mock

func (*TestResource) Range

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

Range mock

func (*TestResource) RuleGroups

func (res *TestResource) RuleGroups() []string

RuleGroups mock

func (*TestResource) ScaleCompleted

func (res *TestResource) ScaleCompleted(uint64) bool

ScaleCompleted mock

func (*TestResource) SetData

func (res *TestResource) SetData(data []byte)

SetData 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) SetGroup

func (res *TestResource) SetGroup(group uint64)

SetGroup set raft group

func (*TestResource) SetID

func (res *TestResource) SetID(id uint64)

SetID mock

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) SetUnique

func (res *TestResource) SetUnique(value string)

SetUnique mock

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) Unique

func (res *TestResource) Unique() string

Unique 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