当前位置:网站首页>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())
}
边栏推荐
- Backup and restore of Android local SQLite database
- 这18个网站能让你的页面背景炫酷起来
- Redis6 transaction and locking mechanism
- Laravel generate entity
- 内网穿透工具 netapp
- Ueditor + PHP enables Alibaba cloud OSS upload
- Binder communication process and servicemanager creation process
- Multi person cooperation project to see how many lines of code each person has written
- [cloud resources] what software is good for cloud resource security management? Why?
- Mmseg - Mutli view time series data inspection and visualization
猜你喜欢

The real king of caching, Google guava is just a brother
![[cloud resources] what software is good for cloud resource security management? Why?](/img/c2/85d6b4a956afc99c2dc195a1ac3938.png)
[cloud resources] what software is good for cloud resource security management? Why?

What about data leakage? " Watson k'7 moves to eliminate security threats

MMSeg——Mutli-view时序数据检查与可视化

jasypt配置文件加密|快速入门|实战

When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.

Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error

What is a network port

Flutter 3.0更新后如何应用到小程序开发中

C object storage
随机推荐
redis6数据类型及操作总结
Laravel generate entity
Write API documents first or code first?
不知道这4种缓存模式,敢说懂缓存吗?
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
Ueditor + PHP enables Alibaba cloud OSS upload
Jetpack Compose入门到精通
Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
Catch all asynchronous artifact completable future
Solution to the prompt of could not close zip file during phpword use
Data Lake (VII): Iceberg concept and review what is a data Lake
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
Backup and restore of Android local SQLite database
C object storage
Can and can FD
What about data leakage? " Watson k'7 moves to eliminate security threats
MMSeg——Mutli-view时序数据检查与可视化
多人合作项目查看每个人写了多少行代码
Log4j utilization correlation
These 18 websites can make your page background cool