被代理的 WeKnora 收到 SIGTERM 会先关监听再 exit(1),在途请求被切断。 排空改到真正的连接入口:闸门停止接客、等在途连接归零、写 drain.json 并 exit 0;协调器只认这条证据,写者退出码只作记录。 顺带修掉维护占用的一条死锁:释放后的窗口此前不能被新作业接管, 等于第一次同步之后谁也再进不去;持有中的窗口仍只允许原作业重入。
This commit is contained in:
@@ -125,7 +125,23 @@ func (c *Coordinator) RunWindow(ctx context.Context, job string, prepare func(co
|
||||
}
|
||||
}
|
||||
|
||||
// 停写入者 + 排空 + 关入口:任何一步不成立都不许往下写。
|
||||
// 顺序是有原因的:入口先停(新请求被拒、在途请求跑完),写者后停。
|
||||
// 反过来做,正在处理的请求就会被 SIGTERM 切断——那不算排空。
|
||||
if c.gate != nil && (j.Gate == nil || !j.Gate.Drained) {
|
||||
evidence, gateErr := c.gate.CloseIngress(ctx)
|
||||
if gateErr != nil {
|
||||
return c.abandonWindow(ctx, &j, fmt.Errorf("关闭目标入口失败:%w", gateErr), "gate_failed")
|
||||
}
|
||||
if !evidence.Closed || !evidence.Drained {
|
||||
return c.abandonWindow(ctx, &j, errors.New("目标入口未确认排空(仍有在途请求)"), "gate_not_drained")
|
||||
}
|
||||
j.Gate = &evidence
|
||||
if err = c.save(j); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
}
|
||||
|
||||
// 停写入者:任何一步不成立都不许往下写。
|
||||
if stopErr := c.stopAll(ctx, &j); stopErr != nil {
|
||||
return c.abandonWindow(ctx, &j, stopErr, "stop_failed")
|
||||
}
|
||||
@@ -284,6 +300,10 @@ func (c *Coordinator) verifyDrain(ctx context.Context, j *journal) error {
|
||||
if needed == 0 {
|
||||
return nil
|
||||
}
|
||||
// 入口层已经证明"在途请求全部结束"时,写者的退出码只作为记录:
|
||||
// 被代理的 WeKnora 收到 SIGTERM 会自己 exit(1)(upstream bug),
|
||||
// 那不代表请求被切断——请求早在入口关闭时就已经跑完了。
|
||||
gateDrained := j.Gate != nil && j.Gate.Closed && j.Gate.Drained
|
||||
items, err := inventory(ctx, c.control)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -303,18 +323,18 @@ func (c *Coordinator) verifyDrain(ctx context.Context, j *journal) error {
|
||||
return errors.New("test writer still running")
|
||||
}
|
||||
if now.ExitCode == nil {
|
||||
if c.level == "instance" {
|
||||
if c.level == "instance" && !gateDrained {
|
||||
return fmt.Errorf("无法证明 %s 的在途请求已排空(控制器没有退出码)", s.ID)
|
||||
}
|
||||
continue
|
||||
}
|
||||
s.ExitCode = now.ExitCode
|
||||
if *now.ExitCode != 0 {
|
||||
if *now.ExitCode != 0 && !gateDrained {
|
||||
return fmt.Errorf("写入者 %s 未优雅退出(exit=%d):在途请求没有完成排空", s.ID, *now.ExitCode)
|
||||
}
|
||||
verified++
|
||||
}
|
||||
j.DrainVerified = verified == needed
|
||||
j.DrainVerified = gateDrained || verified == needed
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user