From: Date: Wed, 23 Apr 2008 11:35:04 +0000 (-0700) Subject: Cleanup of behaviors around ketama X-Git-Tag: _20~1^2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=42b674b747eae466d9ca0d766555c53ae75dc367;p=m6w6%2Flibmemcached Cleanup of behaviors around ketama --- diff --git a/clients/utilities.c b/clients/utilities.c index d19f57ec..c845ed1a 100644 --- a/clients/utilities.c +++ b/clients/utilities.c @@ -92,8 +92,6 @@ void process_hash_option(memcached_st *memc, char *opt_hash) set= MEMCACHED_HASH_FNV1_32; else if (!strcasecmp(opt_hash, "FNV1A_32")) set= MEMCACHED_HASH_FNV1A_32; - else if (!strcasecmp(opt_hash, "KETAMA")) - set= MEMCACHED_HASH_KETAMA; else { fprintf(stderr, "hash: type not recognized %s\n", opt_hash); diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 2dd6ae2d..c33b2af5 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -51,7 +51,8 @@ environments). =item MEMCACHED_BEHAVIOR_HASH -Makes the default hashing algorithm for keys use MD5. The value can be set to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_KETAMA. The behavior for all hashes but MEMCACHED_HASH_DEFAULT is identitical to the Java driver written by Dustin Sallings. +Makes the default hashing algorithm for keys use MD5. The value can be set +to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, and MEMCACHED_HASH_FNV1A_32. The behavior for all hashes but MEMCACHED_HASH_DEFAULT is identitical to the Java driver written by Dustin Sallings. =item MEMCACHED_BEHAVIOR_DISTRIBUTION @@ -71,6 +72,11 @@ Memcached can cache named lookups so that DNS lookups are made only once. Support CAS operations (this is not enabled by default at this point in the server since it imposes a slight performance penalty). +=item MEMCACHED_BEHAVIOR_KETAMA + +Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA +and the hash to MEMCACHED_HASH_MD5. + =item MEMCACHED_BEHAVIOR_POLL_TIMEOUT Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long. diff --git a/libmemcached/common.h b/libmemcached/common.h index 50ee60bf..b2406196 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -70,7 +70,7 @@ typedef enum { MEM_TCP_NODELAY= (1 << 1), MEM_REUSE_MEMORY= (1 << 2), MEM_USE_MD5= (1 << 3), - MEM_USE_KETAMA= (1 << 4), + /* 4 was once Ketama */ MEM_USE_CRC= (1 << 5), MEM_USE_CACHE_LOOKUPS= (1 << 6), MEM_SUPPORT_CAS= (1 << 7), @@ -90,7 +90,7 @@ memcached_return memcached_connect(memcached_server_st *ptr); memcached_return memcached_response(memcached_server_st *ptr, char *buffer, size_t buffer_length, memcached_result_st *result); -unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length); +uint32_t memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length); void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death); #define memcached_server_response_increment(A) (A)->cursor_active++ diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index 351b87cd..aac63f42 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -43,6 +43,18 @@ memcached_return memcached_behavior_set(memcached_st *ptr, run_distribution(ptr); break; } + case MEMCACHED_BEHAVIOR_KETAMA: + if (data) + { + ptr->hash= MEMCACHED_HASH_MD5; + ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA; + } + else + { + ptr->hash= 0; + ptr->distribution= 0; + } + break; case MEMCACHED_BEHAVIOR_HASH: ptr->hash= (memcached_hash)(data); break; @@ -53,9 +65,6 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_VERIFY_KEY: set_behavior_flag(ptr, MEM_VERIFY_KEY, data); break; - case MEMCACHED_BEHAVIOR_KETAMA: - set_behavior_flag(ptr, MEM_USE_KETAMA, data); - break; case MEMCACHED_BEHAVIOR_SORT_HOSTS: { set_behavior_flag(ptr, MEM_USE_SORT_HOSTS, data); @@ -114,11 +123,10 @@ uint64_t memcached_behavior_get(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_DISTRIBUTION: return ptr->distribution; + case MEMCACHED_BEHAVIOR_KETAMA: + return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA && ptr->hash == MEMCACHED_HASH_MD5 ) ? 1 : 0; case MEMCACHED_BEHAVIOR_HASH: return ptr->hash; - case MEMCACHED_BEHAVIOR_KETAMA: - temp_flag= MEM_USE_KETAMA; - break; case MEMCACHED_BEHAVIOR_SORT_HOSTS: temp_flag= MEM_USE_SORT_HOSTS; break; diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index cb7b2095..f1dd52e9 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -107,7 +107,6 @@ typedef enum { MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, - MEMCACHED_HASH_KETAMA, MEMCACHED_HASH_HSIEH, MEMCACHED_HASH_MURMUR, } memcached_hash; diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index 4cb442cb..e2454ac9 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -10,7 +10,6 @@ static uint32_t FNV_32_PRIME= 16777619; /* Prototypes */ static uint32_t internal_generate_hash(char *key, size_t key_length); static uint32_t internal_generate_md5(char *key, size_t key_length); -static uint32_t internal_generate_ketama_md5(char *key, size_t key_length); uint32_t generate_hash(memcached_st *ptr, char *key, size_t key_length) { @@ -81,11 +80,6 @@ uint32_t generate_hash(memcached_st *ptr, char *key, size_t key_length) } } break; - case MEMCACHED_HASH_KETAMA: - { - hash= internal_generate_ketama_md5(key, key_length); - break; - } case MEMCACHED_HASH_HSIEH: { hash= hsieh_hash(key, key_length); @@ -109,7 +103,7 @@ unsigned int dispatch_host(memcached_st *ptr, uint32_t hash) case MEMCACHED_DISTRIBUTION_CONSISTENT: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: { - int num= ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER; + uint32_t num= ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER; WATCHPOINT_ASSERT(ptr->continuum); hash= hash; @@ -163,7 +157,11 @@ unsigned int dispatch_host(memcached_st *ptr, uint32_t hash) return 0; } -unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length) +/* + One day make this public, and have it return the actual memcached_server_st + to the calling application. +*/ +uint32_t memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length) { uint32_t hash= 1; /* Just here to remove compile warning */ @@ -202,18 +200,6 @@ static uint32_t internal_generate_md5(char *key, size_t key_length) md5_signature((unsigned char*)key, (unsigned int)key_length, results); - return (uint32_t)(( results[3] << 24 ) - | ( results[2] << 16 ) - | ( results[1] << 8 ) - | results[0] ); -} - -static uint32_t internal_generate_ketama_md5(char *key, size_t key_length) -{ - unsigned char results[16]; - - md5_signature((unsigned char*)key, (unsigned int)key_length, results); - return ((uint32_t) (results[3] & 0xFF) << 24) | ((uint32_t) (results[2] & 0xFF) << 16) | ((uint32_t) (results[1] & 0xFF) << 8) diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 03ea81e3..18e37d7b 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -143,18 +143,6 @@ static int continuum_item_cmp(const void *t1, const void *t2) return -1; } -static uint32_t internal_generate_ketama_md5(char *key, size_t key_length) -{ - unsigned char results[16]; - - md5_signature((unsigned char*)key, (unsigned int)key_length, results); - - return ( (results[3] ) << 24) - | ( (results[2] ) << 16) - | ( (results[1] ) << 8) - | ( results[0] ); -} - memcached_return update_continuum(memcached_st *ptr) { uint32_t index; @@ -190,7 +178,7 @@ memcached_return update_continuum(memcached_st *ptr) sort_host_length= snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, "%s:%d-%d", list[host_index].hostname, list[host_index].port, index); WATCHPOINT_ASSERT(sort_host_length); - value= internal_generate_ketama_md5(sort_host, sort_host_length); + value= generate_hash(ptr, sort_host, sort_host_length); ptr->continuum[continuum_index].index= host_index; ptr->continuum[continuum_index++].value= value; } diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index 11b4258f..edc5250e 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -36,14 +36,14 @@ static pairs_st *global_pairs; static char *global_keys[GLOBAL_COUNT]; static size_t global_keys_length[GLOBAL_COUNT]; -uint8_t cleanup_pairs(memcached_st *memc) +test_return cleanup_pairs(memcached_st *memc) { pairs_free(global_pairs); return 0; } -uint8_t generate_pairs(memcached_st *memc) +test_return generate_pairs(memcached_st *memc) { unsigned long long x; global_pairs= pairs_generate(GLOBAL_COUNT, 400); @@ -58,7 +58,7 @@ uint8_t generate_pairs(memcached_st *memc) return 0; } -uint8_t drizzle(memcached_st *memc) +test_return drizzle(memcached_st *memc) { unsigned int x; memcached_return rc; @@ -152,7 +152,7 @@ memcached_return enable_consistent(memcached_st *memc) Set the value, then quit to make sure it is flushed. Come back in and test that add fails. */ -uint8_t add_test(memcached_st *memc) +test_return add_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -183,7 +183,7 @@ uint8_t add_test(memcached_st *memc) * repeating add_tests many times * may show a problem in timing */ -uint8_t many_adds(memcached_st *memc) +test_return many_adds(memcached_st *memc) { unsigned int i; for (i = 0; i < TEST_COUNTER; i++){ diff --git a/tests/function.c b/tests/function.c index dc4e6e9a..3f7e096e 100644 --- a/tests/function.c +++ b/tests/function.c @@ -32,7 +32,7 @@ static pairs_st *global_pairs; static char *global_keys[GLOBAL_COUNT]; static size_t global_keys_length[GLOBAL_COUNT]; -uint8_t init_test(memcached_st *not_used) +test_return init_test(memcached_st *not_used) { memcached_st memc; @@ -42,7 +42,7 @@ uint8_t init_test(memcached_st *not_used) return 0; } -uint8_t server_list_null_test(memcached_st *ptr) +test_return server_list_null_test(memcached_st *ptr) { memcached_server_st *server_list; memcached_return rc; @@ -72,7 +72,7 @@ memcached_return server_display_function(memcached_st *ptr, memcached_server_st return MEMCACHED_SUCCESS; } -uint8_t server_sort_test(memcached_st *ptr) +test_return server_sort_test(memcached_st *ptr) { uint8_t x; uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */ @@ -113,7 +113,7 @@ memcached_return server_display_unsort_function(memcached_st *ptr, memcached_ser return MEMCACHED_SUCCESS; } -uint8_t server_unsort_test(memcached_st *ptr) +test_return server_unsort_test(memcached_st *ptr) { uint8_t x; uint32_t counter= 0; /* Prime the value for the assert in server_display_function */ @@ -148,7 +148,7 @@ uint8_t server_unsort_test(memcached_st *ptr) return 0; } -uint8_t allocation_test(memcached_st *not_used) +test_return allocation_test(memcached_st *not_used) { memcached_st *memc; memc= memcached_create(NULL); @@ -158,7 +158,7 @@ uint8_t allocation_test(memcached_st *not_used) return 0; } -uint8_t clone_test(memcached_st *memc) +test_return clone_test(memcached_st *memc) { /* All null? */ { @@ -197,7 +197,7 @@ uint8_t clone_test(memcached_st *memc) return 0; } -uint8_t connection_test(memcached_st *memc) +test_return connection_test(memcached_st *memc) { memcached_return rc; @@ -207,7 +207,7 @@ uint8_t connection_test(memcached_st *memc) return 0; } -uint8_t error_test(memcached_st *memc) +test_return error_test(memcached_st *memc) { memcached_return rc; @@ -219,7 +219,7 @@ uint8_t error_test(memcached_st *memc) return 0; } -uint8_t set_test(memcached_st *memc) +test_return set_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -233,7 +233,7 @@ uint8_t set_test(memcached_st *memc) return 0; } -uint8_t append_test(memcached_st *memc) +test_return append_test(memcached_st *memc) { memcached_return rc; char *key= "fig"; @@ -269,7 +269,7 @@ uint8_t append_test(memcached_st *memc) return 0; } -uint8_t append_binary_test(memcached_st *memc) +test_return append_binary_test(memcached_st *memc) { memcached_return rc; char *key= "numbers"; @@ -315,7 +315,7 @@ uint8_t append_binary_test(memcached_st *memc) return 0; } -uint8_t cas2_test(memcached_st *memc) +test_return cas2_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -359,7 +359,7 @@ uint8_t cas2_test(memcached_st *memc) return 0; } -uint8_t cas_test(memcached_st *memc) +test_return cas_test(memcached_st *memc) { memcached_return rc; char *key= "fun"; @@ -411,7 +411,7 @@ uint8_t cas_test(memcached_st *memc) return 0; } -uint8_t prepend_test(memcached_st *memc) +test_return prepend_test(memcached_st *memc) { memcached_return rc; char *key= "fig"; @@ -451,7 +451,7 @@ uint8_t prepend_test(memcached_st *memc) Set the value, then quit to make sure it is flushed. Come back in and test that add fails. */ -uint8_t add_test(memcached_st *memc) +test_return add_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -471,14 +471,14 @@ uint8_t add_test(memcached_st *memc) /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */ if (setting_value) - assert(rc == MEMCACHED_NOTSTORED || MEMCACHED_STORED); + assert(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED); else assert(rc == MEMCACHED_NOTSTORED); return 0; } -uint8_t add_wrapper(memcached_st *memc) +test_return add_wrapper(memcached_st *memc) { unsigned int x; @@ -488,7 +488,7 @@ uint8_t add_wrapper(memcached_st *memc) return 0; } -uint8_t replace_test(memcached_st *memc) +test_return replace_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -508,7 +508,7 @@ uint8_t replace_test(memcached_st *memc) return 0; } -uint8_t delete_test(memcached_st *memc) +test_return delete_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -525,7 +525,7 @@ uint8_t delete_test(memcached_st *memc) return 0; } -uint8_t flush_test(memcached_st *memc) +test_return flush_test(memcached_st *memc) { memcached_return rc; @@ -542,7 +542,7 @@ memcached_return server_function(memcached_st *ptr, memcached_server_st *server, return MEMCACHED_SUCCESS; } -uint8_t memcached_server_cursor_test(memcached_st *memc) +test_return memcached_server_cursor_test(memcached_st *memc) { char *context= "foo bad"; memcached_server_function callbacks[1]; @@ -553,7 +553,7 @@ uint8_t memcached_server_cursor_test(memcached_st *memc) return 0; } -uint8_t bad_key_test(memcached_st *memc) +test_return bad_key_test(memcached_st *memc) { memcached_return rc; char *key= "foo bad"; @@ -596,7 +596,7 @@ memcached_return read_through_trigger(memcached_st *memc, return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE)); } -uint8_t read_through(memcached_st *memc) +test_return read_through(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -640,7 +640,7 @@ memcached_return delete_trigger(memcached_st *ptr, char *key, size_t key_length return MEMCACHED_SUCCESS; } -uint8_t delete_through(memcached_st *memc) +test_return delete_through(memcached_st *memc) { memcached_trigger_delete_key callback; memcached_return rc; @@ -653,7 +653,7 @@ uint8_t delete_through(memcached_st *memc) return 0; } -uint8_t get_test(memcached_st *memc) +test_return get_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -674,7 +674,7 @@ uint8_t get_test(memcached_st *memc) return 0; } -uint8_t get_test2(memcached_st *memc) +test_return get_test2(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -701,7 +701,7 @@ uint8_t get_test2(memcached_st *memc) return 0; } -uint8_t set_test2(memcached_st *memc) +test_return set_test2(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -720,7 +720,7 @@ uint8_t set_test2(memcached_st *memc) return 0; } -uint8_t set_test3(memcached_st *memc) +test_return set_test3(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -747,7 +747,7 @@ uint8_t set_test3(memcached_st *memc) return 0; } -uint8_t get_test3(memcached_st *memc) +test_return get_test3(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -783,7 +783,7 @@ uint8_t get_test3(memcached_st *memc) return 0; } -uint8_t get_test4(memcached_st *memc) +test_return get_test4(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -823,7 +823,7 @@ uint8_t get_test4(memcached_st *memc) } /* Do not copy the style of this code, I just access hosts to testthis function */ -uint8_t stats_servername_test(memcached_st *memc) +test_return stats_servername_test(memcached_st *memc) { memcached_return rc; memcached_stat_st stat; @@ -834,7 +834,7 @@ uint8_t stats_servername_test(memcached_st *memc) return 0; } -uint8_t increment_test(memcached_st *memc) +test_return increment_test(memcached_st *memc) { uint64_t new_number; memcached_return rc; @@ -859,7 +859,7 @@ uint8_t increment_test(memcached_st *memc) return 0; } -uint8_t decrement_test(memcached_st *memc) +test_return decrement_test(memcached_st *memc) { uint64_t new_number; memcached_return rc; @@ -884,7 +884,7 @@ uint8_t decrement_test(memcached_st *memc) return 0; } -uint8_t quit_test(memcached_st *memc) +test_return quit_test(memcached_st *memc) { memcached_return rc; char *key= "fudge"; @@ -904,7 +904,7 @@ uint8_t quit_test(memcached_st *memc) return 0; } -uint8_t mget_result_test(memcached_st *memc) +test_return mget_result_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -961,7 +961,7 @@ uint8_t mget_result_test(memcached_st *memc) return 0; } -uint8_t mget_result_alloc_test(memcached_st *memc) +test_return mget_result_alloc_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -1021,7 +1021,7 @@ unsigned int callback_counter(memcached_st *ptr, memcached_result_st *result, vo return 0; } -uint8_t mget_result_function(memcached_st *memc) +test_return mget_result_function(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -1052,7 +1052,7 @@ uint8_t mget_result_function(memcached_st *memc) return 0; } -uint8_t mget_test(memcached_st *memc) +test_return mget_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -1107,7 +1107,7 @@ uint8_t mget_test(memcached_st *memc) return 0; } -uint8_t get_stats_keys(memcached_st *memc) +test_return get_stats_keys(memcached_st *memc) { char **list; char **ptr; @@ -1125,7 +1125,7 @@ uint8_t get_stats_keys(memcached_st *memc) return 0; } -uint8_t version_string_test(memcached_st *memc) +test_return version_string_test(memcached_st *memc) { const char *version_string; @@ -1136,7 +1136,7 @@ uint8_t version_string_test(memcached_st *memc) return 0; } -uint8_t get_stats(memcached_st *memc) +test_return get_stats(memcached_st *memc) { unsigned int x; char **list; @@ -1164,7 +1164,7 @@ uint8_t get_stats(memcached_st *memc) return 0; } -uint8_t add_host_test(memcached_st *memc) +test_return add_host_test(memcached_st *memc) { unsigned int x; memcached_server_st *servers; @@ -1206,7 +1206,7 @@ memcached_return cleanup_test_callback(memcached_st *ptr) return MEMCACHED_SUCCESS; } -uint8_t callback_test(memcached_st *memc) +test_return callback_test(memcached_st *memc) { /* Test User Data */ { @@ -1246,7 +1246,7 @@ uint8_t callback_test(memcached_st *memc) } /* We don't test the behavior itself, we test the switches */ -uint8_t behavior_test(memcached_st *memc) +test_return behavior_test(memcached_st *memc) { unsigned long long value; unsigned int set= 1; @@ -1294,7 +1294,7 @@ uint8_t behavior_test(memcached_st *memc) } /* Test case provided by Cal Haldenbrand */ -uint8_t user_supplied_bug1(memcached_st *memc) +test_return user_supplied_bug1(memcached_st *memc) { unsigned int setter= 1; unsigned int x; @@ -1341,7 +1341,7 @@ uint8_t user_supplied_bug1(memcached_st *memc) } /* Test case provided by Cal Haldenbrand */ -uint8_t user_supplied_bug2(memcached_st *memc) +test_return user_supplied_bug2(memcached_st *memc) { int errors; unsigned int setter; @@ -1397,7 +1397,7 @@ uint8_t user_supplied_bug2(memcached_st *memc) /* Do a large mget() over all the keys we think exist */ #define KEY_COUNT 3000 // * 1024576 -uint8_t user_supplied_bug3(memcached_st *memc) +test_return user_supplied_bug3(memcached_st *memc) { memcached_return rc; unsigned int setter; @@ -1457,7 +1457,7 @@ uint8_t user_supplied_bug3(memcached_st *memc) } /* Make sure we behave properly if server list has no values */ -uint8_t user_supplied_bug4(memcached_st *memc) +test_return user_supplied_bug4(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -1520,7 +1520,7 @@ uint8_t user_supplied_bug4(memcached_st *memc) } #define VALUE_SIZE_BUG5 1048064 -uint8_t user_supplied_bug5(memcached_st *memc) +test_return user_supplied_bug5(memcached_st *memc) { memcached_return rc; char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"}; @@ -1578,7 +1578,7 @@ uint8_t user_supplied_bug5(memcached_st *memc) return 0; } -uint8_t user_supplied_bug6(memcached_st *memc) +test_return user_supplied_bug6(memcached_st *memc) { memcached_return rc; char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"}; @@ -1643,7 +1643,7 @@ uint8_t user_supplied_bug6(memcached_st *memc) return 0; } -uint8_t user_supplied_bug8(memcached_st *memc) +test_return user_supplied_bug8(memcached_st *memc) { memcached_return rc; memcached_st *mine; @@ -1674,7 +1674,7 @@ uint8_t user_supplied_bug8(memcached_st *memc) } /* Test flag store/retrieve */ -uint8_t user_supplied_bug7(memcached_st *memc) +test_return user_supplied_bug7(memcached_st *memc) { memcached_return rc; char *keys= "036790384900"; @@ -1718,7 +1718,7 @@ uint8_t user_supplied_bug7(memcached_st *memc) return 0; } -uint8_t user_supplied_bug9(memcached_st *memc) +test_return user_supplied_bug9(memcached_st *memc) { memcached_return rc; char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"}; @@ -1763,7 +1763,7 @@ uint8_t user_supplied_bug9(memcached_st *memc) } /* We are testing with aggressive timeout to get failures */ -uint8_t user_supplied_bug10(memcached_st *memc) +test_return user_supplied_bug10(memcached_st *memc) { char *key= "foo"; char *value; @@ -1804,7 +1804,7 @@ uint8_t user_supplied_bug10(memcached_st *memc) /* We are looking failures in the async protocol */ -uint8_t user_supplied_bug11(memcached_st *memc) +test_return user_supplied_bug11(memcached_st *memc) { char *key= "foo"; char *value; @@ -1844,7 +1844,7 @@ uint8_t user_supplied_bug11(memcached_st *memc) /* Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist. */ -uint8_t user_supplied_bug12(memcached_st *memc) +test_return user_supplied_bug12(memcached_st *memc) { memcached_return rc; uint32_t flags; @@ -1883,7 +1883,7 @@ uint8_t user_supplied_bug12(memcached_st *memc) Bug found where command total one more than MEMCACHED_MAX_BUFFER set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169 */ -uint8_t user_supplied_bug13(memcached_st *memc) +test_return user_supplied_bug13(memcached_st *memc) { char key[] = "key34567890"; char *overflow; @@ -1921,7 +1921,7 @@ uint8_t user_supplied_bug13(memcached_st *memc) set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169 */ -uint8_t user_supplied_bug14(memcached_st *memc) +test_return user_supplied_bug14(memcached_st *memc) { int setter= 1; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter); @@ -1966,7 +1966,7 @@ uint8_t user_supplied_bug14(memcached_st *memc) /* Look for zero length value problems */ -uint8_t user_supplied_bug15(memcached_st *memc) +test_return user_supplied_bug15(memcached_st *memc) { uint32_t x; memcached_return rc; @@ -2003,7 +2003,7 @@ uint8_t user_supplied_bug15(memcached_st *memc) return 0; } -uint8_t result_static(memcached_st *memc) +test_return result_static(memcached_st *memc) { memcached_result_st result; memcached_result_st *result_ptr; @@ -2016,7 +2016,7 @@ uint8_t result_static(memcached_st *memc) return 0; } -uint8_t result_alloc(memcached_st *memc) +test_return result_alloc(memcached_st *memc) { memcached_result_st *result; @@ -2027,7 +2027,7 @@ uint8_t result_alloc(memcached_st *memc) return 0; } -uint8_t string_static_null(memcached_st *memc) +test_return string_static_null(memcached_st *memc) { memcached_string_st string; memcached_string_st *string_ptr; @@ -2040,7 +2040,7 @@ uint8_t string_static_null(memcached_st *memc) return 0; } -uint8_t string_alloc_null(memcached_st *memc) +test_return string_alloc_null(memcached_st *memc) { memcached_string_st *string; @@ -2051,7 +2051,7 @@ uint8_t string_alloc_null(memcached_st *memc) return 0; } -uint8_t string_alloc_with_size(memcached_st *memc) +test_return string_alloc_with_size(memcached_st *memc) { memcached_string_st *string; @@ -2062,7 +2062,7 @@ uint8_t string_alloc_with_size(memcached_st *memc) return 0; } -uint8_t string_alloc_with_size_toobig(memcached_st *memc) +test_return string_alloc_with_size_toobig(memcached_st *memc) { memcached_string_st *string; @@ -2072,7 +2072,7 @@ uint8_t string_alloc_with_size_toobig(memcached_st *memc) return 0; } -uint8_t string_alloc_append(memcached_st *memc) +test_return string_alloc_append(memcached_st *memc) { unsigned int x; char buffer[SMALL_STRING_LEN]; @@ -2095,7 +2095,7 @@ uint8_t string_alloc_append(memcached_st *memc) return 0; } -uint8_t string_alloc_append_toobig(memcached_st *memc) +test_return string_alloc_append_toobig(memcached_st *memc) { memcached_return rc; unsigned int x; @@ -2120,14 +2120,14 @@ uint8_t string_alloc_append_toobig(memcached_st *memc) return 0; } -uint8_t cleanup_pairs(memcached_st *memc) +test_return cleanup_pairs(memcached_st *memc) { pairs_free(global_pairs); return 0; } -uint8_t generate_pairs(memcached_st *memc) +test_return generate_pairs(memcached_st *memc) { unsigned long long x; global_pairs= pairs_generate(GLOBAL_COUNT, 400); @@ -2142,7 +2142,7 @@ uint8_t generate_pairs(memcached_st *memc) return 0; } -uint8_t generate_large_pairs(memcached_st *memc) +test_return generate_large_pairs(memcached_st *memc) { unsigned long long x; global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10); @@ -2157,14 +2157,14 @@ uint8_t generate_large_pairs(memcached_st *memc) return 0; } -uint8_t generate_data(memcached_st *memc) +test_return generate_data(memcached_st *memc) { execute_set(memc, global_pairs, global_count); return 0; } -uint8_t generate_buffer_data(memcached_st *memc) +test_return generate_buffer_data(memcached_st *memc) { int latch= 0; @@ -2175,7 +2175,7 @@ uint8_t generate_buffer_data(memcached_st *memc) return 0; } -uint8_t get_read(memcached_st *memc) +test_return get_read(memcached_st *memc) { unsigned int x; memcached_return rc; @@ -2201,7 +2201,7 @@ uint8_t get_read(memcached_st *memc) return 0; } -uint8_t mget_read(memcached_st *memc) +test_return mget_read(memcached_st *memc) { memcached_return rc; @@ -2227,7 +2227,7 @@ uint8_t mget_read(memcached_st *memc) return 0; } -uint8_t mget_read_result(memcached_st *memc) +test_return mget_read_result(memcached_st *memc) { memcached_return rc; @@ -2252,7 +2252,7 @@ uint8_t mget_read_result(memcached_st *memc) return 0; } -uint8_t mget_read_function(memcached_st *memc) +test_return mget_read_function(memcached_st *memc) { memcached_return rc; unsigned int counter; @@ -2268,7 +2268,7 @@ uint8_t mget_read_function(memcached_st *memc) return 0; } -uint8_t delete_generate(memcached_st *memc) +test_return delete_generate(memcached_st *memc) { unsigned int x; @@ -2280,7 +2280,7 @@ uint8_t delete_generate(memcached_st *memc) return 0; } -uint8_t delete_buffer_generate(memcached_st *memc) +test_return delete_buffer_generate(memcached_st *memc) { int latch= 0; unsigned int x; @@ -2296,14 +2296,14 @@ uint8_t delete_buffer_generate(memcached_st *memc) return 0; } -uint8_t free_data(memcached_st *memc) +test_return free_data(memcached_st *memc) { pairs_free(global_pairs); return 0; } -uint8_t add_host_test1(memcached_st *memc) +test_return add_host_test1(memcached_st *memc) { unsigned int x; memcached_return rc; @@ -2398,9 +2398,16 @@ memcached_return pre_hash_fnv1a_32(memcached_st *memc) return MEMCACHED_SUCCESS; } -memcached_return pre_hash_ketama(memcached_st *memc) +memcached_return pre_behavior_ketama(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_KETAMA); + memcached_return rc; + uint64_t value; + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA); + assert(value == 1); return MEMCACHED_SUCCESS; } @@ -2700,7 +2707,7 @@ collection_st collection[] ={ {"fnv1a_64", pre_hash_fnv1a_64, 0, tests}, {"fnv1_32", pre_hash_fnv1_32, 0, tests}, {"fnv1a_32", pre_hash_fnv1a_32, 0, tests}, - {"ketama", pre_hash_ketama, 0, tests}, + {"ketama", pre_behavior_ketama, 0, tests}, {"unix_socket", pre_unix_socket, 0, tests}, {"unix_socket_nodelay", pre_nodelay, 0, tests}, {"poll_timeout", poll_timeout, 0, tests}, diff --git a/tests/plus.cpp b/tests/plus.cpp index 10b2440a..20a537b1 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -15,7 +15,7 @@ #include "test.h" -uint8_t basic_test(memcached_st *memc) +test_return basic_test(memcached_st *memc) { Memcached foo; char *value_set= "This is some data"; @@ -27,9 +27,10 @@ uint8_t basic_test(memcached_st *memc) assert((memcmp(value, value_set, value_length) == 0)); - return 0; + return TEST_SUCCESS; } -uint8_t basic_master_key_test(memcached_st *memc) + +test_return basic_master_key_test(memcached_st *memc) { Memcached foo; char *value_set= "Data for server A"; @@ -47,7 +48,7 @@ uint8_t basic_master_key_test(memcached_st *memc) value= foo.get_by_key(master_key_b, key, &value_length); assert((memcmp(value, value_set, value_length) == 0)); - return 0; + return TEST_SUCCESS; } diff --git a/tests/test.c b/tests/test.c index 998b25f1..47db82c7 100644 --- a/tests/test.c +++ b/tests/test.c @@ -2,7 +2,6 @@ Sample test application. */ #include -#include #include #include #include diff --git a/tests/test.h b/tests/test.h index 0cbb5f0d..7c0e49da 100644 --- a/tests/test.h +++ b/tests/test.h @@ -12,10 +12,17 @@ typedef struct world_st world_st; typedef struct collection_st collection_st; typedef struct test_st test_st; +typedef enum { + TEST_SUCCESS= 0, /* Backwards compatibility */ + TEST_FAILURE, + TEST_MEMORY_ALLOCATION_FAILURE, + TEST_MAXIMUM_RETURN, /* Always add new error code before */ +} test_return; + struct test_st { char *name; unsigned int requires_flush; - uint8_t (*function)(memcached_st *memc); + test_return (*function)(memcached_st *memc); }; struct collection_st {