X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fstats.c;h=cf7f4d68355cc87fc668be0a0775c39407e04b0d;hb=02fa1c85c842e175225f74b0e213a5600d4c03cf;hp=e5f9a20f3eb1df41ba76eb56458fc724bfd8050d;hpb=7c7750f02368b570353ea109f23a0ea26d226e02;p=m6w6%2Flibmemcached diff --git a/libmemcached/stats.c b/libmemcached/stats.c index e5f9a20f..cf7f4d68 100644 --- a/libmemcached/stats.c +++ b/libmemcached/stats.c @@ -33,7 +33,7 @@ static const char *memcached_stat_keys[] = { static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char *value) { - if (strlen(key) < 1) + if (strlen(key) < 1) { WATCHPOINT_STRING(key); return MEMCACHED_UNKNOWN_STAT_KEY; @@ -79,7 +79,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char } else if (!strcmp("curr_items", key)) { - memc_stat->curr_items= (uint32_t) strtol(value, (char **)NULL, 10); + memc_stat->curr_items= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("total_items", key)) { @@ -149,7 +149,9 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char strcmp("cmd_flush", key) == 0 || strcmp("accepting_conns", key) == 0 || strcmp("listen_disabled_num", key) == 0 || - strcmp("conn_yields", key) == 0)) + strcmp("conn_yields", key) == 0 || + strcmp("auth_cmds", key) == 0 || + strcmp("auth_errors", key) == 0)) { WATCHPOINT_STRING(key); return MEMCACHED_UNKNOWN_STAT_KEY; @@ -158,7 +160,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char return MEMCACHED_SUCCESS; } -char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, +char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, const char *key, memcached_return_t *error) { char buffer[SMALL_STRING_LEN]; @@ -224,10 +226,9 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, return ret; } -static memcached_return_t binary_stats_fetch(memcached_st *ptr, - memcached_stat_st *memc_stat, +static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, char *args, - unsigned int server_key) + memcached_server_instance_st *instance) { memcached_return_t rc; @@ -237,7 +238,7 @@ static memcached_return_t binary_stats_fetch(memcached_st *ptr, request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - if (args != NULL) + if (args != NULL) { size_t len= strlen(args); @@ -248,35 +249,35 @@ static memcached_return_t binary_stats_fetch(memcached_st *ptr, request.message.header.request.keylen= htons((uint16_t)len); request.message.header.request.bodylen= htonl((uint32_t) len); - if ((memcached_do(&ptr->hosts[server_key], request.bytes, + if ((memcached_do(instance, request.bytes, sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) || - (memcached_io_write(&ptr->hosts[server_key], args, len, 1) == -1)) + (memcached_io_write(instance, args, len, 1) == -1)) { - memcached_io_reset(&ptr->hosts[server_key]); + memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } } else { - if (memcached_do(&ptr->hosts[server_key], request.bytes, - sizeof(request.bytes), 1) != MEMCACHED_SUCCESS) + if (memcached_do(instance, request.bytes, + sizeof(request.bytes), 1) != MEMCACHED_SUCCESS) { - memcached_io_reset(&ptr->hosts[server_key]); + memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } } - memcached_server_response_decrement(&ptr->hosts[server_key]); - do + memcached_server_response_decrement(instance); + do { - rc= memcached_response(&ptr->hosts[server_key], buffer, + rc= memcached_response(instance, buffer, sizeof(buffer), NULL); if (rc == MEMCACHED_END) break; - unlikely (rc != MEMCACHED_SUCCESS) + unlikely (rc != MEMCACHED_SUCCESS) { - memcached_io_reset(&ptr->hosts[server_key]); + memcached_io_reset(instance); return rc; } @@ -290,37 +291,36 @@ static memcached_return_t binary_stats_fetch(memcached_st *ptr, /* shit... memcached_response will decrement the counter, so I need to ** reset it.. todo: look at this and try to find a better solution. */ - ptr->hosts[server_key].cursor_active= 0; + instance->cursor_active= 0; return MEMCACHED_SUCCESS; } -static memcached_return_t ascii_stats_fetch(memcached_st *ptr, - memcached_stat_st *memc_stat, +static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, char *args, - unsigned int server_key) + memcached_server_instance_st *instance) { memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; size_t send_length; if (args) - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats %s\r\n", args); else - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats\r\n"); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, 1); if (rc != MEMCACHED_SUCCESS) goto error; while (1) { - rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); if (rc == MEMCACHED_STAT) { @@ -357,7 +357,7 @@ error: memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error) { - unsigned int x; + uint32_t x; memcached_return_t rc; memcached_stat_st *stats; @@ -367,7 +367,9 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur return NULL; } - stats= ptr->call_calloc(ptr, ptr->number_of_hosts, sizeof(memcached_stat_st)); + stats= ptr->call_calloc(ptr, memcached_server_count(ptr), sizeof(memcached_stat_st)); + + stats->root= ptr; if (!stats) { @@ -376,14 +378,21 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur } rc= MEMCACHED_SUCCESS; - for (x= 0; x < ptr->number_of_hosts; x++) + for (x= 0; x < memcached_server_count(ptr); x++) { memcached_return_t temp_return; + memcached_server_instance_st *instance; + + instance= memcached_server_instance_fetch(ptr, x); if (ptr->flags.binary_protocol) - temp_return= binary_stats_fetch(ptr, stats + x, args, x); + { + temp_return= binary_stats_fetch(stats + x, args, instance); + } else - temp_return= ascii_stats_fetch(ptr, stats + x, args, x); + { + temp_return= ascii_stats_fetch(stats + x, args, instance); + } if (temp_return != MEMCACHED_SUCCESS) rc= MEMCACHED_SOME_ERRORS; @@ -393,33 +402,40 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur return stats; } -memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args, +memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args, const char *hostname, in_port_t port) { memcached_return_t rc; memcached_st memc; memcached_st *memc_ptr; + memcached_server_instance_st *instance; memc_ptr= memcached_create(&memc); WATCHPOINT_ASSERT(memc_ptr); memcached_server_add(&memc, hostname, port); + instance= memcached_server_instance_fetch(memc_ptr, 0); + if (memc.flags.binary_protocol) - rc= binary_stats_fetch(&memc, memc_stat, args, 0); + { + rc= binary_stats_fetch(memc_stat, args, instance); + } else - rc= ascii_stats_fetch(&memc, memc_stat, args, 0); + { + rc= ascii_stats_fetch(memc_stat, args, instance); + } memcached_free(&memc); return rc; } -/* +/* We make a copy of the keys since at some point in the not so distant future we will add support for "found" keys. */ -char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat, +char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat, memcached_return_t *error) { (void) memc_stat; @@ -449,8 +465,16 @@ void memcached_stat_free(memcached_st *ptr, memcached_stat_st *memc_stat) return; } - if (ptr) + if (memc_stat->root) + { + memc_stat->root->call_free(ptr, memc_stat); + } + else if (ptr) + { ptr->call_free(ptr, memc_stat); + } else + { free(memc_stat); + } }