From: Michael Wallner Date: Tue, 28 Jan 2020 11:22:11 +0000 (+0100) Subject: attempt to fix cachedump test X-Git-Tag: pre_cmake~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fc51e5255fe2e55848823d838c1326dd8d27ccad;p=awesomized%2Flibmemcached attempt to fix cachedump test this should probably be replaced with `lru_crawler metadump all` for newer servers with lru_crawler enabled --- diff --git a/libmemcached/dump.cc b/libmemcached/dump.cc index 4fcf7de2..c0c4ed63 100644 --- a/libmemcached/dump.cc +++ b/libmemcached/dump.cc @@ -46,6 +46,7 @@ static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) { + memcached_version(memc); /* MAX_NUMBER_OF_SLAB_CLASSES is defined to 200 in Memcached 1.4.10 */ for (uint32_t x= 0; x < 200; x++) { @@ -70,10 +71,13 @@ static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callbac { memcached_instance_st* instance= memcached_instance_fetch(memc, server_key); - memcached_return_t vdo_rc; - if (memcached_failed((vdo_rc= memcached_vdo(instance, vector, 3, true)))) - { - return vdo_rc; + // skip slabs >63 for server versions >= 1.4.23 + if (x < 64 || memcached_version_instance_cmp(instance, 1, 4, 23) < 0) { + memcached_return_t vdo_rc; + if (memcached_failed((vdo_rc= memcached_vdo(instance, vector, 3, true)))) + { + return vdo_rc; + } } } diff --git a/libmemcached/version.cc b/libmemcached/version.cc index e779a769..53d24c1c 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -199,6 +199,29 @@ void memcached_version_instance(memcached_instance_st* instance) } } +int8_t memcached_version_instance_cmp(memcached_instance_st *instance, + uint8_t maj, uint8_t min, uint8_t mic) +{ + if (!instance || memcached_server_major_version(instance) == UINT8_MAX) { + return INT8_MIN; + } else { + uint32_t sv, cv; + + sv = memcached_server_micro_version(instance) + |memcached_server_minor_version(instance) << 8 + |memcached_server_major_version(instance) << 16 + ; + cv = mic + |min << 8 + |maj << 16 + ; + if (sv < cv) { + return -1; + } + return sv != cv; + } +} + memcached_return_t memcached_version(memcached_st *shell) { Memcached* memc= memcached2Memcached(shell); diff --git a/libmemcached/version.hpp b/libmemcached/version.hpp index f420a262..0c167433 100644 --- a/libmemcached/version.hpp +++ b/libmemcached/version.hpp @@ -42,3 +42,5 @@ #pragma once void memcached_version_instance(memcached_instance_st*); +int8_t memcached_version_instance_cmp(memcached_instance_st*, + uint8_t maj, uint8_t min, uint8_t mic); diff --git a/tests/libmemcached-1.0/dump.cc b/tests/libmemcached-1.0/dump.cc index 1e19c4a9..c0da31c4 100644 --- a/tests/libmemcached-1.0/dump.cc +++ b/tests/libmemcached-1.0/dump.cc @@ -49,15 +49,18 @@ using namespace libtest; #include "tests/libmemcached-1.0/dump.h" static memcached_return_t callback_dump_counter(const memcached_st *, - const char*, // key, - size_t, // length, + const char* key, + size_t length, void *context) { size_t *counter= (size_t *)context; #if 0 std::cerr.write(key, length); - std::cerr << std::endl; + std::cerr << ": " << *counter << std::endl; +#else + (void)key; + (void)length; #endif *counter= *counter +1; @@ -78,6 +81,9 @@ static memcached_return_t item_counter(const memcached_instance_st * , { return MEMCACHED_FAILURE; } +#if 0 + std::cerr << "# " << number_value << " items " << std::endl; +#endif *counter= *counter +number_value; } @@ -110,22 +116,24 @@ test_return_t memcached_dump_TEST2(memcached_st *memc) { test_skip(false, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - /* The dump test relies on there being at least 32 items in memcached */ for (uint32_t x= 0; x < memcached_dump_TEST2_COUNT; x++) { char key[1024]; - int length= snprintf(key, sizeof(key), "%s%u", __func__, x); + int length= snprintf(key, sizeof(key), "%s_%u", __func__, x); test_true(length > 0); test_compare(MEMCACHED_SUCCESS, memcached_set(memc, key, length, - NULL, 0, // Zero length values + key, length, time_t(0), uint32_t(0))); } memcached_quit(memc); + // give memcached some time + libtest::dream(1, 0); + uint64_t counter= 0; test_compare(MEMCACHED_SUCCESS, memcached_stat_execute(memc, NULL, item_counter, &counter));