当前位置:网站首页>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())
}
边栏推荐
- PHP character capture notes 2020-09-14
- Address book (linked list implementation)
- 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.
- Laravel框架运行报错:No application encryption key has been specified
- Zibll theme external chain redirection go page beautification tutorial
- The real king of caching, Google guava is just a brother
- MySQL - database query - sort query, paging query
- Jetpack Compose入门到精通
- 运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
- aspx 简单的用户登录
猜你喜欢
内网穿透工具 netapp
Solve the problem of invalid uni app configuration page and tabbar
【云资源】云资源安全管理用什么软件好?为什么?
南理工在线交流群
French scholars: the explicability of counter attack under optimal transmission theory
Godson 2nd generation burn PMON and reload system
Win10——轻量级小工具
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
[cloud resources] what software is good for cloud resource security management? Why?
How to deal with the Yellow Icon during the installation of wampserver
随机推荐
通讯录(链表实现)
Scientific running robot pancakeswap clip robot latest detailed tutorial
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
Usage, installation and use of TortoiseSVN
Laravel generate entity
Cloudcompare - point cloud slice
Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
RK3566添加LED
C object storage
2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
Jetpack Compose入门到精通
南理工在线交流群
Binder communication process and servicemanager creation process
aspx 简单的用户登录
嵌入式软件架构设计-消息交互
搭建一个仪式感点满的网站,并内网穿透发布到公网 2/2
Personal component - message prompt
PHP character capture notes 2020-09-14
ELFK部署
【华南理工大学】考研初试复试资料分享