Permalink
Browse files

MB-2897 - use 64-bits for msec_current time

32-bits overlows after 49+ days, and 64-bits should be enough for
anybody.

Change-Id: I769839ee4cb41f10ce808cf7f669c0cd1beb7245
Reviewed-on: http://review.couchbase.org/7748
Reviewed-by: Bin Cui <bin.cui@gmail.com>
Tested-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information...
1 parent d85361d commit 6a26e91a0df1974e9f3f45f7646094fa378c755e @steveyen steveyen committed Jul 6, 2011
Showing with 33 additions and 36 deletions.
  1. +3 −2 agent_stats.c
  2. +5 −7 cproxy.c
  3. +9 −11 cproxy.h
  4. +1 −1 cproxy_config.c
  5. +7 −7 cproxy_front.c
  6. +1 −1 cproxy_multiget.c
  7. +6 −6 cproxy_stats.c
  8. +1 −1 log.c
View
@@ -1329,7 +1329,7 @@ static void add_key_stats_inner(const void *data, void *userdata) {
return;
}
- uint32_t current_time_msec = msec_current_time;
+ uint64_t current_time_msec = msec_current_time;
float rescale_factor_dest = 1.0, rescale_factor_src = 1.0;
if (dest_stats->added_at < kstats->added_at) {
rescale_factor_src = (float)(current_time_msec - dest_stats->added_at)/(current_time_msec - kstats->added_at);
@@ -1597,7 +1597,8 @@ static void map_key_stats_foreach_emit_inner(const void *_key,
char buf_val[32];
snprintf(buf, sizeof(buf), "%s:keys_stats:%s:added_at_msec",
state->name, key);
- snprintf(buf_val, sizeof(buf_val), "%u", kstats->added_at);
+ snprintf(buf_val, sizeof(buf_val), "%llu",
+ (long long unsigned int) kstats->added_at);
conflate_add_field(state->emit->result, buf, buf_val);
}
}
View
@@ -76,7 +76,7 @@ typedef struct {
uint32_t dc_acquired; // Count of acquired (in-use) downstream conns.
char *host_ident;
uint32_t error_count;
- rel_time_t error_time;
+ uint64_t error_time;
// Head & tail of singly linked-list/queue, using
// downstream->next_waiting pointers, where we've reached
@@ -2266,12 +2266,10 @@ void wait_queue_timeout(const int fd,
struct timeval wqt = ptd->behavior_pool.base.wait_queue_timeout;
- // TODO: Millisecond capacity in 32-bit field not enough?
- //
- uint32_t wqt_msec = (wqt.tv_sec * 1000) +
+ uint64_t wqt_msec = (wqt.tv_sec * 1000) +
(wqt.tv_usec / 1000);
- uint32_t cut_msec = msec_current_time - wqt_msec;
+ uint64_t cut_msec = msec_current_time - wqt_msec;
// Run through all the old upstream conn's in
// the wait queue, remove them, and emit errors
@@ -3327,10 +3325,10 @@ conn *zstored_acquire_downstream_conn(downstream *d,
msec_current_time - conns->error_time;
if (settings.verbose > 2) {
- moxi_log_write("zacquire_dc, %s, %d, %d, (%d)\n",
+ moxi_log_write("zacquire_dc, %s, %d, %llu, (%d)\n",
host_ident,
conns->error_count,
- conns->error_time,
+ (long long unsigned int) conns->error_time,
msecs_since_error);
}
View
@@ -22,9 +22,7 @@ int cproxy_init(char *cfg_str,
#define CPROXY_NOT_CAS UINT64_MAX
-// TODO: Millisecond capacity in 32-bit field not enough?
-//
-extern volatile uint32_t msec_current_time;
+extern volatile uint64_t msec_current_time;
uint64_t usec_now(void);
@@ -54,8 +52,8 @@ typedef struct {
void (*item_set_next)(void *it, void *next);
void *(*item_get_prev)(void *it);
void (*item_set_prev)(void *it, void *prev);
- uint32_t (*item_get_exptime)(void *it);
- void (*item_set_exptime)(void *it, uint32_t exptime);
+ uint64_t (*item_get_exptime)(void *it);
+ void (*item_set_exptime)(void *it, uint64_t exptime);
} mcache_funcs;
extern mcache_funcs mcache_item_funcs;
@@ -381,8 +379,8 @@ typedef struct {
struct key_stats {
char key[KEY_MAX_LENGTH + 1];
int refcount;
- uint32_t exptime;
- uint32_t added_at;
+ uint64_t exptime;
+ uint64_t added_at;
key_stats *next;
key_stats *prev;
proxy_stats_cmd stats_cmd[STATS_CMD_TYPE_last][STATS_CMD_last];
@@ -812,9 +810,9 @@ bool mcache_started(mcache *m);
void mcache_stop(mcache *m);
void mcache_reset_stats(mcache *m);
void *mcache_get(mcache *m, char *key, int key_len,
- uint32_t curr_time);
+ uint64_t curr_time);
void mcache_set(mcache *m, void *it,
- uint32_t exptime,
+ uint64_t exptime,
bool add_only,
bool mod_exptime_if_exists);
void mcache_delete(mcache *m, char *key, int key_len);
@@ -824,10 +822,10 @@ void mcache_foreach(mcache *m, mcache_traversal_func f, void *userdata);
// Functions for key stats.
//
key_stats *find_key_stats(proxy_td *ptd, char *key, int key_len,
- uint32_t msec_time);
+ uint64_t msec_time);
void touch_key_stats(proxy_td *ptd, char *key, int key_len,
- uint32_t msec_current_time,
+ uint64_t msec_current_time,
enum_stats_cmd_type cmd_type,
enum_stats_cmd cmd,
int delta_seen,
View
@@ -18,7 +18,7 @@
//
static char *readfile(char *path);
-volatile uint32_t msec_current_time = 0;
+volatile uint64_t msec_current_time = 0;
int msec_cycle = 0;
struct event msec_clockevent;
struct event_base *msec_clockevent_base = NULL;
View
@@ -20,8 +20,8 @@ static void *item_get_next(void *it);
static void item_set_next(void *it, void *next);
static void *item_get_prev(void *it);
static void item_set_prev(void *it, void *prev);
-static uint32_t item_get_exptime(void *it);
-static void item_set_exptime(void *it, uint32_t exptime);
+static uint64_t item_get_exptime(void *it);
+static void item_set_exptime(void *it, uint64_t exptime);
void mcache_item_unlink(mcache *m, void *it);
void mcache_item_touch(mcache *m, void *it);
@@ -162,7 +162,7 @@ void mcache_stop(mcache *m) {
}
void *mcache_get(mcache *m, char *key, int key_len,
- uint32_t curr_time) {
+ uint64_t curr_time) {
(void)key_len;
assert(key);
@@ -181,7 +181,7 @@ void *mcache_get(mcache *m, char *key, int key_len,
if (it != NULL) {
mcache_item_unlink(m, it);
- uint32_t exptime = m->funcs->item_get_exptime(it);
+ uint64_t exptime = m->funcs->item_get_exptime(it);
if ((exptime <= 0) ||
(exptime >= curr_time &&
exptime >= m->oldest_live)) {
@@ -229,7 +229,7 @@ void *mcache_get(mcache *m, char *key, int key_len,
}
void mcache_set(mcache *m, void *it,
- uint32_t exptime,
+ uint64_t exptime,
bool add_only,
bool mod_exptime_if_exists) {
assert(it);
@@ -524,13 +524,13 @@ static void item_set_prev(void *it, void *prev) {
i->prev = (item *) prev;
}
-static uint32_t item_get_exptime(void *it) {
+static uint64_t item_get_exptime(void *it) {
item *i = it;
assert(i);
return i->exptime;
}
-static void item_set_exptime(void *it, uint32_t exptime) {
+static void item_set_exptime(void *it, uint64_t exptime) {
item *i = it;
assert(i);
i->exptime = exptime;
View
@@ -106,7 +106,7 @@ bool multiget_ascii_downstream(downstream *d, conn *uc,
// Snapshot the volatile only once.
//
- uint32_t msec_current_time_snapshot = msec_current_time;
+ uint64_t msec_current_time_snapshot = msec_current_time;
int uc_num = 0;
conn *uc_cur = uc;
View
@@ -49,8 +49,8 @@ static void *key_stats_get_next(void *it);
static void key_stats_set_next(void *it, void *next);
static void *key_stats_get_prev(void *it);
static void key_stats_set_prev(void *it, void *prev);
-static uint32_t key_stats_get_exptime(void *it);
-static void key_stats_set_exptime(void *it, uint32_t exptime);
+static uint64_t key_stats_get_exptime(void *it);
+static void key_stats_set_exptime(void *it, uint64_t exptime);
mcache_funcs mcache_key_stats_funcs = {
.item_key = key_stats_key,
@@ -452,7 +452,7 @@ void cproxy_reset_stats_cmd(proxy_stats_cmd *sc) {
// -------------------------------------------------
key_stats *find_key_stats(proxy_td *ptd, char *key, int key_len,
- uint32_t msec_time) {
+ uint64_t msec_time) {
assert(ptd);
assert(key);
assert(key_len > 0);
@@ -478,7 +478,7 @@ key_stats *find_key_stats(proxy_td *ptd, char *key, int key_len,
}
void touch_key_stats(proxy_td *ptd, char *key, int key_len,
- uint32_t msec_time,
+ uint64_t msec_time,
enum_stats_cmd_type cmd_type,
enum_stats_cmd cmd,
int delta_seen,
@@ -561,13 +561,13 @@ static void key_stats_set_prev(void *it, void *prev) {
i->prev = (key_stats *) prev;
}
-static uint32_t key_stats_get_exptime(void *it) {
+static uint64_t key_stats_get_exptime(void *it) {
key_stats *i = it;
assert(i);
return i->exptime;
}
-static void key_stats_set_exptime(void *it, uint32_t exptime) {
+static void key_stats_set_exptime(void *it, uint64_t exptime) {
key_stats *i = it;
assert(i);
i->exptime = exptime;
View
2 log.c
@@ -32,7 +32,7 @@
#define MAX_LOGBUF_LEN 1000
-extern volatile uint32_t msec_current_time;
+extern volatile uint64_t msec_current_time;
/**
* open the errorlog

0 comments on commit 6a26e91

Please sign in to comment.