码迷,mamicode.com
首页 > 其他好文 > 详细

glusterfs 中的字典查询

时间:2014-07-31 16:24:47      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   os   文件   io   数据   

  glusterfs文件系统是一个分布式的文件系统,但是与很多分布式文件系统不一样,它没有元数服务器,听说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 ever
14                  * need to support resizing the hash table, the resize function
15                  * will have to take into account the possibility that
16                  * "members" is not separately allocated (i.e. don‘t just call
17                  * 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*.  Since
25                  * a data_pair_t consists of five pointers, we‘re wasting four
26                  * pointers‘ worth for N=1, and will overrun what we allocated
27                  * for N>5.  If anybody ever starts using size_hint, we‘ll need
28                  * 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是要分配的字典的大小

glusterfs 中的字典查询,布布扣,bubuko.com

glusterfs 中的字典查询

标签:style   blog   color   使用   os   文件   io   数据   

原文地址:http://www.cnblogs.com/Richard-chen/p/3832712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!