// 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() {
/// 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);
CqlLeaseMgr::CqlLeaseMgr(const DatabaseConnection::ParameterMap ¶meters)
: 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_);
}
/// 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);
// 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: "
// 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: "
<< db_version.second);
}
+ // Now prepare the SQL statements.
conn_.prepareStatements(tagged_statements.begin(),
tagged_statements.begin() + WRITE_STMTS_BEGIN);
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: "
<< db_version.second);
}
+ // Now prepare the SQL statements.
int i = 0;
for( ; tagged_statements[i].text != NULL ; ++i) {
conn_.prepareStatement(tagged_statements[i]);