attempt to fix cachedump test
[awesomized/libmemcached] / libmemcached / dump.cc
index 8ddb2eef859e7a442273510c74457f3f6c3b8037..c0c4ed630c074190a9ca8c30b15893ea48b7d62b 100644 (file)
@@ -46,6 +46,7 @@
 
 static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
 {
+  memcached_version(memc);
   /* MAX_NUMBER_OF_SLAB_CLASSES is defined to 200 in Memcached 1.4.10 */
   for (uint32_t x= 0; x < 200; x++)
   {
@@ -70,14 +71,13 @@ static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callbac
     {
       memcached_instance_st* instance= memcached_instance_fetch(memc, server_key);
 
-      memcached_return_t vdo_rc;
-      if (memcached_success((vdo_rc= memcached_vdo(instance, vector, 3, true))))
-      {
-        // We have sent the message to the server successfully
-      }
-      else
-      {
-        return vdo_rc;
+      // skip slabs >63 for server versions >= 1.4.23
+      if (x < 64 || memcached_version_instance_cmp(instance, 1, 4, 23) < 0) {
+        memcached_return_t vdo_rc;
+        if (memcached_failed((vdo_rc= memcached_vdo(instance, vector, 3, true))))
+        {
+          return vdo_rc;
+        }
       }
     }
 
@@ -114,7 +114,7 @@ static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callbac
       { 
         // All items have been returned
       }
-      else if (response_rc == MEMCACHED_SERVER_ERROR or response_rc == MEMCACHED_CLIENT_ERROR or response_rc == MEMCACHED_ERROR)
+      else if (response_rc == MEMCACHED_SERVER_ERROR)
       {
         /* If we try to request stats cachedump for a slab class that is too big
          * the server will return an incorrect error message:
@@ -126,6 +126,18 @@ static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callbac
         assert(response_rc == MEMCACHED_SUCCESS); // Just fail
         return response_rc;
       }
+      else if (response_rc == MEMCACHED_CLIENT_ERROR)
+      {
+        /* The maximum number of slabs has changed in the past (currently 1<<6-1),
+         * so ignore any client errors complaining about an illegal slab id.
+         */
+        if (0 == strncmp(buffer, "CLIENT_ERROR Illegal slab id", sizeof("CLIENT_ERROR Illegal slab id") - 1)) {
+          memcached_error_free(*instance);
+          memcached_error_free(*memc);
+        } else {
+          return response_rc;
+        }
+      }
       else
       {
         // IO error of some sort must have occurred