mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
[#2734] tcp_user_timeout for PostgreSQL 12+
Added conditional compilation to set tcp_user_timeout parameter for the PostgreSQL 12 or later. Log a warning for earlier PostgreSQL versions.
This commit is contained in:
@@ -802,6 +802,7 @@ if test "$PG_CONFIG" != "" ; then
|
||||
PGSQL_LIBS=`$PG_CONFIG --libdir`
|
||||
PGSQL_LIBS="-L$PGSQL_LIBS -lpq"
|
||||
PGSQL_VERSION=`$PG_CONFIG --version`
|
||||
PGSQL_MAJOR_VERSION=`$PG_CONFIG --version | cut -f2 -d' ' | cut -f1 -d'.'`
|
||||
|
||||
AC_SUBST(PGSQL_CPPFLAGS)
|
||||
AC_SUBST(PGSQL_LIBS)
|
||||
@@ -831,6 +832,10 @@ if test "$PG_CONFIG" != "" ; then
|
||||
|
||||
# Note that PostgreSQL is present in the config.h file
|
||||
AC_DEFINE([HAVE_PGSQL], [1], [PostgreSQL is present])
|
||||
|
||||
if test $PGSQL_MAJOR_VERSION -ge 12; then
|
||||
AC_DEFINE([HAVE_PGSQL_TCP_USER_TIMEOUT], [1], [PostgreSQL connection parameter tcp_user_timeout supported])
|
||||
fi
|
||||
fi
|
||||
|
||||
# ... and at the shell level, so Makefile.am can take action depending on this.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@@ -22,20 +22,21 @@ const int DB_DBG_TRACE_DETAIL = isc::log::DBGLVL_TRACE_DETAIL;
|
||||
|
||||
/// @brief Map of translated messages.
|
||||
const DbLogger::MessageMap db_message_map = {
|
||||
{ DB_INVALID_ACCESS, DATABASE_INVALID_ACCESS },
|
||||
{ DB_INVALID_ACCESS, DATABASE_INVALID_ACCESS },
|
||||
|
||||
{ PGSQL_DEALLOC_ERROR, DATABASE_PGSQL_DEALLOC_ERROR },
|
||||
{ PGSQL_FATAL_ERROR, DATABASE_PGSQL_FATAL_ERROR },
|
||||
{ PGSQL_START_TRANSACTION, DATABASE_PGSQL_START_TRANSACTION },
|
||||
{ PGSQL_COMMIT, DATABASE_PGSQL_COMMIT },
|
||||
{ PGSQL_ROLLBACK, DATABASE_PGSQL_ROLLBACK },
|
||||
{ PGSQL_CREATE_SAVEPOINT, DATABASE_PGSQL_CREATE_SAVEPOINT },
|
||||
{ PGSQL_ROLLBACK_SAVEPOINT, DATABASE_PGSQL_ROLLBACK_SAVEPOINT },
|
||||
{ PGSQL_DEALLOC_ERROR, DATABASE_PGSQL_DEALLOC_ERROR },
|
||||
{ PGSQL_FATAL_ERROR, DATABASE_PGSQL_FATAL_ERROR },
|
||||
{ PGSQL_START_TRANSACTION, DATABASE_PGSQL_START_TRANSACTION },
|
||||
{ PGSQL_COMMIT, DATABASE_PGSQL_COMMIT },
|
||||
{ PGSQL_ROLLBACK, DATABASE_PGSQL_ROLLBACK },
|
||||
{ PGSQL_CREATE_SAVEPOINT, DATABASE_PGSQL_CREATE_SAVEPOINT },
|
||||
{ PGSQL_ROLLBACK_SAVEPOINT, DATABASE_PGSQL_ROLLBACK_SAVEPOINT },
|
||||
{ PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED, DATABASE_PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED },
|
||||
|
||||
{ MYSQL_FATAL_ERROR, DATABASE_MYSQL_FATAL_ERROR },
|
||||
{ MYSQL_START_TRANSACTION, DATABASE_MYSQL_START_TRANSACTION },
|
||||
{ MYSQL_COMMIT, DATABASE_MYSQL_COMMIT },
|
||||
{ MYSQL_ROLLBACK, DATABASE_MYSQL_ROLLBACK },
|
||||
{ MYSQL_FATAL_ERROR, DATABASE_MYSQL_FATAL_ERROR },
|
||||
{ MYSQL_START_TRANSACTION, DATABASE_MYSQL_START_TRANSACTION },
|
||||
{ MYSQL_COMMIT, DATABASE_MYSQL_COMMIT },
|
||||
{ MYSQL_ROLLBACK, DATABASE_MYSQL_ROLLBACK },
|
||||
};
|
||||
|
||||
isc::log::Logger database_logger("database");
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@@ -58,6 +58,7 @@ enum DbMessageID {
|
||||
PGSQL_ROLLBACK,
|
||||
PGSQL_CREATE_SAVEPOINT,
|
||||
PGSQL_ROLLBACK_SAVEPOINT,
|
||||
PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED,
|
||||
|
||||
MYSQL_FATAL_ERROR,
|
||||
MYSQL_START_TRANSACTION,
|
||||
|
@@ -80,6 +80,12 @@ inserted into multiple tables with multiple INSERT statements
|
||||
and there may be a need to rollback the whole transaction if
|
||||
any of these INSERT statements fail.
|
||||
|
||||
% DATABASE_PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED tcp_user_timeout is not supported in this PostgreSQL version
|
||||
This warning message is issued when a user has configured the tcp_user_timeout
|
||||
parameter in the connection to the PostgreSQL database but the installed database
|
||||
does not support this parameter. This parameter is supported by the PostgreSQL
|
||||
version 12 or later. The parameter setting will be ignored.
|
||||
|
||||
% DATABASE_TO_JSON_BOOLEAN_ERROR Internal logic error: invalid boolean value found in database connection parameters: %1=%2
|
||||
This error message is printed when conversion to JSON of the internal state is requested,
|
||||
but the connection string contains a boolean parameter with invalid value. It is a programming
|
||||
|
@@ -249,11 +249,17 @@ PgSqlConnection::getConnParameters() {
|
||||
isc_throw(DbInvalidTimeout, ex.what());
|
||||
}
|
||||
|
||||
// Append timeouts.
|
||||
// Append connection timeout.
|
||||
std::ostringstream oss;
|
||||
oss << " connect_timeout = " << connect_timeout;
|
||||
|
||||
if (tcp_user_timeout > 0) {
|
||||
// tcp_user_timeout parameter is a PostgreSQL 12+ feature.
|
||||
#ifdef HAVE_PGSQL_TCP_USER_TIMEOUT
|
||||
oss << " tcp_user_timeout = " << tcp_user_timeout * 1000;
|
||||
#else
|
||||
DB_LOG_WARN(PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED).arg();
|
||||
#endif
|
||||
}
|
||||
dbconnparameters += oss.str();
|
||||
|
||||
|
@@ -611,7 +611,9 @@ TEST_F(PgSqlConnectionTest, connectionTimeoutInvalid3) {
|
||||
EXPECT_THROW(conn.getConnParameters(), DbInvalidTimeout);
|
||||
}
|
||||
|
||||
// Tests that valid tcp user timeout is accepted.
|
||||
// Tests that valid tcp user timeout is accepted. This parameter is
|
||||
// supported by PostgreSQL 12 and later.
|
||||
#ifdef HAVE_PGSQL_TCP_USER_TIMEOUT
|
||||
TEST_F(PgSqlConnectionTest, tcpUserTimeout) {
|
||||
std::string conn_str = connectionString(PGSQL_VALID_TYPE, VALID_NAME,
|
||||
VALID_USER, VALID_PASSWORD,
|
||||
@@ -622,6 +624,7 @@ TEST_F(PgSqlConnectionTest, tcpUserTimeout) {
|
||||
EXPECT_TRUE(parameters.find("tcp_user_timeout = 8000") != std::string::npos)
|
||||
<< "parameter not found in " << parameters;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests that a zero tcp user timeout is accepted.
|
||||
TEST_F(PgSqlConnectionTest, tcpUserTimeoutZero) {
|
||||
|
Reference in New Issue
Block a user