From: Brian Aker Date: Tue, 12 Jan 2010 20:20:04 +0000 (-0800) Subject: Partial encapsulation of memcached_st->hosts X-Git-Tag: 0.40~128 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=14fbb41f4a761f96a047c36f9eaae33e6b57d21f;p=awesomized%2Flibmemcached Partial encapsulation of memcached_st->hosts --- diff --git a/libmemcached/auto.c b/libmemcached/auto.c index 8d3e1bc7..017f7f39 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.c @@ -25,7 +25,7 @@ static memcached_return_t memcached_auto(memcached_st *ptr, memcached_server_instance_st *instance; bool no_reply= ptr->flags.no_reply; - unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0) + 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)) @@ -85,7 +85,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, memcached_server_instance_st *instance; bool no_reply= ptr->flags.no_reply; - unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0) + unlikely (memcached_server_count(ptr) == 0) return MEMCACHED_NO_SERVERS; server_key= memcached_generate_hash(ptr, master_key, master_key_length); diff --git a/libmemcached/behavior.c b/libmemcached/behavior.c index 4813a3b8..6d168860 100644 --- a/libmemcached/behavior.c +++ b/libmemcached/behavior.c @@ -252,13 +252,16 @@ uint64_t memcached_behavior_get(memcached_st *ptr, { int sock_size; socklen_t sock_length= sizeof(int); + memcached_server_instance_st *instance; + + instance= memcached_server_instance_fetch(ptr, 0); /* REFACTOR */ /* We just try the first host, and if it is down we return zero */ - if ((memcached_connect(&ptr->hosts[0])) != MEMCACHED_SUCCESS) + if ((memcached_connect(instance)) != MEMCACHED_SUCCESS) return 0; - if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET, + if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length)) return 0; /* Zero means error */ @@ -268,15 +271,18 @@ uint64_t memcached_behavior_get(memcached_st *ptr, { int sock_size; socklen_t sock_length= sizeof(int); + memcached_server_instance_st *instance; + + instance= memcached_server_instance_fetch(ptr, 0); /** @note REFACTOR */ /* We just try the first host, and if it is down we return zero */ - if ((memcached_connect(&ptr->hosts[0])) != MEMCACHED_SUCCESS) + if ((memcached_connect(instance)) != MEMCACHED_SUCCESS) return 0; - if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET, + if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length)) return 0; /* Zero means error */ diff --git a/libmemcached/delete.c b/libmemcached/delete.c index 8b531acd..32d946ba 100644 --- a/libmemcached/delete.c +++ b/libmemcached/delete.c @@ -33,7 +33,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, unlikely (rc != MEMCACHED_SUCCESS) return rc; - unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0) + unlikely (memcached_server_count(ptr) == 0) return MEMCACHED_NO_SERVERS; server_key= memcached_generate_hash(ptr, master_key, master_key_length); diff --git a/libmemcached/flush.c b/libmemcached/flush.c index e9c63705..cb044b0c 100644 --- a/libmemcached/flush.c +++ b/libmemcached/flush.c @@ -32,6 +32,8 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, for (x= 0; x < memcached_server_count(ptr); x++) { bool no_reply= ptr->flags.no_reply; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); if (expiration) send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, @@ -41,10 +43,10 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "flush_all%s\r\n", no_reply ? " noreply" : ""); - rc= memcached_do(&ptr->hosts[x], buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, 1); if (rc == MEMCACHED_SUCCESS && !no_reply) - (void)memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); } return MEMCACHED_SUCCESS; @@ -53,7 +55,7 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, static memcached_return_t memcached_flush_binary(memcached_st *ptr, time_t expiration) { - unsigned int x; + uint32_t x; protocol_binary_request_flush request= {.bytes= {0}}; unlikely (memcached_server_count(ptr) == 0) @@ -68,22 +70,33 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, for (x= 0; x < memcached_server_count(ptr); x++) { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + if (ptr->flags.no_reply) + { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSHQ; + } else + { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH; - if (memcached_do(&ptr->hosts[x], request.bytes, + } + + if (memcached_do(instance, request.bytes, sizeof(request.bytes), 1) != MEMCACHED_SUCCESS) { - memcached_io_reset(&ptr->hosts[x]); + memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } } for (x= 0; x < memcached_server_count(ptr); x++) { - if (memcached_server_response_count(&ptr->hosts[x]) > 0) - (void)memcached_response(&ptr->hosts[x], NULL, 0, NULL); + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + if (memcached_server_response_count(instance) > 0) + (void)memcached_response(instance, NULL, 0, NULL); } return MEMCACHED_SUCCESS; diff --git a/libmemcached/flush_buffers.c b/libmemcached/flush_buffers.c index aeae5205..c037cb7b 100644 --- a/libmemcached/flush_buffers.c +++ b/libmemcached/flush_buffers.c @@ -5,17 +5,22 @@ memcached_return_t memcached_flush_buffers(memcached_st *memc) memcached_return_t ret= MEMCACHED_SUCCESS; for (uint32_t x= 0; x < memcached_server_count(memc); ++x) - if (memc->hosts[x].write_buffer_offset != 0) + { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc, x); + + if (instance->write_buffer_offset != 0) { - if (memc->hosts[x].fd == -1 && - (ret= memcached_connect(&memc->hosts[x])) != MEMCACHED_SUCCESS) + if (instance->fd == -1 && + (ret= memcached_connect(instance)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(ret); return ret; } - if (memcached_io_write(&memc->hosts[x], NULL, 0, 1) == -1) + if (memcached_io_write(instance, NULL, 0, 1) == -1) ret= MEMCACHED_SOME_ERRORS; } + } return ret; } diff --git a/libmemcached/get.c b/libmemcached/get.c index 7032a1a5..97f1c299 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -181,15 +181,18 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, */ for (x= 0; x < memcached_server_count(ptr); x++) { - if (memcached_server_response_count(&ptr->hosts[x])) + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + if (memcached_server_response_count(instance)) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; if (ptr->flags.no_block) - (void)memcached_io_write(&ptr->hosts[x], NULL, 0, 1); + (void)memcached_io_write(instance, NULL, 0, 1); - while(memcached_server_response_count(&ptr->hosts[x])) - (void)memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result); + while(memcached_server_response_count(instance)) + (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result); } } @@ -271,10 +274,13 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, */ for (x= 0; x < memcached_server_count(ptr); x++) { - if (memcached_server_response_count(&ptr->hosts[x])) + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + if (memcached_server_response_count(instance)) { /* We need to do something about non-connnected hosts in the future */ - if ((memcached_io_write(&ptr->hosts[x], "\r\n", 2, 1)) == -1) + if ((memcached_io_write(instance, "\r\n", 2, 1)) == -1) { rc= MEMCACHED_SOME_ERRORS; } @@ -429,23 +435,28 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; for (x= 0; x < memcached_server_count(ptr); x++) - if (memcached_server_response_count(&ptr->hosts[x])) + { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + if (memcached_server_response_count(instance)) { - if (memcached_io_write(&ptr->hosts[x], NULL, 0, 1) == -1) + if (memcached_io_write(instance, NULL, 0, 1) == -1) { - memcached_server_response_reset(&ptr->hosts[x]); - memcached_io_reset(&ptr->hosts[x]); + memcached_server_response_reset(instance); + memcached_io_reset(instance); rc= MEMCACHED_SOME_ERRORS; } - if (memcached_io_write(&ptr->hosts[x], request.bytes, + if (memcached_io_write(instance, request.bytes, sizeof(request.bytes), 1) == -1) { - memcached_server_response_reset(&ptr->hosts[x]); - memcached_io_reset(&ptr->hosts[x]); + memcached_server_response_reset(instance); + memcached_io_reset(instance); rc= MEMCACHED_SOME_ERRORS; } } + } } @@ -473,6 +484,8 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, for (x= 0; x < number_of_keys; ++x) { + memcached_server_instance_st *instance; + if (hash[x] == memcached_server_count(ptr)) continue; /* Already successfully sent */ @@ -488,12 +501,14 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, if (dead_servers[server]) continue; - if (memcached_server_response_count(&ptr->hosts[server]) == 0) + instance= memcached_server_instance_fetch(ptr, server); + + if (memcached_server_response_count(instance) == 0) { - rc= memcached_connect(&ptr->hosts[server]); + rc= memcached_connect(instance); if (rc != MEMCACHED_SUCCESS) { - memcached_io_reset(&ptr->hosts[server]); + memcached_io_reset(instance); dead_servers[server]= true; success= false; continue; @@ -520,18 +535,18 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, * that we might have processed some of the responses etc. For now, * just make sure we work _correctly_ */ - if ((memcached_io_write(&ptr->hosts[server], request.bytes, + if ((memcached_io_write(instance, request.bytes, sizeof(request.bytes), 0) == -1) || - (memcached_io_write(&ptr->hosts[server], keys[x], + (memcached_io_write(instance, keys[x], key_length[x], 1) == -1)) { - memcached_io_reset(&ptr->hosts[server]); + memcached_io_reset(instance); dead_servers[server]= true; success= false; continue; } - memcached_server_response_increment(&ptr->hosts[server]); + memcached_server_response_increment(instance); hash[x]= memcached_server_count(ptr); } diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 95d6ac0f..e3e9e9c6 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -28,8 +28,11 @@ static void sort_hosts(memcached_st *ptr) { if (memcached_server_count(ptr)) { - qsort(ptr->hosts, memcached_server_count(ptr), sizeof(memcached_server_instance_st), compare_servers); - ptr->hosts[0].number_of_hosts= memcached_server_count(ptr); + memcached_server_instance_st *instance; + + qsort(memcached_server_list(ptr), memcached_server_count(ptr), sizeof(memcached_server_instance_st), compare_servers); + instance= memcached_server_instance_fetch(ptr, 0); + instance->number_of_hosts= memcached_server_count(ptr); } } @@ -109,7 +112,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) return MEMCACHED_ERRNO; } - list = ptr->hosts; + list = memcached_server_list(ptr); /* count live servers (those without a retry delay set) */ is_auto_ejecting= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS); @@ -302,29 +305,40 @@ memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st return MEMCACHED_SUCCESS; count= memcached_servers_count(list); - new_host_list= ptr->call_realloc(ptr, ptr->hosts, + new_host_list= ptr->call_realloc(ptr, memcached_server_list(ptr), sizeof(memcached_server_instance_st) * (count + memcached_server_count(ptr))); if (! new_host_list) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - ptr->hosts= new_host_list; + memcached_server_list_set(ptr, new_host_list); for (x= 0; x < count; x++) { + memcached_server_instance_st *instance; + if ((ptr->flags.use_udp && list[x].type != MEMCACHED_CONNECTION_UDP) || ((list[x].type == MEMCACHED_CONNECTION_UDP) && ! (ptr->flags.use_udp)) ) return MEMCACHED_INVALID_HOST_PROTOCOL; WATCHPOINT_ASSERT(list[x].hostname[0] != 0); - memcached_server_create(ptr, &ptr->hosts[memcached_server_count(ptr)]); + + instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + + memcached_server_create(ptr, instance); /* TODO check return type */ - (void)memcached_server_create_with(ptr, &ptr->hosts[memcached_server_count(ptr)], list[x].hostname, + (void)memcached_server_create_with(ptr, instance, list[x].hostname, list[x].port, list[x].weight, list[x].type); ptr->number_of_hosts++; } - ptr->hosts[0].number_of_hosts= memcached_server_count(ptr); + + // Provides backwards compatibility with server list. + { + memcached_server_instance_st *instance; + instance= memcached_server_instance_fetch(ptr, 0); + instance->number_of_hosts= memcached_server_count(ptr); + } return run_distribution(ptr); } @@ -393,24 +407,27 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, memcached_connection_t type) { memcached_server_instance_st *new_host_list; + memcached_server_instance_st *instance; if ( (ptr->flags.use_udp && type != MEMCACHED_CONNECTION_UDP) || ( (type == MEMCACHED_CONNECTION_UDP) && (! ptr->flags.use_udp) ) ) return MEMCACHED_INVALID_HOST_PROTOCOL; - new_host_list= ptr->call_realloc(ptr, ptr->hosts, + new_host_list= ptr->call_realloc(ptr, memcached_server_list(ptr), sizeof(memcached_server_instance_st) * (ptr->number_of_hosts + 1)); if (new_host_list == NULL) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - ptr->hosts= new_host_list; + memcached_server_list_set(ptr, new_host_list); /* TODO: Check return type */ - (void)memcached_server_create_with(ptr, &ptr->hosts[memcached_server_count(ptr)], hostname, port, weight, type); + instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + (void)memcached_server_create_with(ptr, instance, hostname, port, weight, type); ptr->number_of_hosts++; - memcached_servers_set_count(&ptr->hosts[0], memcached_server_count(ptr)); + instance= memcached_server_instance_fetch(ptr, 0); + memcached_servers_set_count(instance, memcached_server_count(ptr)); return run_distribution(ptr); } @@ -419,7 +436,7 @@ memcached_return_t memcached_server_remove(memcached_server_st *st_ptr) { uint32_t x, host_index; memcached_st *ptr= st_ptr->root; - memcached_server_st *list= ptr->hosts; + memcached_server_st *list= memcached_server_list(ptr); for (x= 0, host_index= 0; x < memcached_server_count(ptr); x++) { diff --git a/libmemcached/io.c b/libmemcached/io.c index 793075a5..179bdc48 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -360,18 +360,21 @@ memcached_server_instance_st *memcached_io_get_readable_server(memcached_st *mem struct pollfd fds[MAX_SERVERS_TO_POLL]; unsigned int host_index= 0; - for (unsigned int x= 0; + for (uint32_t x= 0; x< memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL; ++x) { - if (memc->hosts[x].read_buffer_length > 0) /* I have data in the buffer */ - return &memc->hosts[x]; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc, x); - if (memcached_server_response_count(&memc->hosts[x]) > 0) + if (instance->read_buffer_length > 0) /* I have data in the buffer */ + return instance; + + if (memcached_server_response_count(instance) > 0) { fds[host_index].events = POLLIN; fds[host_index].revents = 0; - fds[host_index].fd = memc->hosts[x].fd; + fds[host_index].fd = instance->fd; ++host_index; } } @@ -379,9 +382,16 @@ memcached_server_instance_st *memcached_io_get_readable_server(memcached_st *mem if (host_index < 2) { /* We have 0 or 1 server with pending events.. */ - for (unsigned int x= 0; x< memcached_server_count(memc); ++x) - if (memcached_server_response_count(&memc->hosts[x]) > 0) - return &memc->hosts[x]; + for (uint32_t x= 0; x< memcached_server_count(memc); ++x) + { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc, x); + + if (memcached_server_response_count(instance) > 0) + { + return instance; + } + } return NULL; } @@ -398,10 +408,13 @@ memcached_server_instance_st *memcached_io_get_readable_server(memcached_st *mem { if (fds[x].revents & POLLIN) { - for (unsigned int y= 0; y < memcached_server_count(memc); ++y) + for (uint32_t y= 0; y < memcached_server_count(memc); ++y) { - if (memc->hosts[y].fd == fds[x].fd) - return &memc->hosts[y]; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc, y); + + if (instance->fd == fds[x].fd) + return instance; } } } diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 38468fb9..2709c084 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -72,9 +72,9 @@ void server_list_free(memcached_st *ptr, memcached_server_st *servers) void memcached_servers_reset(memcached_st *ptr) { - server_list_free(ptr, ptr->hosts); + server_list_free(ptr, memcached_server_list(ptr)); - ptr->hosts= NULL; + memcached_server_list_set(ptr, NULL); ptr->number_of_hosts= 0; ptr->last_disconnected_server= NULL; ptr->server_failure_limit= 0; @@ -84,7 +84,7 @@ void memcached_free(memcached_st *ptr) { /* If we have anything open, lets close it now */ memcached_quit(ptr); - server_list_free(ptr, ptr->hosts); + server_list_free(ptr, memcached_server_list(ptr)); memcached_result_free(&ptr->result); if (ptr->on_cleanup) @@ -154,8 +154,8 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) new_clone->io_key_prefetch= source->io_key_prefetch; new_clone->number_of_replicas= source->number_of_replicas; - if (source->hosts) - rc= memcached_server_push(new_clone, source->hosts); + if (memcached_server_list(source)) + rc= memcached_server_push(new_clone, memcached_server_list(source)); if (rc != MEMCACHED_SUCCESS) { diff --git a/libmemcached/quit.c b/libmemcached/quit.c index a8f70402..c22635a8 100644 --- a/libmemcached/quit.c +++ b/libmemcached/quit.c @@ -69,15 +69,19 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) void memcached_quit(memcached_st *ptr) { - unsigned int x; + uint32_t x; - if (ptr->hosts == NULL || - memcached_server_count(ptr) == 0) + if (memcached_server_count(ptr) == 0) return; - if (ptr->hosts && memcached_server_count(ptr)) + if (memcached_server_count(ptr)) { for (x= 0; x < memcached_server_count(ptr); x++) - memcached_quit_server(&ptr->hosts[x], 0); + { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + memcached_quit_server(instance, 0); + } } } diff --git a/libmemcached/server.c b/libmemcached/server.c index d104d023..0d343f1d 100644 --- a/libmemcached/server.c +++ b/libmemcached/server.c @@ -118,12 +118,14 @@ memcached_return_t memcached_server_cursor(memcached_st *ptr, for (y= 0; y < memcached_server_count(ptr); y++) { uint32_t x; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, y); for (x= 0; x < number_of_callbacks; x++) { unsigned int iferror; - iferror= (*callback[x])(ptr, &ptr->hosts[y], context); + iferror= (*callback[x])(ptr, instance, context); if (iferror) continue; diff --git a/libmemcached/server.h b/libmemcached/server.h index 10fa811c..f7531883 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -65,6 +65,7 @@ static inline uint32_t memcached_servers_set_count(memcached_server_st *servers, #define memcached_server_name(A,B) (B).hostname #define memcached_server_port(A,B) (B).port #define memcached_server_list(A) (A)->hosts +#define memcached_server_list_set(A,B) (A)->hosts=(B) #define memcached_server_response_count(A) (A)->cursor_active LIBMEMCACHED_API diff --git a/libmemcached/verbosity.c b/libmemcached/verbosity.c index 46b120e9..90a16f7e 100644 --- a/libmemcached/verbosity.c +++ b/libmemcached/verbosity.c @@ -2,7 +2,7 @@ memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity) { - unsigned int x; + uint32_t x; size_t send_length; memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -16,8 +16,10 @@ memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity for (x= 0; x < memcached_server_count(ptr); x++) { memcached_return_t rrc; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); - rrc= memcached_do(&ptr->hosts[x], buffer, send_length, 1); + rrc= memcached_do(instance, buffer, send_length, 1); if (rrc != MEMCACHED_SUCCESS) { rc= MEMCACHED_SOME_ERRORS; @@ -27,7 +29,7 @@ memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity unlikely (ptr->flags.use_udp) continue; - rrc= memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + rrc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); if (rrc != MEMCACHED_SUCCESS) rc= MEMCACHED_SOME_ERRORS; } diff --git a/libmemcached/version.c b/libmemcached/version.c index 91e926e3..d854efdc 100644 --- a/libmemcached/version.c +++ b/libmemcached/version.c @@ -34,15 +34,17 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) for (x= 0; x < memcached_server_count(ptr); x++) { memcached_return_t rrc; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); - rrc= memcached_do(&ptr->hosts[x], command, send_length, 1); + rrc= memcached_do(instance, command, send_length, 1); if (rrc != MEMCACHED_SUCCESS) { rc= MEMCACHED_SOME_ERRORS; continue; } - rrc= memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + rrc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); if (rrc != MEMCACHED_SUCCESS) { rc= MEMCACHED_SOME_ERRORS; @@ -53,13 +55,13 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) response_ptr= index(buffer, ' '); response_ptr++; - ptr->hosts[x].major_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10); + instance->major_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10); response_ptr= index(response_ptr, '.'); response_ptr++; - ptr->hosts[x].minor_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10); + instance->minor_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10); response_ptr= index(response_ptr, '.'); response_ptr++; - ptr->hosts[x].micro_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10); + instance->micro_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10); } return rc; @@ -79,10 +81,13 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) { memcached_return_t rrc; - rrc= memcached_do(&ptr->hosts[x], request.bytes, sizeof(request.bytes), 1); + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + rrc= memcached_do(instance, request.bytes, sizeof(request.bytes), 1); if (rrc != MEMCACHED_SUCCESS) { - memcached_io_reset(&ptr->hosts[x]); + memcached_io_reset(instance); rc= MEMCACHED_SOME_ERRORS; continue; } @@ -90,23 +95,26 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) for (x= 0; x < memcached_server_count(ptr); x++) { - if (memcached_server_response_count(&ptr->hosts[x]) > 0) + memcached_server_instance_st *instance= + memcached_server_instance_fetch(ptr, x); + + if (memcached_server_response_count(instance) > 0) { memcached_return_t rrc; char buffer[32]; char *p; - rrc= memcached_response(&ptr->hosts[x], buffer, sizeof(buffer), NULL); + rrc= memcached_response(instance, buffer, sizeof(buffer), NULL); if (rrc != MEMCACHED_SUCCESS) { - memcached_io_reset(&ptr->hosts[x]); + memcached_io_reset(instance); rc= MEMCACHED_SOME_ERRORS; continue; } - ptr->hosts[x].major_version= (uint8_t)strtol(buffer, &p, 10); - ptr->hosts[x].minor_version= (uint8_t)strtol(p + 1, &p, 10); - ptr->hosts[x].micro_version= (uint8_t)strtol(p + 1, NULL, 10); + instance->major_version= (uint8_t)strtol(buffer, &p, 10); + instance->minor_version= (uint8_t)strtol(p + 1, &p, 10); + instance->micro_version= (uint8_t)strtol(p + 1, NULL, 10); } } diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 4092d951..6916a32c 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -100,8 +100,11 @@ test_return_t world_pre_run(libmemcached_test_container_st *container) for (loop= 0; loop < memcached_server_list_count(container->construct.servers); loop++) { - test_truth(container->memc->hosts[loop].fd == -1); - test_truth(container->memc->hosts[loop].cursor_active == 0); + memcached_server_st *instance= + memcached_server_instance_fetch(container->memc, loop); + + test_truth(instance->fd == -1); + test_truth(instance->cursor_active == 0); } return TEST_SUCCESS; diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 04d7e21e..bb5a9deb 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -109,7 +109,7 @@ static test_return_t server_sort_test(memcached_st *ptr __attribute__((unused)) test_ports[x]= (uint32_t)random() % 64000; rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); test_truth(memcached_server_count(local_memc) == x + 1); - test_truth(memcached_servers_count(local_memc->hosts) == x+1); + test_truth(memcached_servers_count(memcached_server_list(local_memc)) == x+1); test_truth(rc == MEMCACHED_SUCCESS); } @@ -5234,6 +5234,9 @@ static test_return_t regression_bug_442914(memcached_st *memc) static test_return_t regression_bug_447342(memcached_st *memc) { + memcached_server_instance_st *instance_one; + memcached_server_instance_st *instance_two; + if (memcached_server_count(memc) < 3 || pre_replication(memc) != MEMCACHED_SUCCESS) return TEST_SKIPPED; @@ -5290,11 +5293,13 @@ static test_return_t regression_bug_447342(memcached_st *memc) * This is to verify correct behavior in the library. Fake that two servers * are dead.. */ - in_port_t port0= memc->hosts[0].port; - in_port_t port2= memc->hosts[2].port; + instance_one= memcached_server_instance_fetch(memc, 0); + instance_two= memcached_server_instance_fetch(memc, 2); + in_port_t port0= instance_one->port; + in_port_t port2= instance_two->port; - memc->hosts[0].port= 0; - memc->hosts[2].port= 0; + instance_one->port= 0; + instance_two->port= 0; rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys); test_truth(rc == MEMCACHED_SUCCESS); @@ -5304,8 +5309,8 @@ static test_return_t regression_bug_447342(memcached_st *memc) test_truth(counter == (unsigned int)max_keys); /* restore the memc handle */ - memc->hosts[0].port= port0; - memc->hosts[2].port= port2; + instance_one->port= port0; + instance_two->port= port2; memcached_quit(memc); @@ -5320,8 +5325,8 @@ static test_return_t regression_bug_447342(memcached_st *memc) } memcached_quit(memc); - memc->hosts[0].port= 0; - memc->hosts[2].port= 0; + instance_one->port= 0; + instance_two->port= 0; /* now retry the command, this time we should have cache misses */ rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys); @@ -5340,8 +5345,8 @@ static test_return_t regression_bug_447342(memcached_st *memc) free(key_length); /* restore the memc handle */ - memc->hosts[0].port= port0; - memc->hosts[2].port= port2; + instance_one->port= port0; + instance_two->port= port2; return TEST_SUCCESS; } @@ -5462,6 +5467,7 @@ static test_return_t test_get_last_disconnect(memcached_st *memc) static test_return_t wrong_failure_counter_test(memcached_st *memc) { memcached_return_t rc; + memcached_server_instance_st *instance; /* Set value to force connection to the server */ const char *key= "marmotte"; @@ -5482,11 +5488,12 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + instance= memcached_server_instance_fetch(memc, 0); /* The test is to see that the memcached_quit doesn't increase the * the server failure conter, so let's ensure that it is zero * before sending quit */ - memc->hosts[0].server_failure_counter= 0; + instance->server_failure_counter= 0; memcached_quit(memc); @@ -5494,7 +5501,7 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) * Please note that this isn't bullet proof, because an error could * occur... */ - test_truth(memc->hosts[0].server_failure_counter == 0); + test_truth(instance->server_failure_counter == 0); /* restore the instance */ memc->number_of_hosts= number_of_hosts;