2021-04-19 15:16:33 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed 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.
|
|
|
|
|
2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-03-05 20:41:34 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-06-08 19:25:37 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
// metaService initialize replica collections in data node from root coord.
|
2021-05-08 15:24:12 +08:00
|
|
|
// Initializing replica collections happens on data node starting. It depends on
|
2021-06-21 17:28:03 +08:00
|
|
|
// a healthy root coord and a valid root coord grpc client.
|
2021-01-19 11:37:16 +08:00
|
|
|
type metaService struct {
|
2021-02-04 20:31:23 +08:00
|
|
|
replica Replica
|
2021-06-08 19:25:37 +08:00
|
|
|
collectionID UniqueID
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord types.RootCoord
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
2021-10-07 23:50:52 +08:00
|
|
|
// newMetaService creates a new metaService with provided RootCoord and collectionID.
|
2021-06-21 17:28:03 +08:00
|
|
|
func newMetaService(rc types.RootCoord, collectionID UniqueID) *metaService {
|
2021-01-19 11:37:16 +08:00
|
|
|
return &metaService{
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: rc,
|
2021-06-08 19:25:37 +08:00
|
|
|
collectionID: collectionID,
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 23:50:52 +08:00
|
|
|
// getCollectionSchema get collection schema with provided collection id at specified timestamp.
|
2021-06-08 19:25:37 +08:00
|
|
|
func (mService *metaService) getCollectionSchema(ctx context.Context, collID UniqueID, timestamp Timestamp) (*schemapb.CollectionSchema, error) {
|
2021-01-25 18:33:10 +08:00
|
|
|
req := &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
2021-01-25 18:33:10 +08:00
|
|
|
MsgID: 0, //GOOSE TODO
|
|
|
|
Timestamp: 0, // GOOSE TODO
|
|
|
|
SourceID: Params.NodeID,
|
|
|
|
},
|
2021-06-08 19:25:37 +08:00
|
|
|
DbName: "default", // GOOSE TODO
|
|
|
|
CollectionID: collID,
|
|
|
|
TimeStamp: timestamp,
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
response, err := mService.rootCoord.DescribeCollection(ctx, req)
|
2021-01-25 18:33:10 +08:00
|
|
|
if err != nil {
|
2021-06-21 17:28:03 +08:00
|
|
|
return nil, fmt.Errorf("Grpc error when describe collection %v from rootcoord: %s", collID, err.Error())
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
|
|
|
|
2021-08-30 10:03:58 +08:00
|
|
|
if response.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
|
|
|
return nil, fmt.Errorf("Describe collection %v from rootcoord wrong: %s", collID, response.GetStatus().GetReason())
|
|
|
|
}
|
|
|
|
|
2021-06-08 19:25:37 +08:00
|
|
|
return response.GetSchema(), nil
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
2021-10-07 23:50:52 +08:00
|
|
|
// printCollectionStruct util function to print schema data, used in tests only.
|
2021-01-19 11:37:16 +08:00
|
|
|
func printCollectionStruct(obj *etcdpb.CollectionMeta) {
|
|
|
|
v := reflect.ValueOf(obj)
|
|
|
|
v = reflect.Indirect(v)
|
|
|
|
typeOfS := v.Type()
|
|
|
|
|
2021-06-08 19:25:37 +08:00
|
|
|
for i := 0; i < v.NumField()-3; i++ {
|
2021-01-19 11:37:16 +08:00
|
|
|
if typeOfS.Field(i).Name == "GrpcMarshalString" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Printf("Field: %s\tValue: %v\n", typeOfS.Field(i).Name, v.Field(i).Interface())
|
|
|
|
}
|
|
|
|
}
|