Skip to content

Commit

Permalink
Merge branch 'master' into save-goleveldb
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch authored Sep 12, 2018
2 parents 4171529 + 4a87403 commit 92240fe
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 288 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ endif

simulator:
CGO_ENABLED=0 go build -o bin/simulator cmd/simulator/main.go
bin/simulator

gofail-enable:
# Converting gofail failpoints...
Expand Down
8 changes: 6 additions & 2 deletions cmd/simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ func initRaftLogger() {

func simStart(pdAddr string, confName string, tickInterval time.Duration, clean ...server.CleanupFunc) {
start := time.Now()
driver := faketikv.NewDriver(pdAddr, confName)
err := driver.Prepare()
driver, err := faketikv.NewDriver(pdAddr, confName)
if err != nil {
simutil.Logger.Fatal("create driver error:", err)
}

err = driver.Prepare()
if err != nil {
simutil.Logger.Fatal("simulator prepare error:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/faketikv/cases/add_nodes_dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newAddNodesDynamic() *Conf {
conf.MaxID = id.maxID

numNodes := 8
e := &AddNodesDynamicInner{}
e := &AddNodesInner{}
e.Step = func(tick int64) uint64 {
if tick%100 == 0 && numNodes < 16 {
numNodes++
Expand Down
14 changes: 1 addition & 13 deletions pkg/faketikv/cases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type Store struct {
ID uint64
Status metapb.StoreState
Labels []metapb.StoreLabel
Labels []*metapb.StoreLabel
Capacity uint64
Available uint64
LeaderWeight float32
Expand Down Expand Up @@ -92,15 +92,3 @@ func NewConf(name string) *Conf {
}
return nil
}

// NeedSplit checks whether the region need to split according it's size
// and number of keys.
func (c *Conf) NeedSplit(size, rows int64) bool {
if c.RegionSplitSize != 0 && size >= c.RegionSplitSize {
return true
}
if c.RegionSplitKeys != 0 && rows >= c.RegionSplitKeys {
return true
}
return false
}
28 changes: 14 additions & 14 deletions pkg/faketikv/cases/event_inner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,57 @@

package cases

// EventInner is a detail template for custom events
// EventInner is a detail template for custom events.
type EventInner interface {
Type() string
}

// WriteFlowOnSpotInner writes bytes in some range
// WriteFlowOnSpotInner writes bytes in some range.
type WriteFlowOnSpotInner struct {
Step func(tick int64) map[string]int64
}

// Type implements the EventInner interface
// Type implements the EventInner interface.
func (w *WriteFlowOnSpotInner) Type() string {
return "write-flow-on-spot"
}

// WriteFlowOnRegionInner writes bytes in some region
// WriteFlowOnRegionInner writes bytes in some region.
type WriteFlowOnRegionInner struct {
Step func(tick int64) map[uint64]int64
}

// Type implements the EventInner interface
// Type implements the EventInner interface.
func (w *WriteFlowOnRegionInner) Type() string {
return "write-flow-on-region"
}

// ReadFlowOnRegionInner reads bytes in some region
// ReadFlowOnRegionInner reads bytes in some region.
type ReadFlowOnRegionInner struct {
Step func(tick int64) map[uint64]int64
}

// Type implements the EventInner interface
// Type implements the EventInner interface.
func (w *ReadFlowOnRegionInner) Type() string {
return "read-flow-on-region"
}

// AddNodesDynamicInner adds nodes dynamically
type AddNodesDynamicInner struct {
// AddNodesInner adds nodes.
type AddNodesInner struct {
Step func(tick int64) uint64
}

// Type implements the EventInner interface
func (w *AddNodesDynamicInner) Type() string {
return "add-nodes-dynamic"
// Type implements the EventInner interface.
func (w *AddNodesInner) Type() string {
return "add-nodes"
}

// DeleteNodesInner removes nodes randomly.
// DeleteNodesInner removes nodes.
type DeleteNodesInner struct {
Step func(tick int64) uint64
}

// Type implements the EventInner interface
// Type implements the EventInner interface.
func (w *DeleteNodesInner) Type() string {
return "delete-nodes"
}
79 changes: 0 additions & 79 deletions pkg/faketikv/cluster.go

This file was deleted.

34 changes: 25 additions & 9 deletions pkg/faketikv/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,40 @@

package faketikv

// Conn records the informations of connection among nodes.
type Conn struct {
Nodes map[uint64]*Node
import (
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/pd/pkg/faketikv/cases"
)

// Connection records the informations of connection among nodes.
type Connection struct {
pdAddr string
Nodes map[uint64]*Node
}

// NewConn returns a conn.
func NewConn(nodes map[uint64]*Node) (*Conn, error) {
conn := &Conn{
Nodes: nodes,
// NewConnection creates nodes according to the configuration and returns the connection among nodes.
func NewConnection(conf *cases.Conf, pdAddr string) (*Connection, error) {
conn := &Connection{
pdAddr: pdAddr,
Nodes: make(map[uint64]*Node),
}

for _, store := range conf.Stores {
node, err := NewNode(store, pdAddr)
if err != nil {
return nil, err
}
conn.Nodes[store.ID] = node
}

return conn, nil
}

func (c *Conn) nodeHealth(storeID uint64) bool {
func (c *Connection) nodeHealth(storeID uint64) bool {
n, ok := c.Nodes[storeID]
if !ok {
return false
}

return n.GetState() == Up
return n.GetState() == metapb.StoreState_Up
}
Loading

0 comments on commit 92240fe

Please sign in to comment.