2021-12-06 21:06:26 +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
|
2021-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-06 21:06:26 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-12-06 21:06:26 +08:00
|
|
|
// 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.
|
2021-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-12-24 20:55:40 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
|
|
|
|
|
|
|
|
#include "segcore/load_index_c.h"
|
|
|
|
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
2021-01-06 18:19:44 +08:00
|
|
|
"path/filepath"
|
2020-12-24 20:55:40 +08:00
|
|
|
"unsafe"
|
2021-03-05 09:21:35 +08:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2020-12-24 20:55:40 +08:00
|
|
|
)
|
|
|
|
|
2021-10-05 21:38:16 +08:00
|
|
|
// LoadIndexInfo is a wrapper of the underlying C-structure C.CLoadIndexInfo
|
2020-12-24 20:55:40 +08:00
|
|
|
type LoadIndexInfo struct {
|
|
|
|
cLoadIndexInfo C.CLoadIndexInfo
|
|
|
|
}
|
|
|
|
|
2020-12-26 14:16:51 +08:00
|
|
|
func newLoadIndexInfo() (*LoadIndexInfo, error) {
|
2020-12-24 20:55:40 +08:00
|
|
|
var cLoadIndexInfo C.CLoadIndexInfo
|
|
|
|
status := C.NewLoadIndexInfo(&cLoadIndexInfo)
|
2021-11-15 16:13:10 +08:00
|
|
|
if err := HandleCStatus(&status, "NewLoadIndexInfo failed"); err != nil {
|
|
|
|
return nil, err
|
2020-12-24 20:55:40 +08:00
|
|
|
}
|
|
|
|
return &LoadIndexInfo{cLoadIndexInfo: cLoadIndexInfo}, nil
|
|
|
|
}
|
|
|
|
|
2020-12-26 14:16:51 +08:00
|
|
|
func deleteLoadIndexInfo(info *LoadIndexInfo) {
|
|
|
|
C.DeleteLoadIndexInfo(info.cLoadIndexInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (li *LoadIndexInfo) appendIndexParam(indexKey string, indexValue string) error {
|
2020-12-24 20:55:40 +08:00
|
|
|
cIndexKey := C.CString(indexKey)
|
2021-03-26 18:40:04 +08:00
|
|
|
defer C.free(unsafe.Pointer(cIndexKey))
|
2020-12-24 20:55:40 +08:00
|
|
|
cIndexValue := C.CString(indexValue)
|
2021-03-26 18:40:04 +08:00
|
|
|
defer C.free(unsafe.Pointer(cIndexValue))
|
2020-12-24 20:55:40 +08:00
|
|
|
status := C.AppendIndexParam(li.cLoadIndexInfo, cIndexKey, cIndexValue)
|
2021-11-15 16:13:10 +08:00
|
|
|
return HandleCStatus(&status, "AppendIndexParam failed")
|
2020-12-24 20:55:40 +08:00
|
|
|
}
|
|
|
|
|
2021-09-14 10:25:26 +08:00
|
|
|
func (li *LoadIndexInfo) appendFieldInfo(fieldID FieldID) error {
|
2020-12-24 20:55:40 +08:00
|
|
|
cFieldID := C.long(fieldID)
|
2021-02-03 11:52:19 +08:00
|
|
|
status := C.AppendFieldInfo(li.cLoadIndexInfo, cFieldID)
|
2021-11-15 16:13:10 +08:00
|
|
|
return HandleCStatus(&status, "AppendFieldInfo failed")
|
2020-12-24 20:55:40 +08:00
|
|
|
}
|
|
|
|
|
2020-12-26 14:16:51 +08:00
|
|
|
func (li *LoadIndexInfo) appendIndex(bytesIndex [][]byte, indexKeys []string) error {
|
2020-12-24 20:55:40 +08:00
|
|
|
var cBinarySet C.CBinarySet
|
|
|
|
status := C.NewBinarySet(&cBinarySet)
|
2021-04-10 10:10:53 +08:00
|
|
|
defer C.DeleteBinarySet(cBinarySet)
|
2020-12-24 20:55:40 +08:00
|
|
|
|
2021-11-15 16:13:10 +08:00
|
|
|
if err := HandleCStatus(&status, "NewBinarySet failed"); err != nil {
|
|
|
|
return err
|
2020-12-24 20:55:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, byteIndex := range bytesIndex {
|
|
|
|
indexPtr := unsafe.Pointer(&byteIndex[0])
|
|
|
|
indexLen := C.long(len(byteIndex))
|
2021-01-06 18:19:44 +08:00
|
|
|
binarySetKey := filepath.Base(indexKeys[i])
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Debug("", zap.String("index key", binarySetKey))
|
2021-01-06 18:19:44 +08:00
|
|
|
indexKey := C.CString(binarySetKey)
|
2020-12-24 20:55:40 +08:00
|
|
|
status = C.AppendBinaryIndex(cBinarySet, indexPtr, indexLen, indexKey)
|
2021-03-26 18:40:04 +08:00
|
|
|
C.free(unsafe.Pointer(indexKey))
|
2021-11-15 16:13:10 +08:00
|
|
|
if err := HandleCStatus(&status, "AppendBinaryIndex failed"); err != nil {
|
|
|
|
return err
|
2020-12-24 20:55:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = C.AppendIndex(li.cLoadIndexInfo, cBinarySet)
|
2021-11-15 16:13:10 +08:00
|
|
|
return HandleCStatus(&status, "AppendIndex failed")
|
2020-12-24 20:55:40 +08:00
|
|
|
}
|