{
char to_write;
size_t send_length;
- memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
-
- LIBMEMCACHED_MEMCACHED_DELETE_START();
+ uint8_t replicas= 0;
+ memcached_return rc[MEMCACHED_MAX_REPLICAS];
if (key_length == 0)
return MEMCACHED_NO_KEY_PROVIDED;
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
{
- rc= MEMCACHED_WRITE_FAILURE;
+ rc[replicas]= MEMCACHED_WRITE_FAILURE;
goto error;
}
to_write= (ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1;
- rc= memcached_do(ptr, server_key, buffer, send_length, to_write);
- if (rc != MEMCACHED_SUCCESS)
- goto error;
-
- if ((ptr->flags & MEM_BUFFER_REQUESTS))
+ do
{
- rc= MEMCACHED_BUFFERED;
- }
- else
- {
- rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL, server_key);
- if (rc == MEMCACHED_DELETED)
- rc= MEMCACHED_SUCCESS;
- }
+ rc[replicas]= memcached_do(&ptr->hosts[server_key], buffer, send_length, to_write);
+ if (rc[replicas] != MEMCACHED_SUCCESS)
+ goto error;
+
+ if ((ptr->flags & MEM_BUFFER_REQUESTS))
+ {
+ rc[replicas]= MEMCACHED_BUFFERED;
+ }
+ else
+ {
+ rc[replicas]= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ if (rc[replicas] == MEMCACHED_DELETED)
+ rc[replicas]= MEMCACHED_SUCCESS;
+ }
+ /* On error we just jump to the next potential server */
error:
- LIBMEMCACHED_MEMCACHED_DELETE_END();
- return rc;
-}
-
-memcached_return memcached_mdelete(memcached_st *ptr,
- char **key, size_t *key_length,
- unsigned int number_of_keys,
- time_t expiration)
-{
- return memcached_mdelete_by_key(ptr, NULL, 0,
- key, key_length,
- number_of_keys, expiration);
-
-}
-
-memcached_return memcached_mdelete_by_key(memcached_st *ptr,
- char *master_key, size_t master_key_length,
- char **key, size_t *key_length,
- unsigned int number_of_keys,
- time_t expiration)
-{
- size_t send_length;
- memcached_return rc= MEMCACHED_SUCCESS;
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- unsigned int master_server_key= 0;
- unsigned int x;
-
- LIBMEMCACHED_MEMCACHED_DELETE_START();
-
- if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
- return MEMCACHED_NO_SERVERS;
-
- if (master_key && master_key_length)
- master_server_key= memcached_generate_hash(ptr, master_key, master_key_length);
-
- for (x= 0; x < number_of_keys; x++)
+ if (replicas > 1 && ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT)
+ {
+ if (server_key == (ptr->number_of_hosts - 1))
+ server_key= 0;
+ else
+ server_key++;
+ }
+ } while ((++replicas) < ptr->number_of_replicas);
+
+ /* As long as one object gets stored, we count this as a success */
+ while (replicas--)
{
- unsigned int server_key;
-
- if (master_key && master_key_length)
- server_key= master_server_key;
- else
- server_key= memcached_generate_hash(ptr, key[x], key_length[x]);
-
- if (expiration)
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s %llu\r\n", (int)(key_length[x]), key[x],
- (unsigned long long)expiration);
- else
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s\r\n", (int)(key_length[x]), key[x]);
-
- (void)memcached_do(ptr, server_key, buffer, send_length, 0);
+ if (rc[replicas] == MEMCACHED_DELETED)
+ return MEMCACHED_SUCCESS;
+ else if (rc[replicas] == MEMCACHED_DELETED)
+ rc[replicas]= MEMCACHED_BUFFERED;
}
- return MEMCACHED_BUFFERED;
+ return rc[0];
}