*/
#include <config.h>
-#include "execute.h"
+#include "clients/execute.h"
unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
{
0, 0);
if (rc != MEMCACHED_SUCCESS and rc != MEMCACHED_BUFFERED)
{
- fprintf(stderr, "Failure on insert (%s) of %.*s\n",
+ fprintf(stderr, "%s:%d Failure on insert (%s) of %.*s\n",
+ __FILE__, __LINE__,
memcached_last_error_message(memc),
(unsigned int)pairs[x].key_length, pairs[x].key);
+
+ // We will try to reconnect and see if that fixes the issue
+ memcached_quit(memc);
}
else
{
for (retrieved= 0,x= 0; x < number_of; x++)
{
- char *value;
size_t value_length;
uint32_t flags;
- unsigned int fetch_key;
- fetch_key= (unsigned int)((unsigned int)random() % number_of);
+ unsigned int fetch_key= (unsigned int)((unsigned int)random() % number_of);
- value= memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length,
- &value_length, &flags, &rc);
+ char *value= memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length,
+ &value_length, &flags, &rc);
if (rc != MEMCACHED_SUCCESS)
{
- fprintf(stderr, "Failure on read(%s) of %.*s\n",
+ fprintf(stderr, "%s:%d Failure on read(%s) of %.*s\n",
+ __FILE__, __LINE__,
memcached_last_error_message(memc),
(unsigned int)pairs[fetch_key].key_length, pairs[fetch_key].key);
}
rc= memcached_fetch_execute(memc, callbacks, (void *)&retrieved, 1);
if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_END)
{
- fprintf(stderr, "Failed to execute mget: %s\n",
+ fprintf(stderr, "%s:%d Failed to execute mget: %s\n",
+ __FILE__, __LINE__,
memcached_strerror(memc, rc));
memcached_quit(memc);
return 0;
}
else
{
- fprintf(stderr, "Failed to execute mget: %s\n",
+ fprintf(stderr, "%s:%d Failed to execute mget: %s\n",
+ __FILE__, __LINE__,
memcached_strerror(memc, rc));
memcached_quit(memc);
return 0;
value= &local_value;
}
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
}
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
}
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
}
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
LIBMEMCACHED_MEMCACHED_DELETE_START();
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
{
memcached_return_t rc;
- if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
const char *key, size_t key_length)
{
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(memc)))
+ if (memcached_failed(rc= initialize_query(memc, true)))
{
return rc;
}
- if (memc->flags.use_udp)
+ if (memcached_is_udp(memc))
{
return MEMCACHED_NOT_SUPPORTED;
}
-
uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
memcached_server_write_instance_st instance;
instance= memcached_server_instance_fetch(memc, server_key);
memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration)
{
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
error= &unused;
}
- if (ptr->flags.use_udp)
+ uint64_t query_id= 0;
+ if (ptr)
{
- if (value_length)
- {
- *value_length= 0;
- }
-
- *error= memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
- return NULL;
+ query_id= ptr->query_id;
}
- uint64_t query_id= ptr->query_id;
- (void)query_id;
-
/* Request the key */
*error= memcached_mget_by_key_real(ptr, group_key, group_key_length,
(const char * const *)&key, &key_length,
1, false);
- assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");
-
+ if (ptr)
+ {
+ assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");
+ }
if (memcached_failed(*error))
{
- if (memcached_has_current_error(*ptr)) // Find the most accurate error
+ if (ptr)
{
- *error= memcached_last_error(ptr);
+ if (memcached_has_current_error(*ptr)) // Find the most accurate error
+ {
+ *error= memcached_last_error(ptr);
+ }
}
if (value_length)
+ {
*value_length= 0;
+ }
return NULL;
}
unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
- if (ptr->flags.use_udp)
+ if (memcached_is_udp(ptr))
{
return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
}
void *context,
unsigned int number_of_callbacks)
{
- if ((ptr->flags.binary_protocol) == 0)
+ memcached_return_t rc;
+ if (memcached_failed(rc= initialize_query(ptr, false)))
+ {
+ return rc;
+ }
+
+ if (memcached_is_udp(ptr))
+ {
+ return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
+ }
+
+ if (memcached_is_binary(ptr) == false)
{
return MEMCACHED_NOT_SUPPORTED;
}
- memcached_return_t rc;
memcached_callback_st *original_callbacks= ptr->callbacks;
memcached_callback_st cb= {
callback,
#include <libmemcached/common.h>
-memcached_return_t initialize_query(memcached_st *self)
+memcached_return_t initialize_query(memcached_st *self, bool increment_query_id)
{
if (self == NULL)
{
return MEMCACHED_INVALID_ARGUMENTS;
}
- self->query_id++;
+ if (increment_query_id)
+ {
+ self->query_id++;
+ }
if (self->state.is_time_for_rebuild)
{
#pragma once
-#ifdef __cplusplus
-extern "C" {
-#endif
+memcached_return_t initialize_query(memcached_st *self, bool increment_query_id);
-LIBMEMCACHED_LOCAL
- memcached_return_t initialize_query(memcached_st *self);
-
-LIBMEMCACHED_LOCAL
memcached_return_t initialize_const_query(const memcached_st *self);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
ssize_t data_read;
do
{
- data_read= recv(ptr->fd, ptr->read_buffer, MEMCACHED_MAX_BUFFER, MSG_DONTWAIT);
+ data_read= ::recv(ptr->fd, ptr->read_buffer, MEMCACHED_MAX_BUFFER, MSG_DONTWAIT);
if (data_read == SOCKET_ERROR)
{
switch (get_socket_errno())
WATCHPOINT_STRING("We had a zero length recv()");
memcached_quit_server(ptr, true);
*nread= -1;
- return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT);
+ return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("::rec() returned zero, server has disconnected"));
}
} while (data_read <= 0);
if (rc== MEMCACHED_PROTOCOL_ERROR or rc == MEMCACHED_UNKNOWN_READ_FAILURE or rc == MEMCACHED_READ_FAILURE)
{
WATCHPOINT_ERROR(rc);
- ret= rc;
memcached_io_reset(ptr);
- memcached_set_error(*ptr, rc, MEMCACHED_AT);
+ ret= rc;
+#if 0
+ ret= memcached_set_error(*ptr, rc, MEMCACHED_AT);
+#endif
}
if (ptr->root->callbacks != NULL)
void memcached_quit(memcached_st *ptr)
{
- if (memcached_failed(initialize_query(ptr)))
+ memcached_return_t rc;
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return;
}
ssize_t read_length= 0;
size_t value_length;
- if (ptr->root->flags.use_udp)
- {
- return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
- }
-
WATCHPOINT_ASSERT(ptr->root);
char *end_ptr= buffer + MEMCACHED_DEFAULT_COMMAND_SIZE;
if (auto_return_value == ULLONG_MAX and errno == ERANGE)
{
- return MEMCACHED_UNKNOWN_READ_FAILURE;
+ return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("Numeric response was out of range"));
}
else if (errno == EINVAL)
{
- return MEMCACHED_UNKNOWN_READ_FAILURE;
+ return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("Numeric response was out of range"));
}
numeric_value= uint64_t(auto_return_value);
break;
}
- return MEMCACHED_UNKNOWN_READ_FAILURE;
+ return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("Could not determine response"));
}
static memcached_return_t binary_read_one_response(memcached_server_write_instance_st ptr,
memcached_result_st *result,
uint64_t& numeric_value)
{
+ if (memcached_is_udp(ptr->root))
+ {
+ return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
+ }
+
memcached_server_response_decrement(ptr);
if (result == NULL)
memcached_result_st *result,
uint64_t& numeric_value)
{
+ if (memcached_is_udp(ptr->root))
+ {
+ return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
+ }
+
/* We may have old commands in the buffer not set, first purge */
if ((ptr->root->flags.no_block) and (memcached_is_processing_input(ptr->root) == false))
{
error= &unused;
}
- memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(self)))
+ if (memcached_failed(*error= initialize_query(self, true)))
{
- *error= rc;
return NULL;
}
- if (self->flags.use_udp)
+ if (memcached_is_udp(self))
{
*error= memcached_set_error(*self, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
return NULL;
}
+ memcached_return_t rc;
size_t args_length= 0;
if (args)
{
return rc;
}
- if (memcached_success(rc= initialize_query(memc_ptr)))
+ if (memcached_success(rc= initialize_query(memc_ptr, true)))
{
size_t args_length= 0;
if (args)
memcached_storage_action_t verb)
{
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
LIBMEMCACHED_MEMCACHED_TOUCH_START();
memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
+ if (memcached_failed(rc= initialize_query(ptr, true)))
{
return rc;
}
memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity)
{
+ memcached_return_t rc;
+ if (memcached_failed(rc= initialize_query(ptr, false)))
+ {
+ return rc;
+ }
+
+ if (memcached_is_udp(ptr))
+ {
+ return MEMCACHED_NOT_SUPPORTED;
+ }
+
memcached_server_fn callbacks[1];
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
}
- struct libmemcached_io_vector_st vector[]=
+ libmemcached_io_vector_st vector[]=
{
{ memcached_literal_param("verbosity ") },
{ buffer, send_length },
return LIBMEMCACHED_VERSION_STRING;
}
-static inline memcached_return_t memcached_version_binary(memcached_st *ptr);
-static inline memcached_return_t memcached_version_textual(memcached_st *ptr);
-
-memcached_return_t memcached_version(memcached_st *ptr)
-{
- memcached_return_t rc;
- if (memcached_failed(rc= initialize_query(ptr)))
- {
- return rc;
- }
-
- if (ptr->flags.use_udp)
- {
- return MEMCACHED_NOT_SUPPORTED;
- }
-
- if (ptr->flags.binary_protocol)
- {
- rc= memcached_version_binary(ptr);
- }
- else
- {
- rc= memcached_version_textual(ptr);
- }
-
- return rc;
-}
-
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
{
- struct libmemcached_io_vector_st vector[]=
+ libmemcached_io_vector_st vector[]=
{
{ memcached_literal_param("version\r\n") },
};
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
- struct libmemcached_io_vector_st vector[]=
+ libmemcached_io_vector_st vector[]=
{
{ request.bytes, sizeof(request.bytes) }
};
return rc;
}
+
+memcached_return_t memcached_version(memcached_st *ptr)
+{
+ memcached_return_t rc;
+ if (memcached_failed(rc= initialize_query(ptr, true)))
+ {
+ return rc;
+ }
+
+ if (memcached_is_udp(ptr))
+ {
+ return MEMCACHED_NOT_SUPPORTED;
+ }
+
+ if (memcached_is_binary(ptr))
+ {
+ rc= memcached_version_binary(ptr);
+ }
+ else
+ {
+ rc= memcached_version_textual(ptr);
+ }
+
+ return rc;
+}
{
unsigned int check_execute= execute_set(memc, global_pairs, global_count);
- test_compare(global_count, check_execute);
+ test_compare_warn_hint(global_count, check_execute, "Possible false, positive, memcached may have ejected key/value based on memory needs");
return TEST_SUCCESS;
}
return TEST_SUCCESS;
}
+static test_return_t version_TEST(memcached_st *memc)
+{
+ test_compare(MEMCACHED_NOT_SUPPORTED, memcached_version(memc));
+ return TEST_SUCCESS;
+}
+
+static test_return_t verbosity_TEST(memcached_st *memc)
+{
+ test_compare(MEMCACHED_NOT_SUPPORTED, memcached_verbosity(memc, 0));
+ return TEST_SUCCESS;
+}
+
+static test_return_t memcached_get_TEST(memcached_st *memc)
+{
+ memcached_return_t rc;
+ test_null(memcached_get(memc,
+ test_literal_param(__func__),
+ 0, 0, &rc));
+ test_compare(MEMCACHED_NOT_SUPPORTED, rc);
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t memcached_mget_execute_by_key_TEST(memcached_st *memc)
+{
+ char **keys= NULL;
+ size_t *key_length= NULL;
+ test_compare(MEMCACHED_NOT_SUPPORTED,
+ memcached_mget_execute_by_key(memc,
+ test_literal_param(__func__), // Group key
+ keys, key_length, // Actual key
+ 0, // Number of keys
+ 0, // callbacks
+ 0, // context
+ 0)); // Number of callbacks
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t memcached_stat_TEST(memcached_st *memc)
+{
+ memcached_return_t rc;
+ test_null(memcached_stat(memc, 0, &rc));
+ test_compare(MEMCACHED_NOT_SUPPORTED, rc);
+
+ return TEST_SUCCESS;
+}
+
static test_return_t set_udp_behavior_test(memcached_st *memc)
{
memcached_quit(memc);
return TEST_SUCCESS;
}
+test_st compatibility_TESTS[] ={
+ {"version", 0, (test_callback_fn*)version_TEST },
+ {"version", 0, (test_callback_fn*)verbosity_TEST },
+ {"memcached_get()", 0, (test_callback_fn*)memcached_get_TEST },
+ {"memcached_mget_execute_by_key()", 0, (test_callback_fn*)memcached_mget_execute_by_key_TEST },
+ {"memcached_stat()", 0, (test_callback_fn*)memcached_stat_TEST },
+ {0, 0, 0}
+};
+
test_st udp_setup_server_tests[] ={
{"set_udp_behavior_test", 0, (test_callback_fn*)set_udp_behavior_test},
{"add_tcp_server_udp_client_test", 0, (test_callback_fn*)add_tcp_server_udp_client_test},
collection_st collection[] ={
{"udp_setup", (test_callback_fn*)init_udp, 0, udp_setup_server_tests},
+ {"compatibility", (test_callback_fn*)init_udp, 0, compatibility_TESTS},
{"udp_io", (test_callback_fn*)init_udp_valgrind, 0, upd_io_tests},
{"udp_binary_io", (test_callback_fn*)binary_init_udp, 0, upd_io_tests},
{0, 0, 0, 0}