Do some actions after an error reply was sent (Log if needed, updates stats, etc.) */
| 537 | |
| 538 | /* Do some actions after an error reply was sent (Log if needed, updates stats, etc.) */ |
| 539 | void afterErrorReply(client *c, const char *s, size_t len, int severity = ERR_CRITICAL) { |
| 540 | /* Increment the thread error counter */ |
| 541 | serverTL->stat_total_error_replies++; |
| 542 | /* Increment the error stats |
| 543 | * If the string already starts with "-..." then the error prefix |
| 544 | * is provided by the caller ( we limit the search to 32 chars). Otherwise we use "-ERR". */ |
| 545 | if (s[0] != '-') { |
| 546 | incrementErrorCount("ERR", 3); |
| 547 | } else { |
| 548 | const char *spaceloc = (const char*)memchr(s, ' ', len < 32 ? len : 32); |
| 549 | if (spaceloc) { |
| 550 | const size_t errEndPos = (size_t)(spaceloc - s); |
| 551 | incrementErrorCount(s+1, errEndPos-1); |
| 552 | } else { |
| 553 | /* Fallback to ERR if we can't retrieve the error prefix */ |
| 554 | incrementErrorCount("ERR", 3); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | int ctype = getClientType(c); |
| 559 | if (ctype == CLIENT_TYPE_MASTER || ctype == CLIENT_TYPE_SLAVE || c->id == CLIENT_ID_AOF) { |
| 560 | const char *to, *from; |
| 561 | |
| 562 | if (c->id == CLIENT_ID_AOF) { |
| 563 | to = "AOF-loading-client"; |
| 564 | from = "server"; |
| 565 | } else if (ctype == CLIENT_TYPE_MASTER) { |
| 566 | to = "master"; |
| 567 | from = "replica"; |
| 568 | } else { |
| 569 | to = "replica"; |
| 570 | from = "master"; |
| 571 | } |
| 572 | |
| 573 | if (len > 4096) len = 4096; |
| 574 | const char *cmdname = c->lastcmd ? c->lastcmd->name : "<unknown>"; |
| 575 | switch (severity) { |
| 576 | case ERR_NOTICE: |
| 577 | serverLog(LL_NOTICE,"== NOTICE == This %s is rejecting a command " |
| 578 | "from its %s: '%.*s' after processing the command " |
| 579 | "'%s'", from, to, (int)len, s, cmdname); |
| 580 | break; |
| 581 | case ERR_WARNING: |
| 582 | serverLog(LL_WARNING,"== WARNING == This %s is rejecting a command " |
| 583 | "from its %s: '%.*s' after processing the command " |
| 584 | "'%s'", from, to, (int)len, s, cmdname); |
| 585 | break; |
| 586 | case ERR_ERROR: |
| 587 | serverLog(LL_WARNING,"== ERROR == This %s is sending an error " |
| 588 | "to its %s: '%.*s' after processing the command " |
| 589 | "'%s'", from, to, (int)len, s, cmdname); |
| 590 | break; |
| 591 | case ERR_CRITICAL: |
| 592 | default: |
| 593 | serverLog(LL_WARNING,"== CRITICAL == This %s is sending an error " |
| 594 | "to its %s: '%.*s' after processing the command " |
| 595 | "'%s'", from, to, (int)len, s, cmdname); |
| 596 | break; |
no test coverage detected