lead to memory issues.
ptr->server_failure_limit= (uint32_t)data;
break;
case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL:
- memcached_quit(ptr); // We need t shutdown all of the connections to make sure we do the correct protocol
+ send_quit(ptr); // We need t shutdown all of the connections to make sure we do the correct protocol
if (data)
{
ptr->flags.verify_key= false;
break;
case MEMCACHED_BEHAVIOR_NO_BLOCK:
ptr->flags.no_block= set_flag(data);
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
ptr->flags.buffer_requests= set_flag(data);
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_USE_UDP:
if (memcached_server_count(ptr))
break;
case MEMCACHED_BEHAVIOR_TCP_NODELAY:
ptr->flags.tcp_nodelay= set_flag(data);
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE:
ptr->flags.tcp_keepalive= set_flag(data);
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
return memcached_behavior_set_distribution(ptr, (memcached_server_distribution_t)data);
break;
case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
ptr->send_size= (int32_t)data;
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
ptr->recv_size= (int32_t)data;
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE:
ptr->tcp_keepidle= (uint32_t)data;
- memcached_quit(ptr);
+ send_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_USER_DATA:
return memcached_set_error_string(ptr, MEMCACHED_DEPRECATED,
#define BUILDING_LIBMEMCACHED 1
-#include "libmemcached/memcached.h"
-#include "libmemcached/watchpoint.h"
-#include "libmemcached/is.h"
-#include "libmemcached/prefix_key.h"
+#include <libmemcached/memcached.h>
+#include <libmemcached/watchpoint.h>
+#include <libmemcached/is.h>
+#include <libmemcached/prefix_key.h>
typedef struct memcached_server_st * memcached_server_write_instance_st;
/* These are private not to be installed headers */
-#include "libmemcached/io.h"
-#include "libmemcached/do.h"
-#include "libmemcached/internal.h"
-#include "libmemcached/array.h"
-#include "libmemcached/libmemcached_probes.h"
-#include "libmemcached/memcached/protocol_binary.h"
-#include "libmemcached/byteorder.h"
-#include "libmemcached/response.h"
-#include "libmemcached/prefix_key.h"
+#include <libmemcached/io.h>
+#include <libmemcached/do.h>
+#include <libmemcached/internal.h>
+#include <libmemcached/array.h>
+#include <libmemcached/libmemcached_probes.h>
+#include <libmemcached/memcached/protocol_binary.h>
+#include <libmemcached/byteorder.h>
+#include <libmemcached/initialize_query.h>
+#include <libmemcached/response.h>
+#include <libmemcached/prefix_key.h>
/* string value */
struct memcached_continuum_item_st
-#include "common.h"
-#include "memcached/protocol_binary.h"
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2006-2009 Brian Aker All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <libmemcached/common.h>
+#include <libmemcached/memcached/protocol_binary.h>
memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
time_t expiration)
time_t expiration)
{
bool to_write;
- memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
uint32_t server_key;
memcached_server_write_instance_st instance;
LIBMEMCACHED_MEMCACHED_DELETE_START();
+ memcached_return_t rc;
+ if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
rc= memcached_validate_key_length(key_length,
ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
{
- /* No support for Binary protocol yet */
+ memcached_return_t rc;
+ if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
+ /*
+ No support for Binary protocol yet
+ @todo Fix this so that we just flush, switch to ascii, and then go back to binary.
+ */
if (ptr->flags.binary_protocol)
return MEMCACHED_FAILURE;
memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration)
{
memcached_return_t rc;
+ if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
LIBMEMCACHED_MEMCACHED_FLUSH_START();
if (ptr->flags.binary_protocol)
unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */
bool is_master_key_set= false;
+ memcached_return_t rc;
+ if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
unlikely (ptr->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
if (number_of_keys == 0)
return MEMCACHED_NOTFOUND;
- if (memcached_server_count(ptr) == 0)
- return MEMCACHED_NO_SERVERS;
-
if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_BAD_KEY_PROVIDED;
If a server fails we warn about errors and start all over with sending keys
to the server.
*/
- memcached_return_t rc= MEMCACHED_SUCCESS;
+ WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS);
size_t hosts_connected= 0;
for (uint32_t x= 0; x < number_of_keys; x++)
{
libmemcached/flush_buffers.h \
libmemcached/get.h \
libmemcached/hash.h \
+ libmemcached/initialize_query.h \
libmemcached/memcached.h \
libmemcached/memcached.hpp \
libmemcached/memcached/protocol_binary.h \
libmemcached/get.c \
libmemcached/hash.c \
libmemcached/hosts.c \
+ libmemcached/initialize_query.cc \
libmemcached/io.c \
libmemcached/key.c \
libmemcached/memcached.c \
.no_block= false,
.no_reply= false,
.randomize_replica_read= false,
- .reuse_memory= false,
.support_cas= false,
.tcp_nodelay= false,
.use_sort_hosts= false,
static void _free(memcached_st *ptr, bool release_st)
{
/* If we have anything open, lets close it now */
- memcached_quit(ptr);
+ send_quit(ptr);
memcached_server_list_free(memcached_server_list(ptr));
memcached_result_free(&ptr->result);
return MEMCACHED_INVALID_ARGUMENTS;
bool stored_is_allocated= memcached_is_allocated(ptr);
+ uint64_t query_id= ptr->query_id;
_free(ptr, false);
memcached_create(ptr);
memcached_set_allocated(ptr, stored_is_allocated);
+ ptr->query_id= query_id;
if (ptr->configure.filename)
{
bool no_block:1; // Don't block
bool no_reply:1;
bool randomize_replica_read:1;
- bool reuse_memory:1;
bool support_cas:1;
bool tcp_nodelay:1;
- bool use_cache_lookups:1;
bool use_sort_hosts:1;
bool use_udp:1;
bool verify_key:1;
int send_size;
int recv_size;
void *user_data;
+ uint64_t query_id;
uint32_t number_of_replicas;
hashkit_st distribution_hashkit;
memcached_result_st result;
}
}
-void memcached_quit(memcached_st *ptr)
+void send_quit(memcached_st *ptr)
{
- if (memcached_server_count(ptr))
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
- {
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(ptr, x);
+ memcached_server_write_instance_st instance=
+ memcached_server_instance_fetch(ptr, x);
- memcached_quit_server(instance, false);
- }
+ memcached_quit_server(instance, false);
+ }
+}
+
+void memcached_quit(memcached_st *ptr)
+{
+ if (initialize_query(ptr) != MEMCACHED_SUCCESS)
+ {
+ return;
}
+
+ send_quit(ptr);
}
LIBMEMCACHED_LOCAL
void memcached_quit_server(memcached_server_st *ptr, bool io_death);
+LIBMEMCACHED_LOCAL
+void send_quit(memcached_st *ptr);
+
#ifdef __cplusplus
}
#endif
void *context,
uint32_t number_of_callbacks)
{
+ memcached_return_t rc;
+ if ((rc= initialize_const_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_instance_st instance=
uint32_t server_key;
memcached_server_instance_st instance;
- *error= memcached_validate_key_length(key_length,
- ptr->flags.binary_protocol);
- unlikely (*error != MEMCACHED_SUCCESS)
+ memcached_return_t rc;
+ if ((rc= initialize_const_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ if (error)
+ *error= rc;
+
return NULL;
+ }
- unlikely (memcached_server_count(ptr) == 0)
+ if ((rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol)) != MEMCACHED_SUCCESS)
{
- *error= MEMCACHED_NO_SERVERS;
+ if (error)
+ *error= rc;
+
return NULL;
}
}
-void memcached_server_error_reset(memcached_server_st *ptr)
+void memcached_server_error_reset(memcached_server_st *self)
{
- ptr->cached_server_error[0]= 0;
+ WATCHPOINT_ASSERT(self);
+ if (! self)
+ return;
+
+ self->cached_server_error[0]= 0;
}
-memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *ptr)
+memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self)
{
- return ptr->last_disconnected_server;
+ WATCHPOINT_ASSERT(self);
+ if (! self)
+ return 0;
+
+ return self->last_disconnected_server;
}
void memcached_server_list_free(memcached_server_list_st self)
uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count)
{
+ WATCHPOINT_ASSERT(servers);
+ if (! servers)
+ return 0;
+
return servers->number_of_hosts= count;
}
uint32_t memcached_server_count(const memcached_st *self)
{
+ WATCHPOINT_ASSERT(self);
+ if (! self)
+ return 0;
+
return self->number_of_hosts;
}
const char *memcached_server_name(memcached_server_instance_st self)
{
+ WATCHPOINT_ASSERT(self);
+ if (! self)
+ return NULL;
+
return self->hostname;
}
in_port_t memcached_server_port(memcached_server_instance_st self)
{
+ WATCHPOINT_ASSERT(self);
+ if (! self)
+ return 0;
+
return self->port;
}
uint32_t memcached_server_response_count(memcached_server_instance_st self)
{
+ WATCHPOINT_ASSERT(self);
+ if (! self)
+ return 0;
+
return self->cursor_active;
}
memcached_return_t rc;
memcached_stat_st *stats;
- if (! self)
+ if ((rc= initialize_query(self)) != MEMCACHED_SUCCESS)
{
- WATCHPOINT_ASSERT(self);
+ if (error)
+ *error= rc;
+
return NULL;
}
WATCHPOINT_ASSERT(error);
-
unlikely (self->flags.use_udp)
{
if (error)
return NULL;
}
+ WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS);
rc= MEMCACHED_SUCCESS;
for (uint32_t x= 0; x < memcached_server_count(self); x++)
{
memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args,
const char *hostname, in_port_t port)
{
- memcached_return_t rc;
memcached_st memc;
memcached_st *memc_ptr;
memcached_server_write_instance_st instance;
memset(memc_stat, 0, sizeof(memcached_stat_st));
memc_ptr= memcached_create(&memc);
- WATCHPOINT_ASSERT(memc_ptr);
+ if (! memc_ptr)
+ return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
memcached_server_add(&memc, hostname, port);
+ memcached_return_t rc;
+ if ((rc= initialize_query(memc_ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
instance= memcached_server_instance_fetch(memc_ptr, 0);
if (memc.flags.binary_protocol)
{
bool to_write;
size_t write_length;
- memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
uint32_t server_key;
memcached_server_write_instance_st instance;
WATCHPOINT_ASSERT(!(value == NULL && value_length > 0));
+ memcached_return_t rc;
+ if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
- unlikely (memcached_server_count(ptr) == 0)
- return MEMCACHED_NO_SERVERS;
-
if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_BAD_KEY_PROVIDED;
%{_mandir}/man1/memdump.1.gz
%{_mandir}/man1/memerror.1.gz
%{_mandir}/man1/memflush.1.gz
+%{_mandir}/man1/memaslap.1.gz
%{_mandir}/man1/memrm.1.gz
%{_mandir}/man1/memslap.1.gz
%{_mandir}/man1/memstat.1.gz
%{_includedir}/libmemcached/callback.h
%{_includedir}/libmemcached/configure.h
%{_includedir}/libmemcached/constants.h
+%{_includedir}/libhashkit/str_algorithm.h
+%{_includedir}/libmemcached/memcached/vbucket.h
%{_includedir}/libmemcached/delete.h
%{_includedir}/libmemcached/dump.h
%{_includedir}/libmemcached/error.h
{ // Test all of the flags
test_true(memc_clone->flags.no_block == memc->flags.no_block);
test_true(memc_clone->flags.tcp_nodelay == memc->flags.tcp_nodelay);
- test_true(memc_clone->flags.reuse_memory == memc->flags.reuse_memory);
- test_true(memc_clone->flags.use_cache_lookups == memc->flags.use_cache_lookups);
test_true(memc_clone->flags.support_cas == memc->flags.support_cas);
test_true(memc_clone->flags.buffer_requests == memc->flags.buffer_requests);
test_true(memc_clone->flags.use_sort_hosts == memc->flags.use_sort_hosts);