当前位置:网站首页>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())
}
边栏推荐
- uplad_ Labs first three levels
- Huawei push service content, read notes
- STM32 reverse entry
- Record in-depth learning - some bug handling
- Godson 2nd generation burn PMON and reload system
- Scientific running robot pancakeswap clip robot latest detailed tutorial
- Laravel framework operation error: no application encryption key has been specified
- Self built shooting range 2022
- Ordering system based on wechat applet
- How to deal with the Yellow Icon during the installation of wampserver
猜你喜欢
随机推荐
一网打尽异步神器CompletableFuture
Jenkins installation
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
几款分布式数据库的对比
Idea remote debugging agent
【 script secret pour l'utilisation de MySQL 】 un jeu en ligne sur l'heure et le type de date de MySQL et les fonctions d'exploitation connexes (3)
MMSeg——Mutli-view时序数据检查与可视化
Huawei push service content, read notes
Ueditor + PHP enables Alibaba cloud OSS upload
zabbix 监控
Binder communication process and servicemanager creation process
laravel-dompdf导出pdf,中文乱码问题解决
Solve the problem of invalid uni app configuration page and tabbar
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
通讯录(链表实现)
搭建一个仪式感点满的网站,并内网穿透发布到公网 2/2
Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
RK3566添加LED
Pancake Bulldog robot V2 (code optimized)