data_node.go 1.4 KB
Newer Older
C
cai.zhang 已提交
1 2 3 4 5 6 7 8 9 10 11
// 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.

X
XuanYang-cn 已提交
12 13 14 15 16
package components

import (
	"context"

X
Xiangyu Wang 已提交
17 18 19
	grpcdatanode "github.com/milvus-io/milvus/internal/distributed/datanode"
	"github.com/milvus-io/milvus/internal/log"
	"github.com/milvus-io/milvus/internal/msgstream"
X
XuanYang-cn 已提交
20 21 22 23
)

type DataNode struct {
	ctx context.Context
24
	svr *grpcdatanode.Server
X
XuanYang-cn 已提交
25 26
}

27
// NewDataNode creates a new DataNode
G
groot 已提交
28
func NewDataNode(ctx context.Context, factory msgstream.Factory) (*DataNode, error) {
29
	svr, err := grpcdatanode.NewServer(ctx, factory)
X
XuanYang-cn 已提交
30
	if err != nil {
31
		return nil, err
X
XuanYang-cn 已提交
32 33 34 35 36 37 38 39
	}

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

40
// Run starts service
X
XuanYang-cn 已提交
41
func (d *DataNode) Run() error {
42
	if err := d.svr.Run(); err != nil {
X
XuanYang-cn 已提交
43 44
		panic(err)
	}
X
XuanYang-cn 已提交
45
	log.Debug("Datanode successfully started")
X
XuanYang-cn 已提交
46 47 48
	return nil
}

49
// Stop terminates service
X
XuanYang-cn 已提交
50
func (d *DataNode) Stop() error {
51 52 53 54
	if err := d.svr.Stop(); err != nil {
		return err
	}
	return nil
X
XuanYang-cn 已提交
55
}