diff options
author | Hemal Shah <hemal@stripe.com> | 2022-10-19 19:17:13 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2023-03-15 17:16:36 -0700 |
commit | 9b3c946f485309cdf50f7fb1622707b5373e33f3 (patch) | |
tree | 50442521e1d2912caddfe0266f5223b0f4b48fb3 /logger.c | |
parent | c04701654413719d4abd7645c6d7b3fba4255e85 (diff) | |
download | memcached-9b3c946f485309cdf50f7fb1622707b5373e33f3.tar.gz |
log: Add a new watcher to watch for deletions.
`watch deletions`: would log all keys which are deleted using either `delete` or `md` command.
The log line would contain the command used, the key, the clsid and size of the deleted item.
Items which result in delete miss or are marked as stale wouldn't show up in the logs
Diffstat (limited to 'logger.c')
-rw-r--r-- | logger.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -137,6 +137,18 @@ static void _logger_log_item_store(logentry *e, const entry_details *d, const vo e->size = sizeof(struct logentry_item_store) + nkey; } +static void _logger_log_item_deleted(logentry *e, const entry_details *d, const void *entry, va_list ap) { + item *it = (item *)entry; + int comm = va_arg(ap, int); + struct logentry_deletion *le = (struct logentry_deletion *) e->data; + le->nkey = it->nkey; + le->cmd = comm; + le->nbytes = it->nbytes; + le->clsid = ITEM_clsid(it); + memcpy(le->key, ITEM_key(it), it->nkey); + e->size = sizeof(struct logentry_deletion) + le->nkey; +} + static void _logger_log_conn_event(logentry *e, const entry_details *d, const void *entry, va_list ap) { struct sockaddr_in6 *addr = va_arg(ap, struct sockaddr_in6 *); socklen_t addrlen = va_arg(ap, socklen_t); @@ -251,6 +263,26 @@ static int _logger_parse_ee(logentry *e, char *scratch) { return total; } +static int _logger_parse_ide(logentry *e, char *scratch) { + int total; + const char *cmd = "na"; + const char * const cmd_map[] = { + "null", "delete", "md" }; + char keybuf[KEY_MAX_URI_ENCODED_LENGTH]; + struct logentry_deletion *le = (struct logentry_deletion *) e->data; + uriencode(le->key, keybuf, le->nkey, KEY_MAX_URI_ENCODED_LENGTH); + + if (le->cmd <= 2) + cmd = cmd_map[le->cmd]; + + total = snprintf(scratch, LOGGER_PARSE_SCRATCH, + "ts=%d.%d gid=%llu type=deleted key=%s cmd=%s clsid=%u size=%d\n", + (int)e->tv.tv_sec, (int)e->tv.tv_usec, (unsigned long long) e->gid, + keybuf, cmd, le->clsid, + le->nbytes > 0 ? le->nbytes - 2 : 0); // CLRF + return total; +} + #ifdef EXTSTORE static int _logger_parse_extw(logentry *e, char *scratch) { int total; @@ -445,6 +477,7 @@ static const entry_details default_entries[] = { }, [LOGGER_CONNECTION_NEW] = {512, LOG_CONNEVENTS, _logger_log_conn_event, _logger_parse_cne, NULL}, [LOGGER_CONNECTION_CLOSE] = {512, LOG_CONNEVENTS, _logger_log_conn_event, _logger_parse_cce, NULL}, + [LOGGER_DELETIONS] = {512, LOG_DELETIONS, _logger_log_item_deleted, _logger_parse_ide, NULL}, #ifdef EXTSTORE [LOGGER_EXTSTORE_WRITE] = {512, LOG_EVICTIONS, _logger_log_ext_write, _logger_parse_extw, NULL}, [LOGGER_COMPACT_START] = {512, LOG_SYSEVENTS, _logger_log_text, _logger_parse_text, |