总结:在此过程:写3秒不可用;读 47秒不可用;切换到完全可用近2分钟
crc32 katema 网卡流量
- //单向链表结构
- typedef struct dictEntry {
- void *key;//key值指针
- union {//
- void *val;
- uint64_t u64;
- int64_t s64;
- double d;
- } v;
- struct dictEntry *next;//单向链表下个元素指针
- } dictEntry;
- //hash表类型
- typedef struct dictType {
- unsigned int (*hashFunction)(const void *key);//哈希计算方法,返回整形变量 time33
- //hash*33+hash+ord(1)
- void *(*keyDup)(void *privdata, const void *key);//对key进行拷贝
- void *(*valDup)(void *privdata, const void *obj);//对value进行拷贝
- int (*keyCompare)(void *privdata, const void *key1, const void *key2);//key比较器
- void (*keyDestructor)(void *privdata, void *key);//销毁key,析构函数
- void (*valDestructor)(void *privdata, void *obj);//销毁value,析构函数
- } dictType;
- /* This is our hash table structure. Every dictionary has two of this as we
- * implement incremental rehashing, for the old to the new table. */
- //hash表结构
- typedef struct dictht {
- dictEntry **table; //hash 表中如果出现hash 碰撞 就用单向连表保存数据结构
- unsigned long size;//桶个数
- unsigned long sizemask;//size-1,方便定位
- unsigned long used;//实际保存的元素数
- } dictht;
- //hash表主表
- typedef struct dict {
- dictType *type;//hash表类型
- void *privdata;
- dictht ht[2];//新旧两张hash 表
- long rehashidx; /* rehashing not in progress if rehashidx == -1 */
- int iterators; /* number of iterators currently running */
- } dict;
- //迭代器
- typedef struct dictIterator {
- dict *d; //当前hash 字典
- long index;//当前索引
- int table, safe;//
- dictEntry *entry, *nextEntry;//循环结构体 以及下一个dictEntry * 结构体
- /* unsafe iterator fingerprint for misuse detection. */
- long long fingerprint;
- } dictIterator;
- #当发生hash碰撞时,dict_can_resize会变成真 当bgsave(快照)&& copy on write(aof)也会强制变成真 rehash
# use "activerehashing yes" if you don't have such hard requirements but
# want to free memory asap when possible.
# 每100毫秒,redis将用1毫秒的时间对Hash表进行重新Hash。
# 采用懒惰Hash方式:操作Hash越多,则重新Hash的可能越多,若根本就不操作Hash,则不会重新Hash
# 默认每秒10次重新hash主字典,释放可能释放的内存
# 重新hash会造成延迟,如果对延迟要求较高,则设为no,禁止重新hash。但可能会浪费很多内存
activerehashing yes
- typedef struct listNode {
- struct listNode *prev;
- struct listNode *next;
- void *value;
- } listNode;
- typedef struct listIter {
- listNode *next;
- int direction;
- } listIter;
- typedef struct list {
- listNode *head;
- listNode *tail;
- void *(*dup)(void *ptr);
- void (*free)(void *ptr);
- int (*match)(void *ptr, void *key);
- unsigned long len;
- } list;
如果问题,欢迎指教
来源: http://www.cnblogs.com/turnswing/p/7987195.html