mirror of https://github.com/milvus-io/milvus.git
[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
parent
9fac1476f3
commit
f2f10cb114
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue