fix(knowledge): Optimize the knowledge domain idgen code (#574)

This commit is contained in:
liuyunchao-1998 2025-08-05 17:34:43 +08:00 committed by GitHub
parent ab0ce50df5
commit c11780b28d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 3 deletions

View File

@ -1497,13 +1497,27 @@ func (k *knowledgeSVC) getObjectURL(ctx context.Context, uri string) (string, er
func (k *knowledgeSVC) genMultiIDs(ctx context.Context, counts int) ([]int64, error) {
allIDs := make([]int64, 0)
retryInterval := 5 * time.Millisecond
for l := 0; l < counts; l += 100 {
r := min(l+100, counts)
batchSize := r - l
ids, err := k.idgen.GenMultiIDs(ctx, batchSize)
var ids []int64
var err error
maxRetries := 5
retryCount := 0
for {
ids, err = k.idgen.GenMultiIDs(ctx, batchSize)
if err != nil {
if retryCount >= maxRetries {
return nil, errorx.New(errno.ErrKnowledgeIDGenCode, errorx.KV("msg", fmt.Sprintf("GenMultiIDs failed, err: %v", err)))
}
logs.CtxErrorf(ctx, "[genMultiIDs] GenMultiIDs failed, retry %d/%d: %v", retryCount+1, maxRetries, err)
time.Sleep(retryInterval)
retryCount++
continue
}
break
}
allIDs = append(allIDs, ids...)
}
return allIDs, nil