glusterfs 中的字典查詢

來源:互聯網
上載者:User

標籤:style   blog   color   使用   os   檔案   io   資料   

  glusterfs檔案系統是一個分布式的檔案系統,但是與很多Distributed File System不一樣,它沒有元數伺服器,聽說swift上也是應用了這個技術的。glusterfs中每個xlator的配置資訊都是用dict進行管理的。dict這玩意兒,說白了就是一個hash表,是一個key/value的記憶體資料庫。今天花了點時間慢慢研究了glusterfs中的設計,覺得還是挺有意思的。

  上篇部落格介紹了glusterfs檔案系統的記憶體池的設計,而glusterfs的記憶體池正應用在這項技術上。首先,glusterfsd在程式初始化時,就建立了三個池dict_pool、dict_pair_pool、dict_data_pool。接下來看看它是怎麼玩這三個記憶體池的呢!

  1、在使用dict之前,首先是建立dict對象,這點是物件導向的思想吧。

1 dict_t *2 get_new_dict (void)3 {4         return get_new_dict_full (1);5 }

  glusterfs調用get_new_dict來建立一個dict對象,接下來看看get_new_dict又做了什麼呢?

 1 dict_t * 2 get_new_dict_full (int size_hint) 3 { 4         dict_t *dict = mem_get0 (THIS->ctx->dict_pool); 5  6         if (!dict) { 7                 return NULL; 8         } 9 10         dict->hash_size = size_hint;11         if (size_hint == 1) {12                 /*13                  * This is the only case we ever see currently.  If we ever14                  * need to support resizing the hash table, the resize function15                  * will have to take into account the possibility that16                  * "members" is not separately allocated (i.e. don‘t just call17                  * realloc() blindly.18                  */19                 dict->members = &dict->members_internal;20         }21         else {22                 /*23                  * We actually need to allocate space for size_hint *pointers*24                  * but we actually allocate space for one *structure*.  Since25                  * a data_pair_t consists of five pointers, we‘re wasting four26                  * pointers‘ worth for N=1, and will overrun what we allocated27                  * for N>5.  If anybody ever starts using size_hint, we‘ll need28                  * to fix this.29                  */30                 GF_ASSERT (size_hint <=31                            (sizeof(data_pair_t) / sizeof(data_pair_t *)));32                 dict->members = mem_get0 (THIS->ctx->dict_pair_pool);33                 if (!dict->members) {34                         mem_put (dict);35                         return NULL;36                 }37         }38 39         LOCK_INIT (&dict->lock);40 41         return dict;42 }

   size_hint是要分配的字典的大小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.