Incomming fixes from Charles on the replication branch.
[m6w6/libmemcached] / lib / memcached_delete.c
index 24dc16601c178dc30b498658701bdae332948a31..16ab0cd56e103abcc2489e7c26d603e48145078d 100644 (file)
@@ -12,7 +12,7 @@ memcached_return memcached_delete_by_key(memcached_st *ptr,
                                          char *key, size_t key_length,
                                          time_t expiration)
 {
-  char to_write;
+  char to_write= (ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1;
   size_t send_length;
   char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
   unsigned int server_key;
@@ -35,13 +35,8 @@ memcached_return memcached_delete_by_key(memcached_st *ptr,
     send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 
                           "delete %.*s\r\n", (int)key_length, key);
 
-  if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
-  {
-    rc[replicas]= MEMCACHED_WRITE_FAILURE;
-    goto error;
-  }
-
-  to_write= (ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1;
+  unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+    return MEMCACHED_WRITE_FAILURE;
 
   do
   {
@@ -55,14 +50,14 @@ memcached_return memcached_delete_by_key(memcached_st *ptr,
     }
     else
     {
-      rc[replicas]= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
-      if (rc[replicas] == MEMCACHED_DELETED)
-        rc[replicas]= MEMCACHED_SUCCESS;
+      char response_buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+
+      rc[replicas]= memcached_response(&ptr->hosts[server_key], response_buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
     }
 
     /* On error we just jump to the next potential server */
 error:
-    if (replicas > 1 && ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT)
+    if (ptr->number_of_replicas > 1)
     {
       if (server_key == (ptr->number_of_hosts - 1))
         server_key= 0;
@@ -76,8 +71,8 @@ error:
   {
     if (rc[replicas] == MEMCACHED_DELETED)
       return MEMCACHED_SUCCESS;
-    else if (rc[replicas] == MEMCACHED_DELETED)
-      rc[replicas]= MEMCACHED_BUFFERED;
+    else if (rc[replicas] == MEMCACHED_BUFFERED)
+      return MEMCACHED_BUFFERED;
   }
 
   return rc[0];