本文整理汇总了Python中mysql.fabric.server.MySQLServer.is_alive方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLServer.is_alive方法的具体用法?Python MySQLServer.is_alive怎么用?Python MySQLServer.is_alive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.fabric.server.MySQLServer
的用法示例。
在下文中一共展示了MySQLServer.is_alive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import is_alive [as 别名]
def _run(self):
"""Function that verifies servers' availabilities.
"""
from mysql.fabric.server import (
Group,
MySQLServer,
ConnectionManager,
)
ignored_status = [MySQLServer.FAULTY]
quarantine = {}
interval = FailureDetector._DETECTION_INTERVAL
detections = FailureDetector._DETECTIONS
detection_timeout = FailureDetector._DETECTION_TIMEOUT
connection_manager = ConnectionManager()
slave_deep_checks = FailureDetector._SLAVE_DEEP_CHECKS
_persistence.init_thread()
while self.__check:
try:
unreachable = set()
group = Group.fetch(self.__group_id)
if group is not None:
for server in group.servers():
if server.status in ignored_status:
### Server is FAULTY
connection_manager.kill_connections(server)
continue
else:
### Server is Not FAULTY
if MySQLServer.is_alive(server, detection_timeout):
### Server is alive
### check depends on `slave_deep_checks` parameter
if slave_deep_checks:
### When server is alive and status != FAULTY
is_master= (group.master == server.uuid)
if not is_master:
### Checking master is dead or alive.
master_server = MySQLServer.fetch(group.master)
if MySQLServer.is_alive(master_server, detection_timeout):
### Checking is replication valid or not if master is alive.
server.connect()
slave_issues, why_slave_issues = \
_replication.check_slave_issues(server)
if slave_issues:
if (why_slave_issues['io_error'] and \
why_slave_issues['io_errno'] == 2003):
### Nothing to do during reconnecting, just logging
_LOGGER.info(why_slave_issues)
else:
### If slave threads are not running, set status to SPARE
server.status = MySQLServer.SPARE
### Done slave_issues.
server.disconnect()
### Endif MySQLServer.is_alive(master_server, detection_timeout)
### Endif not is_master
### Endif slave_deep_checks
continue
### Else MySQLServer.is_alive(server, detection_timeout)
else:
unreachable.add(server.uuid)
_LOGGER.warning(
"Server (%s) in group (%s) is unreachable.",
server.uuid, self.__group_id
)
unstable = False
failed_attempts = 0
if server.uuid not in quarantine:
quarantine[server.uuid] = failed_attempts = 1
else:
failed_attempts = quarantine[server.uuid] + 1
quarantine[server.uuid] = failed_attempts
if failed_attempts >= detections:
unstable = True
can_set_faulty = group.can_set_server_faulty(
server, get_time()
)
if unstable and can_set_faulty:
# We have to make this transactional and make the
# failover (i.e. report failure) robust to failures.
# Otherwise, a master might be set to faulty and
# a new one never promoted.
server.status = MySQLServer.FAULTY
connection_manager.kill_connections(server)
#.........这里部分代码省略.........
示例2: _run
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import is_alive [as 别名]
def _run(self):
"""Function that verifies servers' availabilities.
"""
from mysql.fabric.server import (
Group,
MySQLServer,
ConnectionManager,
)
ignored_status = [MySQLServer.FAULTY]
quarantine = {}
interval = FailureDetector._DETECTION_INTERVAL
detections = FailureDetector._DETECTIONS
detection_timeout = FailureDetector._DETECTION_TIMEOUT
connection_manager = ConnectionManager()
_persistence.init_thread()
while self.__check:
try:
unreachable = set()
group = Group.fetch(self.__group_id)
if group is not None:
for server in group.servers():
if server.status in ignored_status or \
MySQLServer.is_alive(server, detection_timeout):
if server.status == MySQLServer.FAULTY:
connection_manager.kill_connections(server)
continue
unreachable.add(server.uuid)
_LOGGER.warning(
"Server (%s) in group (%s) is unreachable.",
server.uuid, self.__group_id
)
unstable = False
failed_attempts = 0
if server.uuid not in quarantine:
quarantine[server.uuid] = failed_attempts = 1
else:
failed_attempts = quarantine[server.uuid] + 1
quarantine[server.uuid] = failed_attempts
if failed_attempts >= detections:
unstable = True
can_set_faulty = group.can_set_server_faulty(
server, get_time()
)
if unstable and can_set_faulty:
# We have to make this transactional and make the
# failover (i.e. report failure) robust to failures.
# Otherwise, a master might be set to faulty and
# a new one never promoted.
server.status = MySQLServer.FAULTY
connection_manager.kill_connections(server)
procedures = trigger("REPORT_FAILURE", None,
str(server.uuid),
threading.current_thread().name,
MySQLServer.FAULTY, False
)
executor = _executor.Executor()
for procedure in procedures:
executor.wait_for_procedure(procedure)
for uuid in quarantine.keys():
if uuid not in unreachable:
del quarantine[uuid]
except (_errors.ExecutorError, _errors.DatabaseError):
pass
except Exception as error:
_LOGGER.exception(error)
time.sleep(interval / detections)
_persistence.deinit_thread()