2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-08-25 15:45:19 +08:00
|
|
|
|
2020-09-01 16:23:39 +08:00
|
|
|
/*
|
|
|
|
|
2020-10-23 18:01:24 +08:00
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
2020-09-01 16:23:39 +08:00
|
|
|
|
2020-10-31 15:11:47 +08:00
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
|
2020-09-01 16:23:39 +08:00
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
2020-09-01 16:23:39 +08:00
|
|
|
|
|
|
|
*/
|
2020-08-25 15:45:19 +08:00
|
|
|
import "C"
|
2021-01-18 10:38:41 +08:00
|
|
|
import (
|
|
|
|
"github.com/golang/protobuf/proto"
|
2021-03-05 09:21:35 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
2021-01-18 10:38:41 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
|
2021-03-05 09:21:35 +08:00
|
|
|
"go.uber.org/zap"
|
2021-01-18 10:38:41 +08:00
|
|
|
)
|
2020-08-25 15:45:19 +08:00
|
|
|
|
|
|
|
type Collection struct {
|
2020-11-09 16:27:11 +08:00
|
|
|
collectionPtr C.CCollection
|
2020-12-10 16:31:09 +08:00
|
|
|
id UniqueID
|
2021-02-05 10:53:11 +08:00
|
|
|
partitionIDs []UniqueID
|
2021-01-18 10:38:41 +08:00
|
|
|
schema *schemapb.CollectionSchema
|
2020-08-25 15:45:19 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func (c *Collection) ID() UniqueID {
|
2020-12-10 16:31:09 +08:00
|
|
|
return c.id
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
2020-08-25 15:45:19 +08:00
|
|
|
|
2021-01-18 10:38:41 +08:00
|
|
|
func (c *Collection) Schema() *schemapb.CollectionSchema {
|
|
|
|
return c.schema
|
|
|
|
}
|
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
func (c *Collection) addPartitionID(partitionID UniqueID) {
|
|
|
|
c.partitionIDs = append(c.partitionIDs, partitionID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Collection) removePartitionID(partitionID UniqueID) {
|
|
|
|
tmpIDs := make([]UniqueID, 0)
|
|
|
|
for _, id := range c.partitionIDs {
|
|
|
|
if id == partitionID {
|
|
|
|
tmpIDs = append(tmpIDs, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.partitionIDs = tmpIDs
|
|
|
|
}
|
|
|
|
|
2021-01-18 10:38:41 +08:00
|
|
|
func newCollection(collectionID UniqueID, schema *schemapb.CollectionSchema) *Collection {
|
2020-09-21 18:16:06 +08:00
|
|
|
/*
|
2020-11-09 16:27:11 +08:00
|
|
|
CCollection
|
2020-12-10 16:31:09 +08:00
|
|
|
NewCollection(const char* schema_proto_blob);
|
2020-10-24 10:45:57 +08:00
|
|
|
*/
|
2021-01-18 10:38:41 +08:00
|
|
|
schemaBlob := proto.MarshalTextString(schema)
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
cSchemaBlob := C.CString(schemaBlob)
|
|
|
|
collection := C.NewCollection(cSchemaBlob)
|
|
|
|
|
|
|
|
var newCollection = &Collection{
|
|
|
|
collectionPtr: collection,
|
|
|
|
id: collectionID,
|
2021-01-18 10:38:41 +08:00
|
|
|
schema: schema,
|
2020-12-10 16:31:09 +08:00
|
|
|
}
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Debug("create collection", zap.Int64("collectionID", collectionID))
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
return newCollection
|
2020-08-25 15:45:19 +08:00
|
|
|
}
|
2020-11-05 10:52:50 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func deleteCollection(collection *Collection) {
|
|
|
|
/*
|
|
|
|
void
|
|
|
|
deleteCollection(CCollection collection);
|
|
|
|
*/
|
|
|
|
cPtr := collection.collectionPtr
|
|
|
|
C.DeleteCollection(cPtr)
|
2021-03-05 09:21:35 +08:00
|
|
|
|
|
|
|
collection.collectionPtr = nil
|
|
|
|
|
|
|
|
log.Debug("delete collection", zap.Int64("collectionID", collection.ID()))
|
|
|
|
|
|
|
|
collection = nil
|
2020-11-05 10:52:50 +08:00
|
|
|
}
|