博客
关于我
Swift中的Account Server代码解读
阅读量:184 次
发布时间:2019-02-28

本文共 3931 字,大约阅读时间需要 13 分钟。

Swift的Account Server、Container Server和Object Server通过Paste Deploy加载WSGI Application,分别由AccountController、ContainerController和ObjectController处理用户的HTTP请求。这些服务与Proxy Server类似,均通过run_wsgi()函数启动。Account Server的配置文件位于/etc/swift/account-server/目录下。

Paste Deploy的配置文件中,[pipeline:main]管道定义了健康检查和重建功能,接着调用account-server模块。setup.cfg文件定义了entry_points,指定了各个服务的app_factory函数,包括swift.account.server、swift.container.server等。

结合配置文件和setup.cfg,Paste Deploy最终使用swift.account.server模块的app_factory函数加载Account Server的WSGI Application,即swift.account.server.AccountController。该Controller与swift/proxy/controllers目录下的Controller不同,后者负责将HTTP请求转发给Account Server,而AccountController则是对请求的最终处理。

以PUT操作为例,Account PUT请求有两种语义:一种是创建Account,另一种是创建Account中的Container。两者的区别在于路径参数是否包含Container信息。

AccountController的实现如下:

class AccountController(object):    """WSGI controller for the account server."""    def PUT(self, req):        """Handle HTTP PUT request."""        # 从请求参数中获取drive, part, account, container信息        drive, part, account, container = split_and_validate_path(req, 3, 4)        if self.mount_check and not check_mount(self.root, drive):            return HTTPInsufficientStorage(drive=drive, request=req)                if container:            # PUT account container            if 'x-timestamp' not in req.headers:                timestamp = Timestamp(time.time())            else:                timestamp = valid_timestamp(req)                        pending_timeout = None            container_policy_index = req.headers.get('X-Backend-Storage-Policy-Index', 0)            if 'x-trans-id' in req.headers:                pending_timeout = 3                        broker = self._get_account_broker(drive, part, account, pending_timeout=pending_timeout)            if account.startswith(self.auto_create_account_prefix) and not os.path.exists(broker.db_file):                try:                    broker.initialize(timestamp.internal)                except DatabaseAlreadyExists:                    pass            if req.headers.get('x-account-override-deleted', 'no').lower() != 'yes' and broker.is_deleted():                return HTTPNotFound(request=req)                        broker.put_container(container, req.headers['x-put-timestamp'],                                  req.headers['x-delete-timestamp'],                                  req.headers['x-object-count'],                                  req.headers['x-bytes-used'],                                  container_policy_index)            if req.headers['x-delete-timestamp'] > req.headers['x-put-timestamp']:                return HTTPNoContent(request=req)            else:                return HTTPCreated(request=req)        else:            # PUT account            timestamp = valid_timestamp(req)            broker = self._get_account_broker(drive, part, account)            if not os.path.exists(broker.db_file):                try:                    broker.initialize(timestamp.internal)                    created = True                except DatabaseAlreadyExists:                    created = False            elif broker.is_status_deleted():                return self._deleted_response(broker, req, HTTPForbidden, body='Recently deleted')            else:                created = broker.is_deleted()                broker.update_put_timestamp(timestamp.internal)                if broker.is_deleted():                    return HTTPConflict(request=req)                        metadata = {}            metadata.update((key, (value, timestamp.internal)) for key, value in req.headers.iteritems() if is_sys_or_user_meta('account', key))            if metadata:                broker.update_metadata(metadata, validate_metadata=True)                        if created:                return HTTPCreated(request=req)            else:                return HTTPAccepted(request=req)

该Controller通过路径参数分割和验证请求,检查存储位置并调用相应的Broker进行操作。Broker负责处理具体的账户操作,包括创建账户和账户中的容器。

转载地址:http://flej.baihongyu.com/

你可能感兴趣的文章
NIFI1.21.0_NIFI和hadoop蹦了_200G集群磁盘又满了_Jps看不到进程了_Unable to write in /tmp. Aborting----大数据之Nifi工作笔记0052
查看>>
NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表多表增量同步_增删改数据分发及删除数据实时同步_通过分页解决变更记录过大问题_02----大数据之Nifi工作笔记0054
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_根据binlog实现数据实时delete同步_实际操作04---大数据之Nifi工作笔记0043
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置binlog_使用处理器抓取binlog数据_实际操作01---大数据之Nifi工作笔记0040
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置数据路由_实现数据插入数据到目标数据库_实际操作03---大数据之Nifi工作笔记0042
查看>>
NIFI从MySql中离线读取数据再导入到MySql中_03_来吧用NIFI实现_数据分页获取功能---大数据之Nifi工作笔记0038
查看>>
NIFI从PostGresql中离线读取数据再导入到MySql中_带有数据分页获取功能_不带分页不能用_NIFI资料太少了---大数据之Nifi工作笔记0039
查看>>
NIFI同步MySql数据_到SqlServer_错误_驱动程序无法通过使用安全套接字层(SSL)加密与SQL Server_Navicat连接SqlServer---大数据之Nifi工作笔记0047
查看>>
Nifi同步过程中报错create_time字段找不到_实际目标表和源表中没有这个字段---大数据之Nifi工作笔记0066
查看>>
NIFI大数据进阶_FlowFile拓扑_对FlowFile内容和属性的修改删除添加_介绍和描述_以及实际操作---大数据之Nifi工作笔记0023
查看>>
NIFI大数据进阶_NIFI的模板和组的使用-介绍和实际操作_创建组_嵌套组_模板创建下载_导入---大数据之Nifi工作笔记0022
查看>>
NIFI大数据进阶_NIFI监控的强大功能介绍_处理器面板_进程组面板_summary监控_data_provenance事件源---大数据之Nifi工作笔记0025
查看>>
NIFI大数据进阶_NIFI集群知识点_集群的断开_重连_退役_卸载_总结---大数据之Nifi工作笔记0018
查看>>
NIFI大数据进阶_内嵌ZK模式集群1_搭建过程说明---大数据之Nifi工作笔记0015
查看>>
NIFI大数据进阶_外部ZK模式集群1_实际操作搭建NIFI外部ZK模式集群---大数据之Nifi工作笔记0017
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_01_实际操作---大数据之Nifi工作笔记0029
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_02_实际操作_splitjson处理器_puthdfs处理器_querydatabasetable处理器---大数据之Nifi工作笔记0030
查看>>
NIFI大数据进阶_连接与关系_设置数据流负载均衡_设置背压_设置展现弯曲_介绍以及实际操作---大数据之Nifi工作笔记0027
查看>>
NIFI数据库同步_多表_特定表同时同步_实际操作_MySqlToMysql_可推广到其他数据库_Postgresql_Hbase_SqlServer等----大数据之Nifi工作笔记0053
查看>>
NIFI汉化_替换logo_二次开发_Idea编译NIFI最新源码_详细过程记录_全解析_Maven编译NIFI避坑指南001---大数据之Nifi工作笔记0068
查看>>