成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

OpenStack Swift源碼導讀:業務整體架構和Proxy進程

移動開發 iOS OpenStack
OpenStack的源碼分析在網上已經非常多了,針對各個部分的解讀亦是非常詳盡。這里我根據自己的理解把之前讀過的Swift源碼的一些要點記錄一下,希望給需要的同學能帶來一些幫助。

OpenStack的源碼分析在網上已經非常多了,針對各個部分的解讀亦是非常詳盡。這里我根據自己的理解把之前讀過的Swift源碼的一些要點記錄一下,希望給需要的同學能帶來一些幫助。

一、Swift的整體框架圖

Swift代碼樹

 

如上圖,Swift的源碼目錄結構。其中proxy是前端的業務接入進程。account、container和object目錄分別是賬戶、容器 和對象的業務處理邏輯進程。common目錄是一些通用工具代碼。common中比較重要的有:哈希環的處理邏輯。接下來會依次介紹各個進程的源碼邏輯和 一些關鍵點機制。

各個業務進程或模塊之間的邏輯關系可以參考《Openstack Swift簡介》文中的架構圖。

二、Proxy進程的業務處理

首先需要掌握基于PasteDeploy的堆棧式WSGI架構。根據PasteDeploy定義的各個層,可以很快理清配置文件定義的代碼流程,從 middleware到server。找到最外層的middleware,即是業務的入口。對于proxy進程,可以簡單給出業務時序圖:

WSGI業務流程示意圖

每一層的分工非常清晰,如在proxy進程默認配置文件中,最上層是做異常處理,所有的業務流程拋出的未處理的異常,在這里都將得到處理。

Proxy進程會分析請求的URI(account、container和object組成的資源路徑)和請求方法(put、del等)來分析當前 請求的資源的具體類型,然后分貝找到控制該資源的controller,由controller來分發請求到具體的資源server。分發到原則是一致性 哈希環。一致性哈希環在系統初始化時由工具生成,在《Swift 和 Keystone單機安裝總結》一文中有具體的操作步驟。

在《Openstack Swift簡介》從理論上面介紹了具體的節點尋找過程。采用md5值加移位的方式來確定part,然后找到所有的虛擬節點。具體的代碼為:

  1. container_partition, containers = self.app.container_ring.get_nodes(  
  2.  
  3.  self.account_name, self.container_name) 
  4. def get_nodes(self, account, container=None, obj=None):  
  5.  
  6.  """  
  7.  Get the partition and nodes  
  8. for an account/container/object.  
  9.  If a node is responsible  
  10. for more than one replica, it will  
  11.  only appear in the  
  12. output once. 
  13.  :param account: account name  
  14.  :param  
  15. container: container name  
  16.  :param obj: object name  
  17.  
  18.  :returns: a tuple of (partition, list of node dicts) 
  19.  Each node dict will have at least the following keys: 
  20.  ======  
  21. ===============================================================  
  22.  
  23.  id unique integer  
  24. identifier amongst devices  
  25.  weight a float of the  
  26. relative weight of this device as compared to  
  27.  
  28.  others;  
  29. this indicates how many partitions the builder will try  
  30.  
  31.  to assign  
  32. to this device  
  33.  zone integer indicating  
  34. which zone the device is in; a given  
  35.  
  36.  partition  
  37. will not be assigned to multiple devices within the  
  38.  
  39.  same zone  
  40.  
  41.  ip the ip address of the  
  42. device  
  43.  port the tcp port of the device  
  44.  
  45.  device the device's name on disk (sdb1, for  
  46. example)  
  47.  meta general use 'extra'  
  48. field; for example: the online date, the  
  49.  
  50.  hardware  
  51. description  
  52.  ======  
  53. ===============================================================  
  54.  
  55.  """  
  56.  part = self.get_part(account,  
  57. container, obj)  
  58.  return part,  
  59. self._get_part_nodes(part) 
  60. def get_part(self, account, container=None, obj=None):  
  61.   
  62. """  
  63.  Get the partition for an  
  64. account/container/object. 
  65.  :param account: account name  
  66.  :param  
  67. container: container name  
  68.  :param obj: object name  
  69.  
  70.  :returns: the partition number  
  71.  """  
  72.  
  73.  key = hash_path(account, container, obj, raw_digest=True)  
  74.  
  75.  if time() >; self._rtime:  
  76.  
  77.  self._reload()  
  78.  
  79.  part = struct.unpack_from('>;I', key)[0] >>  
  80. self._part_shift  
  81.  return part 
  82. def _get_part_nodes(self, part):  
  83.  part_nodes = []  
  84.  
  85.  seen_ids = set()  
  86.  for r2p2d in  
  87. self._replica2part2dev_id:  
  88.  if  
  89. part <; len(r2p2d):  
  90.  
  91.  dev_id =  
  92. r2p2d[part]  
  93.  
  94.  if dev_id  
  95. not in seen_ids:  
  96.  
  97.   
  98. part_nodes.append(self.devs[dev_id])  
  99.  
  100.   
  101. seen_ids.add(dev_id)  
  102.  return part_nodes 

然后根據quorum原則來決定當前請求至少需要幾個節點成功即可返回。如NWR分別為322,則至少需要2個節點寫成功,才能確保此次寫成功。體現在公用的make_request方法中:

  1. def make_requests(self, req, ring, part, method, path, headers,  
  2.   
  3. query_string=''):  
  4.  """  
  5.  Sends an  
  6. HTTP request to multiple nodes and aggregates the results.  
  7.  
  8.  It attempts the primary nodes concurrently, then iterates  
  9. over the  
  10.  handoff nodes as needed. 
  11.  :param req: a request sent by the client  
  12.  
  13.  :param ring: the ring used for finding backend servers  
  14.  
  15.  :param part: the partition number  
  16.   
  17. :param method: the method to send to the backend  
  18.  :param  
  19. path: the path to send to the backend  
  20.  
  21.   
  22. (full path ends up being /<$device>/<$part>/<$path>)  
  23.  
  24.  :param headers: a list of dicts, where each dict  
  25. represents one  
  26.  
  27.   
  28. backend request that should be made.  
  29.  :param query_string:  
  30. optional query string to send to the backend  
  31.  :returns: a  
  32. swob.Response object  
  33.  """  
  34.   
  35. start_nodes = ring.get_part_nodes(part)  
  36.  nodes =  
  37. GreenthreadSafeIterator(self.app.iter_nodes(ring, part))  
  38.   
  39. pile = GreenAsyncPile(len(start_nodes))  
  40.  for head in  
  41. headers:  
  42.   
  43. pile.spawn(self._make_request, nodes, part, method, path,  
  44.  
  45.   
  46. head, query_string, self.app.logger.thread_locals)  
  47.   
  48. response = []  
  49.  statuses = []  
  50.  for  
  51. resp in pile:  
  52.  if not resp:  
  53.  
  54.  continue  
  55.  
  56.  response.append(resp)  
  57.  
  58.  statuses.append(resp[0])  
  59.  
  60.  if self.have_quorum(statuses,  
  61. len(start_nodes)):  
  62.  
  63.  break  
  64.  
  65.  # give any pending requests *some* chance to finish  
  66.  
  67.  pile.waitall(self.app.post_quorum_timeout)  
  68.  
  69.  while len(response) <; len(start_nodes):  
  70.  
  71.   
  72. response.append((HTTP_SERVICE_UNAVAILABLE, ''''''))  
  73.   
  74. statuses, reasons, resp_headers, bodies = zip(*response)  
  75.   
  76. return self.best_response(req, statuses, reasons, bodies,  
  77.  
  78.   
  79. '%s %s' % (self.server_type, req.method),  
  80.  
  81.   
  82. headers=resp_headers)
責任編輯:閆佳明 來源: http://shentar.me
相關推薦

2012-07-12 16:00:32

OpenStackSwift架構

2012-05-17 13:47:37

OpenStack架構

2016-11-25 13:14:50

Flume架構源碼

2024-08-26 10:31:23

2022-03-18 15:55:15

鴻蒙操作系統架構

2017-07-17 11:52:54

jQuery源碼分析前端框架類庫

2022-12-05 08:41:39

Redis調試環境源碼

2021-02-06 13:28:21

鴻蒙HarmonyOS應用開發

2015-01-12 14:55:36

2018-05-17 22:45:05

2013-04-18 09:29:03

OpenStack云管理平臺Folsom平臺

2011-08-01 13:32:22

惠普OpenStack云端架構

2011-08-01 09:15:25

惠普OpenStack云端建構

2013-07-26 09:16:13

SwiftOpenStackSwiftStack

2016-11-04 21:46:46

UnderscoreJavascript

2009-06-24 14:25:13

JSF整體架構

2016-04-11 14:24:08

用戶畫像技術架構數據分析

2013-07-09 09:16:37

OpenStack企業業務模式私有云

2013-12-10 09:57:35

Openstack S開源云存儲Openstack

2014-11-27 13:29:29

OpenStackSwift開源
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 中文在线一区 | 日本成人免费网站 | 亚洲人人 | 久久国产美女视频 | 特级特黄特色的免费大片 | 久久机热 | 午夜精品一区二区三区在线视频 | 欧美v在线观看 | 看av网址 | 精品久久久久久久久久久 | 亚洲一区二区高清 | 天堂av免费观看 | 精品国产一区二区三区性色 | 久久综合一区 | 天天玩夜夜操 | 亚洲一区二区精品视频在线观看 | 欧美一区二区免费 | 日韩福利视频 | 中文字幕一区在线观看视频 | 国产亚洲一区二区三区在线观看 | 操操操日日日 | 欧美自拍第一页 | 久久久亚洲综合 | 精久久久 | 亚洲国产精品一区二区三区 | 亚洲成人免费视频在线 | 二区在线观看 | 日韩在线免费播放 | 久久蜜桃av一区二区天堂 | 另类在线 | 国产成人精品亚洲日本在线观看 | 亚洲精品一区二区冲田杏梨 | 免费视频二区 | 免费黄色av网站 | 久久只有精品 | 成人在线视频免费观看 | 91精品国产色综合久久 | 精品国产伦一区二区三区观看方式 | 99精品99| 97精品久久 | 午夜精品久久久久久不卡欧美一级 |