]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5629] Cql lease and host now validate schema version
authorThomas Markwalder <tmark@isc.org>
Thu, 31 May 2018 18:30:49 +0000 (14:30 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 31 May 2018 18:30:49 +0000 (14:30 -0400)
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

src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_host_data_source.h
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/pgsql_lease_mgr.cc

index 549984802454e06e3276de38eea14d6bdf7f03e8..2ba860bd3b68cdec0a3ce1da55811bb37969fbbd 100644 (file)
@@ -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() {
index 75d4d45a1d60fad1fbac00b18a9a9cb8698f699b..6208eae5280a572da11c8a8c254183adfa203732 100644 (file)
@@ -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);
index 0b10becfe1ee3a4fb331d9a5aa20e30819d85543..b0ddeca159cd19689a15acf26fb7fa8b2015f739 100644 (file)
@@ -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_);
 }
 
index ecd47864a763a738a8627700a8ed1e174eace6f2..69adf64500a503f833b626bb86d714b8c8263895 100644 (file)
@@ -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);
index c4dfae044be2129f9c29ee1c942fab99f548af52..537c0cb6376cd70a607040bdb053509da360c5e3 100644 (file)
@@ -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: "
index 91a207efbf05a38afc30a5f3f7b84b03b1c7055a..5213f8636703273c061af98a456d4a8fba58d1d3 100644 (file)
@@ -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);
 
index 7e368db7784ac24f933527b1b3e013926d21402e..f6e2a1843400d07627130a60d4db885e063f8e37 100644 (file)
@@ -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]);