2021-12-09 14:19:40 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package indexcoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
2022-07-07 14:44:21 +08:00
|
|
|
"strings"
|
2021-12-09 14:19:40 +08:00
|
|
|
|
2022-09-16 16:56:49 +08:00
|
|
|
"github.com/milvus-io/milvus/api/schemapb"
|
2021-12-09 14:19:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
)
|
|
|
|
|
2021-12-20 17:47:23 +08:00
|
|
|
// getDimension gets the dimension of data from building index request.
|
2022-08-25 15:48:54 +08:00
|
|
|
func getDimension(req *indexpb.CreateIndexRequest) (int64, error) {
|
2021-12-09 14:19:40 +08:00
|
|
|
for _, kvPair := range req.GetTypeParams() {
|
|
|
|
key, value := kvPair.GetKey(), kvPair.GetValue()
|
|
|
|
if key == "dim" {
|
|
|
|
dim, err := strconv.ParseInt(value, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
errMsg := "dimension is invalid"
|
|
|
|
log.Error(errMsg)
|
|
|
|
return 0, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
return dim, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errMsg := "dimension is not in type params"
|
|
|
|
log.Error(errMsg)
|
|
|
|
return 0, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
2021-12-22 20:03:38 +08:00
|
|
|
// estimateIndexSize estimates how much memory will be occupied by IndexNode when building an index.
|
2021-12-09 14:19:40 +08:00
|
|
|
func estimateIndexSize(dim int64, numRows int64, dataType schemapb.DataType) (uint64, error) {
|
|
|
|
if dataType == schemapb.DataType_FloatVector {
|
|
|
|
return uint64(dim) * uint64(numRows) * 4, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if dataType == schemapb.DataType_BinaryVector {
|
|
|
|
return uint64(dim) / 8 * uint64(numRows), nil
|
|
|
|
}
|
|
|
|
|
2022-03-21 14:23:24 +08:00
|
|
|
// TODO: optimize here.
|
|
|
|
return 0, nil
|
2022-03-29 15:35:27 +08:00
|
|
|
}
|
2022-07-07 14:44:21 +08:00
|
|
|
|
|
|
|
func parseBuildIDFromFilePath(key string) (UniqueID, error) {
|
|
|
|
ss := strings.Split(key, "/")
|
|
|
|
if strings.HasSuffix(key, "/") {
|
|
|
|
return strconv.ParseInt(ss[len(ss)-2], 10, 64)
|
|
|
|
}
|
|
|
|
return strconv.ParseInt(ss[len(ss)-1], 10, 64)
|
|
|
|
}
|