Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run install TiDB synchronously #7

Merged
merged 2 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update tidb
  • Loading branch information
siddontang committed May 31, 2018
commit 8d8f4a6841128e797fd1bfece987aee9d87720f3
1 change: 1 addition & 0 deletions db/tidb/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (c *bankClient) SetUp(ctx context.Context, nodes []string, node string) err
return nil
}

log.Printf("begin to create table accounts on node %s", node)
sql := `create table if not exists accounts
(id int not null primary key,
balance bigint not null)`
Expand Down
35 changes: 31 additions & 4 deletions db/tidb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ var (

// db is the TiDB database.
type db struct {
nodes []string
nodes []string
installBlocker util.BlockRunner
}

// SetUp initializes the database.
Expand All @@ -46,15 +47,30 @@ func (db *db) SetUp(ctx context.Context, nodes []string, node string) error {

db.nodes = nodes

db.installBlocker.Init(len(nodes))

log.Printf("install archieve on node %s", node)
if err := util.InstallArchive(ctx, node, archiveURL, deployDir); err != nil {

var err error
db.installBlocker.Run(func() {
err = util.InstallArchive(ctx, node, archiveURL, deployDir)
})
if err != nil {
return err
}

util.Mkdir(ctx, node, path.Join(deployDir, "conf"))
util.Mkdir(ctx, node, path.Join(deployDir, "log"))

if err := util.WriteFile(ctx, node, pdConfig, strconv.Quote("[replication]\nmax-replicas=5")); err != nil {
pdCfs := []string{
"tick-interval=\"100ms\"",
"election-interval=\"500ms\"",
"tso-save-interval=\"500ms\"",
"[replication]",
"max-replicas=5",
}

if err := util.WriteFile(ctx, node, pdConfig, strconv.Quote(strings.Join(pdCfs, "\n"))); err != nil {
return err
}

Expand Down Expand Up @@ -161,8 +177,19 @@ func (db *db) start(ctx context.Context, node string, inSetUp bool) error {
return err
}

var err error
if inSetUp {
time.Sleep(30 * time.Second)
for i := 0; i < 12; i++ {
if err = ssh.Exec(ctx, node, "curl", fmt.Sprintf("http://%s:10080/status", node)); err == nil {
break
}
log.Printf("try to wait tidb run on %s", node)
time.Sleep(10 * time.Second)
}
}

if err != nil {
return err
}

if !util.IsDaemonRunning(ctx, node, tidbBinary, tidbPID) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (c *Controller) Run() {
c.tearDownDB()

c.recorder.Close()

log.Printf("finish test")
}

func (c *Controller) syncExec(f func(i int)) {
Expand Down Expand Up @@ -158,7 +160,7 @@ func (c *Controller) setUpClient() {
}

func (c *Controller) tearDownClient() {
log.Printf("begin to set up client")
log.Printf("begin to tear down client")
c.syncExec(func(i int) {
client := c.clients[i]
node := c.nodes[i]
Expand All @@ -173,6 +175,8 @@ func (c *Controller) onClientLoop(i int) {
client := c.clients[i]
node := c.nodes[i]

log.Printf("begin to run command on node %s", node)

ctx, cancel := context.WithTimeout(c.ctx, c.cfg.RunTime)
defer cancel()

Expand Down