]> git.saurik.com Git - redis.git/commitdiff
test adapted to run with diskstore, and a few bugs fixed
authorantirez <antirez@gmail.com>
Sun, 9 Jan 2011 17:25:34 +0000 (18:25 +0100)
committerantirez <antirez@gmail.com>
Sun, 9 Jan 2011 17:25:34 +0000 (18:25 +0100)
src/aof.c
src/db.c
src/debug.c
src/diskstore.c
src/dscache.c
tests/test_helper.tcl
tests/unit/other.tcl

index 0c25cf6c62213a4ddfb38d2c89a412f592c574dc..56392f2aac7d0757458556c2c58ced2f316a4f3e 100644 (file)
--- a/src/aof.c
+++ b/src/aof.c
@@ -529,7 +529,10 @@ int rewriteAppendOnlyFileBackground(void) {
     pid_t childpid;
 
     if (server.bgrewritechildpid != -1) return REDIS_ERR;
-    redisAssert(server.ds_enabled == 0);
+    if (server.ds_enabled != 0) {
+        redisLog(REDIS_WARNING,"BGREWRITEAOF called with diskstore enabled: AOF is not supported when diskstore is enabled. Operation not performed.");
+        return REDIS_ERR;
+    }
     if ((childpid = fork()) == 0) {
         /* Child */
         char tmpfile[256];
index 6276c992b27be23db0b15801fc96fdfbd674729a..1f321c01a130fd1938cee786cea4268589b7db41 100644 (file)
--- a/src/db.c
+++ b/src/db.c
@@ -201,7 +201,8 @@ int dbDelete(redisDb *db, robj *key) {
     return dictDelete(db->dict,key->ptr) == DICT_OK;
 }
 
-/* Empty the whole database */
+/* Empty the whole database.
+ * If diskstore is enabled this function will just flush the in-memory cache. */
 long long emptyDb() {
     int j;
     long long removed = 0;
@@ -210,6 +211,7 @@ long long emptyDb() {
         removed += dictSize(server.db[j].dict);
         dictEmpty(server.db[j].dict);
         dictEmpty(server.db[j].expires);
+        if (server.ds_enabled) dictEmpty(server.db[j].io_negcache);
     }
     return removed;
 }
index a727962eab229db2d2290474f60c527a140ab77b..49f7ab2ac46c9fda45c25053926d1648ed1ce6c5 100644 (file)
@@ -177,7 +177,20 @@ void computeDatasetDigest(unsigned char *final) {
 void debugCommand(redisClient *c) {
     if (!strcasecmp(c->argv[1]->ptr,"segfault")) {
         *((char*)-1) = 'x';
+    } else if (!strcasecmp(c->argv[1]->ptr,"flushcache")) {
+        if (!server.ds_enabled) {
+            addReplyError(c, "DEBUG FLUSHCACHE called with diskstore off.");
+            return;
+        } else {
+            emptyDb();
+            addReply(c,shared.ok);
+            return;
+        }
     } else if (!strcasecmp(c->argv[1]->ptr,"reload")) {
+        if (server.ds_enabled) {
+            addReply(c,shared.ok);
+            return;
+        }
         if (rdbSave(server.dbfilename) != REDIS_OK) {
             addReply(c,shared.err);
             return;
index 382afb4fb14300d3376813a24ca69d6013eee985..49c8706a48528141eb48bf3bab6dbada6bb837f4 100644 (file)
@@ -456,7 +456,7 @@ void *dsRdbSave_thread(void *arg) {
     /* Use RENAME to make sure the DB file is changed atomically only
      * if the generate DB file is ok. */
     if (rename(tmpfile,filename) == -1) {
-        redisLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno));
+        redisLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s (diskstore)", strerror(errno));
         unlink(tmpfile);
         dsRdbSaveSetState(REDIS_BGSAVE_THREAD_DONE_ERR);
         return NULL;
index 20c66d5926dfb13548fb5246fd50a6fef90b0afd..8243e794827ae1f9160ee58d94dee5396b71e503 100644 (file)
@@ -185,8 +185,7 @@ int cacheFreeOneEntry(void) {
          * are swappable objects */
         int maxtries = 100;
 
-        if (dictSize(db->dict) == 0) continue;
-        for (i = 0; i < 5; i++) {
+        for (i = 0; i < 5 && dictSize(db->dict); i++) {
             dictEntry *de;
             double swappability;
             robj keyobj;
index ec207b13af78a7c47ebfda0c26b9483af3853c90..aef2311c9f0cf9749376bd1ba8fdc310fe7624bd 100644 (file)
@@ -13,7 +13,7 @@ set ::host 127.0.0.1
 set ::port 16379
 set ::traceleaks 0
 set ::valgrind 0
-set ::verbose 0
+set ::verbose 1
 set ::denytags {}
 set ::allowtags {}
 set ::external 0; # If "1" this means, we are running against external instance
@@ -104,14 +104,13 @@ proc s {args} {
 }
 
 proc cleanup {} {
-    if {$::diskstore} {
-        puts "Cleanup: warning may take some minute (diskstore enabled)"
-    }
+    puts "Cleanup: warning may take some time..."
     catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
     catch {exec rm -rf {*}[glob tests/tmp/server.*]}
 }
 
 proc execute_everything {} {
+    if 0 {
     execute_tests "unit/auth"
     execute_tests "unit/protocol"
     execute_tests "unit/basic"
@@ -128,9 +127,11 @@ proc execute_everything {} {
     execute_tests "integration/aof"
 #    execute_tests "integration/redis-cli"
     execute_tests "unit/pubsub"
+    }
 
     # run tests with diskstore enabled
     set ::diskstore 1
+    lappend ::denytags nodiskstore
     set ::global_overrides {diskstore-enabled yes}
     execute_tests "unit/protocol"
     execute_tests "unit/basic"
index c142ba7f018f12f232deb10bb880d3268330670d..98a532c9ba5c5e1bc450fdfea422d38b0cda5fcb 100644 (file)
@@ -46,7 +46,7 @@ start_server {tags {"other"}} {
         set _ $err
     } {*invalid*}
 
-    tags {consistency} {
+    tags {consistency nodiskstore} {
         if {![catch {package require sha1}]} {
             test {Check consistency of different data types after a reload} {
                 r flushdb
@@ -102,12 +102,19 @@ start_server {tags {"other"}} {
         r flushdb
         r set x 10
         r expire x 1000
-        r save
-        r debug reload
+        if {$::diskstore} {
+            r debug flushcache
+        } else {
+            r save
+            r debug reload
+        }
         set ttl [r ttl x]
         set e1 [expr {$ttl > 900 && $ttl <= 1000}]
-        r bgrewriteaof
-        waitForBgrewriteaof r
+        if {!$::diskstore} {
+            r bgrewriteaof
+            waitForBgrewriteaof r
+            r debug loadaof
+        }
         set ttl [r ttl x]
         set e2 [expr {$ttl > 900 && $ttl <= 1000}]
         list $e1 $e2