From: Trond Norbye Date: Tue, 6 Oct 2009 13:59:34 +0000 (+0200) Subject: Bug 421108: memstat reports same value for bytes, bytes_read and bytes_written X-Git-Tag: 0.34~11^2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b2aca5463d5f5e12969f6ee3eaf40297311a1057;p=m6w6%2Flibmemcached Bug 421108: memstat reports same value for bytes, bytes_read and bytes_written --- diff --git a/libmemcached/memcached_stats.c b/libmemcached/memcached_stats.c index 0f4a97f7..04928f04 100644 --- a/libmemcached/memcached_stats.c +++ b/libmemcached/memcached_stats.c @@ -185,8 +185,6 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_items); else if (!memcmp("total_items", key, strlen("total_items"))) length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_items); - else if (!memcmp("bytes", key, strlen("bytes"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes); else if (!memcmp("curr_connections", key, strlen("curr_connections"))) length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_connections); else if (!memcmp("total_connections", key, strlen("total_connections"))) @@ -207,6 +205,8 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_read); else if (!memcmp("bytes_written", key, strlen("bytes_written"))) length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_written); + else if (!memcmp("bytes", key, strlen("bytes"))) + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes); else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes"))) length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->limit_maxbytes); else if (!memcmp("threads", key, strlen("threads"))) diff --git a/tests/function.c b/tests/function.c index 66f819de..e87aa28a 100644 --- a/tests/function.c +++ b/tests/function.c @@ -4580,6 +4580,41 @@ static test_return regression_bug_434843_buffered(memcached_st *memc) return regression_bug_434843(memc); } +static test_return regression_bug_421108(memcached_st *memc) +{ + memcached_return rc; + memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc); + assert(rc == MEMCACHED_SUCCESS); + + char *bytes= memcached_stat_get_value(memc, memc_stat, "bytes", &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(bytes != NULL); + char *bytes_read= memcached_stat_get_value(memc, memc_stat, + "bytes_read", &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(bytes_read != NULL); + + char *bytes_written= memcached_stat_get_value(memc, memc_stat, + "bytes_written", &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(bytes_written != NULL); + + /* + * We did a flush before running the test, so bytes should be 0, but + * bytes_read and butes_written cannot be zero ;-) + */ + assert(strcmp(bytes, "0") == 0); + assert(strcmp(bytes, bytes_read) != 0); + assert(strcmp(bytes, bytes_written) != 0); + + /* Release allocated resources */ + free(bytes); + free(bytes_read); + free(bytes_written); + memcached_stat_free(NULL, memc_stat); + return TEST_SUCCESS; +} + test_st udp_setup_server_tests[] ={ {"set_udp_behavior_test", 0, set_udp_behavior_test}, {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test}, @@ -4743,6 +4778,7 @@ test_st regression_tests[]= { {"lp:434484", 1, regression_bug_434484 }, {"lp:434843", 1, regression_bug_434843 }, {"lp:434843 buffered", 1, regression_bug_434843_buffered }, + {"lp:421108", 1, regression_bug_421108 }, {0, 0, 0} };