本文共 5189 字,大约阅读时间需要 17 分钟。
[pipeline:main]pipeline = healthcheck recon account-server[app:account-server]use = egg:swift#account
[entry_points]paste.app_factory = proxy = swift.proxy.server:app_factory object = swift.obj.server:app_factory mem_object = swift.obj.mem_server:app_factory container = swift.container.server:app_factory account = swift.account.server:app_factory
#swift/account/server.pyclass AccountController(object):def app_factory(global_conf, **local_conf): """paste.deploy app factory for creating WSGI account server apps""" conf = global_conf.copy() conf.update(local_conf)return AccountController(conf)
#swift/account/server.pyclass AccountController(object): """WSGI controller for the account server.""" def PUT(self, req): """Handle HTTP PUT request.""" #从请求参数req里面获取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) #如果container的信息不为空,则视该请求为创建某个account的container 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 #构建并返回一个AccountBroker类的实例。AccountBroker类继承于 #DatabaseBroker类,其内部包括了针对account数据库文件的操作函数。 #可以把partition理解为一个目录,每一个partition中的accout数据是以这个目录 #中的数据库文件形式存在的。 #该partition中的每一个account都对应一个数据库文件。 #AccountBroker这个类将操作account数据库文件的函数加以封装, #作为其成员函数来使用 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: #如果该account的数据库文件尚未存在,则调用AccountBroker类的 #initialize()函数创建该数据文件。 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) #通过调用AccountBroker中的put_container()函数将container的信息 #写入该account的数据库文件中去。 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) #如果container的信息为空,则视该请求为创建account else: # put account timestamp = valid_timestamp(req) #获取一个AccountBroker的实例 broker = self._get_account_broker(drive, part, account) #如果该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)
转载地址:http://flej.baihongyu.com/