diff options
author | dormando <dormando@rydia.net> | 2016-12-30 12:29:28 -0800 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2017-01-04 22:43:20 -0800 |
commit | 87a70654c176dfe984449b4b5c6c85cbddec469a (patch) | |
tree | 3759e34595d7a2bbac611622b704245cab95c730 | |
parent | bb174641e09feaafe80d86514375a552a5b47780 (diff) | |
download | memcached-87a70654c176dfe984449b4b5c6c85cbddec469a.tar.gz |
fix store log and add ttl
the TTL is relative so you won't see the exact TTL on entry. Also fixes two
off-by-one's for the status values.
-rw-r--r-- | logger.c | 18 | ||||
-rw-r--r-- | logger.h | 4 | ||||
-rw-r--r-- | memcached.c | 6 | ||||
-rw-r--r-- | memcached.h | 3 |
4 files changed, 21 insertions, 10 deletions
@@ -152,18 +152,18 @@ static int _logger_thread_parse_ise(logentry *e, char *scratch) { char keybuf[KEY_MAX_LENGTH * 3 + 1]; struct logentry_item_store *le = (struct logentry_item_store *) e->data; const char * const status_map[] = { - "stored", "exists", "not_found", "too_large", "no_memory" }; + "not_stored", "stored", "exists", "not_found", "too_large", "no_memory" }; const char * const cmd_map[] = { - "add", "set", "replace", "append", "prepend", "cas" }; + "null", "add", "set", "replace", "append", "prepend", "cas" }; if (le->cmd <= 5) cmd = cmd_map[le->cmd]; uriencode(le->key, keybuf, le->nkey, LOGGER_PARSE_SCRATCH); total = snprintf(scratch, LOGGER_PARSE_SCRATCH, - "ts=%d.%d gid=%llu type=item_store key=%s status=%s cmd=%s\n", + "ts=%d.%d gid=%llu type=item_store key=%s status=%s cmd=%s ttl=%u\n", (int)e->tv.tv_sec, (int)e->tv.tv_usec, (unsigned long long) e->gid, - keybuf, status_map[le->status], cmd); + keybuf, status_map[le->status], cmd, le->ttl); return total; } @@ -596,11 +596,16 @@ static void _logger_log_item_get(logentry *e, const int was_found, const char *k } static void _logger_log_item_store(logentry *e, const enum store_item_type status, - const int comm, char *key, const int nkey) { + const int comm, char *key, const int nkey, rel_time_t ttl) { struct logentry_item_store *le = (struct logentry_item_store *) e->data; le->status = status; le->cmd = comm; le->nkey = nkey; + if (ttl != 0) { + le->ttl = ttl - current_time; + } else { + le->ttl = 0; + } memcpy(le->key, key, nkey); e->size = sizeof(struct logentry_item_store) + nkey; } @@ -667,7 +672,8 @@ enum logger_ret_type logger_log(logger *l, const enum log_entry_type event, cons int comm = va_arg(ap, int); char *skey = va_arg(ap, char *); size_t snkey = va_arg(ap, size_t); - _logger_log_item_store(e, status, comm, skey, snkey); + rel_time_t sttl = va_arg(ap, rel_time_t); + _logger_log_item_store(e, status, comm, skey, snkey, sttl); break; } @@ -10,6 +10,9 @@ #define LOGGER_ENTRY_MAX_SIZE 2048 #define GET_LOGGER() ((logger *) pthread_getspecific(logger_key)); +/* Inlined from memcached.h - should go into sub header */ +typedef unsigned int rel_time_t; + enum log_entry_type { LOGGER_ASCII_CMD = 0, LOGGER_EVICTION, @@ -62,6 +65,7 @@ struct logentry_item_get { struct logentry_item_store { int status; int cmd; + rel_time_t ttl; uint8_t nkey; char key[]; }; diff --git a/memcached.c b/memcached.c index 6f2e484..7b53f46 100644 --- a/memcached.c +++ b/memcached.c @@ -2256,7 +2256,7 @@ static void process_bin_update(conn *c) { } /* FIXME: losing c->cmd since it's translated below. refactor? */ LOGGER_LOG(c->thread->l, LOG_MUTATIONS, LOGGER_ITEM_STORE, - NULL, status, 0, key, nkey); + NULL, status, 0, key, nkey, it->exptime); /* Avoid stale data persisting in cache because we failed alloc. * Unacceptable for SET. Anywhere else too? */ @@ -2693,7 +2693,7 @@ enum store_item_type do_store_item(item *it, int comm, conn *c, const uint32_t h c->cas = ITEM_get_cas(it); } LOGGER_LOG(c->thread->l, LOG_MUTATIONS, LOGGER_ITEM_STORE, NULL, - stored, comm, ITEM_key(it), it->nkey); + stored, comm, ITEM_key(it), it->nkey, it->exptime); return stored; } @@ -3439,7 +3439,7 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken status = NO_MEMORY; } LOGGER_LOG(c->thread->l, LOG_MUTATIONS, LOGGER_ITEM_STORE, - NULL, status, comm, key, nkey); + NULL, status, comm, key, nkey, 0); /* swallow the data line */ c->write_and_go = conn_swallow; c->sbytes = vlen; diff --git a/memcached.h b/memcached.h index dd31cb3..567bcfa 100644 --- a/memcached.h +++ b/memcached.h @@ -221,7 +221,8 @@ enum delta_result_type { }; /** Time relative to server start. Smaller than time_t on 64-bit systems. */ -typedef unsigned int rel_time_t; +// TODO: Move to sub-header. needed in logger.h +//typedef unsigned int rel_time_t; /** Use X macros to avoid iterating over the stats fields during reset and * aggregation. No longer have to add new stats in 3+ places. |