Commit 868996c8 authored by Thomas Markwalder's avatar Thomas Markwalder

[5629] Cql lease and host now validate schema version

src/lib/dhcpsrv/cql_host_data_source.cc
    CqlHostDataSourceImpl::CqlHostDataSourceImpl() - added schema
    version validation

src/lib/dhcpsrv/cql_lease_mgr.cc
    CqlLeaseMgr::CqlLeaseMgr() - added schema version validation
parent 3a4e9893
......@@ -1612,9 +1612,21 @@ CqlHostDataSourceImpl::CqlHostDataSourceImpl(const CqlConnection::ParameterMap&
// Open the database.
dbconn_.openDatabase();
// Prepare the version exchange first.
dbconn_.prepareStatements(CqlVersionExchange::tagged_statements_);
// Validate the schema version.
std::pair<uint32_t, uint32_t> code_version(CQL_SCHEMA_VERSION_MAJOR,
CQL_SCHEMA_VERSION_MINOR);
std::pair<uint32_t, uint32_t> db_version = getVersion();
if (code_version != db_version) {
isc_throw(DbOpenError, "Cassandra schema version mismatch: need version: "
<< code_version.first << "." << code_version.second
<< " found version: " << db_version.first << ".");
}
// Prepare all possible statements.
dbconn_.prepareStatements(CqlHostExchange::tagged_statements_);
dbconn_.prepareStatements(CqlVersionExchange::tagged_statements_);
}
CqlHostDataSourceImpl::~CqlHostDataSourceImpl() {
......
......@@ -78,7 +78,8 @@ public:
/// concerned with the database.
///
/// @throw isc::dhcp::NoDatabaseName Mandatory database name not given
/// @throw isc::dhcp::DbOpenError Error opening the database
/// @throw isc::dhcp::DbOpenError Error opening the database or if the
/// schema version is invalid.
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
explicit CqlHostDataSource(const DatabaseConnection::ParameterMap& parameters);
......
......@@ -1854,9 +1854,24 @@ CqlLeaseStatsQuery::executeSelect(const CqlConnection& connection, const AnyArra
CqlLeaseMgr::CqlLeaseMgr(const DatabaseConnection::ParameterMap &parameters)
: LeaseMgr(), dbconn_(parameters) {
dbconn_.openDatabase();
// Prepare the version exchange first.
dbconn_.prepareStatements(CqlVersionExchange::tagged_statements_);
// Validate the schema version.
std::pair<uint32_t, uint32_t> code_version(CQL_SCHEMA_VERSION_MAJOR,
CQL_SCHEMA_VERSION_MINOR);
std::pair<uint32_t, uint32_t> db_version = getVersion();
if (code_version != db_version) {
isc_throw(DbOpenError,
"Cassandra schema version mismatch: need version: "
<< code_version.first << "." << code_version.second
<< " found version: " << db_version.first << ".");
}
// Now prepare the rest of the exchanges.
dbconn_.prepareStatements(CqlLease4Exchange::tagged_statements_);
dbconn_.prepareStatements(CqlLease6Exchange::tagged_statements_);
dbconn_.prepareStatements(CqlVersionExchange::tagged_statements_);
dbconn_.prepareStatements(CqlLeaseStatsQuery::tagged_statements_);
}
......
......@@ -66,7 +66,8 @@ public:
/// concerned with the database.
///
/// @throw isc::dhcp::NoDatabaseName Mandatory database name not given
/// @throw isc::dhcp::DbOpenError Error opening the database
/// @throw isc::dhcp::DbOpenError Error opening the database or the schema
/// version is invalid.
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
explicit CqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters);
......
......@@ -2305,7 +2305,7 @@ MySqlHostDataSourceImpl(const MySqlConnection::ParameterMap& parameters)
// Test schema version before we try to prepare statements.
std::pair<uint32_t, uint32_t> code_version(MYSQL_SCHEMA_VERSION_MAJOR,
MYSQL_SCHEMA_VERSION_MINOR);
MYSQL_SCHEMA_VERSION_MINOR);
std::pair<uint32_t, uint32_t> db_version = getVersion();
if (code_version != db_version) {
isc_throw(DbOpenError, "MySQL schema version mismatch: need version: "
......
......@@ -1700,8 +1700,10 @@ PgSqlHostDataSourceImpl(const PgSqlConnection::ParameterMap& parameters)
// Open the database.
conn_.openDatabase();
pair<uint32_t, uint32_t> code_version(PG_SCHEMA_VERSION_MAJOR, PG_SCHEMA_VERSION_MINOR);
pair<uint32_t, uint32_t> db_version = getVersion();
// Validate the schema version first.
std::pair<uint32_t, uint32_t> code_version(PG_SCHEMA_VERSION_MAJOR,
PG_SCHEMA_VERSION_MINOR);
std::pair<uint32_t, uint32_t> db_version = getVersion();
if (code_version != db_version) {
isc_throw(DbOpenError,
"PostgreSQL schema version mismatch: need version: "
......@@ -1710,6 +1712,7 @@ PgSqlHostDataSourceImpl(const PgSqlConnection::ParameterMap& parameters)
<< db_version.second);
}
// Now prepare the SQL statements.
conn_.prepareStatements(tagged_statements.begin(),
tagged_statements.begin() + WRITE_STMTS_BEGIN);
......
......@@ -996,8 +996,10 @@ PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
exchange6_(new PgSqlLease6Exchange()), conn_(parameters) {
conn_.openDatabase();
pair<uint32_t, uint32_t> code_version(PG_SCHEMA_VERSION_MAJOR, PG_SCHEMA_VERSION_MINOR);
pair<uint32_t, uint32_t> db_version = getVersion();
// Validate schema version first.
std::pair<uint32_t, uint32_t> code_version(PG_SCHEMA_VERSION_MAJOR,
PG_SCHEMA_VERSION_MINOR);
std::pair<uint32_t, uint32_t> db_version = getVersion();
if (code_version != db_version) {
isc_throw(DbOpenError,
"PostgreSQL schema version mismatch: need version: "
......@@ -1006,6 +1008,7 @@ PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
<< db_version.second);
}
// Now prepare the SQL statements.
int i = 0;
for( ; tagged_statements[i].text != NULL ; ++i) {
conn_.prepareStatement(tagged_statements[i]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment