[skip e2e] Expire migration session asap and fix exit code (#20224)

Signed-off-by: longjiquan <jiquan.long@zilliz.com>

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
pull/20233/head
Jiquan Long 2022-11-01 11:47:34 +08:00 committed by GitHub
parent 9fac1476f3
commit f2f10cb114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -20,7 +20,7 @@ func Warning(msg string) {
}
func Exit(msg string) {
ExitWithOption(WithAbnormalExit(), WithMsg(msg))
ExitWithOption(WithAbnormalExit(), WithExitCode(Unexpected), WithMsg(msg))
}
func ExitIf(err error) {

View File

@ -3,6 +3,7 @@ package migration
import (
"context"
"fmt"
"strings"
"sync"
"time"
@ -213,8 +214,28 @@ func (r *Runner) Migrate() error {
return target.Save(targetMetas)
}
func (r *Runner) waitUntilSessionExpired() {
for {
err := r.checkSessionsWithPrefix(Role)
if err == nil {
console.Success("migration session expired")
return
}
// TODO: better to wrap this error.
if !strings.Contains(err.Error(), "there are still sessions alive") {
console.Warning(err.Error())
return
}
// 1s may be enough to expire the lease session.
time.Sleep(time.Second)
}
}
func (r *Runner) Stop() {
r.session.Revoke(time.Second)
r.waitUntilSessionExpired()
r.cancel()
r.wg.Wait()
}