Skip to content

Commit

Permalink
improve 'watch' command processing a little
Browse files Browse the repository at this point in the history
moves to its own function, respods "OK\r\n" to client, allows multiple
arguments for multiple flags. Needs more thought before adding sampling.
  • Loading branch information
dormando committed Jun 17, 2016
1 parent 1b03a9c commit efa436f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
1 change: 1 addition & 0 deletions logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, uint16_t
pthread_mutex_unlock(&logger_stack_lock);
return LOGGER_ADD_WATCHER_FAILED;
}
bipbuf_offer(w->buf, (unsigned char *) "OK\r\n", 4);

watchers[x] = w;
watcher_count++;
Expand Down
1 change: 0 additions & 1 deletion logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ typedef struct _logentry {
#define LOG_CONNEVENTS (1<<5) /* new client, closed, etc */
#define LOG_EVICTIONS (1<<6) /* defailts of evicted items */
#define LOG_STRICT (1<<7) /* block worker instead of drop */
#define LOG_TIME (1<<8) /* log the entry time */
#define LOG_RAWCMDS (1<<9) /* raw ascii commands */

typedef struct _logger {
Expand Down
64 changes: 37 additions & 27 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -3435,6 +3435,42 @@ static void process_slabs_automove_command(conn *c, token_t *tokens, const size_
return;
}

/* TODO: decide on syntax for sampling? */
static void process_watch_command(conn *c, token_t *tokens, const size_t ntokens) {
uint16_t f = 0;
int x;
assert(c != NULL);

set_noreply_maybe(c, tokens, ntokens);
if (ntokens > 2) {
for (x = COMMAND_TOKEN + 1; x < ntokens - 1; x++) {
if ((strcmp(tokens[x].value, "rawcmds") == 0)) {
f |= LOG_RAWCMDS;
} else if ((strcmp(tokens[x].value, "evictions") == 0)) {
f |= LOG_EVICTIONS;
} else {
out_string(c, "ERROR");
return;
}
}
} else {
f |= LOG_RAWCMDS;
}

switch(logger_add_watcher(c, c->sfd, f)) {
case LOGGER_ADD_WATCHER_TOO_MANY:
out_string(c, "WATCHER_TOO_MANY log watcher limit reached");
break;
case LOGGER_ADD_WATCHER_FAILED:
out_string(c, "WATCHER_FAILED failed to add log watcher");
break;
case LOGGER_ADD_WATCHER_OK:
conn_set_state(c, conn_watch);
event_del(&c->event);
break;
}
}

static void process_command(conn *c, char *command) {

token_t tokens[MAX_TOKENS];
Expand Down Expand Up @@ -3677,33 +3713,7 @@ static void process_command(conn *c, char *command) {
out_string(c, "ERROR");
}
} else if (ntokens > 1 && strcmp(tokens[COMMAND_TOKEN].value, "watch") == 0) {
uint16_t f = 0;
/* TODO: pass to function for full argument processing. */
/* This is very temporary... need to decide on a real flag parser. */
if (ntokens == 3) {
if ((strcmp(tokens[COMMAND_TOKEN + 1].value, "rawcmds") == 0)) {
f |= LOG_RAWCMDS;
} else if ((strcmp(tokens[COMMAND_TOKEN + 1].value, "evictions") == 0)) {
f |= LOG_EVICTIONS;
} else {
out_string(c, "ERROR");
}
} else {
f |= LOG_RAWCMDS;
}
f |= LOG_TIME; /* not optional yet */
switch(logger_add_watcher(c, c->sfd, f)) {
case LOGGER_ADD_WATCHER_TOO_MANY:
out_string(c, "WATCHER_TOO_MANY log watcher limit reached");
break;
case LOGGER_ADD_WATCHER_FAILED:
out_string(c, "WATCHER_FAILED failed to add log watcher");
break;
case LOGGER_ADD_WATCHER_OK:
conn_set_state(c, conn_watch);
event_del(&c->event);
break;
}
process_watch_command(c, tokens, ntokens);
} else if ((ntokens == 3 || ntokens == 4) && (strcmp(tokens[COMMAND_TOKEN].value, "verbosity") == 0)) {
process_verbosity_command(c, tokens, ntokens);
} else {
Expand Down

0 comments on commit efa436f

Please sign in to comment.