From ca663a567bc8d3facb22b035bcad19349e42a9b1 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 18 Jun 2012 08:38:18 -0700 Subject: [PATCH] Remove how use instance (keep API intact) --- clients/memstat.cc | 8 +- libmemcached-1.0/server.h | 9 + libmemcached-1.0/struct/memcached.h | 4 +- libmemcached-1.0/types.h | 3 +- libmemcached/common.h | 8 + libmemcached/connect.cc | 16 +- libmemcached/error.cc | 47 ++- libmemcached/error.hpp | 22 +- libmemcached/fetch.cc | 2 +- libmemcached/flush.cc | 2 +- libmemcached/get.cc | 22 +- libmemcached/hosts.cc | 76 ++++- libmemcached/include.am | 1 + libmemcached/instance.cc | 390 ++++++++++++++++++++++++ libmemcached/instance.h | 98 ++++++ libmemcached/instance.hpp | 58 ++++ libmemcached/io.cc | 17 +- libmemcached/memcached.cc | 14 +- libmemcached/quit.cc | 2 +- libmemcached/quit.hpp | 2 +- libmemcached/sasl.cc | 4 +- libmemcached/sasl.hpp | 2 +- libmemcached/server.cc | 175 ++--------- libmemcached/server.hpp | 29 +- libmemcached/server_instance.h | 2 +- libmemcached/server_list.cc | 47 ++- libmemcached/server_list.hpp | 11 +- libmemcached/verbosity.cc | 2 +- libmemcachedutil/pid.cc | 6 +- libmemcachedutil/ping.cc | 8 +- libmemcachedutil/version.cc | 10 +- libtest/memcached.hpp | 70 +++++ tests/failure.cc | 1 + tests/libmemcached-1.0/debug.cc | 2 + tests/libmemcached-1.0/generate.cc | 6 +- tests/libmemcached-1.0/ketama.cc | 1 + tests/libmemcached-1.0/mem_functions.cc | 14 +- tests/libmemcached-1.0/parser.cc | 5 +- tests/libmemcached-1.0/pool.cc | 2 + tests/libmemcached-1.0/print.cc | 10 +- tests/libmemcached-1.0/replication.cc | 2 + tests/mem_udp.cc | 2 + tests/print.h | 4 +- 43 files changed, 925 insertions(+), 291 deletions(-) create mode 100644 libmemcached/instance.cc create mode 100644 libmemcached/instance.h create mode 100644 libmemcached/instance.hpp create mode 100644 libtest/memcached.hpp diff --git a/clients/memstat.cc b/clients/memstat.cc index 88221cf3..1eab6f9f 100644 --- a/clients/memstat.cc +++ b/clients/memstat.cc @@ -84,13 +84,13 @@ static memcached_return_t stat_printer(memcached_server_instance_st instance, } static memcached_return_t server_print_callback(const memcached_st *, - const memcached_server_st *instance, + memcached_server_instance_st instance, void *) { std::cerr << memcached_server_name(instance) << ":" << memcached_server_port(instance) << - " " << int(instance->major_version) << - "." << int(instance->minor_version) << - "." << int(instance->micro_version) << std::endl; + " " << int(memcached_server_major_version(instance)) << + "." << int(memcached_server_minor_version(instance)) << + "." << int(memcached_server_micro_version(instance)) << std::endl; return MEMCACHED_SUCCESS; } diff --git a/libmemcached-1.0/server.h b/libmemcached-1.0/server.h index 74f32133..f6430eca 100644 --- a/libmemcached-1.0/server.h +++ b/libmemcached-1.0/server.h @@ -106,6 +106,15 @@ in_port_t memcached_server_port(const memcached_server_instance_st self); LIBMEMCACHED_API const char *memcached_server_type(const memcached_server_instance_st ptr); +LIBMEMCACHED_API +uint8_t memcached_server_major_version(const memcached_server_instance_st ptr); + +LIBMEMCACHED_API +uint8_t memcached_server_minor_version(const memcached_server_instance_st ptr); + +LIBMEMCACHED_API +uint8_t memcached_server_micro_version(const memcached_server_instance_st ptr); + #ifdef __cplusplus } // extern "C" #endif diff --git a/libmemcached-1.0/struct/memcached.h b/libmemcached-1.0/struct/memcached.h index 2bffbebb..138f9ef9 100644 --- a/libmemcached-1.0/struct/memcached.h +++ b/libmemcached-1.0/struct/memcached.h @@ -71,8 +71,8 @@ struct memcached_st { unsigned int version; } server_info; uint32_t number_of_hosts; - memcached_server_st *servers; - memcached_server_st *last_disconnected_server; + struct memcached_instance_st *servers; + struct memcached_instance_st *last_disconnected_server; int32_t snd_timeout; int32_t rcv_timeout; uint32_t server_failure_limit; diff --git a/libmemcached-1.0/types.h b/libmemcached-1.0/types.h index 18ac99c2..7ae29c2e 100644 --- a/libmemcached-1.0/types.h +++ b/libmemcached-1.0/types.h @@ -48,7 +48,8 @@ struct memcached_error_t; // All of the flavors of memcache_server_st struct memcached_server_st; -typedef const struct memcached_server_st *memcached_server_instance_st; +struct memcached_instance_st; +typedef const struct memcached_instance_st *memcached_server_instance_st; typedef struct memcached_server_st *memcached_server_list_st; struct memcached_callback_st; diff --git a/libmemcached/common.h b/libmemcached/common.h index 2d031509..92f44de4 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -73,6 +73,7 @@ #include #include +#include #include #ifdef HAVE_POLL_H @@ -115,6 +116,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include #include #include +#include #include #include #include @@ -169,8 +171,14 @@ memcached_return_t run_distribution(memcached_st *ptr); #define memcached_server_response_decrement(A) (A)->cursor_active-- #define memcached_server_response_reset(A) (A)->cursor_active=0 +#define memcached_instance_response_increment(A) (A)->cursor_active++ +#define memcached_instance_response_decrement(A) (A)->cursor_active-- +#define memcached_instance_response_reset(A) (A)->cursor_active=0 + bool memcached_purge(memcached_server_write_instance_st ptr); +struct memcached_instance_st* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key); + #ifdef __cplusplus } #endif diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 8e8092c8..a8a2c5a4 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -46,7 +46,7 @@ #define SOCK_CLOEXEC 0 #endif -static memcached_return_t connect_poll(memcached_server_st *server) +static memcached_return_t connect_poll(memcached_instance_st *server) { struct pollfd fds[1]; fds[0].fd= server->fd; @@ -139,7 +139,7 @@ static memcached_return_t connect_poll(memcached_server_st *server) return memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT); } -static memcached_return_t set_hostinfo(memcached_server_st *server) +static memcached_return_t set_hostinfo(memcached_instance_st *server) { assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET); if (server->address_info) @@ -203,7 +203,7 @@ static memcached_return_t set_hostinfo(memcached_server_st *server) return MEMCACHED_SUCCESS; } -static inline void set_socket_nonblocking(memcached_server_st *server) +static inline void set_socket_nonblocking(memcached_instance_st *server) { #ifdef WIN32 u_long arg= 1; @@ -240,7 +240,7 @@ static inline void set_socket_nonblocking(memcached_server_st *server) #endif } -static void set_socket_options(memcached_server_st *server) +static void set_socket_options(memcached_instance_st *server) { assert_msg(server->fd != INVALID_SOCKET, "invalid socket was passed to set_socket_options()"); @@ -349,7 +349,7 @@ static void set_socket_options(memcached_server_st *server) set_socket_nonblocking(server); } -static memcached_return_t unix_socket_connect(memcached_server_st *server) +static memcached_return_t unix_socket_connect(memcached_instance_st *server) { #ifndef WIN32 WATCHPOINT_ASSERT(server->fd == INVALID_SOCKET); @@ -400,7 +400,7 @@ static memcached_return_t unix_socket_connect(memcached_server_st *server) #endif } -static memcached_return_t network_connect(memcached_server_st *server) +static memcached_return_t network_connect(memcached_instance_st *server) { bool timeout_error_occured= false; @@ -554,7 +554,7 @@ static memcached_return_t network_connect(memcached_server_st *server) if (memcached_has_current_error(*server)) { - return memcached_server_error_return(server); + return memcached_instance_error_return(server); } if (timeout_error_occured and server->state < MEMCACHED_SERVER_STATE_IN_PROGRESS) @@ -704,7 +704,7 @@ static memcached_return_t _memcached_connect(memcached_server_write_instance_st if (memcached_has_current_error(*server)) { memcached_mark_server_for_timeout(server); - assert(memcached_failed(memcached_server_error_return(server))); + assert(memcached_failed(memcached_instance_error_return(server))); } else { diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 96a5532b..bc931de6 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -50,7 +50,7 @@ struct memcached_error_t char message[MAX_ERROR_LENGTH]; }; -static void _set(memcached_server_st& server, memcached_st& memc) +static void _set(memcached_instance_st& server, memcached_st& memc) { if (server.error_messages and server.error_messages->query_id != server.root->query_id) { @@ -204,10 +204,10 @@ memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc return memcached_set_error(memc, rc, at, tmp); } -memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, const char *str, size_t length) +memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, const char *str, size_t length) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); - assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st"); + assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st"); memcached_string_t tmp= { str, length }; return memcached_set_error(self, rc, at, tmp); @@ -240,7 +240,7 @@ memcached_return_t memcached_set_parser_error(memcached_st& memc, return memcached_set_error(memc, MEMCACHED_PARSE_ERROR, at, buffer, length); } -static inline size_t append_host_to_string(memcached_server_st& self, char* buffer, const size_t buffer_length) +static inline size_t append_host_to_string(memcached_instance_st& self, char* buffer, const size_t buffer_length) { size_t size= 0; switch (self.type) @@ -260,10 +260,10 @@ static inline size_t append_host_to_string(memcached_server_st& self, char* buff return size; } -memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, memcached_string_t& str) +memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, memcached_string_t& str) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); - assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st"); + assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st"); if (memcached_fatal(rc) == false) { return rc; @@ -297,9 +297,9 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu return rc; } -memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at) +memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at) { - assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st"); + assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st"); if (memcached_fatal(rc) == false) { return rc; @@ -340,7 +340,7 @@ memcached_return_t memcached_set_errno(memcached_st& self, int local_errno, cons return memcached_set_errno(self, local_errno, at, tmp); } -memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errno, const char *at, const char *str, size_t length) +memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, const char *str, size_t length) { memcached_string_t tmp= { str, length }; return memcached_set_errno(self, local_errno, at, tmp); @@ -372,7 +372,7 @@ memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, cons return rc; } -memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errno, const char *at, memcached_string_t& str) +memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, memcached_string_t& str) { if (local_errno == 0) { @@ -402,7 +402,7 @@ memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errn return rc; } -memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errno, const char *at) +memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at) { if (local_errno == 0) { @@ -487,6 +487,12 @@ void memcached_error_free(memcached_st& self) self.error_messages= NULL; } +void memcached_error_free(memcached_instance_st& self) +{ + _error_free(self.error_messages); + self.error_messages= NULL; +} + void memcached_error_free(memcached_server_st& self) { _error_free(self.error_messages); @@ -525,7 +531,7 @@ bool memcached_has_current_error(memcached_st &memc) return false; } -bool memcached_has_current_error(memcached_server_st& server) +bool memcached_has_current_error(memcached_instance_st& server) { return memcached_has_current_error(*(server.root)); } @@ -581,7 +587,7 @@ const char *memcached_server_error(const memcached_server_instance_st server) } -memcached_error_t *memcached_error_copy(const memcached_server_st& server) +memcached_error_t *memcached_error_copy(const memcached_instance_st& server) { if (server.error_messages == NULL) { @@ -609,3 +615,18 @@ memcached_return_t memcached_server_error_return(memcached_server_instance_st pt return MEMCACHED_SUCCESS; } + +memcached_return_t memcached_instance_error_return(memcached_instance_st* instance) +{ + if (instance == NULL) + { + return MEMCACHED_INVALID_ARGUMENTS; + } + + if (instance and instance->error_messages) + { + return instance->error_messages->rc; + } + + return MEMCACHED_SUCCESS; +} diff --git a/libmemcached/error.hpp b/libmemcached/error.hpp index c2cdcc51..26c56367 100644 --- a/libmemcached/error.hpp +++ b/libmemcached/error.hpp @@ -54,51 +54,55 @@ LIBMEMCACHED_LOCAL memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at); LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_server_st&, memcached_return_t rc, const char *at); + memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at); LIBMEMCACHED_LOCAL memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at, const char *str, size_t length); LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_server_st&, memcached_return_t rc, const char *at, const char *str, size_t length); + memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at, const char *str, size_t length); LIBMEMCACHED_LOCAL memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc, const char *at, memcached_string_t& str); LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_server_st&, memcached_return_t rc, const char *at, memcached_string_t& str); + memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at, memcached_string_t& str); LIBMEMCACHED_LOCAL memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, memcached_string_t& str); LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at, memcached_string_t& str); + memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at, memcached_string_t& str); LIBMEMCACHED_LOCAL memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, const char *str, size_t length); LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at, const char *str, size_t length); + memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at, const char *str, size_t length); LIBMEMCACHED_LOCAL memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at); LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at); + memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at); LIBMEMCACHED_LOCAL bool memcached_has_current_error(memcached_st&); LIBMEMCACHED_LOCAL -bool memcached_has_current_error(memcached_server_st&); +bool memcached_has_current_error(memcached_instance_st&); LIBMEMCACHED_LOCAL void memcached_error_free(memcached_st&); +void memcached_error_free(memcached_server_st& self); + LIBMEMCACHED_LOCAL -void memcached_error_free(memcached_server_st&); +void memcached_error_free(memcached_instance_st&); LIBMEMCACHED_LOCAL -memcached_error_t *memcached_error_copy(const memcached_server_st&); +memcached_error_t *memcached_error_copy(const memcached_instance_st&); + +memcached_return_t memcached_instance_error_return(memcached_instance_st*); #endif diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index 27ea3a84..2fd0dc51 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -191,7 +191,7 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } *error= MEMCACHED_MAXIMUM_RETURN; // We use this to see if we ever go into the loop - memcached_server_st *server; + memcached_instance_st *server; while ((server= memcached_io_get_readable_server(ptr))) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; diff --git a/libmemcached/flush.cc b/libmemcached/flush.cc index 0c6141d8..6afcce9a 100644 --- a/libmemcached/flush.cc +++ b/libmemcached/flush.cc @@ -86,7 +86,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); - if (memcached_server_response_count(instance) > 0) + if (memcached_instance_response_count(instance) > 0) { (void)memcached_response(instance, NULL, 0, NULL); } diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 9aa884f4..88220e6b 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -246,7 +246,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); - if (memcached_server_response_count(instance)) + if (memcached_instance_response_count(instance)) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -255,7 +255,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, memcached_io_write(instance); } - while(memcached_server_response_count(instance)) + while(memcached_instance_response_count(instance)) { (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result); } @@ -305,7 +305,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, }; - if (memcached_server_response_count(instance) == 0) + if (memcached_instance_response_count(instance) == 0) { rc= memcached_connect(instance); @@ -322,14 +322,14 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, continue; } WATCHPOINT_ASSERT(instance->cursor_active == 0); - memcached_server_response_increment(instance); + memcached_instance_response_increment(instance); WATCHPOINT_ASSERT(instance->cursor_active == 1); } else { if ((memcached_io_writev(instance, (vector + 1), 3, false)) == false) { - memcached_server_response_reset(instance); + memcached_instance_response_reset(instance); failures_occured_in_sending= true; continue; } @@ -358,7 +358,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); - if (memcached_server_response_count(instance)) + if (memcached_instance_response_count(instance)) { /* We need to do something about non-connnected hosts in the future */ if ((memcached_io_write(instance, "\r\n", 2, true)) == -1) @@ -482,7 +482,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key); - if (memcached_server_response_count(instance) == 0) + if (memcached_instance_response_count(instance) == 0) { rc= memcached_connect(instance); if (memcached_failed(rc)) @@ -556,11 +556,11 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); initialize_binary_request(instance, request.message.header); - if (memcached_server_response_count(instance)) + if (memcached_instance_response_count(instance)) { if (memcached_io_write(instance) == false) { - memcached_server_response_reset(instance); + memcached_instance_response_reset(instance); memcached_io_reset(instance); rc= MEMCACHED_SOME_ERRORS; } @@ -568,7 +568,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, if (memcached_io_write(instance, request.bytes, sizeof(request.bytes), true) == -1) { - memcached_server_response_reset(instance); + memcached_instance_response_reset(instance); memcached_io_reset(instance); rc= MEMCACHED_SOME_ERRORS; } @@ -626,7 +626,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server); - if (memcached_server_response_count(instance) == 0) + if (memcached_instance_response_count(instance) == 0) { rc= memcached_connect(instance); diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 337a999a..898bff9d 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -64,7 +64,7 @@ static void sort_hosts(memcached_st *ptr) { memcached_server_write_instance_st instance; - qsort(memcached_server_list(ptr), memcached_server_count(ptr), sizeof(memcached_server_st), compare_servers); + qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(memcached_instance_st), compare_servers); instance= memcached_server_instance_fetch(ptr, 0); instance->number_of_hosts= memcached_server_count(ptr); } @@ -132,7 +132,6 @@ static int continuum_item_cmp(const void *t1, const void *t2) static memcached_return_t update_continuum(memcached_st *ptr) { uint32_t continuum_index= 0; - memcached_server_st *list; uint32_t pointer_counter= 0; uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER; uint32_t pointer_per_hash= 1; @@ -144,7 +143,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) return memcached_set_errno(*ptr, errno, MEMCACHED_AT); } - list= memcached_server_list(ptr); + memcached_instance_st *list= memcached_instance_list(ptr); /* count live servers (those without a retry delay set) */ bool is_auto_ejecting= _is_auto_eject_host(ptr); @@ -352,19 +351,19 @@ static memcached_return_t server_add(memcached_st *ptr, { assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); - memcached_server_st *new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (ptr->number_of_hosts + 1), memcached_server_st); + memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (ptr->number_of_hosts + 1), memcached_instance_st); if (new_host_list == NULL) { return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } - memcached_server_list_set(ptr, new_host_list); + memcached_instance_set(ptr, new_host_list); /* TODO: Check return type */ memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); - if (__server_create_with(ptr, instance, hostname, port, weight, type) == NULL) + if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL) { return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } @@ -378,7 +377,7 @@ static memcached_return_t server_add(memcached_st *ptr, // @note we place the count in the bottom of the server list instance= memcached_server_instance_fetch(ptr, 0); - memcached_servers_set_count(instance, memcached_server_count(ptr)); + memcached_instance_set_count(instance, memcached_server_count(ptr)); return run_distribution(ptr); } @@ -393,15 +392,14 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv uint32_t count= memcached_server_list_count(list); - memcached_server_st *new_host_list; - new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (count + memcached_server_count(ptr)), memcached_server_st); + memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (count + memcached_server_count(ptr)), memcached_instance_st); if (new_host_list == NULL) { return MEMCACHED_MEMORY_ALLOCATION_FAILURE; } - memcached_server_list_set(ptr, new_host_list); + memcached_instance_set(ptr, new_host_list); for (uint32_t x= 0; x < count; x++) { @@ -414,9 +412,61 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv WATCHPOINT_ASSERT(instance); memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) }; - if (__server_create_with(ptr, instance, - hostname, - list[x].port, list[x].weight, list[x].type) == NULL) + if (__instance_create_with(ptr, instance, + hostname, + list[x].port, list[x].weight, list[x].type) == NULL) + { + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + } + + if (list[x].weight > 1) + { + ptr->ketama.weighted= true; + } + + ptr->number_of_hosts++; + } + + // Provides backwards compatibility with server list. + { + memcached_server_write_instance_st instance; + instance= memcached_server_instance_fetch(ptr, 0); + instance->number_of_hosts= memcached_server_count(ptr); + } + + return run_distribution(ptr); +} + +memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st* list, uint32_t number_of_hosts) +{ + if (list == NULL) + { + return MEMCACHED_SUCCESS; + } + + memcached_instance_st* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (number_of_hosts +memcached_server_count(ptr)), memcached_instance_st); + + if (new_host_list == NULL) + { + return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + } + + memcached_instance_set(ptr, new_host_list); + + for (uint32_t x= 0; x < number_of_hosts; x++) + { + memcached_server_write_instance_st instance; + + WATCHPOINT_ASSERT(list[x].hostname[0] != 0); + + // We have extended the array, and now we will find it, and use it. + instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + WATCHPOINT_ASSERT(instance); + + memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) }; + if (__instance_create_with(ptr, instance, + hostname, + list[x].port, list[x].weight, list[x].type) == NULL) { return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } diff --git a/libmemcached/include.am b/libmemcached/include.am index 99663d30..95616ddc 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -51,6 +51,7 @@ libmemcached_libmemcached_la_CFLAGS= -DBUILDING_LIBMEMCACHED libmemcached_libmemcached_la_CXXFLAGS= -DBUILDING_LIBMEMCACHED +libmemcached_libmemcached_la_SOURCES+= libmemcached/instance.cc libmemcached_libmemcached_la_SOURCES+= \ ${libhashkit_libhashkit_la_SOURCES} \ libmemcached/allocators.cc \ diff --git a/libmemcached/instance.cc b/libmemcached/instance.cc new file mode 100644 index 00000000..0662b8f6 --- /dev/null +++ b/libmemcached/instance.cc @@ -0,0 +1,390 @@ +/* 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. + * + */ + +/* + This is a partial implementation for fetching/creating memcached_instance_st objects. +*/ +#include + +static inline void _server_init(memcached_instance_st *self, memcached_st *root, + const memcached_string_t& hostname, + in_port_t port, + uint32_t weight, memcached_connection_t type) +{ + self->options.is_shutting_down= false; + self->options.is_dead= false; + self->number_of_hosts= 0; + self->cursor_active= 0; + self->port= port; + self->fd= INVALID_SOCKET; + self->io_bytes_sent= 0; + self->request_id= 0; + self->server_failure_counter= 0; + self->server_failure_counter_query_id= 0; + self->weight= weight ? weight : 1; // 1 is the default weight value + self->io_wait_count.read= 0; + self->io_wait_count.write= 0; + self->io_wait_count.timeouts= 0; + self->io_wait_count._bytes_read= 0; + self->major_version= UINT8_MAX; + self->micro_version= UINT8_MAX; + self->minor_version= UINT8_MAX; + self->type= type; + self->error_messages= NULL; + self->read_ptr= self->read_buffer; + self->read_buffer_length= 0; + self->read_data_length= 0; + self->write_buffer_offset= 0; + self->address_info= NULL; + self->address_info_next= NULL; + + self->state= MEMCACHED_SERVER_STATE_NEW; + self->next_retry= 0; + + self->root= root; + if (root) + { + self->version= ++root->server_info.version; + } + else + { + self->version= UINT_MAX; + } + self->limit_maxbytes= 0; + memcpy(self->hostname, hostname.c_str, hostname.size); + self->hostname[hostname.size]= 0; +} + +static memcached_instance_st *_server_create(memcached_instance_st *self, const memcached_st *memc) +{ + if (self == NULL) + { + self= libmemcached_xmalloc(memc, struct memcached_instance_st); + + if (self == NULL) + { + return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */ + } + + self->options.is_allocated= true; + } + else + { + self->options.is_allocated= false; + } + + self->options.is_initialized= true; + + return self; +} + +memcached_instance_st *__instance_create_with(memcached_st *memc, + memcached_instance_st* self, + const memcached_string_t& hostname, + const in_port_t port, + uint32_t weight, + const memcached_connection_t type) +{ + if (memcached_is_valid_servername(hostname) == false) + { + memcached_set_error(*memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid hostname provided")); + return NULL; + } + + self= _server_create(self, memc); + + if (self == NULL) + { + return NULL; + } + + _server_init(self, const_cast(memc), hostname, port, weight, type); + + if (memc and memcached_is_udp(memc)) + { + self->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH; + memcached_io_init_udp_header(self, 0); + } + + if (memc) + { + memcached_connect_try(self); + } + + return self; +} + +void __instance_free(memcached_instance_st *self) +{ + memcached_quit_server(self, false); + + if (self->address_info) + { + freeaddrinfo(self->address_info); + self->address_info= NULL; + self->address_info_next= NULL; + } + + memcached_error_free(*self); + + if (memcached_is_allocated(self)) + { + libmemcached_free(self->root, self); + } + else + { + self->options.is_initialized= false; + } +} + +void memcached_instance_free(memcached_instance_st *self) +{ + if (self == NULL) + { + return; + } + + if (memcached_instance_count(self)) + { + memcached_instance_list_free(self, memcached_instance_count(self)); + return; + } + + __instance_free(self); +} + +/* + If we do not have a valid object to clone from, we toss an error. +*/ +memcached_server_st *memcached_instance_2_server(memcached_instance_st *source) +{ + /* We just do a normal create if source is missing */ + if (source == NULL) + { + return NULL; + } + + memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) }; + return __server_create_with(source->root, NULL, + hostname, + source->port, source->weight, + source->type); + +} + +memcached_return_t memcached_server_cursor(const memcached_st *ptr, + const memcached_server_fn *callback, + void *context, + uint32_t number_of_callbacks) +{ + memcached_return_t rc; + if (memcached_failed(rc= initialize_const_query(ptr))) + { + return rc; + } + + size_t errors= 0; + for (uint32_t x= 0; x < memcached_instance_list_count(ptr); x++) + { + memcached_server_instance_st instance= + memcached_server_instance_by_position(ptr, x); + + for (uint32_t y= 0; y < number_of_callbacks; y++) + { + memcached_return_t ret= (*callback[y])(ptr, instance, context); + + if (memcached_failed(ret)) + { + errors++; + continue; + } + } + } + + return errors ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; +} + +memcached_return_t memcached_server_execute(memcached_st *ptr, + memcached_server_execute_fn callback, + void *context) +{ + if (callback == NULL) + { + return MEMCACHED_INVALID_ARGUMENTS; + } + + bool some_errors= false;; + for (uint32_t x= 0; x < memcached_instance_list_count(ptr); x++) + { + memcached_instance_st* instance= memcached_server_instance_fetch(ptr, x); + + memcached_return_t rc= (*callback)(ptr, instance, context); + if (rc == MEMCACHED_INVALID_ARGUMENTS) + { + return rc; + } + else if (memcached_fatal(rc)) + { + some_errors= true; + } + } + + (void)some_errors; + return MEMCACHED_SUCCESS; +} + +memcached_server_instance_st memcached_server_by_key(memcached_st *ptr, + const char *key, + size_t key_length, + memcached_return_t *error) +{ + memcached_return_t unused; + if (not error) + { + error= &unused; + } + + + memcached_return_t rc; + if (memcached_failed(rc= initialize_const_query(ptr))) + { + *error= rc; + return NULL; + } + + if (memcached_failed((memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))) + { + *error= memcached_last_error(ptr); + return NULL; + } + + uint32_t server_key= memcached_generate_hash(ptr, key, key_length); + return memcached_server_instance_by_position(ptr, server_key); +} + +/* + If we do not have a valid object to clone from, we toss an error. +*/ +static memcached_instance_st *memcached_instance_clone(memcached_instance_st *source) +{ + /* We just do a normal create if source is missing */ + if (source == NULL) + { + return NULL; + } + + memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) }; + return __instance_create_with(source->root, + NULL, + hostname, + source->port, source->weight, + source->type); +} + +void set_last_disconnected_host(memcached_server_write_instance_st self) +{ + assert(self->root); + if (self->root == NULL) + { + return; + } + + if (self->root->last_disconnected_server and self->root->last_disconnected_server->version == self->version) + { + return; + } + + // const_cast + memcached_st *root= (memcached_st *)self->root; + + memcached_instance_free(root->last_disconnected_server); + root->last_disconnected_server= memcached_instance_clone(self); + root->last_disconnected_server->version= self->version; +} + +memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self) +{ + WATCHPOINT_ASSERT(self); + if (self == NULL) + { + return 0; + } + + return self->last_disconnected_server; +} + +uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count) +{ + WATCHPOINT_ASSERT(servers); + if (servers == NULL) + { + return 0; + } + + return servers->number_of_hosts= count; +} + +const char *memcached_instance_name(const memcached_server_instance_st self) +{ + WATCHPOINT_ASSERT(self); + if (self == NULL) + return NULL; + + return self->hostname; +} + +in_port_t memcached_instance_port(const memcached_server_instance_st self) +{ + WATCHPOINT_ASSERT(self); + if (self == NULL) + { + return 0; + } + + return self->port; +} + +uint32_t memcached_instance_response_count(const memcached_instance_st* self) +{ + WATCHPOINT_ASSERT(self); + if (self == NULL) + { + return 0; + } + + return self->cursor_active; +} diff --git a/libmemcached/instance.h b/libmemcached/instance.h new file mode 100644 index 00000000..77388d2c --- /dev/null +++ b/libmemcached/instance.h @@ -0,0 +1,98 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * 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. + * + */ + + +#pragma once + +#ifndef WIN32 +#include +#endif + +#ifdef NI_MAXHOST +#define MEMCACHED_NI_MAXHOST NI_MAXHOST +#else +#define MEMCACHED_NI_MAXHOST 1025 +#endif + +#ifdef NI_MAXSERV +#define MEMCACHED_NI_MAXSERV NI_MAXSERV +#else +#define MEMCACHED_NI_MAXSERV 32 +#endif + +struct memcached_instance_st { + struct { + bool is_allocated:1; + bool is_initialized:1; + bool is_shutting_down:1; + bool is_dead:1; + } options; + uint32_t number_of_hosts; + uint32_t cursor_active; + in_port_t port; + memcached_socket_t fd; + uint32_t io_bytes_sent; /* # bytes sent since last read */ + uint32_t request_id; + uint32_t server_failure_counter; + uint64_t server_failure_counter_query_id; + uint32_t weight; + uint32_t version; + enum memcached_server_state_t state; + struct { + uint32_t read; + uint32_t write; + uint32_t timeouts; + size_t _bytes_read; + } io_wait_count; + uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set. + uint8_t micro_version; // ditto, and note that this is the third, not second version bit + uint8_t minor_version; // ditto + memcached_connection_t type; + char *read_ptr; + size_t read_buffer_length; + size_t read_data_length; + size_t write_buffer_offset; + struct addrinfo *address_info; + struct addrinfo *address_info_next; + time_t next_retry; + struct memcached_st *root; + uint64_t limit_maxbytes; + struct memcached_error_t *error_messages; + char read_buffer[MEMCACHED_MAX_BUFFER]; + char write_buffer[MEMCACHED_MAX_BUFFER]; + char hostname[MEMCACHED_NI_MAXHOST]; +}; diff --git a/libmemcached/instance.hpp b/libmemcached/instance.hpp new file mode 100644 index 00000000..3c9dea35 --- /dev/null +++ b/libmemcached/instance.hpp @@ -0,0 +1,58 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * 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. + * + */ + + +#pragma once + +struct memcached_instance_st *__instance_create_with(memcached_st *memc, + struct memcached_instance_st* self, + const memcached_string_t& hostname, + const in_port_t port, + uint32_t weight, + const memcached_connection_t type); +void __instance_free(struct memcached_instance_st *); + +memcached_server_st *memcached_instance_2_server(struct memcached_instance_st*); + +memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st*, uint32_t); + +uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count); +const char *memcached_instance_name(const memcached_server_instance_st self); +in_port_t memcached_instance_port(const memcached_server_instance_st self); +uint32_t memcached_instance_response_count(const memcached_instance_st* self); +uint32_t memcached_instance_count(const memcached_st* self); + diff --git a/libmemcached/io.cc b/libmemcached/io.cc index 48e5ecff..d2e40043 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -287,7 +287,7 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, if (memcached_has_error(ptr)) { - return memcached_server_error_return(ptr); + return memcached_instance_error_return(ptr); } return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT, @@ -449,7 +449,7 @@ static memcached_return_t _io_fill(memcached_server_write_instance_st ptr) break; } - return memcached_server_error_return(ptr); + return memcached_instance_error_return(ptr); } else if (data_read == 0) { @@ -729,11 +729,11 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st return instance; } - if (memcached_server_response_count(instance) > 0) + if (memcached_instance_response_count(instance) > 0) { - fds[host_index].events = POLLIN; - fds[host_index].revents = 0; - fds[host_index].fd = instance->fd; + fds[host_index].events= POLLIN; + fds[host_index].revents= 0; + fds[host_index].fd= instance->fd; ++host_index; } } @@ -743,10 +743,9 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st /* We have 0 or 1 server with pending events.. */ for (uint32_t x= 0; x< memcached_server_count(memc); ++x) { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(memc, x); + memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x); - if (memcached_server_response_count(instance) > 0) + if (memcached_instance_response_count(instance) > 0) { return instance; } diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 548f2355..0574cc6c 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -128,12 +128,12 @@ static void __memcached_free(memcached_st *ptr, bool release_st) { /* If we have anything open, lets close it now */ send_quit(ptr); - memcached_server_list_free(memcached_server_list(ptr)); + memcached_instance_list_free(memcached_instance_list(ptr), memcached_instance_list_count(ptr)); memcached_result_free(&ptr->result); memcached_virtual_bucket_free(ptr); - memcached_server_free(ptr->last_disconnected_server); + memcached_instance_free(ptr->last_disconnected_server); if (ptr->on_cleanup) { @@ -275,11 +275,11 @@ void memcached_servers_reset(memcached_st *self) { if (self) { - memcached_server_list_free(memcached_server_list(self)); + memcached_instance_list_free(memcached_instance_list(self), self->number_of_hosts); - memcached_server_list_set(self, NULL); + memcached_instance_set(self, NULL); self->number_of_hosts= 0; - memcached_server_free(self->last_disconnected_server); + memcached_instance_free(self->last_disconnected_server); self->last_disconnected_server= NULL; } } @@ -288,7 +288,7 @@ void memcached_reset_last_disconnected_server(memcached_st *self) { if (self) { - memcached_server_free(self->last_disconnected_server); + memcached_instance_free(self->last_disconnected_server); self->last_disconnected_server= NULL; } } @@ -421,7 +421,7 @@ void *memcached_set_user_data(memcached_st *ptr, void *data) memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source) { - return memcached_server_push(destination, source->servers); + return memcached_instance_push(destination, source->servers, source->number_of_hosts); } memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) diff --git a/libmemcached/quit.cc b/libmemcached/quit.cc index 929d0ca0..4bf72f64 100644 --- a/libmemcached/quit.cc +++ b/libmemcached/quit.cc @@ -46,7 +46,7 @@ will force data to be completed. */ -void memcached_quit_server(memcached_server_st *ptr, bool io_death) +void memcached_quit_server(memcached_instance_st *ptr, bool io_death) { if (ptr->fd != INVALID_SOCKET) { diff --git a/libmemcached/quit.hpp b/libmemcached/quit.hpp index 171bb655..888cde46 100644 --- a/libmemcached/quit.hpp +++ b/libmemcached/quit.hpp @@ -36,6 +36,6 @@ #pragma once -void memcached_quit_server(memcached_server_st *ptr, bool io_death); +void memcached_quit_server(memcached_instance_st *ptr, bool io_death); void send_quit(memcached_st *ptr); diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index 603c5864..3d93b786 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -65,7 +65,7 @@ sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr) * @param raddr remote address (out) * @return true on success false otherwise (errno contains more info) */ -static memcached_return_t resolve_names(memcached_server_st& server, char *laddr, size_t laddr_length, char *raddr, size_t raddr_length) +static memcached_return_t resolve_names(memcached_instance_st& server, char *laddr, size_t laddr_length, char *raddr, size_t raddr_length) { char host[NI_MAXHOST]; char port[NI_MAXSERV]; @@ -123,7 +123,7 @@ static void sasl_startup_function(void) } // extern "C" -memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *server) +memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server) { if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) { diff --git a/libmemcached/sasl.hpp b/libmemcached/sasl.hpp index 26822682..c5d3f81c 100644 --- a/libmemcached/sasl.hpp +++ b/libmemcached/sasl.hpp @@ -39,4 +39,4 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st *source); -memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *server); +memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server); diff --git a/libmemcached/server.cc b/libmemcached/server.cc index 9345da0b..8d9e9bbd 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -113,7 +113,7 @@ static memcached_server_st *_server_create(memcached_server_st *self, const memc } memcached_server_st *__server_create_with(memcached_st *memc, - memcached_server_write_instance_st self, + memcached_server_st* self, const memcached_string_t& hostname, const in_port_t port, uint32_t weight, @@ -134,31 +134,11 @@ memcached_server_st *__server_create_with(memcached_st *memc, _server_init(self, const_cast(memc), hostname, port, weight, type); - if (memc and memcached_is_udp(memc)) - { - self->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH; - memcached_io_init_udp_header(self, 0); - } - - if (memc) - { - memcached_connect_try(self); - } - return self; } void __server_free(memcached_server_st *self) { - memcached_quit_server(self, false); - - if (self->address_info) - { - freeaddrinfo(self->address_info); - self->address_info= NULL; - self->address_info_next= NULL; - } - memcached_error_free(*self); if (memcached_is_allocated(self)) @@ -187,118 +167,6 @@ void memcached_server_free(memcached_server_st *self) __server_free(self); } -/* - If we do not have a valid object to clone from, we toss an error. -*/ -memcached_server_st *memcached_server_clone(memcached_server_st *destination, - memcached_server_st *source) -{ - /* We just do a normal create if source is missing */ - if (source == NULL) - { - return NULL; - } - - memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) }; - destination= __server_create_with(source->root, destination, - hostname, - source->port, source->weight, - source->type); - return destination; - -} - -memcached_return_t memcached_server_cursor(const memcached_st *ptr, - const memcached_server_fn *callback, - void *context, - uint32_t number_of_callbacks) -{ - memcached_return_t rc; - if (memcached_failed(rc= initialize_const_query(ptr))) - { - return rc; - } - - size_t errors= 0; - for (uint32_t x= 0; x < memcached_server_count(ptr); x++) - { - memcached_server_instance_st instance= - memcached_server_instance_by_position(ptr, x); - - for (uint32_t y= 0; y < number_of_callbacks; y++) - { - memcached_return_t ret= (*callback[y])(ptr, instance, context); - - if (memcached_failed(ret)) - { - errors++; - continue; - } - } - } - - return errors ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; -} - -memcached_return_t memcached_server_execute(memcached_st *ptr, - memcached_server_execute_fn callback, - void *context) -{ - if (callback == NULL) - { - return MEMCACHED_INVALID_ARGUMENTS; - } - - bool some_errors= false;; - for (uint32_t x= 0; x < memcached_server_count(ptr); x++) - { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); - - memcached_return_t rc= (*callback)(ptr, instance, context); - if (rc == MEMCACHED_INVALID_ARGUMENTS) - { - return rc; - } - else if (memcached_fatal(rc)) - { - some_errors= true; - } - } - - (void)some_errors; - return MEMCACHED_SUCCESS; -} - -memcached_server_instance_st memcached_server_by_key(memcached_st *ptr, - const char *key, - size_t key_length, - memcached_return_t *error) -{ - memcached_return_t unused; - if (not error) - { - error= &unused; - } - - - memcached_return_t rc; - if (memcached_failed(rc= initialize_const_query(ptr))) - { - *error= rc; - return NULL; - } - - if (memcached_failed((memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))) - { - *error= memcached_last_error(ptr); - return NULL; - } - - uint32_t server_key= memcached_generate_hash(ptr, key, key_length); - return memcached_server_instance_by_position(ptr, server_key); - -} - void memcached_server_error_reset(memcached_server_st *self) { WATCHPOINT_ASSERT(self); @@ -310,17 +178,6 @@ void memcached_server_error_reset(memcached_server_st *self) memcached_error_free(*self); } -memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self) -{ - WATCHPOINT_ASSERT(self); - if (self == NULL) - { - return 0; - } - - return self->last_disconnected_server; -} - uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count) { WATCHPOINT_ASSERT(servers); @@ -391,3 +248,33 @@ const char *memcached_server_type(const memcached_server_instance_st ptr) return "UNKNOWN"; } + +uint8_t memcached_server_major_version(const memcached_server_instance_st instance) +{ + if (instance) + { + return instance->major_version; + } + + return UINT8_MAX; +} + +uint8_t memcached_server_minor_version(const memcached_server_instance_st instance) +{ + if (instance) + { + return instance->minor_version; + } + + return UINT8_MAX; +} + +uint8_t memcached_server_micro_version(const memcached_server_instance_st instance) +{ + if (instance) + { + return instance->micro_version; + } + + return UINT8_MAX; +} diff --git a/libmemcached/server.hpp b/libmemcached/server.hpp index 5d718949..191402e8 100644 --- a/libmemcached/server.hpp +++ b/libmemcached/server.hpp @@ -44,15 +44,12 @@ #include memcached_server_st *__server_create_with(memcached_st *memc, - memcached_server_write_instance_st host, + memcached_server_st* self, const memcached_string_t& hostname, const in_port_t port, - uint32_t weight, + uint32_t weight, const memcached_connection_t type); -memcached_server_st *memcached_server_clone(memcached_server_st *destination, - memcached_server_st *source); - memcached_return_t memcached_server_add_parsed(memcached_st *ptr, const char *hostname, size_t hostname_length, @@ -72,27 +69,9 @@ static inline void memcached_mark_server_as_clean(memcached_server_write_instanc server->next_retry= 0; } +void memcached_instance_free(memcached_instance_st *); -static inline void set_last_disconnected_host(memcached_server_write_instance_st self) -{ - assert(self->root); - if (self->root == NULL) - { - return; - } - - if (self->root->last_disconnected_server and self->root->last_disconnected_server->version == self->version) - { - return; - } - - // const_cast - memcached_st *root= (memcached_st *)self->root; - - memcached_server_free(root->last_disconnected_server); - root->last_disconnected_server= memcached_server_clone(NULL, self); - root->last_disconnected_server->version= self->version; -} +void set_last_disconnected_host(memcached_server_write_instance_st self); static inline void memcached_mark_server_for_timeout(memcached_server_write_instance_st server) { diff --git a/libmemcached/server_instance.h b/libmemcached/server_instance.h index 8c439920..69613499 100644 --- a/libmemcached/server_instance.h +++ b/libmemcached/server_instance.h @@ -41,7 +41,7 @@ extern "C" { #endif -typedef struct memcached_server_st * memcached_server_write_instance_st; +typedef struct memcached_instance_st * memcached_server_write_instance_st; #ifdef __cplusplus } diff --git a/libmemcached/server_list.cc b/libmemcached/server_list.cc index f03dc356..d2a00922 100644 --- a/libmemcached/server_list.cc +++ b/libmemcached/server_list.cc @@ -46,7 +46,6 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, memcached_return_t *error) { uint32_t count; - memcached_server_list_st new_host_list; memcached_return_t unused; if (error == NULL) @@ -74,10 +73,12 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, count+= memcached_server_list_count(ptr); } - new_host_list= (memcached_server_write_instance_st)realloc(ptr, sizeof(memcached_server_st) * count); - if (not new_host_list) + memcached_server_list_st new_host_list= (memcached_server_st*)realloc(ptr, sizeof(memcached_server_st) * count); + if (new_host_list == NULL) { +#if 0 *error= memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); +#endif return NULL; } @@ -85,7 +86,9 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, /* @todo Check return type */ if (__server_create_with(NULL, &new_host_list[count-1], _hostname, port, weight, port ? MEMCACHED_CONNECTION_TCP : MEMCACHED_CONNECTION_UNIX_SOCKET) == NULL) { +#if 0 *error= memcached_set_errno(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); +#endif return NULL; } @@ -116,7 +119,21 @@ uint32_t memcached_server_list_count(const memcached_server_list_st self) : self->number_of_hosts; } -memcached_server_st *memcached_server_list(const memcached_st *self) +uint32_t memcached_instance_list_count(const memcached_st* self) +{ + return (self == NULL) + ? 0 + : self->number_of_hosts; +} + +uint32_t memcached_instance_count(const memcached_instance_st* self) +{ + return (self == NULL) + ? 0 + : self->number_of_hosts; +} + +memcached_instance_st *memcached_instance_list(const memcached_st *self) { if (self) { @@ -126,15 +143,17 @@ memcached_server_st *memcached_server_list(const memcached_st *self) return NULL; } -void memcached_server_list_set(memcached_st *self, memcached_server_st *list) +void memcached_instance_set(memcached_st *self, memcached_instance_st *list) { self->servers= list; } void memcached_server_list_free(memcached_server_list_st self) { - if (not self) + if (self == NULL) + { return; + } for (uint32_t x= 0; x < memcached_server_list_count(self); x++) { @@ -144,3 +163,19 @@ void memcached_server_list_free(memcached_server_list_st self) libmemcached_free(self->root, self); } + +void memcached_instance_list_free(memcached_instance_st* self, uint32_t instance_count) +{ + if (self == NULL) + { + return; + } + + for (uint32_t x= 0; x < instance_count; x++) + { + assert_msg(not memcached_is_allocated(&self[x]), "You have called memcached_server_list_free(), but you did not pass it a valid memcached_server_list_st"); + __instance_free(&self[x]); + } + + libmemcached_free(self->root, self); +} diff --git a/libmemcached/server_list.hpp b/libmemcached/server_list.hpp index db56721b..3f722647 100644 --- a/libmemcached/server_list.hpp +++ b/libmemcached/server_list.hpp @@ -38,7 +38,14 @@ uint32_t memcached_servers_set_count(memcached_server_list_st servers, uint32_t count); +uint32_t memcached_instance_set_count(memcached_instance_st* servers, uint32_t count); -memcached_server_st *memcached_server_list(const memcached_st *); +memcached_instance_st *memcached_instance_list(const memcached_st *); -void memcached_server_list_set(memcached_st *self, memcached_server_list_st list); +void memcached_instance_set(memcached_st *self, memcached_instance_st* list); + +void memcached_instance_list_free(memcached_instance_st* self, uint32_t); + +uint32_t memcached_server_list_count(const memcached_server_list_st self); +uint32_t memcached_instance_list_count(const memcached_st*); +uint32_t memcached_instance_count(const memcached_instance_st*); diff --git a/libmemcached/verbosity.cc b/libmemcached/verbosity.cc index 334a3316..39810dec 100644 --- a/libmemcached/verbosity.cc +++ b/libmemcached/verbosity.cc @@ -44,7 +44,7 @@ struct context_st }; static memcached_return_t _set_verbosity(const memcached_st *, - const memcached_server_st *server, + const memcached_server_instance_st server, void *context) { libmemcached_io_vector_st *vector= (libmemcached_io_vector_st *)context; diff --git a/libmemcachedutil/pid.cc b/libmemcachedutil/pid.cc index 99f378d1..51948383 100644 --- a/libmemcachedutil/pid.cc +++ b/libmemcachedutil/pid.cc @@ -76,8 +76,8 @@ pid_t libmemcached_util_getpid(const char *hostname, in_port_t port, memcached_r { memcached_server_instance_st instance= memcached_server_instance_by_position(memc_ptr, 0); - assert_msg(instance and instance->error_messages, " "); - if (instance and instance->error_messages) + assert_msg(instance and memcached_server_error(instance), " "); + if (instance and memcached_server_error(instance)) { rc= memcached_server_error_return(instance); } @@ -145,7 +145,7 @@ pid_t libmemcached_util_getpid2(const char *hostname, in_port_t port, const char #if 0 assert_msg(instance and instance->error_messages, " "); #endif - if (instance and instance->error_messages) + if (instance and memcached_server_error(instance)) { rc= memcached_server_error_return(instance); } diff --git a/libmemcachedutil/ping.cc b/libmemcachedutil/ping.cc index 28d11081..b2192a1d 100644 --- a/libmemcachedutil/ping.cc +++ b/libmemcachedutil/ping.cc @@ -65,8 +65,8 @@ bool libmemcached_util_ping(const char *hostname, in_port_t port, memcached_retu memcached_server_instance_st instance= memcached_server_instance_by_position(memc_ptr, 0); - assert_msg(instance and instance->error_messages, " "); - if (instance and instance->error_messages) + assert_msg(instance and memcached_server_error(instance), " "); + if (instance and memcached_server_error(instance)) { rc= memcached_server_error_return(instance); } @@ -119,8 +119,8 @@ bool libmemcached_util_ping2(const char *hostname, in_port_t port, const char *u memcached_server_instance_st instance= memcached_server_instance_by_position(memc_ptr, 0); - assert_msg(instance and instance->error_messages, " "); - if (instance and instance->error_messages) + assert_msg(instance and memcached_server_error(instance), " "); + if (instance and memcached_server_error(instance)) { rc= memcached_server_error_return(instance); } diff --git a/libmemcachedutil/version.cc b/libmemcachedutil/version.cc index 15f888b8..9674c059 100644 --- a/libmemcachedutil/version.cc +++ b/libmemcachedutil/version.cc @@ -49,16 +49,16 @@ struct local_context }; static memcached_return_t check_server_version(const memcached_st *, - const memcached_server_st *instance, + memcached_server_instance_st instance, void *context) { /* Do Nothing */ struct local_context *check= (struct local_context *)context; - if (instance->major_version != UINT8_MAX && - instance->major_version >= check->major_version and - instance->minor_version >= check->minor_version and - instance->micro_version >= check->micro_version ) + if (memcached_server_major_version(instance) != UINT8_MAX && + memcached_server_major_version(instance) >= check->major_version and + memcached_server_minor_version(instance) >= check->minor_version and + memcached_server_micro_version(instance) >= check->micro_version ) { return MEMCACHED_SUCCESS; } diff --git a/libtest/memcached.hpp b/libtest/memcached.hpp new file mode 100644 index 00000000..c4953975 --- /dev/null +++ b/libtest/memcached.hpp @@ -0,0 +1,70 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * + * 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. + * + */ + +#pragma once + +#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED +inline bool operator== (const memcached_st& memc, const memcached_return_t rc) +{ + if (memcached_last_error(&memc) == rc) + { + return true; + } + + return false; +} + +inline bool operator!= (const memcached_st& memc, const memcached_return_t rc) +{ + if (memcached_last_error(&memc) != rc) + { + return true; + } + + return false; +} + +inline bool operator!= (const memcached_return_t rc, const memcached_st& memc) +{ + if (memcached_last_error(&memc) != rc) + { + return true; + } + + return false; +} +#endif + diff --git a/tests/failure.cc b/tests/failure.cc index 445de246..016ea5e4 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -98,6 +98,7 @@ static test_return_t restart_servers(memcached_st *) return TEST_SUCCESS; } +#include "libmemcached/instance.h" static test_return_t cull_TEST(memcached_st *memc) { uint32_t count= memcached_server_count(memc); diff --git a/tests/libmemcached-1.0/debug.cc b/tests/libmemcached-1.0/debug.cc index 5e72a0b6..52170b9a 100644 --- a/tests/libmemcached-1.0/debug.cc +++ b/tests/libmemcached-1.0/debug.cc @@ -46,6 +46,8 @@ using namespace libtest; #include #include +#include "libmemcached/instance.h" + /* Dump each server's keys */ static memcached_return_t print_keys_callback(const memcached_st *, const char *key, diff --git a/tests/libmemcached-1.0/generate.cc b/tests/libmemcached-1.0/generate.cc index 836ea2c9..a3613ca4 100644 --- a/tests/libmemcached-1.0/generate.cc +++ b/tests/libmemcached-1.0/generate.cc @@ -132,7 +132,11 @@ test_return_t generate_data_with_stats(memcached_st *memc) memcached_server_instance_st instance= memcached_server_instance_by_position(memc, host_index); - printf("\nserver %u|%s|%u bytes: %llu\n", host_index, instance->hostname, instance->port, (unsigned long long)(stat_p + host_index)->bytes); + printf("\nserver %u|%s|%u bytes: %llu\n", + host_index, + memcached_server_name(instance), + memcached_server_port(instance), + (unsigned long long)(stat_p + host_index)->bytes); } test_true((unsigned long long)(stat_p + host_index)->bytes); } diff --git a/tests/libmemcached-1.0/ketama.cc b/tests/libmemcached-1.0/ketama.cc index 939236aa..1a70e1cb 100644 --- a/tests/libmemcached-1.0/ketama.cc +++ b/tests/libmemcached-1.0/ketama.cc @@ -40,6 +40,7 @@ #include #include #include +#include #include #include diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 77b4a481..bfacffea 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -91,6 +91,8 @@ using namespace libtest; #include "tests/keys.hpp" +#include "libmemcached/instance.h" + static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options) { /* @@ -172,7 +174,7 @@ test_return_t init_test(memcached_st *not_used) in_port_t test_ports[TEST_PORT_COUNT]; static memcached_return_t server_display_function(const memcached_st *ptr, - const memcached_server_st *server, + memcached_server_instance_st server, void *context) { /* Do Nothing */ @@ -185,7 +187,7 @@ static memcached_return_t server_display_function(const memcached_st *ptr, } static memcached_return_t dump_server_information(const memcached_st *ptr, - const memcached_server_st *instance, + memcached_server_instance_st instance, void *context) { /* Do Nothing */ @@ -291,7 +293,7 @@ test_return_t memcached_server_remove_test(memcached_st*) } static memcached_return_t server_display_unsort_function(const memcached_st*, - const memcached_server_st *server, + memcached_server_instance_st server, void *context) { /* Do Nothing */ @@ -924,7 +926,7 @@ test_return_t flush_test(memcached_st *memc) } static memcached_return_t server_function(const memcached_st *, - const memcached_server_st *, + memcached_server_instance_st, void *) { /* Do Nothing */ @@ -2580,7 +2582,7 @@ test_return_t user_supplied_bug19(memcached_st *) memcached_st *memc= memcached(test_literal_param("--server=localhost:11311/?100 --server=localhost:11312/?100")); - const memcached_server_st *server= memcached_server_by_key(memc, "a", 1, &res); + memcached_server_instance_st server= memcached_server_by_key(memc, "a", 1, &res); test_true(server); memcached_free(memc); @@ -3411,7 +3413,7 @@ test_return_t getpid_test(memcached_st *memc) } static memcached_return_t ping_each_server(const memcached_st*, - const memcached_server_st *instance, + memcached_server_instance_st instance, void*) { // Test both the version that returns a code, and the one that does not. diff --git a/tests/libmemcached-1.0/parser.cc b/tests/libmemcached-1.0/parser.cc index 3afc12ba..03fb73ff 100644 --- a/tests/libmemcached-1.0/parser.cc +++ b/tests/libmemcached-1.0/parser.cc @@ -49,6 +49,7 @@ using namespace libtest; #include #include +#include "libmemcached/instance.h" enum scanner_type_t { @@ -615,7 +616,7 @@ test_return_t random_statement_build_test(memcached_st*) } static memcached_return_t dump_server_information(const memcached_st *, - const memcached_server_st *instance, + memcached_server_instance_st instance, void *) { if (strcmp(memcached_server_name(instance), "localhost")) @@ -664,7 +665,7 @@ struct socket_weight_t { }; static memcached_return_t dump_socket_information(const memcached_st *, - const memcached_server_st *instance, + memcached_server_instance_st instance, void *context) { socket_weight_t *check= (socket_weight_t *)context; diff --git a/tests/libmemcached-1.0/pool.cc b/tests/libmemcached-1.0/pool.cc index 10450dac..ea6501e8 100644 --- a/tests/libmemcached-1.0/pool.cc +++ b/tests/libmemcached-1.0/pool.cc @@ -55,6 +55,8 @@ using namespace libtest; #include #include +#include "libmemcached/instance.h" + #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif diff --git a/tests/libmemcached-1.0/print.cc b/tests/libmemcached-1.0/print.cc index 13c4e1d0..f1c03d07 100644 --- a/tests/libmemcached-1.0/print.cc +++ b/tests/libmemcached-1.0/print.cc @@ -48,7 +48,7 @@ using namespace libtest; #include "tests/print.h" memcached_return_t server_print_callback(const memcached_st*, - const memcached_server_st *server, + memcached_server_instance_st server, void *context) { if (context) @@ -70,13 +70,13 @@ const char * print_version(memcached_st *memc) memcached_return_t server_print_version_callback(const memcached_st *, - const memcached_server_st *server, + memcached_server_instance_st server, void *) { std::cerr << "Server: " << memcached_server_name(server) << ":" << memcached_server_port(server) << " " - << int(server->major_version) << "." - << int(server->minor_version) << "." - << int(server->micro_version) + << int(memcached_server_major_version(server)) << "." + << int(memcached_server_minor_version(server)) << "." + << int(memcached_server_micro_version(server)) << std::endl; return MEMCACHED_SUCCESS; diff --git a/tests/libmemcached-1.0/replication.cc b/tests/libmemcached-1.0/replication.cc index 502bd541..2b79bc15 100644 --- a/tests/libmemcached-1.0/replication.cc +++ b/tests/libmemcached-1.0/replication.cc @@ -111,6 +111,8 @@ test_return_t replication_set_test(memcached_st *memc) return TEST_SUCCESS; } +#include "libmemcached/instance.h" + test_return_t replication_get_test(memcached_st *memc) { diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index 1bc4096a..42dbcb69 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -63,6 +63,8 @@ using namespace libtest; #include +#include "libmemcached/instance.h" + #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif diff --git a/tests/print.h b/tests/print.h index efecc9ed..7460dc3b 100644 --- a/tests/print.h +++ b/tests/print.h @@ -38,11 +38,11 @@ #pragma once memcached_return_t server_print_callback(const memcached_st *ptr, - const memcached_server_st *server, + memcached_server_instance_st server, void *context); memcached_return_t server_print_version_callback(const memcached_st *ptr, - const memcached_server_st *server, + memcached_server_instance_st server, void *context); const char * print_version(memcached_st *memc); -- 2.30.2