深入redis内部之redis启动过程之二
来源:互联网 发布:如何关闭445端口 win7 编辑:程序博客网 时间:2024/05/17 23:30
接上文,继续分析代码
1. 设置线程安全模式
zmalloc_enable_thread_safeness();
/*
设置线程安全标识符为1
*/
void zmalloc_enable_thread_safeness(void) {
zmalloc_thread_safe = 1;
}
2. 内存溢出处理
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
/*
内存溢出的调用方法
*/
void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {
zmalloc_oom_handler = oom_handler;
}
//调用下一级
static void (*zmalloc_oom_handler)(size_t) = zmalloc_default_oom;
//最终调用
static void zmalloc_default_oom(size_t size) {
fprintf(stderr, "zmalloc: Out of memory trying to allocate %zu bytes\n",size);
fflush(stderr);
abort();
}
3.生成hash seed
srand(time(NULL)^getpid()); gettimeofday(&tv,NULL); dictSetHashFunctionSeed(tv.tv_sec^tv.tv_usec^getpid());
3.1 time( )函数
头文件:#include <time.h>
函数定义:time_t time(time_t *timer)
功能描述:该函数返回从1970年1月1日00时00分00秒至今所经过的秒数。如果time_t *timer非空指针,函数也会将返回值存到timer指针指向的内存。
返回值:成功则返回秒数,失败则返回((time_t)-1)值,错误原因存于errno中。
3.2 getpid(取得进程识别码)
表头文件 #include<unistd.h>
定义函数 pid_t getpid(void);
函数说明 getpid()用来取得目前进程的进程识别码。
3.3 srand()函数
void srand(unsigned seed) 初始化随机数发生器。
3.4 gettimeofday()函数
#include<sys/time.h>
int gettimeofday(struct timeval*tv,struct timezone *tz )
gettimeofday()会把目前的时间用tv 结构体返回,当地时区的信息则放到tz所指的结构中
3.5 设置hash seed
static uint32_t dict_hash_function_seed = 5381;void dictSetHashFunctionSeed(uint32_t seed) { dict_hash_function_seed = seed;}
4. 检查是否sentime模式(集群的临时方案)
server.sentinel_mode = checkForSentinelMode(argc,argv);//根据启动的参数来检查是否sentinel模式/* Returns 1 if there is --sentinel among the arguments or if * argv[0] is exactly "redis-sentinel". */int checkForSentinelMode(int argc, char **argv) { int j; if (strstr(argv[0],"redis-sentinel") != NULL) return 1; for (j = 1; j < argc; j++) if (!strcmp(argv[j],"--sentinel")) return 1; return 0;}
- 深入redis内部之redis启动过程之二
- 深入redis内部之redis启动过程之一
- Redis实用教程之二---启动redis
- Redis深入之路(二)
- Redis深入之数据结构
- Redis深入之对象
- redis内部数据结构之字典
- 求知过程之redis
- redis学习心得之二
- redis之二字符串
- redis学习心得之二【redis主从配置】
- redis学习心得之二【redis主从配置】
- redis学习心得之二【redis主从配置】
- Redis系列之Redis主从复制(二)
- 深入Redis内部-Redis 源码讲解
- 深入Redis内部-Redis 源码讲解
- Redis内部数据结构详解之字典(dict)
- 浅述NoSQl之Redis+内部机制
- What is Network Address Translation?---reference
- 代码重构----使用java有限状态机来消除太多的if else判断
- Understanding Java 8 Streams API---reference
- Where Should an Architect Begin?--reference
- 深入redis内部之redis启动过程之一
- 深入redis内部之redis启动过程之二
- Linux服务器性能评估与优化--转
- keepalive学习之软件设计
- java环境变量设置
- VRRP协议介绍--转
- iptables详解--转
- fatal error: Python.h: No such file or directory
- Find command usage in Linux with excellent examples--reference
- How to Configure Tomcat/JBoss and Apache HTTPD for Load Balancing and Failover