procedure

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateInit      = "init"
	StateRunning   = "running"
	StateFinished  = "finished"
	StateFailed    = "failed"
	StateCancelled = "cancelled"
)
View Source
const (
	Version              = "v1"
	PathProcedure        = "procedure"
	PathDeletedProcedure = "deletedProcedure"
)

Variables

View Source
var (
	ErrShardLeaderNotFound  = coderr.NewCodeError(coderr.Internal, "shard leader not found")
	ErrProcedureNotFound    = coderr.NewCodeError(coderr.Internal, "procedure not found")
	ErrClusterConfigChanged = coderr.NewCodeError(coderr.Internal, "cluster config changed")
	ErrTableAlreadyExists   = coderr.NewCodeError(coderr.Internal, "table already exists")
)

Functions

This section is empty.

Types

type CreateTableProcedure

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

func (*CreateTableProcedure) Cancel

func (*CreateTableProcedure) ID

func (p *CreateTableProcedure) ID() uint64

func (*CreateTableProcedure) Start

func (p *CreateTableProcedure) Start(ctx context.Context) error

func (*CreateTableProcedure) State

func (p *CreateTableProcedure) State() State

func (*CreateTableProcedure) Typ

func (p *CreateTableProcedure) Typ() Typ

type CreateTableRequest

type CreateTableRequest struct {
	Cluster   *cluster.Cluster
	SourceReq *metaservicepb.CreateTableRequest

	OnSucceeded func(*cluster.CreateTableResult) error
	OnFailed    func(error) error
}

type DropTableProcedure

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

func (*DropTableProcedure) Cancel

func (p *DropTableProcedure) Cancel(_ context.Context) error

func (*DropTableProcedure) ID

func (p *DropTableProcedure) ID() uint64

func (*DropTableProcedure) Start

func (p *DropTableProcedure) Start(ctx context.Context) error

func (*DropTableProcedure) State

func (p *DropTableProcedure) State() State

func (*DropTableProcedure) Typ

func (p *DropTableProcedure) Typ() Typ

type DropTableRequest

type DropTableRequest struct {
	Cluster   *cluster.Cluster
	SourceReq *metaservicepb.DropTableRequest

	OnSucceeded func(*cluster.TableInfo) error
	OnFailed    func(error) error
}

type EtcdStorageImpl

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

func (EtcdStorageImpl) CreateOrUpdate

func (e EtcdStorageImpl) CreateOrUpdate(ctx context.Context, meta *Meta) error

CreateOrUpdate example: /{rootPath}/v1/procedure/{procedureID} -> {procedureType} + {procedureState} + {data}

func (EtcdStorageImpl) List

func (e EtcdStorageImpl) List(ctx context.Context, batchSize int) ([]*Meta, error)

func (EtcdStorageImpl) MarkDeleted

func (e EtcdStorageImpl) MarkDeleted(ctx context.Context, id uint64) error

MarkDeleted Do a soft deletion, and the deleted key's format is: /{rootPath}/v1/historyProcedure/{clusterID}/{procedureID}

type Factory

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

func NewFactory

func NewFactory(allocator id.Allocator, dispatch eventdispatch.Dispatch) *Factory

func (*Factory) CreateCreateTableProcedure

func (f *Factory) CreateCreateTableProcedure(ctx context.Context, request *CreateTableRequest) (Procedure, error)

func (*Factory) CreateDropTableProcedure

func (f *Factory) CreateDropTableProcedure(ctx context.Context, request *DropTableRequest) (Procedure, error)

func (*Factory) CreateScatterProcedure

func (f *Factory) CreateScatterProcedure(ctx context.Context, request *ScatterRequest) (Procedure, error)

type Info

type Info struct {
	ID    uint64
	Typ   Typ
	State State
}

Info is used to provide immutable description procedure information.

type Manager

type Manager interface {
	// Start must be called before manager is used.
	Start(ctx context.Context) error
	// Stop must be called before manager is dropped.
	Stop(ctx context.Context) error

	// Submit procedure to be executed asynchronously.
	// TODO: change result type, add channel to get whether the procedure executed successfully
	Submit(ctx context.Context, procedure Procedure) error
	// Cancel procedure that has been submitted.
	Cancel(ctx context.Context, procedureID uint64) error
	ListRunningProcedure(ctx context.Context) ([]*Info, error)
}

func NewManagerImpl

func NewManagerImpl(client *clientv3.Client, rootPath string) (Manager, error)

type ManagerImpl

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

func (*ManagerImpl) Cancel

func (m *ManagerImpl) Cancel(ctx context.Context, procedureID uint64) error

func (*ManagerImpl) ListRunningProcedure

func (m *ManagerImpl) ListRunningProcedure(_ context.Context) ([]*Info, error)

func (*ManagerImpl) Start

func (m *ManagerImpl) Start(ctx context.Context) error

func (*ManagerImpl) Stop

func (m *ManagerImpl) Stop(ctx context.Context) error

func (*ManagerImpl) Submit

func (m *ManagerImpl) Submit(_ context.Context, procedure Procedure) error

type Meta

type Meta struct {
	ID      uint64
	Typ     Typ
	State   State
	RawData []byte
}

type Procedure

type Procedure interface {
	// ID of the procedure.
	ID() uint64

	// Typ of the procedure.
	Typ() Typ

	// Start the procedure.
	Start(ctx context.Context) error

	// Cancel the procedure.
	Cancel(ctx context.Context) error

	// State of the procedure. Retrieve the state of this procedure.
	State() State
}

Procedure is used to describe how to execute a set of operations from the scheduler, e.g. SwitchLeaderProcedure, MergeShardProcedure.

func NewCreateTableProcedure

func NewCreateTableProcedure(dispatch eventdispatch.Dispatch, cluster *cluster.Cluster, id uint64, req *metaservicepb.CreateTableRequest, onSucceeded func(*cluster.CreateTableResult) error, onFailed func(error) error) Procedure

func NewDropTableProcedure

func NewDropTableProcedure(dispatch eventdispatch.Dispatch, cluster *cluster.Cluster, id uint64, req *metaservicepb.DropTableRequest, onSucceeded func(*cluster.TableInfo) error, onFailed func(error) error) Procedure

func NewScatterProcedure

func NewScatterProcedure(dispatch eventdispatch.Dispatch, cluster *cluster.Cluster, id uint64, shardIDs []uint32) Procedure

type ScatterCallbackRequest

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

ScatterCallbackRequest is fsm callbacks param.

type ScatterProcedure

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

func (*ScatterProcedure) Cancel

func (p *ScatterProcedure) Cancel(_ context.Context) error

func (*ScatterProcedure) ID

func (p *ScatterProcedure) ID() uint64

func (*ScatterProcedure) Start

func (p *ScatterProcedure) Start(ctx context.Context) error

func (*ScatterProcedure) State

func (p *ScatterProcedure) State() State

func (*ScatterProcedure) Typ

func (p *ScatterProcedure) Typ() Typ

type ScatterRequest

type ScatterRequest struct {
	Cluster  *cluster.Cluster
	ShardIDs []uint32
}

type State

type State string

type Storage

type Storage interface {
	Write
	List(ctx context.Context, batchSize int) ([]*Meta, error)
	MarkDeleted(ctx context.Context, id uint64) error
}

func NewEtcdStorageImpl

func NewEtcdStorageImpl(client *clientv3.Client, rootPath string) Storage

type Typ

type Typ uint
const (
	Create Typ = iota
	Delete
	TransferLeader
	Migrate
	Split
	Merge
	Scatter
	CreateTable
	DropTable
)

type Write

type Write interface {
	CreateOrUpdate(ctx context.Context, meta *Meta) error
}

Jump to

Keyboard shortcuts

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