X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/d934e1e85b1ec1c6d2cd07292cced53770f4a626..0a0f83ab2c02ebf1a9029a473e23ef72d037cac0:/src/redis.c diff --git a/src/redis.c b/src/redis.c index 65cf3ace..603b377f 100644 --- a/src/redis.c +++ b/src/redis.c @@ -583,19 +583,39 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { if ((server.maxidletime && !(loops % 100)) || server.bpop_blocked_clients) closeTimedoutClients(); - /* Check if a background saving or AOF rewrite in progress terminated */ + /* Check if a background saving or AOF rewrite in progress terminated. */ if (server.bgsavechildpid != -1 || server.bgrewritechildpid != -1) { int statloc; pid_t pid; if ((pid = wait3(&statloc,WNOHANG,NULL)) != 0) { + int exitcode = WEXITSTATUS(statloc); + int bysignal = 0; + + if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc); + if (pid == server.bgsavechildpid) { - backgroundSaveDoneHandler(statloc); + backgroundSaveDoneHandler(exitcode,bysignal); } else { - backgroundRewriteDoneHandler(statloc); + backgroundRewriteDoneHandler(exitcode,bysignal); } updateDictResizePolicy(); } + } else if (server.bgsavethread != (pthread_t) -1) { + if (server.bgsavethread != (pthread_t) -1) { + int state; + + pthread_mutex_lock(&server.bgsavethread_mutex); + state = server.bgsavethread_state; + pthread_mutex_unlock(&server.bgsavethread_mutex); + + if (state == REDIS_BGSAVE_THREAD_DONE_OK || + state == REDIS_BGSAVE_THREAD_DONE_ERR) + { + backgroundSaveDoneHandler( + (state == REDIS_BGSAVE_THREAD_DONE_OK) ? 0 : 1, 0); + } + } } else if (!server.ds_enabled) { /* If there is not a background saving in progress check if * we have to save now */ @@ -749,7 +769,6 @@ void initServerConfig() { server.syslog_enabled = 0; server.syslog_ident = zstrdup("redis"); server.syslog_facility = LOG_LOCAL0; - server.glueoutputbuf = 1; server.daemonize = 0; server.appendonly = 0; server.appendfsync = APPENDFSYNC_EVERYSEC; @@ -778,6 +797,7 @@ void initServerConfig() { server.list_max_ziplist_value = REDIS_LIST_MAX_ZIPLIST_VALUE; server.set_max_intset_entries = REDIS_SET_MAX_INTSET_ENTRIES; server.shutdown_asap = 0; + server.cache_flush_delay = 0; updateLRUClock(); resetServerSaveParams(); @@ -826,8 +846,7 @@ void initServer() { server.slaves = listCreate(); server.monitors = listCreate(); server.unblocked_clients = listCreate(); - server.cache_flush_queue = listCreate(); - server.cache_flush_delay = 0; + server.cache_io_queue = listCreate(); createSharedObjects(); server.el = aeCreateEventLoop(); @@ -857,6 +876,7 @@ void initServer() { if (server.ds_enabled) { server.db[j].io_keys = dictCreate(&keylistDictType,NULL); server.db[j].io_negcache = dictCreate(&setDictType,NULL); + server.db[j].io_queued = dictCreate(&setDictType,NULL); } server.db[j].id = j; } @@ -867,6 +887,8 @@ void initServer() { server.cronloops = 0; server.bgsavechildpid = -1; server.bgrewritechildpid = -1; + server.bgsavethread_state = REDIS_BGSAVE_THREAD_UNACTIVE; + server.bgsavethread = (pthread_t) -1; server.bgrewritebuf = sdsempty(); server.aofbuf = sdsempty(); server.lastsave = time(NULL); @@ -1278,6 +1300,19 @@ sds genRedisInfoString(void) { eta ); } + + info = sdscat(info,"allocation_stats:"); + for (j = 0; j <= ZMALLOC_MAX_ALLOC_STAT; j++) { + size_t count = zmalloc_allocations_for_size(j); + if (count) { + if (info[sdslen(info)-1] != ':') info = sdscatlen(info,",",1); + info = sdscatprintf(info,"%s%d=%zu", + (j == ZMALLOC_MAX_ALLOC_STAT) ? ">=" : "", + j,count); + } + } + info = sdscat(info,"\r\n"); + for (j = 0; j < server.dbnum; j++) { long long keys, vkeys; @@ -1440,7 +1475,7 @@ void createPidFile(void) { /* Try to write the pid file in a best-effort way. */ FILE *fp = fopen(server.pidfile,"w"); if (fp) { - fprintf(fp,"%d\n",getpid()); + fprintf(fp,"%d\n",(int)getpid()); fclose(fp); } }