fix: Fix invalid pre-allocated segment IDs (#44350)

Mark the task as failed when PreAllocatedSegmentIDs is nil.

issue: https://github.com/milvus-io/milvus/issues/44349

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2025-09-15 10:27:58 +08:00 committed by GitHub
parent baa84e0b2b
commit c15290c125
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,6 +18,7 @@ package datacoord
import (
"context"
"fmt"
"strconv"
"sync"
"time"
@ -86,12 +87,16 @@ func (csm *compactionTaskMeta) reloadFromKV() error {
return err
}
for _, task := range compactionTasks {
// To maintain compatibility with versions ≤v2.4.12, which use `ResultSegments` as preallocate segment IDs.
if task.PreAllocatedSegmentIDs == nil && len(task.GetResultSegments()) == 2 {
task.PreAllocatedSegmentIDs = &datapb.IDRange{
Begin: task.GetResultSegments()[0],
End: task.GetResultSegments()[1],
}
// Compatibility handling: for milvus ≤v2.4, since compaction task has no PreAllocatedSegmentIDs field,
// here we just mark the task as failed and wait for the compaction trigger to generate a new one.
if task.PreAllocatedSegmentIDs == nil {
log.Warn("PreAllocatedSegmentIDs is nil, mark the task as failed",
zap.Int64("taskID", task.GetPlanID()),
zap.String("type", task.GetType().String()),
zap.String("originalState", task.State.String()),
)
task.State = datapb.CompactionTaskState_failed
task.FailReason = fmt.Sprintf("PreAllocatedSegmentIDs is nil, taskID: %v", task.GetPlanID())
}
csm.saveCompactionTaskMemory(task)
}