From 8b7c3455b964d634453cfe7acdb833db10a2fed5 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 6 Feb 2012 16:56:42 +0100 Subject: [PATCH] freeMemoryIfNeeded() minor refactoring --- src/networking.c | 21 +++++++++++++++++++++ src/redis.c | 24 +----------------------- src/redis.h | 1 + 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/networking.c b/src/networking.c index 412f77dd0..e92f680c2 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1315,3 +1315,24 @@ void asyncCloseClientOnOutputBufferLimitReached(redisClient *c) { sdsfree(client); } } + +/* Helper function used by freeMemoryIfNeeded() in order to flush slaves + * output buffers without returning control to the event loop. */ +void flushSlavesOutputBuffers(void) { + listIter li; + listNode *ln; + + listRewind(server.slaves,&li); + while((ln = listNext(&li))) { + redisClient *slave = listNodeValue(ln); + int events; + + events = aeGetFileEvents(server.el,slave->fd); + if (events & AE_WRITABLE && + slave->replstate == REDIS_REPL_ONLINE && + listLength(slave->reply)) + { + sendReplyToClient(server.el,slave->fd,slave,0); + } + } +} diff --git a/src/redis.c b/src/redis.c index 4b9ba618d..b4acd6eaa 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1832,7 +1832,6 @@ int freeMemoryIfNeeded(void) { /* Compute how much memory we need to free. */ mem_tofree = mem_used - server.maxmemory; - printf("USED: %zu, TOFREE: %zu\n", mem_used, mem_tofree); mem_freed = 0; while (mem_freed < mem_tofree) { int j, k, keys_freed = 0; @@ -1923,7 +1922,6 @@ int freeMemoryIfNeeded(void) { delta = (long long) zmalloc_used_memory(); dbDelete(db,keyobj); delta -= (long long) zmalloc_used_memory(); - // printf("%lld\n",delta); mem_freed += delta; server.stat_evictedkeys++; decrRefCount(keyobj); @@ -1933,27 +1931,7 @@ int freeMemoryIfNeeded(void) { * start spending so much time here that is impossible to * deliver data to the slaves fast enough, so we force the * transmission here inside the loop. */ - if (slaves) { - listIter li; - listNode *ln; - - listRewind(server.slaves,&li); - while((ln = listNext(&li))) { - redisClient *slave = listNodeValue(ln); - int events; - - events = aeGetFileEvents(server.el,slave->fd); - printf("EVENTS: %d\n", events); - if (events & AE_WRITABLE && - slave->replstate == REDIS_REPL_ONLINE && - listLength(slave->reply)) - { - printf("SLAVE %d -> %d\n", - slave->fd, (int) listLength(slave->reply)); - sendReplyToClient(server.el,slave->fd,slave,0); - } - } - } + if (slaves) flushSlavesOutputBuffers(); } } if (!keys_freed) return REDIS_ERR; /* nothing to free... */ diff --git a/src/redis.h b/src/redis.h index 4d51c9df8..982f33fe5 100644 --- a/src/redis.h +++ b/src/redis.h @@ -820,6 +820,7 @@ void freeClientsInAsyncFreeQueue(void); void asyncCloseClientOnOutputBufferLimitReached(redisClient *c); int getClientLimitClassByName(char *name); char *getClientLimitClassName(int class); +void flushSlavesOutputBuffers(void); #ifdef __GNUC__ void addReplyErrorFormat(redisClient *c, const char *fmt, ...)