data_node.go 2.1 KB
Newer Older
1 2 3 4 5 6
// 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
C
cai.zhang 已提交
7 8
// with the License. You may obtain a copy of the License at
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
C
cai.zhang 已提交
10
//
11 12 13 14 15
// 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.
C
cai.zhang 已提交
16

X
XuanYang-cn 已提交
17 18 19 20 21
package components

import (
	"context"

E
Enwei Jiao 已提交
22
	"github.com/milvus-io/milvus/api/commonpb"
23
	"github.com/milvus-io/milvus/api/milvuspb"
X
Xiangyu Wang 已提交
24 25
	grpcdatanode "github.com/milvus-io/milvus/internal/distributed/datanode"
	"github.com/milvus-io/milvus/internal/log"
26
	"github.com/milvus-io/milvus/internal/util/dependency"
E
Enwei Jiao 已提交
27
	"github.com/milvus-io/milvus/internal/util/typeutil"
X
XuanYang-cn 已提交
28 29
)

30
// DataNode implements DataNode grpc server
X
XuanYang-cn 已提交
31 32
type DataNode struct {
	ctx context.Context
33
	svr *grpcdatanode.Server
X
XuanYang-cn 已提交
34 35
}

36
// NewDataNode creates a new DataNode
G
godchen 已提交
37
func NewDataNode(ctx context.Context, factory dependency.Factory) (*DataNode, error) {
38
	svr, err := grpcdatanode.NewServer(ctx, factory)
X
XuanYang-cn 已提交
39
	if err != nil {
40
		return nil, err
X
XuanYang-cn 已提交
41 42 43 44 45 46 47 48
	}

	return &DataNode{
		ctx: ctx,
		svr: svr,
	}, nil
}

49
// Run starts service
X
XuanYang-cn 已提交
50
func (d *DataNode) Run() error {
51
	if err := d.svr.Run(); err != nil {
X
XuanYang-cn 已提交
52 53
		panic(err)
	}
X
XuanYang-cn 已提交
54
	log.Debug("Datanode successfully started")
X
XuanYang-cn 已提交
55 56 57
	return nil
}

58
// Stop terminates service
X
XuanYang-cn 已提交
59
func (d *DataNode) Stop() error {
60 61 62 63
	if err := d.svr.Stop(); err != nil {
		return err
	}
	return nil
X
XuanYang-cn 已提交
64
}
D
dragondriver 已提交
65

66
// GetComponentStates returns DataNode's states
E
Enwei Jiao 已提交
67 68 69 70 71 72 73 74 75 76
func (d *DataNode) Health(ctx context.Context) commonpb.StateCode {
	resp, err := d.svr.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
	if err != nil {
		return commonpb.StateCode_Abnormal
	}
	return resp.State.GetStateCode()
}

func (d *DataNode) GetName() string {
	return typeutil.DataNodeRole
D
dragondriver 已提交
77
}