diff --git a/src/Makefile.am b/src/Makefile.am index 8d9386a..6ad04c4 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,6 +2,7 @@ bin_PROGRAMS = memcached memcached-debug memcached_SOURCES = memcached.c slabs.c slabs.h items.c items.h assoc.c assoc.h memcached.h thread.c stats.c stats.h binary_sm.c binary_sm.h binary_protocol.h memcached_debug_SOURCES = $(memcached_SOURCES) +memcached_CFLAGS = -Wall memcached_CPPFLAGS = -DNDEBUG memcached_LDADD = @LIBOBJS@ memcached_debug_LDADD = $(memcached_LDADD) diff --git a/src/assoc.h b/src/assoc.h index 3b32162..2797f32 100644 --- a/src/assoc.h +++ b/src/assoc.h @@ -1,3 +1,6 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +#if !defined(_assoc_h_) +#define _assoc_h_ /* associative array */ void assoc_init(void); item *assoc_find(const char *key, const size_t nkey); @@ -5,3 +8,5 @@ int assoc_insert(item *item); void assoc_delete(const char *key, const size_t nkey); void do_assoc_move_next_bucket(void); uint32_t hash( const void *key, size_t length, const uint32_t initval); +int do_assoc_expire_regex(char *pattern); +#endif /* #if !defined(_assoc_h_) */ diff --git a/src/binary_protocol.h b/src/binary_protocol.h index 5a2d467..9278a83 100644 --- a/src/binary_protocol.h +++ b/src/binary_protocol.h @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -#if !defined(_facebook_memcache_binary_protocol_h_) -#define _facebook_memcache_binary_protocol_h_ +#if !defined(_memcache_binary_protocol_h_) +#define _memcache_binary_protocol_h_ #include @@ -183,4 +183,4 @@ typedef struct string_rep_s { // string goes here. } string_rep_t; -#endif /* #if !defined(_facebook_memcache_binary_protocol_h_) */ +#endif /* #if !defined(_memcache_binary_protocol_h_) */ diff --git a/src/binary_sm.h b/src/binary_sm.h index 27a4550..c058d93 100644 --- a/src/binary_sm.h +++ b/src/binary_sm.h @@ -1,11 +1,11 @@ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -#if !defined(_facebook_binary_sm_h_) -#define _facebook_binary_sm_h_ +#if !defined(_binary_sm_h_) +#define _binary_sm_h_ #include "memcached.h" extern void process_binary_protocol(conn* c); extern bp_hdr_pool_t* bp_allocate_hdr_pool(bp_hdr_pool_t* next); -#endif /* #if !defined(_facebook_binary_sm_h_) */ +#endif /* #if !defined(_binary_sm_h_) */ diff --git a/src/items.c b/src/items.c index c1db8b8..8bee1f9 100755 --- a/src/items.c +++ b/src/items.c @@ -1,6 +1,5 @@ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* $Id$ */ -#include "memcached.h" #include #include #include @@ -14,6 +13,9 @@ #include #include +#include "memcached.h" +#include "slabs.h" + /* Forward Declarations */ static void item_link_q(item *it); static void item_unlink_q(item *it); @@ -282,7 +284,7 @@ void do_item_update(item *it) { if (it->time < current_time - ITEM_UPDATE_INTERVAL) { assert((it->it_flags & ITEM_SLABBED) == 0); - if (it->it_flags & ITEM_LINKED != 0) { + if ((it->it_flags & ITEM_LINKED) != 0) { item_unlink_q(it); it->time = current_time; item_link_q(it); diff --git a/src/memcached.c b/src/memcached.c index b62f366..e9d188a 100755 --- a/src/memcached.c +++ b/src/memcached.c @@ -60,6 +60,12 @@ #endif #endif +#if __WORDSIZE == 64 +#define PRINTF_INT64_MODIFIER "l" +#else +#define PRINTF_INT64_MODIFIER "ll" +#endif + /* * forward declarations */ @@ -916,26 +922,26 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) { pos += sprintf(pos, "STAT uptime %u\r\n", now); pos += sprintf(pos, "STAT time %ld\r\n", now + stats.started); pos += sprintf(pos, "STAT version " VERSION "\r\n"); - pos += sprintf(pos, "STAT pointer_size %d\r\n", 8 * sizeof(void *)); + pos += sprintf(pos, "STAT pointer_size %lu\r\n", 8 * sizeof(void *)); #ifndef WIN32 - pos += sprintf(pos, "STAT rusage_user %ld.%06ld\r\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec); - pos += sprintf(pos, "STAT rusage_system %ld.%06ld\r\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec); + pos += sprintf(pos, "STAT rusage_user %ld.%06d\r\n", usage.ru_utime.tv_sec, (int) usage.ru_utime.tv_usec); + pos += sprintf(pos, "STAT rusage_system %ld.%06d\r\n", usage.ru_stime.tv_sec, (int) usage.ru_stime.tv_usec); #endif /* !WIN32 */ pos += sprintf(pos, "STAT curr_items %u\r\n", stats.curr_items); pos += sprintf(pos, "STAT total_items %u\r\n", stats.total_items); - pos += sprintf(pos, "STAT bytes %llu\r\n", stats.curr_bytes); + pos += sprintf(pos, "STAT bytes %" PRINTF_INT64_MODIFIER "u\r\n", stats.curr_bytes); pos += sprintf(pos, "STAT curr_connections %u\r\n", stats.curr_conns - 1); /* ignore listening conn */ pos += sprintf(pos, "STAT total_connections %u\r\n", stats.total_conns); pos += sprintf(pos, "STAT connection_structures %u\r\n", stats.conn_structs); - pos += sprintf(pos, "STAT cmd_get %llu\r\n", stats.get_cmds); - pos += sprintf(pos, "STAT cmd_set %llu\r\n", stats.set_cmds); - pos += sprintf(pos, "STAT get_hits %llu\r\n", stats.get_hits); - pos += sprintf(pos, "STAT get_misses %llu\r\n", stats.get_misses); + pos += sprintf(pos, "STAT cmd_get %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_cmds); + pos += sprintf(pos, "STAT cmd_set %" PRINTF_INT64_MODIFIER "u\r\n", stats.set_cmds); + pos += sprintf(pos, "STAT get_hits %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_hits); + pos += sprintf(pos, "STAT get_misses %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_misses); pos += sprintf(pos, "STAT hit_rate %g%%\r\n", (stats.get_hits + stats.get_misses) == 0 ? 0.0 : (double)stats.get_hits * 100 / (stats.get_hits + stats.get_misses)); - pos += sprintf(pos, "STAT evictions %llu\r\n", stats.evictions); - pos += sprintf(pos, "STAT bytes_read %llu\r\n", stats.bytes_read); - pos += sprintf(pos, "STAT bytes_written %llu\r\n", stats.bytes_written); - pos += sprintf(pos, "STAT limit_maxbytes %llu\r\n", (uint64_t) settings.maxbytes); + pos += sprintf(pos, "STAT evictions %" PRINTF_INT64_MODIFIER "u\r\n", stats.evictions); + pos += sprintf(pos, "STAT bytes_read %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_read); + pos += sprintf(pos, "STAT bytes_written %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_written); + pos += sprintf(pos, "STAT limit_maxbytes %" PRINTF_INT64_MODIFIER "u\r\n", (uint64_t) settings.maxbytes); pos += sprintf(pos, "STAT threads %u\r\n", settings.num_threads); pos += sprintf(pos, "STAT slabs_rebalance %d\r\n", slabs_get_rebalance_interval()); pos += sprintf(pos, "END"); diff --git a/src/memcached.h b/src/memcached.h index 17feca4..3087217 100755 --- a/src/memcached.h +++ b/src/memcached.h @@ -309,11 +309,14 @@ void do_run_deferred_deletes(void); char *do_add_delta(item *item, int incr, const unsigned int delta, char *buf, uint32_t* res_val); int do_store_item(item *item, int comm); conn *conn_new(const int sfd, const int init_state, const int event_flags, const int read_buffer_size, const bool is_udp, const bool is_binary, struct event_base *base); +void conn_cleanup(conn *c); void conn_close(conn *c); void accept_new_conns(const bool do_accept, const bool is_binary); bool update_event(conn *c, const int new_flags); int add_iov(conn *c, const void *buf, int len, bool is_start); int add_msghdr(conn *c); +rel_time_t realtime(const time_t exptime); +int build_udp_headers(conn *c); #include "stats.h" #include "slabs.h" @@ -429,7 +432,7 @@ int mt_store_item(item *item, int comm); # define slabs_rebalance() do_slabs_rebalance() # define slabs_stats(x) do_slabs_stats(x) # define store_item(x,y) do_store_item(x,y) -# define thread_init(x,y) 0 +# define thread_init(x,y) ; # define STATS_LOCK() /**/ # define STATS_UNLOCK() /**/ diff --git a/src/slabs.h b/src/slabs.h index c36b0d8..ff328bd 100644 --- a/src/slabs.h +++ b/src/slabs.h @@ -1,3 +1,8 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ + +#if !defined(_slabs_h_) +#define _slabs_h_ + /* slabs memory allocation */ /** Init the subsystem. 1st argument is the limit on no. of bytes to allocate, @@ -28,12 +33,16 @@ char* do_slabs_stats(int *buflen); -1 = tried. busy. send again shortly. */ int do_slabs_reassign(unsigned char srcid, unsigned char dstid); +void slabs_add_hit(void *it, int unique); +void slabs_add_eviction(unsigned int clsid); + /* Find the worst performed slab class to free one slab from it and assign it to the best performed slab class. */ -void do_slab_rebalance(); +void do_slabs_rebalance(); /* 0 to turn off rebalance_interval; otherwise, this number is in seconds. * These two functions are actually implemented in items.c. */ void slabs_set_rebalance_interval(int interval); int slabs_get_rebalance_interval(); +#endif /* #if !defined(_slabs_h_) */ diff --git a/src/stats.h b/src/stats.h index 56db428..b679dff 100644 --- a/src/stats.h +++ b/src/stats.h @@ -1,8 +1,17 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ + +#if !defined(_stats_h_) +#define _stats_h + /* stats */ -void stats_prefix_init(void); -void stats_prefix_clear(void); -void stats_prefix_record_get(const char *key, const bool is_hit); -void stats_prefix_record_delete(const char *key); -void stats_prefix_record_set(const char *key); +extern void stats_prefix_init(void); +extern void stats_prefix_clear(void); +extern void stats_prefix_record_get(const char *key, const bool is_hit); +extern void stats_prefix_record_delete(const char *key); +extern void stats_prefix_record_set(const char *key); +extern void stats_prefix_record_byte_total_change(char *key, long bytes); +extern void stats_prefix_record_removal(char *key, size_t bytes, rel_time_t time, long flags); + /*@null@*/ -char *stats_prefix_dump(int *length); +extern char *stats_prefix_dump(int *length); +#endif /* #if !defined(_stats_h_) */ diff --git a/src/thread.c b/src/thread.c index 9825bad..5e77533 100644 --- a/src/thread.c +++ b/src/thread.c @@ -289,7 +289,7 @@ static void *worker_libevent(void *arg) { pthread_cond_signal(&init_cond); pthread_mutex_unlock(&init_lock); - return (void*) event_base_loop(me->base, 0); + return (void*) (intptr_t) event_base_loop(me->base, 0); }