milvus/internal/storage/binlog_util.go
congqixia e9d777b336
Fix ParseSegmentIDBinlog panicks with bad input (#18413)
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2022-07-26 19:32:30 +08:00

19 lines
503 B
Go

package storage
import (
"fmt"
"strconv"
"strings"
)
// ParseSegmentIDByBinlog parse segment id from binlog paths
// if path format is not expected, returns error
func ParseSegmentIDByBinlog(path string) (UniqueID, error) {
// binlog path should consist of "[prefix]/insertLog/collID/partID/segID/fieldID/fileName"
keyStr := strings.Split(path, "/")
if len(keyStr) != 7 {
return 0, fmt.Errorf("%s is not a valid binlog path", path)
}
return strconv.ParseInt(keyStr[len(keyStr)-3], 10, 64)
}