Skip to content

Commit

Permalink
Add extra logging when reporting errors from masters - especially in …
Browse files Browse the repository at this point in the history
…rreplay
  • Loading branch information
JohnSully committed Mar 4, 2020
1 parent 6c78ec7 commit 5397f0b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ client *createClient(int fd, int iel) {
c->bufposAsync = 0;
c->client_tracking_redirection = 0;
c->casyncOpsPending = 0;
c->master_error = 0;
memset(c->uuid, 0, UUID_BINARY_LEN);

listSetFreeMethod(c->pubsub_patterns,decrRefCountVoid);
Expand Down Expand Up @@ -432,6 +433,34 @@ void addReplyProtoAsync(client *c, const char *s, size_t len) {
addReplyProtoCore(c, s, len, true);
}

std::string escapeString(sds str)
{
std::string newstr;
size_t len = sdslen(str);
for (size_t ich = 0; ich < len; ++ich)
{
char ch = str[ich];
switch (ch)
{
case '\n':
newstr += "\\n";
break;

case '\t':
newstr += "\\t";
break;

case '\r':
newstr += "\\r";
break;

default:
newstr += ch;
}
}
return newstr;
}

/* Low level function called by the addReplyError...() functions.
* It emits the protocol for a Redis error, in the form:
*
Expand Down Expand Up @@ -464,6 +493,12 @@ void addReplyErrorLengthCore(client *c, const char *s, size_t len, bool fAsync)
serverLog(LL_WARNING,"== CRITICAL == This %s is sending an error "
"to its %s: '%s' after processing the command "
"'%s'", from, to, s, cmdname);

if (c->querybuf && sdslen(c->querybuf)) {
std::string str = escapeString(c->querybuf);
serverLog(LL_WARNING, "\tquerybuf: %s", str.c_str());
}
c->master_error = 1;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/replication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3482,6 +3482,8 @@ void replicaReplayCommand(client *c)
cFake->flags &= ~(CLIENT_MASTER | CLIENT_PREVENT_REPL_PROP);
bool fExec = ccmdPrev != serverTL->commandsExecuted;
cFake->lock.unlock();
if (cFake->master_error)
addReplyError(c, "Error in rreplay command, please check logs");
if (fExec || cFake->flags & CLIENT_MULTI)
{
addReply(c, shared.ok);
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ typedef struct client {

int iel; /* the event loop index we're registered with */
struct fastlock lock;
int master_error;
} client;

struct saveparam {
Expand Down

0 comments on commit 5397f0b

Please sign in to comment.