2022-07-15 13:54:26 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2022-07-26 19:32:30 +08:00
|
|
|
"fmt"
|
2022-07-15 13:54:26 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2022-08-10 17:04:37 +08:00
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2022-07-15 13:54:26 +08:00
|
|
|
)
|
|
|
|
|
2022-07-26 19:32:30 +08:00
|
|
|
// ParseSegmentIDByBinlog parse segment id from binlog paths
|
|
|
|
// if path format is not expected, returns error
|
2022-08-10 17:04:37 +08:00
|
|
|
func ParseSegmentIDByBinlog(rootPath, path string) (UniqueID, error) {
|
|
|
|
// check path contains rootPath as prefix
|
|
|
|
if !strings.HasPrefix(path, rootPath) {
|
|
|
|
return 0, fmt.Errorf("path \"%s\" does not contains rootPath \"%s\"", path, rootPath)
|
|
|
|
}
|
|
|
|
p := path[len(rootPath):]
|
|
|
|
|
|
|
|
// remove leading "/"
|
|
|
|
for strings.HasPrefix(p, "/") {
|
|
|
|
p = p[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
// binlog path should consist of "[log_type]/collID/partID/segID/fieldID/fileName"
|
|
|
|
keyStr := strings.Split(p, "/")
|
2022-09-30 14:18:55 +08:00
|
|
|
|
|
|
|
logType := keyStr[0]
|
|
|
|
if logType == common.SegmentDeltaLogPath {
|
|
|
|
if len(keyStr) == 5 {
|
|
|
|
return strconv.ParseInt(keyStr[3], 10, 64)
|
|
|
|
}
|
|
|
|
return 0, fmt.Errorf("%s is not a valid delta log path", path)
|
2022-08-10 17:04:37 +08:00
|
|
|
}
|
|
|
|
|
2022-09-30 14:18:55 +08:00
|
|
|
// log type are binlog or statslog
|
2022-08-10 17:04:37 +08:00
|
|
|
if len(keyStr) == 6 {
|
|
|
|
return strconv.ParseInt(keyStr[len(keyStr)-3], 10, 64)
|
2022-07-26 19:32:30 +08:00
|
|
|
}
|
2022-08-10 17:04:37 +08:00
|
|
|
return 0, fmt.Errorf("%s is not a valid binlog path", path)
|
2022-07-15 13:54:26 +08:00
|
|
|
}
|