2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 22:15:23 +00:00

[3780] MySQL and Postgres lease managers now exit on fatal error detection

src/lib/dhcpsrv/dhcpsrv_messages.mes
    added messages DHCPSRV_MYSQL_FATAL_ERROR, DHCPSRV_PGSQL_FATAL_ERROR

src/lib/dhcpsrv/mysql_lease_mgr.cc
    added MySQL client error code include

    MySqlLeaseMgr::checkError() - method is no longer inlined in
    the header.  Expanded to detect unrecoverable errors, log
    them and call exit().

src/lib/dhcpsrv/mysql_lease_mgr.h
    Removed inline implemenation of MySqlLeaseMgr::checkError(),
    and expanded commentary

src/lib/dhcpsrv/pgsql_lease_mgr.cc
    PgSqlLeaseMgr::addLeaseCommon() - now uses checkStatementError()

    PgSqlLeaseMgr::checkStatementError() - Expanded to detect
    unrecoverable errors, log them and call exit().

src/lib/dhcpsrv/pgsql_lease_mgr.h
    Expanded commentary for PgSqlLeaseMgr::checkStatementError()
This commit is contained in:
Thomas Markwalder
2015-10-23 16:41:27 -04:00
parent 360b740097
commit be964a2b42
5 changed files with 94 additions and 18 deletions

View File

@@ -23,6 +23,7 @@
#include <boost/static_assert.hpp>
#include <mysqld_error.h>
#include <errmsg.h>
#include <iostream>
#include <iomanip>
@@ -2122,5 +2123,38 @@ MySqlLeaseMgr::rollback() {
}
}
void
MySqlLeaseMgr::checkError(int status, StatementIndex index,
const char* what) const {
if (status != 0) {
switch(mysql_errno(conn_.mysql_)) {
// These are the ones we consider fatal. Remember this method is
// used to check errors of API calls made subsequent to successfully
// connecting. Errors occuring while attempting to connect are
// checked in the connection code. An alternative would be to call
// mysql_ping() - assuming autoreconnect is off. If that fails
// then we know connection is toast.
case CR_SERVER_GONE_ERROR:
case CR_SERVER_LOST:
case CR_OUT_OF_MEMORY:
case CR_CONNECTION_ERROR:
// We're exiting on fatal
LOG_ERROR(dhcpsrv_logger, DHCPSRV_MYSQL_FATAL_ERROR)
.arg(what)
.arg(conn_.text_statements_[index])
.arg(mysql_error(conn_.mysql_))
.arg(mysql_errno(conn_.mysql_));
exit (-1);
default:
// Connection is ok, so it must be an SQL error
isc_throw(DbOperationError, what << " for <"
<< conn_.text_statements_[index] << ">, reason: "
<< mysql_error(conn_.mysql_) << " (error code "
<< mysql_errno(conn_.mysql_) << ")");
}
}
}
}; // end of isc::dhcp namespace
}; // end of isc namespace