Repository: milvus-io/milvus
File: internal/datanode/meta_service.go (Go)

Code before:
	rootCoord    types.RootCoord
}

func newMetaService(rc types.RootCoord, collectionID UniqueID) *metaService {
	return &metaService{
		rootCoord:    rc,
		collectionID: collectionID,
	}
}

func (mService *metaService) getCollectionSchema(ctx context.Context, collID UniqueID, timestamp Timestamp) (*schemapb.CollectionSchema, error) {
	// fmt.Println("Describing collection", collID)
	req := &milvuspb.DescribeCollectionRequest{
		Base: &commonpb.MsgBase{
			MsgType:   commonpb.MsgType_DescribeCollection,
			MsgID:     0, //GOOSE TODO
			Timestamp: 0, // GOOSE TODO
			SourceID:  Params.NodeID,
		},
		DbName:       "default", // GOOSE TODO
		CollectionID: collID,
		TimeStamp:    timestamp,
	}

	response, err := mService.rootCoord.DescribeCollection(ctx, req)
	if response != nil && response.Status.ErrorCode != commonpb.ErrorCode_Success {
		return nil, fmt.Errorf("Describe collection %v from rootcoord wrong: %s", collID, response.Status.Reason)
	}

	if err != nil {
		return nil, fmt.Errorf("Grpc error when describe collection %v from rootcoord: %s", collID, err.Error())
	}

	return response.GetSchema(), nil
}

func printCollectionStruct(obj *etcdpb.CollectionMeta) {
	v := reflect.ValueOf(obj)
	v = reflect.Indirect(v)
	typeOfS := v.Type()

	for i := 0; i < v.NumField()-3; i++ {
		if typeOfS.Field(i).Name == "GrpcMarshalString" {
			continue
		}
		fmt.Printf("Field: %s\tValue: %v\n", typeOfS.Field(i).Name, v.Field(i).Interface())
	}
}


Review comment (bug):
It's better to use grpc functions
```go
if response.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
    return nil, fmt.Errorf("Describe collection %v from rootcoord wrong: %s", collID, response.GetStatus().GetReason())
}
```

Code after:
	rootCoord    types.RootCoord
}

func newMetaService(rc types.RootCoord, collectionID UniqueID) *metaService {
	return &metaService{
		rootCoord:    rc,
		collectionID: collectionID,
	}
}

func (mService *metaService) getCollectionSchema(ctx context.Context, collID UniqueID, timestamp Timestamp) (*schemapb.CollectionSchema, error) {
	// fmt.Println("Describing collection", collID)
	req := &milvuspb.DescribeCollectionRequest{
		Base: &commonpb.MsgBase{
			MsgType:   commonpb.MsgType_DescribeCollection,
			MsgID:     0, //GOOSE TODO
			Timestamp: 0, // GOOSE TODO
			SourceID:  Params.NodeID,
		},
		DbName:       "default", // GOOSE TODO
		CollectionID: collID,
		TimeStamp:    timestamp,
	}

	response, err := mService.rootCoord.DescribeCollection(ctx, req)
	if response.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
		return nil, fmt.Errorf("Describe collection %v from rootcoord wrong: %s", collID, response.GetStatus().GetReason())
	}

	if err != nil {
		return nil, fmt.Errorf("Grpc error when describe collection %v from rootcoord: %s", collID, err.Error())
	}

	return response.GetSchema(), nil
}

func printCollectionStruct(obj *etcdpb.CollectionMeta) {
	v := reflect.ValueOf(obj)
	v = reflect.Indirect(v)
	typeOfS := v.Type()

	for i := 0; i < v.NumField()-3; i++ {
		if typeOfS.Field(i).Name == "GrpcMarshalString" {
			continue
		}
		fmt.Printf("Field: %s\tValue: %v\n", typeOfS.Field(i).Name, v.Field(i).Interface())
	}
}