fix(search): BuildIndex concurrency error (#7035)

This commit is contained in:
Rammiah
2024-08-22 00:44:55 +08:00
committed by GitHub
parent 74887922b4
commit 48f50a2ceb
6 changed files with 55 additions and 22 deletions

View File

@ -19,7 +19,7 @@ type UpdateIndexReq struct {
}
func BuildIndex(c *gin.Context) {
if search.Running.Load() {
if search.Running() {
common.ErrorStrResp(c, "index is running", 400)
return
}
@ -45,7 +45,7 @@ func UpdateIndex(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
if search.Running.Load() {
if search.Running() {
common.ErrorStrResp(c, "index is running", 400)
return
}
@ -72,16 +72,20 @@ func UpdateIndex(c *gin.Context) {
}
func StopIndex(c *gin.Context) {
if !search.Running.Load() {
quit := search.Quit.Load()
if quit == nil {
common.ErrorStrResp(c, "index is not running", 400)
return
}
search.Quit <- struct{}{}
select {
case *quit <- struct{}{}:
default:
}
common.SuccessResp(c)
}
func ClearIndex(c *gin.Context) {
if search.Running.Load() {
if search.Running() {
common.ErrorStrResp(c, "index is running", 400)
return
}