Skip to content

Commit edd0490

Browse files
authored
support wait tiflash replica ready (#142)
1 parent 12f3756 commit edd0490

File tree

4 files changed

+6995
-6965
lines changed

4 files changed

+6995
-6965
lines changed

src/main.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,12 @@ func (t *tester) Run() error {
521521
return errors.Annotate(err, fmt.Sprintf("Could not parse regex in --replace_regex: line: %d sql:%v", q.Line, q.Query))
522522
}
523523
t.replaceRegex = regex
524+
case Q_WAIT_TIFLASH_REPLICA_READY:
525+
// wait tiflash replica ready
526+
err := t.waitTiFlashReplicaReady()
527+
if err != nil {
528+
log.WithFields(log.Fields{"command": q.firstWord, "arguments": q.Query, "line": q.Line, "err": err.Error()}).Warn("wait for tiflash replica ready failed")
529+
}
524530
default:
525531
log.WithFields(log.Fields{"command": q.firstWord, "arguments": q.Query, "line": q.Line}).Warn("command not implemented")
526532
}
@@ -1039,6 +1045,24 @@ func (t *tester) executeStmtString(query string) (string, error) {
10391045
return result, nil
10401046
}
10411047

1048+
func (t *tester) waitTiFlashReplicaReady() error {
1049+
for {
1050+
select {
1051+
case <-time.After(100 * time.Millisecond):
1052+
result, err := t.executeStmtString(`select count(*) from information_schema.tiflash_replica where AVAILABLE=0;`)
1053+
if err != nil {
1054+
return err
1055+
}
1056+
if result == "0" {
1057+
return nil
1058+
}
1059+
case <-time.After(2 * time.Minute):
1060+
return errors.New("wait tiflash replica ready timeout")
1061+
}
1062+
}
1063+
1064+
}
1065+
10421066
func (t *tester) openResult() error {
10431067
if record {
10441068
return nil
@@ -1233,7 +1257,6 @@ func main() {
12331257
}
12341258
log.SetLevel(ll)
12351259
}
1236-
12371260
if xmlPath != "" {
12381261
_, err := os.Stat(xmlPath)
12391262
if err == nil {

0 commit comments

Comments
 (0)