]> git.saurik.com Git - redis.git/blobdiff - src/aof.c
bio.o added to redis-server objects
[redis.git] / src / aof.c
index 0ebe4457d95a3e26d823ceb5a03010dc76945124..45dbc0db456dd81e6ee964f94559b04d12adb775 100644 (file)
--- a/src/aof.c
+++ b/src/aof.c
@@ -81,10 +81,17 @@ void flushAppendOnlyFile(void) {
         }
         exit(1);
     }
-    sdsfree(server.aofbuf);
-    server.aofbuf = sdsempty();
     server.appendonly_current_size += nwritten;
 
+    /* Re-use AOF buffer when it is small enough. The maximum comes from the
+     * arena size of 4k minus some overhead (but is otherwise arbitrary). */
+    if ((sdslen(server.aofbuf)+sdsavail(server.aofbuf)) < 4000) {
+        sdsclear(server.aofbuf);
+    } else {
+        sdsfree(server.aofbuf);
+        server.aofbuf = sdsempty();
+    }
+
     /* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
      * children doing I/O in the background. */
     if (server.no_appendfsync_on_rewrite &&
@@ -103,17 +110,29 @@ void flushAppendOnlyFile(void) {
     }
 }
 
-sds catAppendOnlyGenericCommand(sds buf, int argc, robj **argv) {
-    int j;
-    buf = sdscatprintf(buf,"*%d\r\n",argc);
+sds catAppendOnlyGenericCommand(sds dst, int argc, robj **argv) {
+    char buf[32];
+    int len, j;
+    robj *o;
+
+    buf[0] = '*';
+    len = 1+ll2string(buf+1,sizeof(buf)-1,argc);
+    buf[len++] = '\r';
+    buf[len++] = '\n';
+    dst = sdscatlen(dst,buf,len);
+
     for (j = 0; j < argc; j++) {
-        robj *o = getDecodedObject(argv[j]);
-        buf = sdscatprintf(buf,"$%lu\r\n",(unsigned long)sdslen(o->ptr));
-        buf = sdscatlen(buf,o->ptr,sdslen(o->ptr));
-        buf = sdscatlen(buf,"\r\n",2);
+        o = getDecodedObject(argv[j]);
+        buf[0] = '$';
+        len = 1+ll2string(buf+1,sizeof(buf)-1,sdslen(o->ptr));
+        buf[len++] = '\r';
+        buf[len++] = '\n';
+        dst = sdscatlen(dst,buf,len);
+        dst = sdscatlen(dst,o->ptr,sdslen(o->ptr));
+        dst = sdscatlen(dst,"\r\n",2);
         decrRefCount(o);
     }
-    return buf;
+    return dst;
 }
 
 sds catAppendOnlyExpireAtCommand(sds buf, robj *key, robj *seconds) {