From: Brian Aker Date: Wed, 11 Jul 2012 22:47:04 +0000 (-0400) Subject: Merge doc update. X-Git-Tag: 1.0.10~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d40eca3b5b67ef4403f92254e8c6d0253da62553;hp=38c7c4e5444881eee8f76c6050e146c137c3781e;p=awesomized%2Flibmemcached Merge doc update. --- diff --git a/clients/memaslap.c b/clients/memaslap.c index 37e93ec3..8053775c 100644 --- a/clients/memaslap.c +++ b/clients/memaslap.c @@ -594,7 +594,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_BINARY_PROTOCOL: /* --binary or -B */ - ms_setting.binary_prot= true; + ms_setting.binary_prot_= true; break; case OPT_TPS: /* --tps or -P */ @@ -800,7 +800,6 @@ static void ms_print_memslap_stats(struct timeval *start_time, /* the loop of the main thread, wait the work threads to complete */ static void ms_monitor_slap_mode() { - int second= 0; struct timeval start_time, end_time; /* Wait all the threads complete initialization. */ @@ -828,6 +827,7 @@ static void ms_monitor_slap_mode() /* running in "run time" mode, user specify run time */ if (ms_setting.run_time > 0) { + int second= 0; gettimeofday(&start_time, NULL); while (1) { diff --git a/clients/memcp.cc b/clients/memcp.cc index 59bd7478..c56a79cd 100644 --- a/clients/memcp.cc +++ b/clients/memcp.cc @@ -207,6 +207,7 @@ int main(int argc, char *argv[]) if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) { std::cerr << "Error allocating file buffer(" << strerror(errno) << ")" << std::endl; + close(fd); exit(EXIT_FAILURE); } @@ -214,12 +215,14 @@ int main(int argc, char *argv[]) if ((read_length= ::read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1) { std::cerr << "Error while reading file " << file_buffer_ptr << " (" << strerror(errno) << ")" << std::endl; + close(fd); exit(EXIT_FAILURE); } if (read_length != sbuf.st_size) { std::cerr << "Failure while reading file. Read length was not equal to stat() length" << std::endl; + close(fd); exit(EXIT_FAILURE); } diff --git a/clients/ms_conn.c b/clients/ms_conn.c index 3a6fd8e7..b4d5f673 100644 --- a/clients/ms_conn.c +++ b/clients/ms_conn.c @@ -358,7 +358,7 @@ static int ms_conn_init(ms_conn_t *c, c->mlget_task.mlget_num= 0; c->mlget_task.value_index= -1; /* default invalid value */ - if (ms_setting.binary_prot) + if (ms_setting.binary_prot_) { c->protocol= binary_prot; } diff --git a/clients/ms_setting.c b/clients/ms_setting.c index c3444c9a..3eb4d0e6 100644 --- a/clients/ms_setting.c +++ b/clients/ms_setting.c @@ -683,7 +683,7 @@ static void ms_build_distr() exit(1); } - if (! ms_setting.binary_prot + if (! ms_setting.binary_prot_ && ((start_len > MAX_KEY_SIZE) || (end_len > MAX_KEY_SIZE))) { fprintf(stderr, "key length must be less than 250 bytes.\n"); @@ -880,7 +880,7 @@ static void ms_setting_slapmode_init_pre() ms_setting.reconnect= false; ms_setting.verbose= false; ms_setting.facebook_test= false; - ms_setting.binary_prot= false; + ms_setting.binary_prot_= false; ms_setting.stat_freq= 0; ms_setting.srv_str= NULL; ms_setting.cfg_file= NULL; diff --git a/clients/ms_setting.h b/clients/ms_setting.h index 964dc400..ec060c41 100644 --- a/clients/ms_setting.h +++ b/clients/ms_setting.h @@ -153,7 +153,7 @@ typedef struct setting bool verbose; /* whether it outputs detailed information when verification */ bool facebook_test; /* facebook test, TCP set and multi-get with UDP */ uint32_t sock_per_conn; /* number of socks per connection structure */ - bool binary_prot; /* whether it use binary protocol */ + bool binary_prot_; /* whether it use binary protocol */ int expected_tps; /* expected throughput */ uint32_t rep_write_srv; /* which servers are used to do replication writing */ } ms_setting_st; diff --git a/clients/ms_stats.c b/clients/ms_stats.c index 49a5ab6e..8d62a5aa 100644 --- a/clients/ms_stats.c +++ b/clients/ms_stats.c @@ -219,10 +219,6 @@ void ms_dump_format_stats(ms_stat_t *stat, double global_std= 0; double global_log= 0; - uint64_t diff_time= 0; - uint64_t diff_events= 0; - double diff_squares= 0; - double diff_log_product= 0; double period_average= 0; uint64_t period_tps= 0; double period_rate= 0; @@ -241,17 +237,17 @@ void ms_dump_format_stats(ms_stat_t *stat, * global_average) / (double)(events - 1)); global_log= exp(stat->log_product / (double)events); - diff_time= stat->total_time - stat->pre_total_time; - diff_events= events - stat->pre_events; + uint64_t diff_time= stat->total_time - stat->pre_total_time; + uint64_t diff_events= events - stat->pre_events; if (diff_events >= 1) { period_average= (double)(diff_time / diff_events); period_tps= diff_events / (uint64_t)freq; period_rate= (double)diff_events * obj_size / 1024 / 1024 / freq; - diff_squares= (double)stat->squares - (double)stat->pre_squares; + double diff_squares= (double)stat->squares - (double)stat->pre_squares; period_std= sqrt((diff_squares - (double)diff_events * period_average * period_average) / (double)(diff_events - 1)); - diff_log_product= stat->log_product - stat->pre_log_product; + double diff_log_product= stat->log_product - stat->pre_log_product; period_log= exp(diff_log_product / (double)diff_events); } diff --git a/libmemcached-1.0/struct/memcached.h b/libmemcached-1.0/struct/memcached.h index 0b4f8976..63b07a00 100644 --- a/libmemcached-1.0/struct/memcached.h +++ b/libmemcached-1.0/struct/memcached.h @@ -100,11 +100,11 @@ struct memcached_st { memcached_result_st result; struct { - bool weighted; + bool weighted_; uint32_t continuum_count; // Ketama uint32_t continuum_points_counter; // Ketama time_t next_distribution_rebuild; // Ketama - memcached_continuum_item_st *continuum; // Ketama + struct memcached_continuum_item_st *continuum; // Ketama } ketama; struct memcached_virtual_bucket_t *virtual_bucket; diff --git a/libmemcached-1.0/types.h b/libmemcached-1.0/types.h index bb7e1a65..dc61a819 100644 --- a/libmemcached-1.0/types.h +++ b/libmemcached-1.0/types.h @@ -81,6 +81,5 @@ typedef struct memcached_callback_st memcached_callback_st; // The following two structures are internal, and never exposed to users. typedef struct memcached_string_st memcached_string_st; typedef struct memcached_string_t memcached_string_t; -typedef struct memcached_continuum_item_st memcached_continuum_item_st; #endif diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index e8bcf857..c381a513 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -42,9 +42,9 @@ #include #include -static bool __is_ketama(memcached_st *ptr) +bool memcached_is_consistent_distribution(const memcached_st* memc) { - switch (ptr->distribution) + switch (memc->distribution) { case MEMCACHED_DISTRIBUTION_CONSISTENT: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: @@ -355,9 +355,9 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->flags.verify_key; case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED: - if (__is_ketama(ptr)) + if (memcached_is_consistent_distribution(ptr)) { - return ptr->ketama.weighted; + return memcached_is_weighted_ketama(ptr); } return false; @@ -365,7 +365,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->distribution; case MEMCACHED_BEHAVIOR_KETAMA: - return __is_ketama(ptr); + return memcached_is_consistent_distribution(ptr); case MEMCACHED_BEHAVIOR_HASH: return hashkit_get_function(&ptr->hashkit); @@ -522,7 +522,7 @@ memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcac case MEMCACHED_DISTRIBUTION_CONSISTENT: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: - ptr->ketama.weighted= false; + memcached_set_weighted_ketama(ptr, false); break; case MEMCACHED_DISTRIBUTION_RANDOM: @@ -532,7 +532,7 @@ memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcac break; case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: - ptr->ketama.weighted= true; + memcached_set_weighted_ketama(ptr, true); break; case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: diff --git a/libmemcached/behavior.hpp b/libmemcached/behavior.hpp index ee38f97a..0b06c0ca 100644 --- a/libmemcached/behavior.hpp +++ b/libmemcached/behavior.hpp @@ -36,4 +36,5 @@ #pragma once +bool memcached_is_consistent_distribution(const memcached_st*); bool _is_auto_eject_host(const memcached_st *ptr); diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 2a07a395..4875615f 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -118,11 +118,17 @@ static int continuum_item_cmp(const void *t1, const void *t2) /* Why 153? Hmmm... */ WATCHPOINT_ASSERT(ct1->value != 153); if (ct1->value == ct2->value) + { return 0; + } else if (ct1->value > ct2->value) + { return 1; + } else + { return -1; + } } static memcached_return_t update_continuum(memcached_st *ptr) @@ -167,8 +173,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) live_servers= memcached_server_count(ptr); } - uint64_t is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); - uint32_t points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER); + uint32_t points_per_server= (uint32_t) (memcached_is_weighted_ketama(ptr) ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER); if (live_servers == 0) { @@ -191,7 +196,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) } uint64_t total_weight= 0; - if (is_ketama_weighted) + if (memcached_is_weighted_ketama(ptr)) { for (uint32_t host_index = 0; host_index < memcached_server_count(ptr); ++host_index) { @@ -209,7 +214,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) continue; } - if (is_ketama_weighted) + if (memcached_is_weighted_ketama(ptr)) { float pct= (float)list[host_index].weight / (float)total_weight; pointer_per_server= (uint32_t) ((::floor((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4); @@ -253,7 +258,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) fprintf(stdout, "update_continuum: key is %s\n", sort_host); } - if (is_ketama_weighted) + if (memcached_is_weighted_ketama(ptr)) { for (uint32_t x= 0; x < pointer_per_hash; x++) { @@ -301,7 +306,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) memcached_literal_param("snprintf(sizeof(sort_host)))")); } - if (is_ketama_weighted) + if (memcached_is_weighted_ketama(ptr)) { for (uint32_t x = 0; x < pointer_per_hash; x++) { @@ -366,7 +371,10 @@ static memcached_return_t server_add(memcached_st *ptr, if (weight > 1) { - ptr->ketama.weighted= true; + if (memcached_is_consistent_distribution(ptr)) + { + memcached_set_weighted_ketama(ptr, true); + } } ptr->number_of_hosts++; @@ -411,7 +419,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv if (list[x].weight > 1) { - ptr->ketama.weighted= true; + memcached_set_weighted_ketama(ptr, true); } ptr->number_of_hosts++; @@ -455,7 +463,7 @@ memcached_return_t memcached_instance_push(memcached_st *ptr, const struct org:: if (list[x].weight > 1) { - ptr->ketama.weighted= true; + memcached_set_weighted_ketama(ptr, true); } ptr->number_of_hosts++; diff --git a/libmemcached/include.am b/libmemcached/include.am index f3525df2..bfa2f140 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -16,6 +16,7 @@ nobase_include_HEADERS+= libmemcached/util.h noinst_HEADERS+= libmemcached/array.h noinst_HEADERS+= libmemcached/assert.hpp noinst_HEADERS+= libmemcached/backtrace.hpp +noinst_HEADERS+= libmemcached/behavior.hpp noinst_HEADERS+= libmemcached/byteorder.h noinst_HEADERS+= libmemcached/common.h noinst_HEADERS+= libmemcached/connect.hpp @@ -64,7 +65,6 @@ libmemcached_libmemcached_la_SOURCES+= libmemcached/array.c libmemcached_libmemcached_la_SOURCES+= libmemcached/auto.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/backtrace.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/behavior.cc -libmemcached_libmemcached_la_SOURCES+= libmemcached/behavior.hpp libmemcached_libmemcached_la_SOURCES+= libmemcached/byteorder.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/callback.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/connect.cc diff --git a/libmemcached/io.cc b/libmemcached/io.cc index 837959da..866830aa 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -330,7 +330,16 @@ static bool io_flush(org::libmemcached::Instance* ptr, WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); WATCHPOINT_ASSERT(write_length > 0); - int flags= with_flush ? MSG_NOSIGNAL|MSG_DONTWAIT : MSG_NOSIGNAL|MSG_DONTWAIT|MSG_MORE; + int flags; + if (with_flush) + { + flags= MSG_NOSIGNAL|MSG_DONTWAIT; + } + else + { + flags= MSG_NOSIGNAL|MSG_DONTWAIT|MSG_MORE; + } + ssize_t sent_length= ::send(ptr->fd, local_write_ptr, write_length, flags); if (sent_length == SOCKET_ERROR) diff --git a/libmemcached/is.h b/libmemcached/is.h index 3815a0ad..126bc9a7 100644 --- a/libmemcached/is.h +++ b/libmemcached/is.h @@ -59,6 +59,8 @@ #define memcached_is_auto_eject_hosts(__object) ((__object)->flags.auto_eject_hosts) #define memcached_is_use_sort_hosts(__object) ((__object)->flags.use_sort_hosts) +#define memcached_is_weighted_ketama(__object) ((__object)->ketama.weighted_) + #define memcached_set_aes(__object, __flag) ((__object).flags.is_aes= __flag) #define memcached_set_udp(__object, __flag) ((__object).flags.use_udp= __flag) #define memcached_set_verify_key(__object, __flag) ((__object).flags.verify_key= __flag) @@ -83,3 +85,5 @@ #define memcached_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value)) #define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value)) #define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated= (__value)) + +#define memcached_set_weighted_ketama(__object, __value) ((__object)->ketama.weighted_= (__value)) diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 3504b23a..c52873ad 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -77,7 +77,7 @@ static inline bool _memcached_init(memcached_st *self) self->ketama.continuum_count= 0; self->ketama.continuum_points_counter= 0; self->ketama.next_distribution_rebuild= 0; - self->ketama.weighted= false; + self->ketama.weighted_= false; self->number_of_hosts= 0; self->servers= NULL; diff --git a/libmemcached/server_list.cc b/libmemcached/server_list.cc index 4b3c6293..8205edc9 100644 --- a/libmemcached/server_list.cc +++ b/libmemcached/server_list.cc @@ -89,6 +89,7 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, #if 0 *error= memcached_set_errno(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); #endif + free(new_host_list); return NULL; } diff --git a/tests/keys.hpp b/tests/keys.hpp index 54d6e4f5..342346fc 100644 --- a/tests/keys.hpp +++ b/tests/keys.hpp @@ -85,7 +85,7 @@ public: { for (libtest::vchar_ptr_t::iterator iter= _keys.begin(); iter != _keys.end(); - iter++) + ++iter) { ::free(*iter); } diff --git a/tests/libmemcached-1.0/all_tests.cc b/tests/libmemcached-1.0/all_tests.cc index bfa64c24..8aeac4d9 100644 --- a/tests/libmemcached-1.0/all_tests.cc +++ b/tests/libmemcached-1.0/all_tests.cc @@ -82,7 +82,7 @@ void get_world(Framework *world) else { // Assume a minimum of 3, and a maximum of 8 - world->servers().set_servers_to_run(libtest::number_of_cpus() > 3 ? + world->servers().set_servers_to_run((libtest::number_of_cpus() > 3) ? std::min(libtest::number_of_cpus(), size_t(8)) : 3); } diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index cba7c957..9fdf6bf3 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -390,7 +390,7 @@ test_return_t clone_test(memcached_st *memc) test_true(memc_clone->flags.buffer_requests == memc->flags.buffer_requests); test_true(memc_clone->flags.use_sort_hosts == memc->flags.use_sort_hosts); test_true(memc_clone->flags.verify_key == memc->flags.verify_key); - test_true(memc_clone->ketama.weighted == memc->ketama.weighted); + test_true(memc_clone->ketama.weighted_ == memc->ketama.weighted_); test_true(memc_clone->flags.binary_protocol == memc->flags.binary_protocol); test_true(memc_clone->flags.hash_with_namespace == memc->flags.hash_with_namespace); test_true(memc_clone->flags.reply == memc->flags.reply); @@ -614,7 +614,7 @@ test_return_t memcached_mget_mixed_memcached_get_TEST(memcached_st *memc) for (libtest::vchar_ptr_t::iterator iter= keys.begin(); iter != keys.end(); - iter++) + ++iter) { test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc,