prophet

package module
Version: v0.0.0-...-f9cf199 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: Apache-2.0 Imports: 34 Imported by: 0

README

prophet

Embedded distributed coordinator

Documentation

Overview

Package prophet is a generated GoMock package.

Package prophet is a generated GoMock package.

Package prophet is a generated GoMock package.

Package prophet is a generated GoMock package.

Package prophet is a generated GoMock package.

Index

Constants

View Source
const (
	// NoneAction none action
	NoneAction = Action(0)
	// ScaleOutAction all resources will received a scale operation when a new container join the cluster
	ScaleOutAction = Action(1)
)
View Source
const (
	// DefaultTimeout default timeout
	DefaultTimeout = time.Second * 3
	// DefaultRequestTimeout default request timeout
	DefaultRequestTimeout = 10 * time.Second
	// DefaultSlowRequestTime default slow request time
	DefaultSlowRequestTime = time.Second * 1
)
View Source
const (
	// Pending job is wait to running
	Pending = JobState(0)
	// Running job is running
	Running = JobState(1)
	// Cancelling job is cancelling
	Cancelling = JobState(2)
	// Cancelled job is cancelled
	Cancelled = JobState(3)
	// Finished job is complete
	Finished = JobState(4)
	// Failed job is failed when execute
	Failed = JobState(5)
)

Variables

View Source
var (
	// ErrSchedulerExisted error with scheduler is existed
	ErrSchedulerExisted = errors.New("scheduler is existed")
	// ErrSchedulerNotFound error with scheduler is not found
	ErrSchedulerNotFound = errors.New("scheduler is not found")
)
View Source
var (
	// ErrNorLeader not leader
	ErrNorLeader = errors.New("Not Leader")
	// ErrDoTimeout timeout
	ErrDoTimeout = errors.New("Do Timeout")
)
View Source
var (
	// AddPeer add peer
	AddPeer = ChangePeerType(0)
	// RemovePeer remove peer
	RemovePeer = ChangePeerType(1)
	// ScalePeer scale peer
	ScalePeer = ChangePeerType(2)
)
View Source
var (
	// ErrDisposed is returned when an operation is performed on a disposed
	// queue.
	ErrDisposed = errors.New(`queue: disposed`)

	// ErrTimeout is returned when an applicable queue operation times out.
	ErrTimeout = errors.New(`queue: poll timed out`)

	// ErrEmptyQueue is returned when an non-applicable queue operation was called
	// due to the queue's empty item state
	ErrEmptyQueue = errors.New(`queue: empty queue`)
)
View Source
var (
	// EventInit event init
	EventInit = 1 << 1
	// EventResourceCreated event resource created
	EventResourceCreated = 1 << 2
	// EventResourceLeaderChanged event resource leader changed
	EventResourceLeaderChanged = 1 << 3
	// EventResourceChaned event resource changed
	EventResourceChaned = 1 << 4
	// EventContainerCreated  event container create
	EventContainerCreated = 1 << 5
	// EventContainerChanged  event container create
	EventContainerChanged = 1 << 6

	// EventFlagResource all resource event
	EventFlagResource = EventResourceCreated | EventResourceLeaderChanged | EventResourceChaned
	// EventFlagContainer all container event
	EventFlagContainer = EventContainerCreated | EventContainerChanged
	// EventFlagAll all event
	EventFlagAll = 0xffffffff
)
View Source
var (
	// ErrJobCancelled error job cancelled
	ErrJobCancelled = errors.New("Job cancelled")
)

Functions

func EmptyPeer

func EmptyPeer(value Peer) bool

EmptyPeer returns a peer is a empty peer

func ExecuteInParallel

func ExecuteInParallel(q *Queue, fn func(interface{}))

ExecuteInParallel will (in parallel) call the provided function with each item in the queue until the queue is exhausted. When the queue is exhausted execution is complete and all goroutines will be killed. This means that the queue will be disposed so cannot be used again.

func GeometricMean

func GeometricMean(input Float64Data) (float64, error)

GeometricMean gets the geometric mean for a slice of numbers

func HarmonicMean

func HarmonicMean(input Float64Data) (float64, error)

HarmonicMean gets the harmonic mean for a slice of numbers

func MatchEvent

func MatchEvent(event, flag int) bool

MatchEvent returns the flag has the target event

func Max

func Max(input Float64Data) (max float64, err error)

Max finds the highest number in a slice

func Mean

func Mean(input Float64Data) (float64, error)

Mean gets the average of a slice of numbers

func Median

func Median(input Float64Data) (median float64, err error)

Median gets the median number in a slice of numbers

func Min

func Min(input Float64Data) (min float64, err error)

Min finds the lowest number in a set of data

func Mode

func Mode(input Float64Data) (mode []float64, err error)

Mode gets the mode of a slice of numbers

func PopulationVariance

func PopulationVariance(input Float64Data) (pvar float64, err error)

PopulationVariance finds the amount of variance within a population

func SetLogger

func SetLogger(l Logger)

SetLogger set the log for prophet

func StandardDeviation

func StandardDeviation(input Float64Data) (sdev float64, err error)

StandardDeviation the amount of variation in the dataset

func StandardDeviationPopulation

func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)

StandardDeviationPopulation finds the amount of variation from the population

func Sum

func Sum(input Float64Data) (sum float64, err error)

Sum adds all the numbers of a slice together

Types

type Action

type Action int

Action the action on the cluster join the cluster

type Adapter

type Adapter interface {
	// NewResource return a new resource
	NewResource() Resource
	// NewContainer return a new container
	NewContainer() Container
	// FetchLeaderResources fetch loacle leader resource
	FetchLeaderResources() []uint64
	// FetchResourceHB fetch resource HB
	FetchResourceHB(id uint64) *ResourceHeartbeatReq
	// FetchContainerHB fetch container HB
	FetchContainerHB() *ContainerHeartbeatReq
	// ResourceHBInterval fetch resource HB interface
	ResourceHBInterval() time.Duration
	// ContainerHBInterval fetch container HB interface
	ContainerHBInterval() time.Duration
	// HBHandler HB hander
	HBHandler() HeartbeatHandler
}

Adapter prophet adapter

type Cfg

type Cfg struct {
	// RPCAddr prophet rpc addr
	RPCAddr string

	// MaxScheduleRetries maximum retry times for schedule
	MaxScheduleRetries int
	// MaxScheduleInterval maximum schedule interval per scheduler
	MaxScheduleInterval time.Duration
	// MinScheduleInterval minimum schedule interval per scheduler
	MinScheduleInterval time.Duration
	// TimeoutWaitOperatorComplete timeout for waitting teh operator complete
	TimeoutWaitOperatorComplete time.Duration
	// MaxFreezeScheduleInterval freeze the container for a while if shouldSchedule is returns false
	MaxFreezeScheduleInterval time.Duration
	// MaxAllowContainerDownDuration maximum down time of removed from replicas
	MaxAllowContainerDownDuration time.Duration
	// MaxRebalanceLeader maximum count of transfer leader operator
	MaxRebalanceLeader uint64
	// MaxRebalanceReplica maximum count of remove|add replica operator
	MaxRebalanceReplica uint64
	// MaxScheduleReplica maximum count of schedule replica operator
	MaxScheduleReplica uint64
	// MaxLimitSnapshotsCount maximum count of node about snapshot
	MaxLimitSnapshotsCount uint64
	// CountResourceReplicas replica number per resource
	CountResourceReplicas int
	// MinAvailableStorageUsedRate minimum storage used rate of container, if the rate is over this value, skip the container
	MinAvailableStorageUsedRate int
	// LocationLabels the label used for location
	LocationLabels []string
	// MaxRPCCons rpc conns
	MaxRPCCons int
	// MaxRPCConnIdle rpc conn max idle time
	MaxRPCConnIdle time.Duration
	// MaxRPCTimeout rpc max timeout
	MaxRPCTimeout time.Duration

	StorageNode bool
	LeaseTTL    int64
	Schedulers  []Scheduler
	Handler     RoleChangeHandler

	EnableScaleOnNewStore bool
}

Cfg prophet cfg

type ChangePeerType

type ChangePeerType byte

ChangePeerType change peer type

type Container

type Container interface {
	Serializable

	// 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() []Pair
	// State returns the state of the container
	State() State
	// Clone returns the cloned value
	Clone() Container
	// ActionOnJoinCluster returns the cluster will do what when a new container join the cluster
	ActionOnJoinCluster() 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 ContainerHeartbeatReq

type ContainerHeartbeatReq struct {
	Data               []byte    `json:"data"`
	StorageCapacity    uint64    `json:"storageCapacity"`
	StorageAvailable   uint64    `json:"storageAvailable"`
	LeaderCount        uint64    `json:"leaderCount"`
	ReplicaCount       uint64    `json:"replicaCount"`
	SendingSnapCount   uint64    `json:"sendingSnapCount"`
	ReceivingSnapCount uint64    `json:"receivingSnapCount"`
	ApplyingSnapCount  uint64    `json:"applyingSnapCount"`
	Busy               bool      `json:"busy"`  // stop replica balance
	Block              bool      `json:"block"` // stop leader balance
	Container          Container `json:"-"`
}

ContainerHeartbeatReq container hb msg

func (*ContainerHeartbeatReq) Init

func (req *ContainerHeartbeatReq) Init(adapter Adapter) error

Init init

func (*ContainerHeartbeatReq) Prepare

func (req *ContainerHeartbeatReq) Prepare() error

Prepare prepare

type ContainerRuntime

type ContainerRuntime struct {
	// contains filtered or unexported fields
}

ContainerRuntime is the container runtime info

func (*ContainerRuntime) Clone

func (cr *ContainerRuntime) Clone() *ContainerRuntime

Clone returns the container clone info

func (*ContainerRuntime) Downtime

func (cr *ContainerRuntime) Downtime() time.Duration

Downtime returns the container down time

func (*ContainerRuntime) GetLabelValue

func (cr *ContainerRuntime) GetLabelValue(key string) string

GetLabelValue returns label value of key

func (*ContainerRuntime) GetLocationID

func (cr *ContainerRuntime) GetLocationID(keys []string) string

GetLocationID returns location id

func (*ContainerRuntime) HasNoneHeartbeat

func (cr *ContainerRuntime) HasNoneHeartbeat() bool

HasNoneHeartbeat returns if received a heartbeat from the container

func (*ContainerRuntime) IsBlocked

func (cr *ContainerRuntime) IsBlocked() bool

IsBlocked returns the container is blocked from balance if true.

func (*ContainerRuntime) IsUp

func (cr *ContainerRuntime) IsUp() bool

IsUp returns the container is up state

func (*ContainerRuntime) LeaderScore

func (cr *ContainerRuntime) LeaderScore() float64

LeaderScore returns score with leader

func (*ContainerRuntime) ReplicaScore

func (cr *ContainerRuntime) ReplicaScore() float64

ReplicaScore returns score with replica

func (*ContainerRuntime) ResourceCount

func (cr *ContainerRuntime) ResourceCount(kind ResourceKind) uint64

ResourceCount returns resource count by kind

func (*ContainerRuntime) ResourceScore

func (cr *ContainerRuntime) ResourceScore(kind ResourceKind) float64

ResourceScore returns resource score by kind

func (*ContainerRuntime) StorageUsedBytes

func (cr *ContainerRuntime) StorageUsedBytes() uint64

StorageUsedBytes returns container used storage with bytes

func (*ContainerRuntime) StorageUsedRatio

func (cr *ContainerRuntime) StorageUsedRatio() int

StorageUsedRatio returns container used storage with rate

type Coordinator

type Coordinator struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Coordinator resource coordinator

type Elector

type Elector interface {
	// Stop stop elector
	Stop(group uint64)
	// CurrentLeader returns current leader
	CurrentLeader(group uint64) (string, error)
	// ElectionLoop run leader election loop, if the currentLeader is not set, only watch leader.
	ElectionLoop(ctx context.Context, group uint64, currentLeader string, becomeLeader, becomeFollower func())
	// ChangeLeaderTo change leader from old to new
	ChangeLeaderTo(group uint64, oldLeader, newLeader string) error
	// DoIfLeader do some options and returns false if current node is not leader or some conditions check failed
	DoIfLeader(group uint64, node string, conditions []clientv3.Cmp, ops ...clientv3.Op) (bool, error)
}

Elector a leader elector

func NewElector

func NewElector(client *clientv3.Client, options ...ElectorOption) (Elector, error)

NewElector create a elector

type ElectorOption

type ElectorOption func(*electorOptions)

ElectorOption elector option

func WithLeaderLeaseSeconds

func WithLeaderLeaseSeconds(value int64) ElectorOption

WithLeaderLeaseSeconds set leader lease in seconds

func WithLockIfBecomeLeader

func WithLockIfBecomeLeader(value bool) ElectorOption

WithLockIfBecomeLeader set lock enable flag if become leader, If true, will add a distributed lock, and will unlock on become follower, ensure that the other nodes can be changed to leaders after the previous leader has processed the role changes.

func WithPrefix

func WithPrefix(value string) ElectorOption

WithPrefix set data prefix in embed etcd server

type EmbeddedEtcdCfg

type EmbeddedEtcdCfg struct {
	Name         string
	DataPath     string
	Join         string
	EmbedEtcdLog string

	URLsClient          string
	URLsAdvertiseClient string

	URLsPeer          string
	URLsAdvertisePeer string

	InitialCluster      string
	InitialClusterState string
}

EmbeddedEtcdCfg cfg for embedded etcd

type EventNotify

type EventNotify struct {
	Event int    `json:"event"`
	Value []byte `json:"value"`
}

EventNotify event notify

func (*EventNotify) ReadInitEventValues

func (evt *EventNotify) ReadInitEventValues(resourceF func([]byte, uint64), containerF func([]byte))

ReadInitEventValues read all resource info

func (*EventNotify) ReadLeaderChangerValue

func (evt *EventNotify) ReadLeaderChangerValue() (uint64, uint64)

ReadLeaderChangerValue returns the target resource and the new leader returns resourceid, newleaderid

type Filter

type Filter interface {
	// FilterSource returns true means skip this container for schedule
	FilterSource(container *ContainerRuntime) bool
	// FilterTarget returns true means skip this container for schedule
	FilterTarget(container *ContainerRuntime) bool
}

Filter is used for filter container

func NewBlockFilter

func NewBlockFilter() Filter

NewBlockFilter returns a filter for choose resource container by block

func NewCacheFilter

func NewCacheFilter(freezeCache *resourceFreezeCache) Filter

NewCacheFilter returns a filter for choose resource container by runtime cache

func NewDistinctScoreFilter

func NewDistinctScoreFilter(cfg *Cfg, containers []*ContainerRuntime, source *ContainerRuntime) Filter

NewDistinctScoreFilter a filter for ensures that distinct score will not decrease.

func NewExcludedFilter

func NewExcludedFilter(sources, targets map[uint64]struct{}) Filter

NewExcludedFilter returns a filter for choose resource container by excluded value

func NewHealthFilter

func NewHealthFilter(cfg *Cfg) Filter

NewHealthFilter returns a filter for choose resource container by health info

func NewLabelFilter

func NewLabelFilter(labels []Pair) Filter

NewLabelFilter returns label filter, if the container missing the labels, skip it.

func NewSnapshotCountFilter

func NewSnapshotCountFilter(cfg *Cfg) Filter

NewSnapshotCountFilter returns snapshot filter

func NewStateFilter

func NewStateFilter(cfg *Cfg) Filter

NewStateFilter returns a filter for choose resource container by state

func NewStorageThresholdFilter

func NewStorageThresholdFilter(cfg *Cfg) Filter

NewStorageThresholdFilter returns a filter for choose resource container by storage rate

type Float64Data

type Float64Data []float64

Float64Data is a named type for []float64 with helper methods

func (Float64Data) Get

func (f Float64Data) Get(i int) float64

Get item in slice

func (Float64Data) Len

func (f Float64Data) Len() int

Len returns length of slice

func (Float64Data) Less

func (f Float64Data) Less(i, j int) bool

Less returns if one number is less than another

func (Float64Data) Max

func (f Float64Data) Max() (float64, error)

Max returns the maximum number in the data

func (Float64Data) Mean

func (f Float64Data) Mean() (float64, error)

Mean returns the mean of the data

func (Float64Data) Median

func (f Float64Data) Median() (float64, error)

Median returns the median of the data

func (Float64Data) Min

func (f Float64Data) Min() (float64, error)

Min returns the minimum number in the data

func (Float64Data) Mode

func (f Float64Data) Mode() ([]float64, error)

Mode returns the mode of the data

func (Float64Data) Sum

func (f Float64Data) Sum() (float64, error)

Sum returns the total of all the numbers in the data

func (Float64Data) Swap

func (f Float64Data) Swap(i, j int)

Swap switches out two numbers in slice

type HeartbeatHandler

type HeartbeatHandler interface {
	ChangeLeader(resourceID uint64, newLeader *Peer)
	ChangePeer(resourceID uint64, peer *Peer, changeType ChangePeerType)
	ScaleResource(resourceID uint64, byContainerID uint64)
}

HeartbeatHandler handle for heartbeat rsp

type InitWatcher

type InitWatcher struct {
	Flag int `json:"flag"`
}

InitWatcher init watcher

type Job

type Job struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Job is do for something with state

func (*Job) Cancel

func (job *Job) Cancel()

Cancel cancel the job

func (*Job) GetResult

func (job *Job) GetResult() interface{}

GetResult returns job result

func (*Job) IsCancelled

func (job *Job) IsCancelled() bool

IsCancelled returns true if job state is Cancelled

func (*Job) IsCancelling

func (job *Job) IsCancelling() bool

IsCancelling returns true if job state is Cancelling

func (*Job) IsComplete

func (job *Job) IsComplete() bool

IsComplete return true means the job is complete.

func (*Job) IsFailed

func (job *Job) IsFailed() bool

IsFailed returns true if job state is Failed

func (*Job) IsFinished

func (job *Job) IsFinished() bool

IsFinished returns true if job state is Finished

func (*Job) IsNotComplete

func (job *Job) IsNotComplete() bool

IsNotComplete return true means the job is not complete.

func (*Job) IsPending

func (job *Job) IsPending() bool

IsPending returns true if job state is Pending

func (*Job) IsRunning

func (job *Job) IsRunning() bool

IsRunning returns true if job state is Running

func (*Job) SetResult

func (job *Job) SetResult(result interface{})

SetResult set result

type JobState

type JobState int

JobState is the job state

type LocalStorage

type LocalStorage interface {
	// Get returns the key value
	Get(key []byte) ([]byte, error)
	// Set sets the key value to the local storage
	Set(pairs ...[]byte) error
	// Remove remove the key from the local storage
	Remove(keys ...[]byte) error
	// Range visit all values that start with prefix, set limit to 0 for no limit
	Range(prefix []byte, limit uint64, fn func(key, value []byte) bool) error
}

LocalStorage is the local data storage

type LocalStore

type LocalStore interface {
	// BootstrapCluster bootstrap the cluster,
	BootstrapCluster(initResources ...Resource)

	// MustPutResource put the resource to local
	MustPutResource(...Resource)

	// MustRemoveResource remove the res from the local
	MustRemoveResource(...uint64)

	// MustAllocID returns the new id by pd
	MustAllocID() uint64

	// MustCountResources returns local resources count
	MustCountResources() int

	// MustLoadResources load all local resources
	MustLoadResources(func(value []byte) (uint64, error))
}

LocalStore the local data store

func NewLocalStore

func NewLocalStore(meta Container, storage LocalStorage, pd Prophet) LocalStore

NewLocalStore returns a local store

type Logger

type Logger interface {
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
}

Logger logger

type MockAdapter

type MockAdapter struct {
	// contains filtered or unexported fields
}

MockAdapter is a mock of Adapter interface

func NewMockAdapter

func NewMockAdapter(ctrl *gomock.Controller) *MockAdapter

NewMockAdapter creates a new mock instance

func (*MockAdapter) ContainerHBInterval

func (m *MockAdapter) ContainerHBInterval() time.Duration

ContainerHBInterval mocks base method

func (*MockAdapter) EXPECT

func (m *MockAdapter) EXPECT() *MockAdapterMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAdapter) FetchContainerHB

func (m *MockAdapter) FetchContainerHB() *ContainerHeartbeatReq

FetchContainerHB mocks base method

func (*MockAdapter) FetchLeaderResources

func (m *MockAdapter) FetchLeaderResources() []uint64

FetchLeaderResources mocks base method

func (*MockAdapter) FetchResourceHB

func (m *MockAdapter) FetchResourceHB(id uint64) *ResourceHeartbeatReq

FetchResourceHB mocks base method

func (*MockAdapter) HBHandler

func (m *MockAdapter) HBHandler() HeartbeatHandler

HBHandler mocks base method

func (*MockAdapter) NewContainer

func (m *MockAdapter) NewContainer() Container

NewContainer mocks base method

func (*MockAdapter) NewResource

func (m *MockAdapter) NewResource() Resource

NewResource mocks base method

func (*MockAdapter) ResourceHBInterval

func (m *MockAdapter) ResourceHBInterval() time.Duration

ResourceHBInterval mocks base method

type MockAdapterMockRecorder

type MockAdapterMockRecorder struct {
	// contains filtered or unexported fields
}

MockAdapterMockRecorder is the mock recorder for MockAdapter

func (*MockAdapterMockRecorder) ContainerHBInterval

func (mr *MockAdapterMockRecorder) ContainerHBInterval() *gomock.Call

ContainerHBInterval indicates an expected call of ContainerHBInterval

func (*MockAdapterMockRecorder) FetchContainerHB

func (mr *MockAdapterMockRecorder) FetchContainerHB() *gomock.Call

FetchContainerHB indicates an expected call of FetchContainerHB

func (*MockAdapterMockRecorder) FetchLeaderResources

func (mr *MockAdapterMockRecorder) FetchLeaderResources() *gomock.Call

FetchLeaderResources indicates an expected call of FetchLeaderResources

func (*MockAdapterMockRecorder) FetchResourceHB

func (mr *MockAdapterMockRecorder) FetchResourceHB(id interface{}) *gomock.Call

FetchResourceHB indicates an expected call of FetchResourceHB

func (*MockAdapterMockRecorder) HBHandler

func (mr *MockAdapterMockRecorder) HBHandler() *gomock.Call

HBHandler indicates an expected call of HBHandler

func (*MockAdapterMockRecorder) NewContainer

func (mr *MockAdapterMockRecorder) NewContainer() *gomock.Call

NewContainer indicates an expected call of NewContainer

func (*MockAdapterMockRecorder) NewResource

func (mr *MockAdapterMockRecorder) NewResource() *gomock.Call

NewResource indicates an expected call of NewResource

func (*MockAdapterMockRecorder) ResourceHBInterval

func (mr *MockAdapterMockRecorder) ResourceHBInterval() *gomock.Call

ResourceHBInterval indicates an expected call of ResourceHBInterval

type MockContainer

type MockContainer struct {
	// contains filtered or unexported fields
}

MockContainer is a mock of Container interface

func NewMockContainer

func NewMockContainer(ctrl *gomock.Controller) *MockContainer

NewMockContainer creates a new mock instance

func (*MockContainer) ActionOnJoinCluster

func (m *MockContainer) ActionOnJoinCluster() Action

ActionOnJoinCluster mocks base method

func (*MockContainer) Clone

func (m *MockContainer) Clone() Container

Clone mocks base method

func (*MockContainer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockContainer) ID

func (m *MockContainer) ID() uint64

ID mocks base method

func (*MockContainer) Labels

func (m *MockContainer) Labels() []Pair

Labels mocks base method

func (*MockContainer) Marshal

func (m *MockContainer) Marshal() ([]byte, error)

Marshal mocks base method

func (*MockContainer) SetID

func (m *MockContainer) SetID(id uint64)

SetID mocks base method

func (*MockContainer) ShardAddr

func (m *MockContainer) ShardAddr() string

ShardAddr mocks base method

func (*MockContainer) State

func (m *MockContainer) State() State

State mocks base method

func (*MockContainer) Unmarshal

func (m *MockContainer) Unmarshal(data []byte) error

Unmarshal mocks base method

type MockContainerMockRecorder

type MockContainerMockRecorder struct {
	// contains filtered or unexported fields
}

MockContainerMockRecorder is the mock recorder for MockContainer

func (*MockContainerMockRecorder) ActionOnJoinCluster

func (mr *MockContainerMockRecorder) ActionOnJoinCluster() *gomock.Call

ActionOnJoinCluster indicates an expected call of ActionOnJoinCluster

func (*MockContainerMockRecorder) Clone

func (mr *MockContainerMockRecorder) Clone() *gomock.Call

Clone indicates an expected call of Clone

func (*MockContainerMockRecorder) ID

ID indicates an expected call of ID

func (*MockContainerMockRecorder) Labels

func (mr *MockContainerMockRecorder) Labels() *gomock.Call

Labels indicates an expected call of Labels

func (*MockContainerMockRecorder) Marshal

func (mr *MockContainerMockRecorder) Marshal() *gomock.Call

Marshal indicates an expected call of Marshal

func (*MockContainerMockRecorder) SetID

func (mr *MockContainerMockRecorder) SetID(id interface{}) *gomock.Call

SetID indicates an expected call of SetID

func (*MockContainerMockRecorder) ShardAddr

func (mr *MockContainerMockRecorder) ShardAddr() *gomock.Call

ShardAddr indicates an expected call of ShardAddr

func (*MockContainerMockRecorder) State

func (mr *MockContainerMockRecorder) State() *gomock.Call

State indicates an expected call of State

func (*MockContainerMockRecorder) Unmarshal

func (mr *MockContainerMockRecorder) Unmarshal(data interface{}) *gomock.Call

Unmarshal indicates an expected call of Unmarshal

type MockPeerReplicaHandler

type MockPeerReplicaHandler struct {
	// contains filtered or unexported fields
}

MockPeerReplicaHandler is a mock of PeerReplicaHandler interface

func NewMockPeerReplicaHandler

func NewMockPeerReplicaHandler(ctrl *gomock.Controller) *MockPeerReplicaHandler

NewMockPeerReplicaHandler creates a new mock instance

func (*MockPeerReplicaHandler) AddPeer

func (m *MockPeerReplicaHandler) AddPeer(arg0 Resource, arg1 Peer)

AddPeer mocks base method

func (*MockPeerReplicaHandler) Destory

func (m *MockPeerReplicaHandler) Destory(arg0 Resource)

Destory mocks base method

func (*MockPeerReplicaHandler) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockPeerReplicaHandler) Heartbeat

func (m *MockPeerReplicaHandler) Heartbeat(arg0 Resource) bool

Heartbeat mocks base method

func (*MockPeerReplicaHandler) RemovePeer

func (m *MockPeerReplicaHandler) RemovePeer(arg0 Resource, arg1 Peer) bool

RemovePeer mocks base method

func (*MockPeerReplicaHandler) ResourceBecomeFollower

func (m *MockPeerReplicaHandler) ResourceBecomeFollower(arg0 Resource)

ResourceBecomeFollower mocks base method

func (*MockPeerReplicaHandler) ResourceBecomeLeader

func (m *MockPeerReplicaHandler) ResourceBecomeLeader(arg0 Resource)

ResourceBecomeLeader mocks base method

func (*MockPeerReplicaHandler) Scale

func (m *MockPeerReplicaHandler) Scale(arg0 Resource, arg1 interface{}) (bool, []*PeerReplica)

Scale mocks base method

type MockPeerReplicaHandlerMockRecorder

type MockPeerReplicaHandlerMockRecorder struct {
	// contains filtered or unexported fields
}

MockPeerReplicaHandlerMockRecorder is the mock recorder for MockPeerReplicaHandler

func (*MockPeerReplicaHandlerMockRecorder) AddPeer

func (mr *MockPeerReplicaHandlerMockRecorder) AddPeer(arg0, arg1 interface{}) *gomock.Call

AddPeer indicates an expected call of AddPeer

func (*MockPeerReplicaHandlerMockRecorder) Destory

func (mr *MockPeerReplicaHandlerMockRecorder) Destory(arg0 interface{}) *gomock.Call

Destory indicates an expected call of Destory

func (*MockPeerReplicaHandlerMockRecorder) Heartbeat

func (mr *MockPeerReplicaHandlerMockRecorder) Heartbeat(arg0 interface{}) *gomock.Call

Heartbeat indicates an expected call of Heartbeat

func (*MockPeerReplicaHandlerMockRecorder) RemovePeer

func (mr *MockPeerReplicaHandlerMockRecorder) RemovePeer(arg0, arg1 interface{}) *gomock.Call

RemovePeer indicates an expected call of RemovePeer

func (*MockPeerReplicaHandlerMockRecorder) ResourceBecomeFollower

func (mr *MockPeerReplicaHandlerMockRecorder) ResourceBecomeFollower(arg0 interface{}) *gomock.Call

ResourceBecomeFollower indicates an expected call of ResourceBecomeFollower

func (*MockPeerReplicaHandlerMockRecorder) ResourceBecomeLeader

func (mr *MockPeerReplicaHandlerMockRecorder) ResourceBecomeLeader(arg0 interface{}) *gomock.Call

ResourceBecomeLeader indicates an expected call of ResourceBecomeLeader

func (*MockPeerReplicaHandlerMockRecorder) Scale

func (mr *MockPeerReplicaHandlerMockRecorder) Scale(arg0, arg1 interface{}) *gomock.Call

Scale indicates an expected call of Scale

type MockProphet

type MockProphet struct {
	// contains filtered or unexported fields
}

MockProphet is a mock of Prophet interface

func NewMockProphet

func NewMockProphet(ctrl *gomock.Controller) *MockProphet

NewMockProphet creates a new mock instance

func (*MockProphet) EXPECT

func (m *MockProphet) EXPECT() *MockProphetMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockProphet) GetEtcdClient

func (m *MockProphet) GetEtcdClient() *clientv3.Client

GetEtcdClient mocks base method

func (*MockProphet) GetRPC

func (m *MockProphet) GetRPC() RPC

GetRPC mocks base method

func (*MockProphet) GetStore

func (m *MockProphet) GetStore() Store

GetStore mocks base method

func (*MockProphet) Start

func (m *MockProphet) Start()

Start mocks base method

type MockProphetMockRecorder

type MockProphetMockRecorder struct {
	// contains filtered or unexported fields
}

MockProphetMockRecorder is the mock recorder for MockProphet

func (*MockProphetMockRecorder) GetEtcdClient

func (mr *MockProphetMockRecorder) GetEtcdClient() *gomock.Call

GetEtcdClient indicates an expected call of GetEtcdClient

func (*MockProphetMockRecorder) GetRPC

func (mr *MockProphetMockRecorder) GetRPC() *gomock.Call

GetRPC indicates an expected call of GetRPC

func (*MockProphetMockRecorder) GetStore

func (mr *MockProphetMockRecorder) GetStore() *gomock.Call

GetStore indicates an expected call of GetStore

func (*MockProphetMockRecorder) Start

func (mr *MockProphetMockRecorder) Start() *gomock.Call

Start indicates an expected call of Start

type MockRPC

type MockRPC struct {
	// contains filtered or unexported fields
}

MockRPC is a mock of RPC interface

func NewMockRPC

func NewMockRPC(ctrl *gomock.Controller) *MockRPC

NewMockRPC creates a new mock instance

func (*MockRPC) AllocID

func (m *MockRPC) AllocID() (uint64, error)

AllocID mocks base method

func (*MockRPC) AskSplit

func (m *MockRPC) AskSplit(res Resource) (uint64, []uint64, error)

AskSplit mocks base method

func (*MockRPC) EXPECT

func (m *MockRPC) EXPECT() *MockRPCMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockRPC) TiggerContainerHeartbeat

func (m *MockRPC) TiggerContainerHeartbeat()

TiggerContainerHeartbeat mocks base method

func (*MockRPC) TiggerResourceHeartbeat

func (m *MockRPC) TiggerResourceHeartbeat(id uint64)

TiggerResourceHeartbeat mocks base method

type MockRPCMockRecorder

type MockRPCMockRecorder struct {
	// contains filtered or unexported fields
}

MockRPCMockRecorder is the mock recorder for MockRPC

func (*MockRPCMockRecorder) AllocID

func (mr *MockRPCMockRecorder) AllocID() *gomock.Call

AllocID indicates an expected call of AllocID

func (*MockRPCMockRecorder) AskSplit

func (mr *MockRPCMockRecorder) AskSplit(res interface{}) *gomock.Call

AskSplit indicates an expected call of AskSplit

func (*MockRPCMockRecorder) TiggerContainerHeartbeat

func (mr *MockRPCMockRecorder) TiggerContainerHeartbeat() *gomock.Call

TiggerContainerHeartbeat indicates an expected call of TiggerContainerHeartbeat

func (*MockRPCMockRecorder) TiggerResourceHeartbeat

func (mr *MockRPCMockRecorder) TiggerResourceHeartbeat(id interface{}) *gomock.Call

TiggerResourceHeartbeat indicates an expected call of TiggerResourceHeartbeat

type MockResource

type MockResource struct {
	// contains filtered or unexported fields
}

MockResource is a mock of Resource interface

func NewMockResource

func NewMockResource(ctrl *gomock.Controller) *MockResource

NewMockResource creates a new mock instance

func (*MockResource) Changed

func (m *MockResource) Changed(other Resource) bool

Changed mocks base method

func (*MockResource) Clone

func (m *MockResource) Clone() Resource

Clone mocks base method

func (*MockResource) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockResource) ID

func (m *MockResource) ID() uint64

ID mocks base method

func (*MockResource) Labels

func (m *MockResource) Labels() []Pair

Labels mocks base method

func (*MockResource) Marshal

func (m *MockResource) Marshal() ([]byte, error)

Marshal mocks base method

func (*MockResource) Peers

func (m *MockResource) Peers() []*Peer

Peers mocks base method

func (*MockResource) ScaleCompleted

func (m *MockResource) ScaleCompleted(arg0 uint64) bool

ScaleCompleted mocks base method

func (*MockResource) SetID

func (m *MockResource) SetID(id uint64)

SetID mocks base method

func (*MockResource) SetPeers

func (m *MockResource) SetPeers(peers []*Peer)

SetPeers mocks base method

func (*MockResource) Stale

func (m *MockResource) Stale(other Resource) bool

Stale mocks base method

func (*MockResource) Unmarshal

func (m *MockResource) Unmarshal(data []byte) error

Unmarshal mocks base method

type MockResourceMockRecorder

type MockResourceMockRecorder struct {
	// contains filtered or unexported fields
}

MockResourceMockRecorder is the mock recorder for MockResource

func (*MockResourceMockRecorder) Changed

func (mr *MockResourceMockRecorder) Changed(other interface{}) *gomock.Call

Changed indicates an expected call of Changed

func (*MockResourceMockRecorder) Clone

func (mr *MockResourceMockRecorder) Clone() *gomock.Call

Clone indicates an expected call of Clone

func (*MockResourceMockRecorder) ID

ID indicates an expected call of ID

func (*MockResourceMockRecorder) Labels

func (mr *MockResourceMockRecorder) Labels() *gomock.Call

Labels indicates an expected call of Labels

func (*MockResourceMockRecorder) Marshal

func (mr *MockResourceMockRecorder) Marshal() *gomock.Call

Marshal indicates an expected call of Marshal

func (*MockResourceMockRecorder) Peers

func (mr *MockResourceMockRecorder) Peers() *gomock.Call

Peers indicates an expected call of Peers

func (*MockResourceMockRecorder) ScaleCompleted

func (mr *MockResourceMockRecorder) ScaleCompleted(arg0 interface{}) *gomock.Call

ScaleCompleted indicates an expected call of ScaleCompleted

func (*MockResourceMockRecorder) SetID

func (mr *MockResourceMockRecorder) SetID(id interface{}) *gomock.Call

SetID indicates an expected call of SetID

func (*MockResourceMockRecorder) SetPeers

func (mr *MockResourceMockRecorder) SetPeers(peers interface{}) *gomock.Call

SetPeers indicates an expected call of SetPeers

func (*MockResourceMockRecorder) Stale

func (mr *MockResourceMockRecorder) Stale(other interface{}) *gomock.Call

Stale indicates an expected call of Stale

func (*MockResourceMockRecorder) Unmarshal

func (mr *MockResourceMockRecorder) Unmarshal(data interface{}) *gomock.Call

Unmarshal indicates an expected call of Unmarshal

type MockResourceStore

type MockResourceStore struct {
	// contains filtered or unexported fields
}

MockResourceStore is a mock of ResourceStore interface

func NewMockResourceStore

func NewMockResourceStore(ctrl *gomock.Controller) *MockResourceStore

NewMockResourceStore creates a new mock instance

func (*MockResourceStore) AddReplica

func (m *MockResourceStore) AddReplica(arg0 *PeerReplica)

AddReplica mocks base method

func (*MockResourceStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockResourceStore) ForeachReplica

func (m *MockResourceStore) ForeachReplica(arg0 func(*PeerReplica) bool)

ForeachReplica mocks base method

func (*MockResourceStore) GetContainerAddr

func (m *MockResourceStore) GetContainerAddr(arg0 uint64) (string, error)

GetContainerAddr mocks base method

func (*MockResourceStore) GetPeerReplica

func (m *MockResourceStore) GetPeerReplica(id uint64, leader bool) *PeerReplica

GetPeerReplica mocks base method

func (*MockResourceStore) GetTransport

func (m *MockResourceStore) GetTransport() ReplicaTransport

GetTransport mocks base method

func (*MockResourceStore) HandleReplicaMsg

func (m *MockResourceStore) HandleReplicaMsg(arg0 interface{}) interface{}

HandleReplicaMsg mocks base method

func (*MockResourceStore) LocalStore

func (m *MockResourceStore) LocalStore() LocalStore

LocalStore mocks base method

func (*MockResourceStore) Meta

func (m *MockResourceStore) Meta() Container

Meta mocks base method

func (*MockResourceStore) MustStartTask

func (m *MockResourceStore) MustStartTask(arg0 func(context.Context)) uint64

MustStartTask mocks base method

func (*MockResourceStore) MustStopTask

func (m *MockResourceStore) MustStopTask(arg0 uint64)

MustStopTask mocks base method

func (*MockResourceStore) RemoveReplica

func (m *MockResourceStore) RemoveReplica(id uint64)

RemoveReplica mocks base method

func (*MockResourceStore) Start

func (m *MockResourceStore) Start()

Start mocks base method

type MockResourceStoreMockRecorder

type MockResourceStoreMockRecorder struct {
	// contains filtered or unexported fields
}

MockResourceStoreMockRecorder is the mock recorder for MockResourceStore

func (*MockResourceStoreMockRecorder) AddReplica

func (mr *MockResourceStoreMockRecorder) AddReplica(arg0 interface{}) *gomock.Call

AddReplica indicates an expected call of AddReplica

func (*MockResourceStoreMockRecorder) ForeachReplica

func (mr *MockResourceStoreMockRecorder) ForeachReplica(arg0 interface{}) *gomock.Call

ForeachReplica indicates an expected call of ForeachReplica

func (*MockResourceStoreMockRecorder) GetContainerAddr

func (mr *MockResourceStoreMockRecorder) GetContainerAddr(arg0 interface{}) *gomock.Call

GetContainerAddr indicates an expected call of GetContainerAddr

func (*MockResourceStoreMockRecorder) GetPeerReplica

func (mr *MockResourceStoreMockRecorder) GetPeerReplica(id, leader interface{}) *gomock.Call

GetPeerReplica indicates an expected call of GetPeerReplica

func (*MockResourceStoreMockRecorder) GetTransport

func (mr *MockResourceStoreMockRecorder) GetTransport() *gomock.Call

GetTransport indicates an expected call of GetTransport

func (*MockResourceStoreMockRecorder) HandleReplicaMsg

func (mr *MockResourceStoreMockRecorder) HandleReplicaMsg(arg0 interface{}) *gomock.Call

HandleReplicaMsg indicates an expected call of HandleReplicaMsg

func (*MockResourceStoreMockRecorder) LocalStore

func (mr *MockResourceStoreMockRecorder) LocalStore() *gomock.Call

LocalStore indicates an expected call of LocalStore

func (*MockResourceStoreMockRecorder) Meta

Meta indicates an expected call of Meta

func (*MockResourceStoreMockRecorder) MustStartTask

func (mr *MockResourceStoreMockRecorder) MustStartTask(arg0 interface{}) *gomock.Call

MustStartTask indicates an expected call of MustStartTask

func (*MockResourceStoreMockRecorder) MustStopTask

func (mr *MockResourceStoreMockRecorder) MustStopTask(arg0 interface{}) *gomock.Call

MustStopTask indicates an expected call of MustStopTask

func (*MockResourceStoreMockRecorder) RemoveReplica

func (mr *MockResourceStoreMockRecorder) RemoveReplica(id interface{}) *gomock.Call

RemoveReplica indicates an expected call of RemoveReplica

func (*MockResourceStoreMockRecorder) Start

Start indicates an expected call of Start

type MockRoleChangeHandler

type MockRoleChangeHandler struct {
	// contains filtered or unexported fields
}

MockRoleChangeHandler is a mock of RoleChangeHandler interface

func NewMockRoleChangeHandler

func NewMockRoleChangeHandler(ctrl *gomock.Controller) *MockRoleChangeHandler

NewMockRoleChangeHandler creates a new mock instance

func (*MockRoleChangeHandler) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockRoleChangeHandler) ProphetBecomeFollower

func (m *MockRoleChangeHandler) ProphetBecomeFollower()

ProphetBecomeFollower mocks base method

func (*MockRoleChangeHandler) ProphetBecomeLeader

func (m *MockRoleChangeHandler) ProphetBecomeLeader()

ProphetBecomeLeader mocks base method

type MockRoleChangeHandlerMockRecorder

type MockRoleChangeHandlerMockRecorder struct {
	// contains filtered or unexported fields
}

MockRoleChangeHandlerMockRecorder is the mock recorder for MockRoleChangeHandler

func (*MockRoleChangeHandlerMockRecorder) ProphetBecomeFollower

func (mr *MockRoleChangeHandlerMockRecorder) ProphetBecomeFollower() *gomock.Call

ProphetBecomeFollower indicates an expected call of ProphetBecomeFollower

func (*MockRoleChangeHandlerMockRecorder) ProphetBecomeLeader

func (mr *MockRoleChangeHandlerMockRecorder) ProphetBecomeLeader() *gomock.Call

ProphetBecomeLeader indicates an expected call of ProphetBecomeLeader

type MockSerializable

type MockSerializable struct {
	// contains filtered or unexported fields
}

MockSerializable is a mock of Serializable interface

func NewMockSerializable

func NewMockSerializable(ctrl *gomock.Controller) *MockSerializable

NewMockSerializable creates a new mock instance

func (*MockSerializable) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

type MockSerializableMockRecorder

type MockSerializableMockRecorder struct {
	// contains filtered or unexported fields
}

MockSerializableMockRecorder is the mock recorder for MockSerializable

type MockcodecSerializable

type MockcodecSerializable struct {
	// contains filtered or unexported fields
}

MockcodecSerializable is a mock of codecSerializable interface

func NewMockcodecSerializable

func NewMockcodecSerializable(ctrl *gomock.Controller) *MockcodecSerializable

NewMockcodecSerializable creates a new mock instance

func (*MockcodecSerializable) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockcodecSerializable) Init

func (m *MockcodecSerializable) Init(adapter Adapter) error

Init mocks base method

func (*MockcodecSerializable) Prepare

func (m *MockcodecSerializable) Prepare() error

Prepare mocks base method

type MockcodecSerializableMockRecorder

type MockcodecSerializableMockRecorder struct {
	// contains filtered or unexported fields
}

MockcodecSerializableMockRecorder is the mock recorder for MockcodecSerializable

func (*MockcodecSerializableMockRecorder) Init

func (mr *MockcodecSerializableMockRecorder) Init(adapter interface{}) *gomock.Call

Init indicates an expected call of Init

func (*MockcodecSerializableMockRecorder) Prepare

Prepare indicates an expected call of Prepare

type Node

type Node struct {
	Name string `json:"name"`
	Addr string `json:"addr"`
}

Node is prophet info

type Operator

type Operator interface {
	ResourceID() uint64
	ResourceKind() ResourceKind
	Do(target *ResourceRuntime) (*resourceHeartbeatRsp, bool)
}

Operator is an interface to scheduler resource

type Option

type Option func(*options)

Option is prophet create option

func ParseProphetOptions

func ParseProphetOptions(name string) []Option

ParseProphetOptions parse the prophet options from command line parameter

func ParseProphetOptionsWithPath

func ParseProphetOptionsWithPath(name, path string) []Option

ParseProphetOptionsWithPath parse the prophet options from command line parameter, using spec data path for embed etcd server

func WithCountResourceReplicas

func WithCountResourceReplicas(value int) Option

WithCountResourceReplicas replica number per resource

func WithEmbeddedEtcd

func WithEmbeddedEtcd(cfg *EmbeddedEtcdCfg) Option

WithEmbeddedEtcd using embedded etcd cluster

func WithExternalEtcd

func WithExternalEtcd(client *clientv3.Client) Option

WithExternalEtcd using external etcd cluster

func WithLeaseTTL

func WithLeaseTTL(leaseTTL int64) Option

WithLeaseTTL prophet leader lease ttl

func WithLocationLabels

func WithLocationLabels(value []string) Option

WithLocationLabels the label used for location

func WithMaxAllowContainerDownDuration

func WithMaxAllowContainerDownDuration(value time.Duration) Option

WithMaxAllowContainerDownDuration maximum down time of removed from replicas

func WithMaxFreezeScheduleInterval

func WithMaxFreezeScheduleInterval(value time.Duration) Option

WithMaxFreezeScheduleInterval freeze the container for a while if shouldSchedule is returns false

func WithMaxLimitSnapshotsCount

func WithMaxLimitSnapshotsCount(value uint64) Option

WithMaxLimitSnapshotsCount maximum count of node about snapshot

func WithMaxRPCConnIdle

func WithMaxRPCConnIdle(value time.Duration) Option

WithMaxRPCConnIdle set MaxRPCConnIdle

func WithMaxRPCCons

func WithMaxRPCCons(value int) Option

WithMaxRPCCons set MaxRPCCons

func WithMaxRPCTimeout

func WithMaxRPCTimeout(value time.Duration) Option

WithMaxRPCTimeout set MaxRPCTimeout

func WithMaxRebalanceLeader

func WithMaxRebalanceLeader(value uint64) Option

WithMaxRebalanceLeader maximum count of transfer leader operator

func WithMaxRebalanceReplica

func WithMaxRebalanceReplica(value uint64) Option

WithMaxRebalanceReplica maximum count of remove|add replica operator

func WithMaxScheduleInterval

func WithMaxScheduleInterval(value time.Duration) Option

WithMaxScheduleInterval using MaxScheduleInterval maximum schedule interval per scheduler

func WithMaxScheduleReplica

func WithMaxScheduleReplica(value uint64) Option

WithMaxScheduleReplica maximum count of schedule replica operator

func WithMaxScheduleRetries

func WithMaxScheduleRetries(value int) Option

WithMaxScheduleRetries using MaxScheduleRetries maximum retry times for schedule

func WithMinAvailableStorageUsedRate

func WithMinAvailableStorageUsedRate(value int) Option

WithMinAvailableStorageUsedRate minimum storage used rate of container, if the rate is over this value, skip the container

func WithMinScheduleInterval

func WithMinScheduleInterval(value time.Duration) Option

WithMinScheduleInterval using MinScheduleInterval minimum schedule interval per scheduler

func WithRPCAddr

func WithRPCAddr(value string) Option

WithRPCAddr set rpc address

func WithRoleChangeHandler

func WithRoleChangeHandler(Handler RoleChangeHandler) Option

WithRoleChangeHandler using a role changed handler

func WithScaleOnNewStore

func WithScaleOnNewStore() Option

WithScaleOnNewStore set EnableScaleOnNewStore

func WithScheduler

func WithScheduler(value Scheduler) Option

WithScheduler add a scheduler

func WithTimeoutWaitOperatorComplete

func WithTimeoutWaitOperatorComplete(value time.Duration) Option

WithTimeoutWaitOperatorComplete timeout for waitting teh operator complete

type Pair

type Pair struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Pair key value pair

type Peer

type Peer struct {
	ID          uint64 `json:"id"`
	ContainerID uint64 `json:"cid"`
}

Peer is the resource peer

func FindPeer

func FindPeer(peers []*Peer, containerID uint64) (Peer, bool)

FindPeer find peer at the spec container

func (*Peer) Clone

func (p *Peer) Clone() *Peer

Clone returns a clone value

type PeerReplica

type PeerReplica struct {
	// contains filtered or unexported fields
}

PeerReplica is the Resource peer replicatation. Every Resource has N replicatation in N stores.

func CreatePeerReplica

func CreatePeerReplica(store ResourceStore, meta Resource, handler PeerReplicaHandler, elector Elector) (*PeerReplica, error)

CreatePeerReplica create a resource replica at current container

func NewPeerReplica

func NewPeerReplica(store ResourceStore, meta Resource, peer Peer, handler PeerReplicaHandler, elector Elector) *PeerReplica

NewPeerReplica create a resource replica at current container

func (*PeerReplica) AddPeer

func (pr *PeerReplica) AddPeer(peer Peer)

AddPeer add a peer to this resource

func (*PeerReplica) ChangeLeaderTo

func (pr *PeerReplica) ChangeLeaderTo(leader uint64, cb func(interface{}, error))

ChangeLeaderTo change leader to new leader

func (*PeerReplica) CollectDownPeers

func (pr *PeerReplica) CollectDownPeers(maxDuration time.Duration) []*PeerStats

CollectDownPeers returns the down peers

func (*PeerReplica) CollectPendingPeers

func (pr *PeerReplica) CollectPendingPeers() []*Peer

CollectPendingPeers returns the pending peers

func (*PeerReplica) Destroy

func (pr *PeerReplica) Destroy()

Destroy destory the resource replica from current container

func (*PeerReplica) Do

func (pr *PeerReplica) Do(doFunc func(error), timeout time.Duration)

Do do something async

func (*PeerReplica) Heartbeat

func (pr *PeerReplica) Heartbeat()

Heartbeat send the hb to other peers

func (*PeerReplica) IsLeader

func (pr *PeerReplica) IsLeader() bool

IsLeader returns the peer replica is the leader

func (*PeerReplica) Peer

func (pr *PeerReplica) Peer() *Peer

Peer returns the current peer of this resource

func (*PeerReplica) RemovePeer

func (pr *PeerReplica) RemovePeer(peer Peer)

RemovePeer remove peer

func (*PeerReplica) Resource

func (pr *PeerReplica) Resource() Resource

Resource returns the meta

func (*PeerReplica) Scale

func (pr *PeerReplica) Scale(data interface{})

Scale scale this pr

func (*PeerReplica) Tag

func (pr *PeerReplica) Tag() string

Tag returns the pr tag

type PeerReplicaHandler

type PeerReplicaHandler interface {
	AddPeer(Resource, Peer)
	RemovePeer(Resource, Peer) bool
	Scale(Resource, interface{}) (bool, []*PeerReplica)
	Heartbeat(Resource) bool
	Destory(Resource)

	ResourceBecomeLeader(Resource)
	ResourceBecomeFollower(Resource)
}

PeerReplicaHandler the interface to handle replica event message

type PeerStats

type PeerStats struct {
	Peer        *Peer
	DownSeconds uint64
}

PeerStats peer stats

func (*PeerStats) Clone

func (ps *PeerStats) Clone() *PeerStats

Clone returns a clone value

type Prophet

type Prophet interface {
	// Start start the prophet instance, this will start the lead election, heartbeat loop and listen requests
	Start()
	// GetStore returns the Store
	GetStore() Store
	// GetRPC returns the RPC client
	GetRPC() RPC
	// GetEtcdClient returns the internal etcd instance
	GetEtcdClient() *clientv3.Client
}

Prophet is the distributed scheduler and coordinator

func NewProphet

func NewProphet(name string, adapter Adapter, opts ...Option) Prophet

NewProphet returns a prophet instance

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is the struct responsible for tracking the state of the queue.

func New

func New(hint int64) *Queue

New is a constructor for a new threadsafe queue.

func (*Queue) Dispose

func (q *Queue) Dispose() []interface{}

Dispose will dispose of this queue and returns the items disposed. Any subsequent calls to Get or Put will return an error.

func (*Queue) Disposed

func (q *Queue) Disposed() bool

Disposed returns a bool indicating if this queue has had disposed called on it.

func (*Queue) Empty

func (q *Queue) Empty() bool

Empty returns a bool indicating if this bool is empty.

func (*Queue) Get

func (q *Queue) Get(number int64, items []interface{}) (int64, error)

Get retrieves items from the queue. If there are some items in the queue, get will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue.

func (*Queue) Len

func (q *Queue) Len() int64

Len returns the number of items in this queue.

func (*Queue) Peek

func (q *Queue) Peek() (interface{}, error)

Peek returns a the first item in the queue by value without modifying the queue.

func (*Queue) Poll

func (q *Queue) Poll(number int64, items []interface{}, timeout time.Duration) (int64, error)

Poll retrieves items from the queue. If there are some items in the queue, Poll will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue or the provided timeout is reached. A non-positive timeout will block until items are added. If a timeout occurs, ErrTimeout is returned.

func (*Queue) Put

func (q *Queue) Put(items ...interface{}) error

Put will add the specified items to the queue.

func (*Queue) PutOrUpdate

func (q *Queue) PutOrUpdate(cmp func(interface{}, interface{}) bool, item interface{}) error

PutOrUpdate will add the specified item to the queue, update it if exists

type RPC

type RPC interface {
	TiggerContainerHeartbeat()
	TiggerResourceHeartbeat(id uint64)
	AllocID() (uint64, error)
	AskSplit(res Resource) (uint64, []uint64, error)
}

RPC prophet rpc

type ReplicaTransport

type ReplicaTransport interface {
	Start()
	Stop()

	Send(uint64, interface{})
}

ReplicaTransport transport from peers

func NewReplicaTransport

func NewReplicaTransport(addr string, store ResourceStore, factory func() Resource) ReplicaTransport

NewReplicaTransport returns a replica transport to send and received message

type Resource

type Resource interface {
	Serializable

	// SetID update the resource id
	SetID(id uint64)
	// ID returns the resource id
	ID() uint64
	// Peers returns the repication peers
	Peers() []*Peer
	// SetPeers update the repication peers
	SetPeers(peers []*Peer)
	// 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() []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
}

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

type ResourceHeartbeatReq

type ResourceHeartbeatReq struct {
	Resource     Resource     `json:"-"`
	Data         []byte       `json:"data"`
	LeaderPeer   *Peer        `json:"leaderPeer"`
	DownPeers    []*PeerStats `json:"downPeers"`
	PendingPeers []*Peer      `json:"pendingPeers"`
	ContainerID  uint64       `json:"cid"`
}

ResourceHeartbeatReq resource hb msg

func (*ResourceHeartbeatReq) Init

func (req *ResourceHeartbeatReq) Init(adapter Adapter) error

Init init

func (*ResourceHeartbeatReq) Prepare

func (req *ResourceHeartbeatReq) Prepare() error

Prepare prepare

type ResourceKind

type ResourceKind int

ResourceKind distinguishes different kinds of resources.

const (
	// LeaderKind leader
	LeaderKind ResourceKind = iota
	// ReplicaKind replication of resource
	ReplicaKind
)

type ResourceRuntime

type ResourceRuntime struct {
	// contains filtered or unexported fields
}

ResourceRuntime resource runtime info

func (*ResourceRuntime) Clone

func (res *ResourceRuntime) Clone() *ResourceRuntime

Clone returns a clone resource runtime

func (*ResourceRuntime) GetContainerIDs

func (res *ResourceRuntime) GetContainerIDs() map[uint64]struct{}

GetContainerIDs returns all container id

func (*ResourceRuntime) GetContainerPeer

func (res *ResourceRuntime) GetContainerPeer(containerID uint64) *Peer

GetContainerPeer returns the peer in the container

func (*ResourceRuntime) GetPeer

func (res *ResourceRuntime) GetPeer(peerID uint64) *Peer

GetPeer return the peer

func (*ResourceRuntime) GetPendingPeer

func (res *ResourceRuntime) GetPendingPeer(peerID uint64) *Peer

GetPendingPeer returns pending peer

func (*ResourceRuntime) RemoveContainerPeer

func (res *ResourceRuntime) RemoveContainerPeer(id uint64)

RemoveContainerPeer remove container peer

type ResourceStore

type ResourceStore interface {
	Start()

	Meta() Container
	GetTransport() ReplicaTransport
	GetContainerAddr(uint64) (string, error)
	HandleReplicaMsg(interface{}) interface{}

	ForeachReplica(func(*PeerReplica) bool)

	// GetPeerReplica returns a peer replicatation from the store,
	// when `leader` is true, only return the leader replicatation
	GetPeerReplica(id uint64, leader bool) *PeerReplica
	// AddReplica add a replicatation
	AddReplica(*PeerReplica)
	RemoveReplica(id uint64)

	MustStartTask(func(context.Context)) uint64
	MustStopTask(uint64)

	LocalStore() LocalStore
}

ResourceStore is a container of resources, which maintains a set of resources

func NewResourceStore

func NewResourceStore(meta Container,
	localStore LocalStore,
	pd Prophet,
	elector Elector,
	handler PeerReplicaHandler,
	factory func() Resource,
	hbInterval time.Duration,
	workerCount uint64) ResourceStore

NewResourceStore creates a resource store

type RoleChangeHandler

type RoleChangeHandler interface {
	ProphetBecomeLeader()
	ProphetBecomeFollower()
}

RoleChangeHandler prophet role change handler

type Runner

type Runner struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Runner TODO

func NewRunner

func NewRunner() *Runner

NewRunner returns a task runner

func (*Runner) AddNamedWorker

func (s *Runner) AddNamedWorker(name string) (uint64, error)

AddNamedWorker add a named worker, the named worker has uniq queue, so jobs are linear execution

func (*Runner) IsNamedWorkerBusy

func (s *Runner) IsNamedWorkerBusy(worker string) bool

IsNamedWorkerBusy returns true if named queue is not empty

func (*Runner) RunCancelableTask

func (s *Runner) RunCancelableTask(task func(context.Context)) (uint64, error)

RunCancelableTask run a task that can be cancelled Example: err := s.RunCancelableTask(func(ctx context.Context) {

select {
case <-ctx.Done():
// cancelled
case <-time.After(time.Second):
	// do something
}

}) if err != nil {

// hanle error
return

}

func (*Runner) RunJob

func (s *Runner) RunJob(desc string, task func() error) error

RunJob run a job

func (*Runner) RunJobWithNamedWorker

func (s *Runner) RunJobWithNamedWorker(desc, worker string, task func() error) error

RunJobWithNamedWorker run a job in a named worker

func (*Runner) RunJobWithNamedWorkerWithCB

func (s *Runner) RunJobWithNamedWorkerWithCB(desc, worker string, task func() error, cb func(*Job)) error

RunJobWithNamedWorkerWithCB run a job in a named worker

func (*Runner) RunTask

func (s *Runner) RunTask(task func()) error

RunTask runs a task in new goroutine

func (*Runner) Stop

func (s *Runner) Stop() error

Stop stop all task RunTask will failure with an error Wait complete for the tasks that already in execute Cancel the tasks that is not start

func (*Runner) StopCancelableTask

func (s *Runner) StopCancelableTask(id uint64) error

StopCancelableTask stop cancelable spec task

type Runtime

type Runtime struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Runtime runtime info

func (*Runtime) Container

func (rc *Runtime) Container(id uint64) *ContainerRuntime

Container returns a cloned value of container runtime info

func (*Runtime) Containers

func (rc *Runtime) Containers() []*ContainerRuntime

Containers returns the containers, using clone

func (*Runtime) RandFollowerResource

func (rc *Runtime) RandFollowerResource(id uint64) *ResourceRuntime

RandFollowerResource returns the random follower resource

func (*Runtime) RandLeaderResource

func (rc *Runtime) RandLeaderResource(id uint64) *ResourceRuntime

RandLeaderResource returns the random leader resource

func (*Runtime) Resource

func (rc *Runtime) Resource(id uint64) *ResourceRuntime

Resource returns a cloned value of resource runtime info

func (*Runtime) ResourceContainers

func (rc *Runtime) ResourceContainers(target *ResourceRuntime) []*ContainerRuntime

ResourceContainers returns containers that has the resource's peer

func (*Runtime) ResourceFollowerContainers

func (rc *Runtime) ResourceFollowerContainers(res *ResourceRuntime) []*ContainerRuntime

ResourceFollowerContainers returns all containers for peers exclude leader

func (*Runtime) Resources

func (rc *Runtime) Resources() []*ResourceRuntime

Resources returns the resources, using clone

type Scheduler

type Scheduler interface {
	Name() string
	ResourceKind() ResourceKind
	ResourceLimit() uint64
	Prepare(rt *Runtime) error
	Cleanup(rt *Runtime)
	Schedule(rt *Runtime) Operator
}

Scheduler is an interface to schedule resources.

type Selector

type Selector interface {
	SelectSource(containers []*ContainerRuntime, filters ...Filter) *ContainerRuntime
	SelectTarget(containers []*ContainerRuntime, filters ...Filter) *ContainerRuntime
}

Selector is an interface to select source and target container to schedule.

type Serializable

type Serializable interface {
}

Serializable serializable

type State

type State int

State is the state

const (
	// UP is normal state
	UP State = iota
	// Down is the unavailable state
	Down
	// Tombstone is the destory state
	Tombstone
)

type Store

type Store interface {
	// PutResource puts the meta to the store
	PutResource(meta Resource) error
	// GetResource returns the spec resource
	GetResource(id uint64) (Resource, error)
	// PutContainer puts the meta to the store
	PutContainer(meta Container) error
	// GetContainer returns the spec container
	GetContainer(id uint64) (Container, error)
	// LoadResources load all resources
	LoadResources(limit int64, do func(Resource)) error
	// LoadContainers load all containers
	LoadContainers(limit int64, do func(Container)) error

	// AllocID returns the alloc id
	AllocID() (uint64, error)

	// PutBootstrapped put cluster is bootstrapped
	PutBootstrapped(container Container, resources ...Resource) (bool, error)

	// PutIfNotExists put the value at path
	// returns true, nil, nil if created
	// returns false, exists, nil if not created
	PutIfNotExists(path string, value []byte) (bool, []byte, error)
	// RemoveIfValueMatched returns true if the expect value is and the exists value are matched
	RemoveIfValueMatched(path string, expect []byte) (bool, error)
}

Store meta store

type Watcher

type Watcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Watcher watcher client

func NewWatcher

func NewWatcher(addrs ...string) *Watcher

NewWatcher returns a watcher for watch

func NewWatcherWithProphet

func NewWatcherWithProphet(p Prophet) *Watcher

NewWatcherWithProphet returns a watcher for watch

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stop watch

func (*Watcher) Watch

func (w *Watcher) Watch(flag int) chan *EventNotify

Watch watch event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to