Source code analysis of spark 2.1.0 -- RPC server bootstrap

Taishan is not old 2020-11-13 00:16:00
source code analysis spark 2.1.0


Tips : It's better to read before reading this article :

  1. 《Spark2.1.0 It's built in RPC frame 》
  2. 《spark2.1.0 Source code analysis ——RPC To configure TransportConf》
  3. 《spark2.1.0 Source code analysis ——RPC Client factory TransportClientFactory》
  4. spark2.1.0 Source code analysis ——RPC The server TransportServer》
  5. 《spark2.1.0 Source code analysis ——RPC Pipeline initialization 》
  6. spark2.1.0 Source code analysis ——RPC Transmission pipeline processor details
  7. spark2.1.0 Source code analysis —— Server side RPC processor RpcHandler Detailed explanation

adopt 《spark2.1.0 Source code analysis ——RPC The server TransportServer》 An introduction to , We know TransportServer In the constructor of bootstraps yes TransportServerBootstrap A list of . Interface TransportServerBootstrap Defines the specification of the server boot program , The server boot program is designed to connect the client and the server , The bootstrap program executed on the client pipeline held by the server .TransportServerBootstrap See the code listing for the definition of 1.

Code list 1         TransportServerBootstrap The definition of  

public interface TransportServerBootstrap {
RpcHandler doBootstrap(Channel channel, RpcHandler rpcHandler);
}

TransportServerBootstrap Of doBootstrap Method will be used for RpcHandler Acting as agent , Receive requests from clients .TransportServerBootstrap Yes SaslServerBootstrap and EncryptionCheckerBootstrap Two implementation classes . For a clearer explanation TransportServerBootstrap The meaning of , We use SaslServerBootstrap For example , To explain its realization ( See code list 2).

Code list 2         SaslServerBootstrap Of doBootstrap Realization

 public RpcHandler doBootstrap(Channel channel, RpcHandler rpcHandler) {
return new SaslRpcHandler(conf, channel, rpcHandler, secretKeyHolder);
}

According to the code list 2, We know SaslServerBootstrap Of doBootstrap Method actually creates SaslRpcHandler,SaslRpcHandler Responsible for carrying out SASL(Simple Authentication and Security Layer) encryption .SaslRpcHandler It also inherits RpcHandler, So let's focus on receive Method implementation , See code list 3.

Code list 3        SaslRpcHandler Of receive Method

 @Override
public void receive(TransportClient client, ByteBuffer message, RpcResponseCallback callback) {
if (isComplete) {
// Deliver a message to SaslRpcHandler Downstream of agency RpcHandler And back to
delegate.receive(client, message, callback);
return;
}
ByteBuf nettyBuf = Unpooled.wrappedBuffer(message);
SaslMessage saslMessage;
try {
saslMessage = SaslMessage.decode(nettyBuf);// For messages sent by the client SASL Decrypt
} finally {
nettyBuf.release();
}
if (saslServer == null) {
// If saslServer Not created yet , I need to create SparkSaslServer
client.setClientId(saslMessage.appId);
saslServer = new SparkSaslServer(saslMessage.appId, secretKeyHolder,
conf.saslServerAlwaysEncrypt());
}
byte[] response;
try {
response = saslServer.response(JavaUtils.bufferToArray(// Use saslServer Process decrypted messages
saslMessage.body().nioByteBuffer()));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
callback.onSuccess(ByteBuffer.wrap(response));
if (saslServer.isComplete()) {
logger.debug("SASL authentication successful for channel {}", client);
isComplete = true;// SASL The authentication exchange has been completed
if (SparkSaslServer.QOP_AUTH_CONF.equals(saslServer.getNegotiatedProperty(Sasl.QOP))) {
logger.debug("Enabling encryption for channel {}", client);
// Carry out SASL encryption
SaslEncryption.addToChannel(channel, saslServer, conf.maxSaslEncryptedBlockSize());
saslServer = null;
} else {
saslServer.dispose();
saslServer = null;
}
}
}

According to the code list 3,SaslRpcHandler The steps to process the client message are as follows :

  1. If SASL The authentication exchange has been completed (isComplete be equal to true), Then deliver the message to SaslRpcHandler Downstream of agency RpcHandler And back to .
  2. If SASL Authentication exchange not completed (isComplete be equal to false), Then the message sent by the client is SASL Decrypt .
  3. If saslServer Not created yet , I need to create SparkSaslServer. When SaslRpcHandler This is done when the first message from the client is received .
  4. Use saslServer Process decrypted messages , And pass the result through RpcResponseCallback The callback method of is returned to the client .
  5. If SASL The authentication exchange has been completed , Will isComplete Set as true.
  6. Carry out SASL encryption .

SaslServerBootstrap It's through SaslRpcHandler To the downstream RpcHandler A kind of agency TransportServerBootstrap.EncryptionCheckerBootstrap It's another kind of TransportServerBootstrap The implementation of the , It adds itself to Netty In the pipeline to achieve guidance ,EncryptionCheckerBootstrap Of doBootstrap The implementation of the method is shown in the code listing 4.

Code list 4         EncryptionCheckerBootstrap Of doBootstrap Realization

 @Override
public RpcHandler doBootstrap(Channel channel, RpcHandler rpcHandler) {
channel.pipeline().addFirst("encryptionChecker", this);
return rpcHandler;
}

In detail TransportChannelHandler Then we can be right 《spark2.1.0 Source code analysis ——RPC Pipeline initialization 》 The picture in the article 1 Expand , hold TransportRequestHandler、TransportServerBootstrap And RpcHandler The processing flow of , As shown in the figure below .

RPC The framework server processes the request 、 Response flow chart

                                                                          RPC The framework server processes the request 、 Response flow chart

Some readers may ask , Not in the picture above TransportServerBootstrap The figure of . According to TransportServerBootstrap Two examples of implementation of , We know TransportServerBootstrap It may exist in the middle of the arrow line of any two components in the figure , Start to guide 、 packing 、 The role of agency .

About 《Spark The art of kernel design Architecture design and implementation 》

After nearly a year of preparation ,《Spark The art of kernel design Architecture design and implementation 》 The book is out now , The book is shown in figure :

 

The link to the paper version is as follows :

JD.COM :https://item.jd.com/12302500.html

版权声明
本文为[Taishan is not old]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple