|
12 | 12 | #include "InfoLoggerDispatch.h" |
13 | 13 | #include <mysql.h> |
14 | 14 | #include <mysqld_error.h> |
| 15 | +#include <errmsg.h> |
15 | 16 | #include "utility.h" |
16 | 17 | #include "infoLoggerMessage.h" |
17 | 18 | #include <unistd.h> |
@@ -61,6 +62,9 @@ class InfoLoggerDispatchSQLImpl |
61 | 62 | int commitTimeout = 1000000; // time between commits |
62 | 63 | Timer commitTimer; // timer for transaction |
63 | 64 | int commitNumberOfMsg; // number of messages since last commit |
| 65 | + |
| 66 | + int numberOfSuccessiveFailures = 0; // count consecutive insert failures |
| 67 | + int maxNumberOfRetries = 1; // number of retries allowed |
64 | 68 | }; |
65 | 69 |
|
66 | 70 | void InfoLoggerDispatchSQLImpl::start() |
@@ -393,9 +397,22 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe |
393 | 397 | if ( err == ER_TRUNCATED_WRONG_VALUE_FOR_FIELD) { |
394 | 398 | return returnDroppedMessage(msg, m); |
395 | 399 | } |
396 | | - // retry with new connection - usually it means server was down |
397 | | - disconnectDB(); |
398 | | - return returnDelayedMessage(); |
| 400 | + // server gone - retry with new connection |
| 401 | + if (( err == CR_SERVER_LOST ) || ( err == CR_SERVER_GONE_ERROR )) { |
| 402 | + disconnectDB(); |
| 403 | + return returnDelayedMessage(); |
| 404 | + } |
| 405 | + |
| 406 | + numberOfSuccessiveFailures++; |
| 407 | + if (numberOfSuccessiveFailures <= maxNumberOfRetries) { |
| 408 | + disconnectDB(); |
| 409 | + return returnDelayedMessage(); |
| 410 | + } |
| 411 | + numberOfSuccessiveFailures = 0; |
| 412 | + |
| 413 | + // by default: drop message |
| 414 | + parent->logError("Unhandled error code %d after %d attempts", mysql_errno(db), maxNumberOfRetries); |
| 415 | + return returnDroppedMessage(msg, m); |
399 | 416 | } |
400 | 417 |
|
401 | 418 | insertCount++; |
|
0 commit comments