-
Notifications
You must be signed in to change notification settings - Fork 708
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
support gracefully shutdown #728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以及建议格式化一下代码
internal/reader/parsing_aof.go
Outdated
@@ -724,7 +725,7 @@ func (aofInfo *INFO) ParsingSingleAppendOnlyFile(FileName string, AOFTimeStamp i | |||
log.Infof("Reading RDB Base File on AOF loading...") | |||
rdbOpt := RdbReaderOptions{Filepath: AOFFilepath} | |||
ldRDB := NewRDBReader(&rdbOpt) | |||
ldRDB.StartRead() | |||
ldRDB.StartRead(context.TODO()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里尽量不要用 context.TODO
@@ -44,6 +46,8 @@ type scanStandaloneReader struct { | |||
ScanPercentByDbId string `json:"scan_percent"` | |||
NeedUpdateCount int64 `json:"need_update_count"` | |||
} | |||
|
|||
isStop atomic.Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要用这个?
@@ -86,7 +94,7 @@ func (r *scanStandaloneReader) subscript() { | |||
log.Panicf(err.Error()) | |||
} | |||
regex := regexp.MustCompile(`\d+`) | |||
for { | |||
for !r.isStop.Load() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽量不要用这样的方式
可以在 for 循环里用 select 来解决
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是指这样吗?
for {
select {
case <-ch:
goto Label
default:
// do something...
}
}
Label:
因为break不会跳出for循环,感觉golang这里设计的挺让人难受的,就没这么用...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为你这里没有剩下的逻辑,你 case <- ctx.Done 之后,直接进入 Close 逻辑,然后 Return 就行,不需要额外的处理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的问题是如果你每次 for loop 都来 atomic Load 然后比较,会额外吃很多 CPU
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
明白了,我修改一下,谢谢~
@@ -223,7 +233,7 @@ func (r *syncStandaloneReader) receiveAOF(rd io.Reader) { | |||
aofWriter := rotate.NewAOFWriter(r.stat.Name, r.stat.Dir, r.stat.AofReceivedOffset) | |||
defer aofWriter.Close() | |||
buf := make([]byte, 16*1024) // 16KB is enough for writing file | |||
for { | |||
for !r.isStop.Load() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
@Zheaoli hi, I have fixed it, please check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM cc @suxb201
测试挂了,得看下为什么 |
看了下日志,应该是CI的问题? |
我来修复下。 |
@jjz921024 CI 修复了,需要你 rebase 代码再试一下。 |
@suxb201 rebase了 |
@jjz921024 还是有问题,我晚些看下。 |
@jjz921024 辛苦
|
for #727
Modifications:
IsClosed
indacate the reader should be closeIsClosed
at the loop ofSyncReader
andScanReader