milvus各组件的结构体分析2

milvus各组件的结构体分析2

分析各组件的服务端API。

rootcoord

go 复制代码
// Server grpc wrapper
type Server struct {
    //自身提供的api功能接口
	rootCoord   types.RootCoordComponent
	grpcServer  *grpc.Server
	grpcErrChan chan error

	wg sync.WaitGroup

	ctx    context.Context
	cancel context.CancelFunc

	serverID atomic.Int64

	etcdCli    *clientv3.Client
	tikvCli    *txnkv.Client
	dataCoord  types.DataCoordClient
	queryCoord types.QueryCoordClient

	newDataCoordClient  func(string, *clientv3.Client) types.DataCoordClient
	newQueryCoordClient func(string, *clientv3.Client) types.QueryCoordClient
}

types.RootCoordComponent是一个接口。

包含了dataCoord和queryCoord客户端。

dataCoord由newDataCoordClient赋值。

queryCoord由newQueryCoordClient赋值。

从结构体可以看出:

1.Server结构体包裹了一个rootCoord接口,用来实现rootCoord的一些API功能。

go 复制代码
type RootCoordComponent interface {
    RootCoord
    SetAddress(address string)
    SetEtcdClient(etcdClient *clientv3.Client)
    SetTiKVClient(client *txnkv.Client)
    UpdateStateCode(commonpb.StateCode)
    SetDataCoordClient(dataCoord DataCoordClient) error
    SetQueryCoordClient(queryCoord QueryCoordClient) error
    SetProxyCreator(func(ctx context.Context, addr string, nodeID int64) (ProxyClient, error))
    GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error)
}

RootCoord也是一个接口,里面包含接口Component,这个接口有方法

Init()、Start()、Stop()、Regiter()。

2.Server结构体包含了客户端etcdCli和tikvCli,根据配置文件选择使用etcd还是tikv作为元数据存储。

3.包含一个grpcServer结构体

4.Server结构体包含了dataCoord客户端,说明rootcoord会和datacoord通信。

types.DataCoordClient是一个接口。

go 复制代码
type DataCoordClient interface {
    io.Closer
    datapb.DataCoordClient
}

datapb.DataCoordClient也是一个接口,是datacoord service的客户端接口。

5.Server结构体包含了queryCoord客户端,说明rootcoord会和queryCoord通信。

types.QueryCoordClient是一个接口。

go 复制代码
type QueryCoordClient interface {
	io.Closer
	querypb.QueryCoordClient
}

querypb.QueryCoordClient也是一个接口,是querycoord service的客户端接口。

datacoord

没有indexcoord,和datacoord合并。

go 复制代码
// Server is the grpc server of datacoord
type Server struct {
	ctx    context.Context
	cancel context.CancelFunc

	serverID atomic.Int64

	wg        sync.WaitGroup
	dataCoord types.DataCoordComponent

	etcdCli *clientv3.Client
	tikvCli *txnkv.Client

	grpcErrChan chan error
	grpcServer  *grpc.Server
}

从结构体可以看出:

1.Server结构体包裹了一个dataCoord接口,用来实现dataCoord的一些API功能。

go 复制代码
type DataCoordComponent interface {
    DataCoord
    SetAddress(address string)
    SetEtcdClient(etcdClient *clientv3.Client)
    SetTiKVClient(client *txnkv.Client)
    SetRootCoordClient(rootCoord RootCoordClient)
    SetDataNodeCreator(func(context.Context, string, int64) (DataNodeClient, error))
    SetIndexNodeCreator(func(context.Context, string, int64) (IndexNodeClient, error))
}

2.Server结构体包含了客户端etcdCli和tikvCli,根据配置文件选择使用etcd还是tikv作为元数据存储。

3.包含一个grpcServer结构体。

datacoord并不像rootcoord包含有其它组件的客户端。

querycoord

go 复制代码
// Server is the grpc server of QueryCoord.
type Server struct {
	wg         sync.WaitGroup
	loopCtx    context.Context
	loopCancel context.CancelFunc
	grpcServer *grpc.Server

	serverID atomic.Int64

	grpcErrChan chan error

	queryCoord types.QueryCoordComponent

	factory dependency.Factory

	etcdCli *clientv3.Client
	tikvCli *txnkv.Client

	dataCoord types.DataCoordClient
	rootCoord types.RootCoordClient
}

从结构体可以看出:

1.Server结构体包裹了一个querycoord接口,用来实现querycoord的一些API功能。

go 复制代码
type QueryCoordComponent interface {
    QueryCoord
    SetAddress(address string)
    SetEtcdClient(etcdClient *clientv3.Client)
    SetTiKVClient(client *txnkv.Client)
    UpdateStateCode(stateCode commonpb.StateCode)
    SetDataCoordClient(dataCoord DataCoordClient) error
    SetRootCoordClient(rootCoord RootCoordClient) error
    SetQueryNodeCreator(func(ctx context.Context, addr string, nodeID int64) (QueryNodeClient, error))
}

2.Server结构体包含了客户端etcdCli和tikvCli,根据配置文件选择使用etcd还是tikv作为元数据存储。

3.包含一个grpcServer结构体。

4.Server结构体包含了dataCoord客户端,说明querycoord会和datacoord通信。

5.Server结构体包含了rootCoord客户端,说明querycoord会和rootCoord通信。

indexcoord

没有indexcoord,和datacoord合并。

datanode

go 复制代码
type Server struct {
	datanode    types.DataNodeComponent
	wg          sync.WaitGroup
	grpcErrChan chan error
	grpcServer  *grpc.Server
	ctx         context.Context
	cancel      context.CancelFunc
	etcdCli     *clientv3.Client
	factory     dependency.Factory

	serverID atomic.Int64

	rootCoord types.RootCoord
	dataCoord types.DataCoord

	newRootCoordClient func(string, *clientv3.Client) (types.RootCoordClient, error)
	newDataCoordClient func(string, *clientv3.Client) (types.DataCoordClient, error)
}

从结构体可以看出:

1.Server结构体包裹了一个datanode接口,用来实现datanode的一些API功能。

go 复制代码
type DataNodeComponent interface {
    DataNode
    UpdateStateCode(stateCode commonpb.StateCode)
    GetStateCode() commonpb.StateCode
    SetAddress(address string)
    GetAddress() string
    SetEtcdClient(etcdClient *clientv3.Client)
    SetRootCoordClient(rootCoord RootCoordClient) error
    SetDataCoordClient(dataCoord DataCoordClient) error
}

2.Server结构体包含了客户端etcdCli。为什么这里没有tikvCli??

3.包含一个grpcServer结构体。

4.包含了rootCoord和dataCoord接口。

indexnode

go 复制代码
// Server is the grpc wrapper of IndexNode.
type Server struct {
	indexnode types.IndexNodeComponent

	grpcServer  *grpc.Server
	grpcErrChan chan error

	serverID atomic.Int64

	loopCtx    context.Context
	loopCancel func()
	loopWg     sync.WaitGroup

	etcdCli *clientv3.Client
}

从结构体可以看出:

1.Server结构体包裹了一个indexnode接口,用来实现indexnode的一些API功能。

go 复制代码
type IndexNodeComponent interface {
    IndexNode
    SetAddress(address string)
    GetAddress() string
    SetEtcdClient(etcdClient *clientv3.Client)
    UpdateStateCode(stateCode commonpb.StateCode)
}

2.Server结构体包含了客户端etcdCli。为什么这里没有tikvCli??

3.包含一个grpcServer结构体。

不包含其它组件。

querynode

go 复制代码
// Server is the grpc server of QueryNode.
type Server struct {
	querynode   types.QueryNodeComponent
	wg          sync.WaitGroup
	ctx         context.Context
	cancel      context.CancelFunc
	grpcErrChan chan error

	serverID atomic.Int64

	grpcServer *grpc.Server

	etcdCli *clientv3.Client
}

从结构体可以看出:

1.Server结构体包裹了一个querynode接口,用来实现querynode的一些API功能。

go 复制代码
type QueryNodeComponent interface {
    QueryNode
    UpdateStateCode(stateCode commonpb.StateCode)
    SetAddress(address string)
    GetAddress() string
    SetEtcdClient(etcdClient *clientv3.Client)
}

2.Server结构体包含了客户端etcdCli。为什么这里没有tikvCli??

3.包含一个grpcServer结构体。

不包含其它组件。

proxy

go 复制代码
// Server is the Proxy Server
type Server struct {
	ctx                context.Context
	wg                 sync.WaitGroup
	proxy              types.ProxyComponent
	httpListener       net.Listener
	grpcListener       net.Listener
	tcpServer          cmux.CMux
	httpServer         *http.Server
	grpcInternalServer *grpc.Server
	grpcExternalServer *grpc.Server

	serverID atomic.Int64

	etcdCli          *clientv3.Client
	rootCoordClient  types.RootCoordClient
	dataCoordClient  types.DataCoordClient
	queryCoordClient types.QueryCoordClient
}

从结构体可以看出:

1.Server结构体包裹了一个proxy接口,用来实现proxy的一些API功能。

go 复制代码
type ProxyComponent interface {
    Proxy
    SetAddress(address string)
    GetAddress() string
    SetEtcdClient(etcdClient *clientv3.Client)
    SetRootCoordClient(rootCoord RootCoordClient)
    SetDataCoordClient(dataCoord DataCoordClient)
    SetQueryCoordClient(queryCoord QueryCoordClient)
    SetQueryNodeCreator(func(ctx context.Context, addr string, nodeID int64) (QueryNodeClient, error))
    GetRateLimiter() (Limiter, error)
    UpdateStateCode(stateCode commonpb.StateCode)
}

2.Server结构体包含了客户端etcdCli。为什么这里没有tikvCli??

3.包含客户端rootCoordClient、dataCoordClient、queryCoordClient。

相关推荐
林太白几秒前
Next.js超简洁完整篇
前端·后端·react.js
前端付豪1 分钟前
汇丰登录风控体系拆解:一次 FaceID 被模拟攻击的调查纪实
前端·后端·架构
天生我材必有用_吴用9 分钟前
Three.js开发必备:模型对象和材质详解
前端
万变不离其宗_89 分钟前
echarts使用笔记
前端·笔记·echarts
寒士obj9 分钟前
类加载的过程
java·开发语言
时光足迹12 分钟前
电子书阅读器之章节拆分
前端·javascript·react.js
无名之逆12 分钟前
大三自学笔记:探索Hyperlane框架的心路历程
java·开发语言·前端·spring boot·后端·rust·编程
Chuck1sn14 分钟前
我把 Cursor AI 整合到 Ruoyi 中,从此让 Java 脚手架脱离人工!
java·vue.js·后端
郭顺发16 分钟前
个人网站大更新,还是有个总站比较好
前端
水木石画室17 分钟前
Spring Boot 常用注解面试题深度解析
java·spring boot·后端