simulator

package
v0.0.0-...-50c8040 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddNodes

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

AddNodes adds nodes.

func (*AddNodes) Run

func (e *AddNodes) Run(raft *RaftEngine, tickCount int64) bool

Run implements the event interface.

type Client

type Client interface {
	GetClusterID(ctx context.Context) uint64
	AllocID(ctx context.Context) (uint64, error)
	Bootstrap(ctx context.Context, store *metapb.Store, region *metapb.Region) error
	PutStore(ctx context.Context, store *metapb.Store) error
	StoreHeartbeat(ctx context.Context, stats *pdpb.StoreStats) error
	RegionHeartbeat(ctx context.Context, region *core.RegionInfo) error
	PutPDConfig(*PDConfig) error

	Close()
}

Client is a PD (Placement Driver) client. It should not be used after calling Close().

func NewClient

func NewClient(pdAddr string, tag string) (Client, <-chan *pdpb.RegionHeartbeatResponse, error)

NewClient creates a PD client.

type Connection

type Connection struct {
	Nodes map[uint64]*Node
	// contains filtered or unexported fields
}

Connection records the information of connection among nodes.

func NewConnection

func NewConnection(simCase *cases.Case, pdAddr string, storeConfig *SimConfig) (*Connection, error)

NewConnection creates nodes according to the configuration and returns the connection among nodes.

type Coprocessor

type Coprocessor struct {
	RegionSplitSize typeutil.ByteSize `toml:"region-split-size" json:"region-split-size"`
	RegionSplitKey  uint64            `toml:"region-split-keys" json:"region-split-keys"`
}

Coprocessor the configuration for coprocessor.

type DeleteNodes

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

DeleteNodes deletes nodes.

func (*DeleteNodes) Run

func (e *DeleteNodes) Run(raft *RaftEngine, tickCount int64) bool

Run implements the event interface.

type Driver

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

Driver promotes the cluster status change.

func NewDriver

func NewDriver(pdAddr string, caseName string, simConfig *SimConfig) (*Driver, error)

NewDriver returns a driver.

func (*Driver) ChangePDConfig

func (d *Driver) ChangePDConfig() error

ChangePDConfig changes pd config

func (*Driver) Check

func (d *Driver) Check() bool

Check checks if the simulation is completed.

func (*Driver) GetBootstrapInfo

func (d *Driver) GetBootstrapInfo(r *RaftEngine) (*metapb.Store, *metapb.Region, error)

GetBootstrapInfo returns a valid bootstrap store and region.

func (*Driver) Prepare

func (d *Driver) Prepare() error

Prepare initializes cluster information, bootstraps cluster and starts nodes.

func (*Driver) Start

func (d *Driver) Start() error

Start starts all nodes.

func (*Driver) Stop

func (d *Driver) Stop()

Stop stops all nodes.

func (*Driver) Tick

func (d *Driver) Tick()

Tick invokes nodes' Tick.

func (*Driver) TickCount

func (d *Driver) TickCount() int64

TickCount returns the simulation's tick count.

type Event

type Event interface {
	Run(raft *RaftEngine, tickCount int64) bool
}

Event affects the status of the cluster.

type EventRunner

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

EventRunner includes all events.

func NewEventRunner

func NewEventRunner(events []cases.EventDescriptor, raftEngine *RaftEngine) *EventRunner

NewEventRunner creates an event runner.

func (*EventRunner) Tick

func (er *EventRunner) Tick(tickCount int64)

Tick ticks the event run

type Node

type Node struct {
	*metapb.Store
	syncutil.RWMutex
	// contains filtered or unexported fields
}

Node simulates a TiKV.

func NewNode

func NewNode(s *cases.Store, pdAddr string, config *SimConfig) (*Node, error)

NewNode returns a Node.

func (*Node) AddTask

func (n *Node) AddTask(task *Task)

AddTask adds task in this node.

func (*Node) GetState

func (n *Node) GetState() metapb.StoreState

GetState returns current node state.

func (*Node) Start

func (n *Node) Start() error

Start starts the node.

func (*Node) Stop

func (n *Node) Stop()

Stop stops this node.

func (*Node) Tick

func (n *Node) Tick(wg *sync.WaitGroup)

Tick steps node status change.

type PDConfig

type PDConfig struct {
	PlacementRules []*placement.Rule
	LocationLabels typeutil.StringSlice
}

PDConfig saves some config which may be changed in PD.

type RaftEngine

type RaftEngine struct {
	syncutil.RWMutex
	// contains filtered or unexported fields
}

RaftEngine records all raft information.

func NewRaftEngine

func NewRaftEngine(conf *cases.Case, conn *Connection, storeConfig *SimConfig) *RaftEngine

NewRaftEngine creates the initialized raft with the configuration.

func (*RaftEngine) BootstrapRegion

func (r *RaftEngine) BootstrapRegion() *core.RegionInfo

BootstrapRegion gets a region to construct bootstrap info.

func (*RaftEngine) GetRegion

func (r *RaftEngine) GetRegion(regionID uint64) *core.RegionInfo

GetRegion returns the RegionInfo with regionID.

func (*RaftEngine) GetRegionByKey

func (r *RaftEngine) GetRegionByKey(regionKey []byte) *core.RegionInfo

GetRegionByKey searches the RegionInfo from regionTree

func (*RaftEngine) GetRegionChange

func (r *RaftEngine) GetRegionChange(storeID uint64) []uint64

GetRegionChange returns a list of RegionID for a given store.

func (*RaftEngine) GetRegions

func (r *RaftEngine) GetRegions() []*core.RegionInfo

GetRegions gets all RegionInfo from regionMap

func (*RaftEngine) NeedSplit

func (r *RaftEngine) NeedSplit(size, rows int64) bool

NeedSplit checks whether the region needs to split according its size and number of keys.

func (*RaftEngine) ResetRegionChange

func (r *RaftEngine) ResetRegionChange(storeID uint64, regionID uint64)

ResetRegionChange resets RegionInfo on a specific store with a given Region ID

func (*RaftEngine) SetRegion

func (r *RaftEngine) SetRegion(region *core.RegionInfo) []*core.RegionInfo

SetRegion sets the RegionInfo with regionID

type RaftStore

type RaftStore struct {
	Capacity                typeutil.ByteSize `toml:"capacity" json:"capacity"`
	ExtraUsedSpace          typeutil.ByteSize `toml:"extra-used-space" json:"extra-used-space"`
	RegionHeartBeatInterval typeutil.Duration `toml:"pd-heartbeat-tick-interval" json:"pd-heartbeat-tick-interval"`
	StoreHeartBeatInterval  typeutil.Duration `toml:"pd-store-heartbeat-tick-interval" json:"pd-store-heartbeat-tick-interval"`
}

RaftStore the configuration for raft store.

type ReadFlowOnRegion

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

ReadFlowOnRegion reads bytes in some region

func (*ReadFlowOnRegion) Run

func (e *ReadFlowOnRegion) Run(raft *RaftEngine, tickCount int64) bool

Run implements the event interface.

type SimConfig

type SimConfig struct {
	// tick
	CaseName        string            `toml:"case-name"`
	SimTickInterval typeutil.Duration `toml:"sim-tick-interval"`
	// store
	StoreIOMBPerSecond int64       `toml:"store-io-per-second"`
	StoreVersion       string      `toml:"store-version"`
	RaftStore          RaftStore   `toml:"raftstore"`
	Coprocessor        Coprocessor `toml:"coprocessor"`
	// server
	ServerConfig *config.Config `toml:"server"`
}

SimConfig is the simulator configuration.

func NewSimConfig

func NewSimConfig(serverLogLevel string) *SimConfig

NewSimConfig create a new configuration of the simulator.

func (*SimConfig) Adjust

func (sc *SimConfig) Adjust(meta *toml.MetaData) error

Adjust is used to adjust configurations

type Task

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

Task running in node.

func (*Task) Desc

func (t *Task) Desc() string

Desc returns the description of the Task.

func (*Task) RegionID

func (t *Task) RegionID() uint64

RegionID returns the region-id of the Task.

func (*Task) Step

func (t *Task) Step(engine *RaftEngine) (isFinished bool)

Step execute once on the Task.

type WriteFlowOnRegion

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

WriteFlowOnRegion writes bytes in some region.

func (*WriteFlowOnRegion) Run

func (e *WriteFlowOnRegion) Run(raft *RaftEngine, tickCount int64) bool

Run implements the event interface.

type WriteFlowOnSpot

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

WriteFlowOnSpot writes bytes in some range.

func (*WriteFlowOnSpot) Run

func (e *WriteFlowOnSpot) Run(raft *RaftEngine, tickCount int64) bool

Run implements the event interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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