|
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() |
@@ -384,13 +388,31 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe |
384 | 388 | // Do the insertion |
385 | 389 | if (mysql_stmt_execute(stmt)) { |
386 | 390 | parent->logError("mysql_stmt_exec() failed: (%d) %s", mysql_errno(db), mysql_error(db)); |
| 391 | + unsigned int err = mysql_errno(db); |
387 | 392 | // column too long |
388 | | - if (mysql_errno(db) == ER_DATA_TOO_LONG) { |
| 393 | + if ( err == ER_DATA_TOO_LONG) { |
| 394 | + return returnDroppedMessage(msg, m); |
| 395 | + } |
| 396 | + // column with wrong value |
| 397 | + if ( err == ER_TRUNCATED_WRONG_VALUE_FOR_FIELD) { |
389 | 398 | return returnDroppedMessage(msg, m); |
390 | 399 | } |
391 | | - // retry with new connection - usually it means server was down |
392 | | - disconnectDB(); |
393 | | - 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); |
394 | 416 | } |
395 | 417 |
|
396 | 418 | insertCount++; |
|
0 commit comments