size_t mem_used, mem_tofree, mem_freed;
int slaves = listLength(server.slaves);
- /* Remove the size of slaves output buffers from the count of used
- * memory. */
+ /* Remove the size of slaves output buffers and AOF buffer from the
+ * count of used memory. */
mem_used = zmalloc_used_memory();
if (slaves) {
listIter li;
mem_used -= obuf_bytes;
}
}
+ if (server.aof_state != REDIS_AOF_OFF) {
+ mem_used -= sdslen(server.aof_buf);
+ mem_used -= sdslen(server.aof_rewrite_buf);
+ }
/* Check if we are over the memory limit. */
if (mem_used <= server.maxmemory) return REDIS_OK;
/* 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;
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);
* 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... */