当前位置:网站首页>PostgreSQL database high availability Patroni source code learning - etcd class
PostgreSQL database high availability Patroni source code learning - etcd class
2022-07-03 04:09:00 【Tertium FATUM】
Etcd Class inherits from AbstractEtcd abstract class ,AbstractEtcd Abstract classes inherit from AbstractDCS(AbstractEtcd The constructor of will pass in EtcdClient class ).Etcd The constructor of the class will first call the constructor of the parent class , And then __do_not_watch Members are set to False.
class Etcd(AbstractEtcd):
def __init__(self, config):
super(Etcd, self).__init__(config, EtcdClient, (etcd.EtcdLeaderElectionInProgress, EtcdRaftInternal))
self.__do_not_watch = False
Function name | purpose | Code |
---|---|---|
touch_member(self, data, permanent=False) | self._client.set(self.member_path, json.dumps(data, separators=(’,’, ‘:’)), None if permanent else self._ttl) | |
take_leader(self) | self.retry(self._client.write, self.leader_path, self._name, ttl=self._ttl) | |
set_failover_value(self, value, index=None) | self._client.write(self.failover_path, value, prevIndex=index or 0) | |
set_config_value(self, value, index=None) | self._client.write(self.config_path, value, prevIndex=index or 0) | |
_write_leader_optime(self, last_lsn) | self._client.set(self.leader_optime_path, last_lsn) | |
_write_status(self, value) | self._client.set(self.status_path, value) | |
_update_leader(self) | self.retry(self._client.write, self.leader_path, self._name, prevValue=self._name, ttl=self._ttl) | |
_delete_leader(self) | self._client.delete(self.leader_path, prevValue=self._name) | |
initialize(self, create_new=True, sysid="") | self.retry(self._client.write, self.initialize_path, sysid, prevExist=(not create_new)) | |
cancel_initialization(self) | self.retry(self._client.delete, self.initialize_path) | |
delete_cluster(self) | self.retry(self._client.delete, self.client_path(’’), recursive=True) | |
set_history_value(self, value) | self._client.write(self.history_path, value) | |
set_sync_state_value(self, value, index=None) | self.retry(self._client.write, self.sync_path, value, prevIndex=index or 0) | |
delete_sync_state(self, index=None) | self.retry(self._client.delete, self.sync_path, prevIndex=index or 0) |
def attempt_to_acquire_leader(self, permanent=False):
try:
return bool(self.retry(self._client.write, self.leader_path, self._name, ttl=None if permanent else self._ttl, prevExist=False))
except etcd.EtcdAlreadyExist:
logger.info('Could not take out TTL lock')
except (RetryFailedError, etcd.EtcdException):
pass
return False
watch Member functions
watch Member functions
def watch(self, leader_index, timeout):
if self.__do_not_watch:
self.__do_not_watch = False
return True
if leader_index:
end_time = time.time() + timeout
while timeout >= 1: # when timeout is too small urllib3 doesn't have enough time to connect
try:
result = self._client.watch(self.leader_path, index=leader_index, timeout=timeout + 0.5)
self._has_failed = False
if result.action == 'compareAndSwap':
time.sleep(0.01)
# Synchronous work of all cluster members with etcd is less expensive
# than reestablishing http connection every time from every replica.
return True
except etcd.EtcdWatchTimedOut:
self._has_failed = False
return False
except (etcd.EtcdEventIndexCleared, etcd.EtcdWatcherCleared): # Watch failed
self._has_failed = False
return True # leave the loop, because watch with the same parameters will fail anyway
except etcd.EtcdException as e:
self._handle_exception(e, 'watch', True)
timeout = end_time - time.time()
try:
return super(Etcd, self).watch(None, timeout)
finally:
self.event.clear()
边栏推荐
- 深潜Kotlin协程(十九):Flow 概述
- [set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
- [learning notes] seckill - seckill project - (11) project summary
- How does the pytorch project run?
- 2022deepbrainchain biweekly report no. 104 (01.16-02.15)
- Supervised pre training! Another exploration of text generation!
- Reflection and planning of a sophomore majoring in electronic information engineering
- Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
- Pdf editing tool movavi pdfchef 2022 direct download
- The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
猜你喜欢
2022deepbrainchain biweekly report no. 104 (01.16-02.15)
China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
Web session management security issues
【刷题篇】多数元素(超级水王问题)
Error in compiled file: error: unmapped character encoding GBK
CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
[home push IMessage] software installation virtual host rental tothebuddy delay
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
pytorch是什么?pytorch是一个软件吗?
JMeter starts from zero (III) -- simple use of regular expressions
随机推荐
When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker
DAPP for getting started with eth
Arduino application development - LCD display GIF dynamic diagram
Nodejs Foundation: shallow chat URL and querystring module
eth入门之DAPP
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
[Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
JS realizes the animation effect of text and pictures in the visual area
What is the correct way to compare ntext columns with constant values- What's the right way to compare an NTEXT column with a constant value?
Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness
[brush questions] find the number pair distance with the smallest K
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
What is pytorch? Is pytorch a software?
In Net 6 project using startup cs
2022年已过半,得抓紧
js实现在可视区内,文字图片动画效果
SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
有监督预训练!文本生成又一探索!
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
Makefile demo