DAOS通信机制-dRPC

daos: 2.6.0

1. 概述

dRPC(DAOS Remote Procedure Call)在DAOS中特指由DAOS开发的远程调用框架,而不是由STORJ研发的dRPC框架。dRPC主要用于控制平面与数据平面的通信。

DAOS实现的dRPC框架与gRPC框架基本上相同,都是依赖Protobuf序列化协议来定义所有的消息结构,唯一不同在于dRPC是基于Socket套接字来进行通信的,而gRPC基于HTTP/2协议进行通信。

dRPC的具体函数调用被封装在dRPC module中,在使用时,需要在daos_server启动中注册dRPC module。

   

2. dRPC代码实现

2.1. protobuf的定义

在DAOS中,dRPC通信机制中的所有消息结构都是在src/proto/drpc.proto文件中定义的。然后通过gRPC插件protoc-gen-go编译出go语言版本的dRPC接口文件,存放在src/control/drpc/目录下。

drpc.proto文件很简单,主要定义了CallResponse两个消息结构。相关定义如下:

// Status represents the valid values for a response status.
message Call {
  int32 module = 1; // ID of the module to process the call.
  int32 method = 2; // ID of the method to be executed.
  int64 sequence = 3; // Sequence number for matching a response to this call.
  bytes body = 4; // Input payload to be used by the method.
}
......

// Response describes the result of a dRPC call.
message Response {
	int64 sequence = 1; // Sequence number of the Call that triggered this response.
	Status status = 2; // High-level status of the RPC. If SUCCESS, method-specific status may be included in the body.
	bytes body = 3; // Output payload produced by the method.
}

 

2.2. go语言实现

2.2.1. dRPC client

dRPC client代码实现在src/control/drpc/drpc_client.go文件中。NewClientConnection是创建dRPC client入口函数。

基本流程

创建一个客户端连接

conn := drpc.NewClientConnection("/var/run/my_socket.sock")

连接dRPC server

err := conn.Connect()

发送消息

call := drpc.Call{}
// Set up the Call with module, method, and body
resp, err := drpc.SendMsg(call)

2.2.2. dRPC server

dRPC server代码实在src/control/drpc/drpc_server.go文件中。NewDomainSocketServer是创建dRPC server入口函数。dRPC server在处理请求时,是通过调用相应的dRPC module去处理的。为了实现该目的,dRPC server在初始化过程中会注册各种各样的dRPC modules。dRPC modules的相关定义在src/control/drpc/modules.go文件中。

基本流程

创建一个dRPC server

drpcServer, err := drpc.NewDomainSocketServer(log, "/var/run/my_socket.sock", 0600)

注册dRPC modules

drpcServer.RegisterRPCModule(&MyExampleModule{})
drpcServer.RegisterRPCModule(&AnotherExampleModule{})

启动dRPC server

err = drpc.Start()

   

3. 参考资料

https://github.com/daos-stack/daos/blob/v2.6.0/src/control/drpc/README.md