mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-01 03:18:29 +08:00
1919353f02
Signed-off-by: yun.zhang <yun.zhang@zilliz.com> Signed-off-by: yun.zhang <yun.zhang@zilliz.com>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
|
)
|
|
|
|
// ParseSegmentIDByBinlog parse segment id from binlog paths
|
|
// if path format is not expected, returns error
|
|
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, "/")
|
|
|
|
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)
|
|
}
|
|
|
|
// log type are binlog or statslog
|
|
if len(keyStr) == 6 {
|
|
return strconv.ParseInt(keyStr[len(keyStr)-3], 10, 64)
|
|
}
|
|
return 0, fmt.Errorf("%s is not a valid binlog path", path)
|
|
}
|