mirror of
https://github.com/fluencelabs/redis
synced 2025-03-22 18:40:50 +00:00
Cache timezone and daylight active flag for safer logging.
With such information will be able to use a private localtime() implementation serverLog(), which does not use any locking and is both thread and fork() safe.
This commit is contained in:
parent
18d8205bbd
commit
81778d91bf
13
src/server.c
13
src/server.c
@ -977,6 +977,14 @@ void updateCachedTime(void) {
|
|||||||
time_t unixtime = time(NULL);
|
time_t unixtime = time(NULL);
|
||||||
atomicSet(server.unixtime,unixtime);
|
atomicSet(server.unixtime,unixtime);
|
||||||
server.mstime = mstime();
|
server.mstime = mstime();
|
||||||
|
|
||||||
|
/* To get information about daylight saving time, we need to call localtime_r
|
||||||
|
* and cache the result. However calling localtime_r in this context is safe
|
||||||
|
* since we will never fork() while here, in the main thread. The logging
|
||||||
|
* function will call a thread safe version of localtime that has no locks. */
|
||||||
|
struct tm tm;
|
||||||
|
localtime_r(&server.unixtime,&tm);
|
||||||
|
server.daylight_active = tm.tm_isdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is our timer interrupt, called server.hz times per second.
|
/* This is our timer interrupt, called server.hz times per second.
|
||||||
@ -1419,10 +1427,12 @@ void initServerConfig(void) {
|
|||||||
pthread_mutex_init(&server.lruclock_mutex,NULL);
|
pthread_mutex_init(&server.lruclock_mutex,NULL);
|
||||||
pthread_mutex_init(&server.unixtime_mutex,NULL);
|
pthread_mutex_init(&server.unixtime_mutex,NULL);
|
||||||
|
|
||||||
|
updateCachedTime();
|
||||||
getRandomHexChars(server.runid,CONFIG_RUN_ID_SIZE);
|
getRandomHexChars(server.runid,CONFIG_RUN_ID_SIZE);
|
||||||
server.runid[CONFIG_RUN_ID_SIZE] = '\0';
|
server.runid[CONFIG_RUN_ID_SIZE] = '\0';
|
||||||
changeReplicationId();
|
changeReplicationId();
|
||||||
clearReplicationId2();
|
clearReplicationId2();
|
||||||
|
server.timezone = timezone; /* Initialized by tzset(). */
|
||||||
server.configfile = NULL;
|
server.configfile = NULL;
|
||||||
server.executable = NULL;
|
server.executable = NULL;
|
||||||
server.hz = CONFIG_DEFAULT_HZ;
|
server.hz = CONFIG_DEFAULT_HZ;
|
||||||
@ -2000,7 +2010,6 @@ void initServer(void) {
|
|||||||
server.aof_last_write_status = C_OK;
|
server.aof_last_write_status = C_OK;
|
||||||
server.aof_last_write_errno = 0;
|
server.aof_last_write_errno = 0;
|
||||||
server.repl_good_slaves_count = 0;
|
server.repl_good_slaves_count = 0;
|
||||||
updateCachedTime();
|
|
||||||
|
|
||||||
/* Create the timer callback, this is our way to process many background
|
/* Create the timer callback, this is our way to process many background
|
||||||
* operations incrementally, like clients timeout, eviction of unaccessed
|
* operations incrementally, like clients timeout, eviction of unaccessed
|
||||||
@ -3861,9 +3870,11 @@ int main(int argc, char **argv) {
|
|||||||
spt_init(argc, argv);
|
spt_init(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
setlocale(LC_COLLATE,"");
|
setlocale(LC_COLLATE,"");
|
||||||
|
tzset(); /* Populates 'timezone' global. */
|
||||||
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
|
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
|
||||||
srand(time(NULL)^getpid());
|
srand(time(NULL)^getpid());
|
||||||
gettimeofday(&tv,NULL);
|
gettimeofday(&tv,NULL);
|
||||||
|
|
||||||
char hashseed[16];
|
char hashseed[16];
|
||||||
getRandomHexChars(hashseed,sizeof(hashseed));
|
getRandomHexChars(hashseed,sizeof(hashseed));
|
||||||
dictSetHashFunctionSeed((uint8_t*)hashseed);
|
dictSetHashFunctionSeed((uint8_t*)hashseed);
|
||||||
|
@ -1192,6 +1192,8 @@ struct redisServer {
|
|||||||
int list_compress_depth;
|
int list_compress_depth;
|
||||||
/* time cache */
|
/* time cache */
|
||||||
time_t unixtime; /* Unix time sampled every cron cycle. */
|
time_t unixtime; /* Unix time sampled every cron cycle. */
|
||||||
|
time_t timezone; /* Cached timezone. As set by tzset(). */
|
||||||
|
int daylight_active; /* Currently in daylight saving time. */
|
||||||
long long mstime; /* Like 'unixtime' but with milliseconds resolution. */
|
long long mstime; /* Like 'unixtime' but with milliseconds resolution. */
|
||||||
/* Pubsub */
|
/* Pubsub */
|
||||||
dict *pubsub_channels; /* Map channels to list of subscribed clients */
|
dict *pubsub_channels; /* Map channels to list of subscribed clients */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user