当前位置:网站首页>Source code analysis of etcd database -- peer RT of inter cluster network layer client
Source code analysis of etcd database -- peer RT of inter cluster network layer client
2022-07-05 13:48:00 【Tertium FATUM】
peerRt(RoundTripper type ) Mainly responsible for the realization of etcdserver Network request and other functions , Used to send version or lease The service request . We know it is in ETCD Database source code analysis ——etcdserver bootstrap The second step in initialization is to initialize . How to use it ?
Such as server/etcdserver/cluster_util.go Of promoteMemberHTTP Shown , Use peerRt establish http client , Then construct the request Url And specify the request method as POST, establish http Request Structure , call http Client's do Function to make a request to the server , And get its response .
func promoteMemberHTTP(ctx context.Context, url string, id uint64, peerRt http.RoundTripper) ([]*membership.Member, error) {
cc := &http.Client{
Transport: peerRt} // Use peerRt establish http client
// TODO: refactor member http handler code cannot import etcdhttp, so manually construct url
requestUrl := url + "/members/promote/" + fmt.Sprintf("%d", id)
req, err := http.NewRequest("POST", requestUrl, nil)
if err != nil {
return nil, err }
req = req.WithContext(ctx)
resp, err := cc.Do(req)
if err != nil {
return nil, err }
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err }
// Processing request timed out
if resp.StatusCode == http.StatusRequestTimeout {
return nil, errors.ErrTimeout }
if resp.StatusCode == http.StatusPreconditionFailed {
// both ErrMemberNotLearner and ErrLearnerNotReady have same http status code
if strings.Contains(string(b), errors.ErrLearnerNotReady.Error()) {
return nil, errors.ErrLearnerNotReady }
if strings.Contains(string(b), membership.ErrMemberNotLearner.Error()) {
return nil, membership.ErrMemberNotLearner }
return nil, fmt.Errorf("member promote: unknown error(%s)", string(b))
}
if resp.StatusCode == http.StatusNotFound {
return nil, membership.ErrIDNotFound }
// Other types of errors
if resp.StatusCode != http.StatusOK {
// all other types of errors
return nil, fmt.Errorf("member promote: unknown error(%s)", string(b))
}
var membs []*membership.Member
if err := json.Unmarshal(b, &membs); err != nil {
return nil, err } // Deserialize request response content
return membs, nil
}
as follows server/etcdserver/adapters.go Medium GetMembersVersions Is also used peerRt obtain MembersVersions.
func (s *serverVersionAdapter) GetMembersVersions() map[string]*version.Versions {
return getMembersVersions(s.lg, s.cluster, s.MemberId(), s.peerRt, s.Cfg.ReqTimeout())
}
边栏推荐
- kafaka 日志收集
- Simple PHP paging implementation
- redis6数据类型及操作总结
- Multi person cooperation project to see how many lines of code each person has written
- Personal component - message prompt
- 53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
- Scientific running robot pancakeswap clip robot latest detailed tutorial
- 2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
- 多人合作项目查看每个人写了多少行代码
- Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
猜你喜欢

NFT value and white paper acquisition

Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications

今年上半年,通信行业发生了哪些事?

Laravel框架运行报错:No application encryption key has been specified

基于微信小程序的订餐系统

laravel-dompdf导出pdf,中文乱码问题解决
Jetpack Compose入门到精通

运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化

研究生可以不用学英语?只要考研英语或六级分数高!

FPGA learning notes: vivado 2019.1 add IP MicroBlaze
随机推荐
[daily question] 1200 Minimum absolute difference
一网打尽异步神器CompletableFuture
Hide Chinese name
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
ETCD数据库源码分析——集群间网络层客户端peerRt
RK3566添加LED
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Laravel framework operation error: no application encryption key has been specified
TortoiseSVN使用情形、安装与使用
研究生可以不用学英语?只要考研英语或六级分数高!
stm32逆向入门
Wonderful express | Tencent cloud database June issue
这18个网站能让你的页面背景炫酷起来
Aspx simple user login
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
FPGA learning notes: vivado 2019.1 add IP MicroBlaze
web3.eth. Filter related
内网穿透工具 netapp
Redis6 master-slave replication and clustering
通讯录(链表实现)