OpenStack_Swift源代码分析——ObjectReplicator源代码分析(1)
1、ObjectorReplicator的启动
首先执行启动脚本
swift-init object-replicator start
此执行脚本的执行过程和ring执行脚本执行过程差点儿相同。找到swift 源代码bin下的swift-object-replicator其代码例如以下所看到的
if __name__ == '__main__':
parser = OptionParser("%prog CONFIG [options]")
parser.add_option('-d', '--devices',
help='Replicate only given devices. '
'Comma-separated list')
parser.add_option('-p', '--partitions',
help='Replicate only given partitions. '
'Comma-separated list')
conf_file, options = parse_options(parser=parser, once=True)
run_daemon(ObjectReplicator, conf_file, **options)
最后一行:
run_daemon(ObjectReplicator, conf_file, **options)
也就是要运行run_daemon()函数。为其传入的是ObjectReplicator和配置文件參数已经选项參数,以下继续看run_daemon方法。他是swift/daemon.py下Daemon类中的方法。看详细代码实现:
def run_daemon(klass, conf_file, section_name='', once=False, **kwargs):
"""
Loads settings from conf, then instantiates daemon "klass" and runs the
daemon with the specified once kwarg. The section_name will be derived
from the daemon "klass" if not provided (e.g. ObjectReplicator =>
object-replicator). :param klass: Class to instantiate, subclass of common.daemon.Daemon
:param conf_file: Path to configuration file
:param section_name: Section name from conf file to load config from
:param once: Passed to daemon run method
"""
# very often the config section_name is based on the class name
# the None singleton will be passed through to readconf as is
if section_name is '':
#得到section_name = ojbect-replicator sub()为正則表達式
section_name = sub(r'([a-z])([A-Z])', r'\1-\2',
klass.__name__).lower() conf = utils.readconf(conf_file, section_name,
log_name=kwargs.get('log_name')) # once on command line (i.e. daemonize=false) will over-ride config
once = once or not utils.config_true_value(conf.get('daemonize', 'true')) # pre-configure logger
if 'logger' in kwargs:
logger = kwargs.pop('logger')
else:
logger = utils.get_logger(conf, conf.get('log_name', section_name),
log_to_console=kwargs.pop('verbose', False),
log_route=section_name) # disable fallocate if desired
if utils.config_true_value(conf.get('disable_fallocate', 'no')):
utils.disable_fallocate()
# set utils.FALLOCATE_RESERVE if desired
reserve = int(conf.get('fallocate_reserve', 0))
if reserve > 0:
utils.FALLOCATE_RESERVE = reserve # By default, disable eventlet printing stacktraces
eventlet_debug = utils.config_true_value(conf.get('eventlet_debug', 'no'))
eventlet.debug.hub_exceptions(eventlet_debug) # Ensure TZ environment variable exists to avoid stat('/etc/localtime') on
# some platforms. This locks in reported times to the timezone in which
# the server first starts running in locations that periodically change
# timezones.
os.environ['TZ'] = time.strftime("%z", time.gmtime()) try:
#開始执行
klass(conf).run(once=once, **kwargs)
except KeyboardInterrupt:
logger.info('User quit')
logger.info('Exited')
因ObjectReplicator继承了Daemon类,代码片段
klass(conf).run(once=once, **kwargs)
ObjectReplicator运行run方法,主要此时传入的once为False一般once在測试时能够设为True。
继续看run方法,在Objector中没有实现run方法,其继承了父类的方法,
def run(self, once=False, **kwargs):
"""Run the daemon"""
utils.validate_configuration()
utils.drop_privileges(self.conf.get('user', 'swift'))
utils.capture_stdio(self.logger, **kwargs) def kill_children(*args):
#SIGTERM = 15 SIG_IGN = 1L
signal.signal(signal.SIGTERM, signal.SIG_IGN)
os.killpg(0, signal.SIGTERM)
sys.exit() signal.signal(signal.SIGTERM, kill_children)
if once:
self.run_once(**kwargs)
else:
self.run_forever(**kwargs)
因once为False所以执行的是run_forever方法。从方法名字面上就能够看出这是一个永久执行的程序。也就是会成为守护进程。
def run_forever(self, *args, **kwargs):
self.logger.info(_("Starting object replicator in daemon mode."))
# Run the replicator continually
while True:
start = time.time()
self.logger.info(_("Starting object replication pass."))
# Run the replicator
#运行replicator 程序
self.replicate()
total = (time.time() - start) / 60
self.logger.info(
_("Object replication complete. (%.02f minutes)"), total)
dump_recon_cache({'object_replication_time': total,
'object_replication_last': time.time()},
self.rcache, self.logger)
self.logger.debug(_('Replication sleeping for %s seconds.'),
self.run_pause)
#sleep 一段时间时间自己在部署时自己设定,也能够默觉得30秒
sleep(self.run_pause)
在run_forever方法中会运行replicate()方法。下一节介绍replicate方法的详细实现
OpenStack_Swift源代码分析——ObjectReplicator源代码分析(1)的更多相关文章
- OpenStack_Swift源代码分析——ObjectReplicator源代码分析(2)
1.Replicator运行代码具体分析 上篇问中介绍了启动Replicator的详细过程,以下解说Replicator的运行代码的详细实现,首先看replicate方法: def replicate ...
- 分析setting源代码获取sd卡大小
分析setting源代码获取sd卡大小 android系统有一个特点,即开源,我们可以得到任何一个应用的源代码,比如我们不知道这样的android代码怎么写,我们可以打开模拟器里面的设置(settin ...
- 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现
本文转载自http://www.ibm.com/developerworks/cn/java/j-lo-tree/ 目录: TreeSet 和 TreeMap 的关系 TreeMap 的添加节点 Tr ...
- Memcached源代码分析 - Memcached源代码分析之消息回应(3)
文章列表: <Memcached源代码分析 - Memcached源代码分析之基于Libevent的网络模型(1)> <Memcached源代码分析 - Memcached源代码分析 ...
- x264源代码简单分析:宏块分析(Analysis)部分-帧间宏块(Inter)
===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...
- x264源代码简单分析:宏块分析(Analysis)部分-帧内宏块(Intra)
===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...
- 常用 Java 静态代码分析工具的分析与比较
常用 Java 静态代码分析工具的分析与比较 简介: 本文首先介绍了静态代码分析的基 本概念及主要技术,随后分别介绍了现有 4 种主流 Java 静态代码分析工具 (Checkstyle,FindBu ...
- [转载] 常用 Java 静态代码分析工具的分析与比较
转载自http://www.oschina.net/question/129540_23043 简介: 本文首先介绍了静态代码分析的基本概念及主要技术,随后分别介绍了现有 4 种主流 Java 静态代 ...
- 【转载】常用 Java 静态代码分析工具的分析与比较
摘自:http://www.oschina.net/question/129540_23043常用 Java 静态代码分析工具的分析与比较 简介: 本文首先介绍了静态代码分析的基本概念及主要技术,随后 ...
随机推荐
- ECNUOJ 2574 Principles of Compiler
Principles of Compiler Time Limit:1000MS Memory Limit:65536KBTotal Submit:473 Accepted:106 Descripti ...
- 《SAS编程与数据挖掘商业案例》学习笔记之十八
接着曾经的<SAS编程与数据挖掘商业案例>,之前全是sas的基础知识,如今開始进入数据挖掘方面笔记,本文主要介绍数据挖掘基本流程以及应用方向,并以logistic回归为例说明. 一:数据挖 ...
- [Python] Boolean Or "Mask" Index Arrays filter with numpy
NumPy Reference: Indexing Integer array indexing Boolean array indexing Note: The expression a < ...
- 文件的默认权限:umask
1. 文件的默认权限 linux下当我们新建一个文件和文件夹时,该文件和文件夹的默认权限是什么? 通过umask命令来查看: $ umask 0002 $ umask -S u=rwx,g=rwx,o ...
- oracle_序列、索引、同义词
①序列 1.序列: 可供多个用户用来产生唯一数值的数据库对象 自己主动提供唯一的数值 共享对象 主要用于提供主键值 将序列值装入内存能够提高訪问效率 2.CREA ...
- CF Mike and Feet (求连续区间内长度为i的最小值)单调栈
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【HeadFirst设计模式——开篇】
近期在看HeadFirst,接下来的一段时间会陆续更新有关HeadFirst设计模式相关的文章.记得非常久之前在学习大话设计模式的时候,仅仅是走马观花的大致走过一遍.至于里面非常多东西都掌握的不是非常 ...
- jsbrige
http://www.cnblogs.com/zhangqie/p/6724252.html
- vue8 生命周期
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android自定义组件系列【14】——Android5.0按钮波纹效果实现
今天任老师发表了一篇关于Android5.0中按钮按下的波纹效果实现<Android L中水波纹点击效果的实现>,出于好奇我下载了源代码看了一下效果,正好手边有一个Nexus手机,我结合实 ...