Commit ba7b03d6 authored by Cedric CAFFY's avatar Cedric CAFFY
Browse files

The getSchemaVersion() method of the catalogue now returns a SchemaVersion object

Adapted the cta-catalogue-schema-verify tool to deal with the SchemaVersion object and displaying a warning
in case of running database upgrade
parent ee286857
......@@ -55,6 +55,7 @@ set (CATALOGUE_LIB_SRC_FILES
SchemaCreatingSqliteCatalogue.cpp
SqliteCatalogue.cpp
SqliteCatalogueFactory.cpp
SchemaVersion.cpp
TapeForWriting.cpp
UserSpecifiedANonEmptyLogicalLibrary.cpp
UserSpecifiedANonEmptyTape.cpp
......
......@@ -62,6 +62,7 @@
#include "common/log/LogContext.hpp"
#include "common/log/Logger.hpp"
#include "common/optional.hpp"
#include "SchemaVersion.hpp"
#include <list>
#include <map>
......@@ -747,12 +748,16 @@ public:
virtual void verifySchemaVersion() = 0;
/**
* Returns the map of strings to uint64 for the SCHEMA_VERSION_MAJOR
* and SCHEMA_VERSION_MINOR.
* Returns the SchemaVersion object corresponding to the catalogue schema version:
* - SCHEMA_VERSION_MAJOR
* - SCHEMA_VERSION_MINOR
* - SCHEMA_VERSION_MAJOR_NEXT (future major version number of the schema in case of upgrade)
* - SCHEMA_VERSION_MINOR_NEXT (future minor version number of the schema in case of upgrade)
* - STATUS (UPGRADING or COMPLETE)
*
* @return The map for SCHEMA_VERSION_MAJOR and SCHEMA_VERSION_MINOR values.
* @return The SchemaVersion object corresponding to the catalogue schema version
*/
virtual std::map<std::string, uint64_t> getSchemaVersion() const = 0;
virtual SchemaVersion getSchemaVersion() const = 0;
/**
* Returns true if the specified tape pool exists.
......
......@@ -55,8 +55,7 @@ void MetadataGetter::removeObjectNameMatches(std::list<std::string> &objects, co
CatalogueMetadataGetter::CatalogueMetadataGetter(cta::rdbms::Conn& conn):m_conn(conn){}
std::string CatalogueMetadataGetter::getCatalogueVersion(){
std::string schemaVersion;
SchemaVersion CatalogueMetadataGetter::getCatalogueVersion(){
const char *const sql =
"SELECT "
"CTA_CATALOGUE.SCHEMA_VERSION_MAJOR AS SCHEMA_VERSION_MAJOR,"
......@@ -68,12 +67,40 @@ std::string CatalogueMetadataGetter::getCatalogueVersion(){
auto rset = stmt.executeQuery();
if(rset.next()) {
schemaVersion += std::to_string(rset.columnUint64("SCHEMA_VERSION_MAJOR"));
schemaVersion += ".";
schemaVersion += std::to_string(rset.columnUint64("SCHEMA_VERSION_MINOR"));
return schemaVersion;
SchemaVersion::Builder schemaVersionBuilder;
schemaVersionBuilder.schemaVersionMajor(rset.columnUint64("SCHEMA_VERSION_MAJOR"))
.schemaVersionMinor(rset.columnUint64("SCHEMA_VERSION_MINOR"))
//By default, the status is set as COMPLETE (to be backward-compatible with version 1.0 of the schema)
.status(SchemaVersion::Status::COMPLETE);
//The cta-catalogue-schema-verify tool has to be backward-compatible with version 1.0
//of the schema that does not have the NEXT_SCHEMA_VERSION_MAJOR, NEXT_SCHEMA_VERSION_MINOR and the STATUS column
const char *const sql2 =
"SELECT "
"CTA_CATALOGUE.NEXT_SCHEMA_VERSION_MAJOR AS NEXT_SCHEMA_VERSION_MAJOR,"
"CTA_CATALOGUE.NEXT_SCHEMA_VERSION_MINOR AS NEXT_SCHEMA_VERSION_MINOR,"
"CTA_CATALOGUE.STATUS AS STATUS "
"FROM "
"CTA_CATALOGUE";
auto stmt2 = m_conn.createStmt(sql2);
try{
auto rset2 = stmt2.executeQuery();
if(rset2.next()){
auto schemaVersionMajorNext = rset2.columnOptionalUint64("NEXT_SCHEMA_VERSION_MAJOR");
auto schemaVersionMinorNext = rset2.columnOptionalUint64("NEXT_SCHEMA_VERSION_MINOR");
auto schemaStatus = rset2.columnString("STATUS");
if(schemaVersionMajorNext && schemaVersionMinorNext){
schemaVersionBuilder.nextSchemaVersionMajor(schemaVersionMajorNext.value())
.nextSchemaVersionMinor(schemaVersionMinorNext.value())
.status(schemaStatus);
}
}
} catch (const cta::exception::Exception &ex){
}
return schemaVersionBuilder.build();
} else {
throw exception::Exception("SCHEMA_VERSION_MAJOR,SCHEMA_VERSION_MINOR not found in the CTA_CATALOGUE");
throw exception::Exception("CTA_CATALOGUE does not contain any row");
}
}
......@@ -102,6 +129,10 @@ std::list<std::string> CatalogueMetadataGetter::getConstraintNames(const std::st
return constraintNames;
}
std::list<std::string> CatalogueMetadataGetter::getParallelTableNames(){
return m_conn.getParallelTableNames();
}
CatalogueMetadataGetter::~CatalogueMetadataGetter() {}
SQLiteCatalogueMetadataGetter::SQLiteCatalogueMetadataGetter(cta::rdbms::Conn & conn):CatalogueMetadataGetter(conn){}
......@@ -121,14 +152,27 @@ std::list<std::string> SQLiteCatalogueMetadataGetter::getTableNames(){
return tableNames;
}
cta::rdbms::Login::DbType SQLiteCatalogueMetadataGetter::getDbType(){
return cta::rdbms::Login::DbType::DBTYPE_SQLITE;
}
OracleCatalogueMetadataGetter::OracleCatalogueMetadataGetter(cta::rdbms::Conn & conn):CatalogueMetadataGetter(conn){}
OracleCatalogueMetadataGetter::~OracleCatalogueMetadataGetter(){}
cta::rdbms::Login::DbType OracleCatalogueMetadataGetter::getDbType(){
return cta::rdbms::Login::DbType::DBTYPE_ORACLE;
}
MySQLCatalogueMetadataGetter::MySQLCatalogueMetadataGetter(cta::rdbms::Conn& conn):CatalogueMetadataGetter(conn) {}
MySQLCatalogueMetadataGetter::~MySQLCatalogueMetadataGetter(){}
cta::rdbms::Login::DbType MySQLCatalogueMetadataGetter::getDbType(){
return cta::rdbms::Login::DbType::DBTYPE_MYSQL;
}
PostgresCatalogueMetadataGetter::PostgresCatalogueMetadataGetter(cta::rdbms::Conn& conn):CatalogueMetadataGetter(conn) {}
PostgresCatalogueMetadataGetter::~PostgresCatalogueMetadataGetter(){}
cta::rdbms::Login::DbType PostgresCatalogueMetadataGetter::getDbType(){
return cta::rdbms::Login::DbType::DBTYPE_POSTGRESQL;
}
CatalogueMetadataGetter * CatalogueMetadataGetterFactory::create(const rdbms::Login::DbType dbType, cta::rdbms::Conn & conn) {
typedef rdbms::Login::DbType DbType;
......
......@@ -21,6 +21,7 @@
#include "rdbms/Conn.hpp"
#include "rdbms/Login.hpp"
#include "SchemaCreatingSqliteCatalogue.hpp"
#include "SchemaVersion.hpp"
#include <list>
namespace cta {
......@@ -54,11 +55,13 @@ class CatalogueMetadataGetter: public MetadataGetter {
public:
CatalogueMetadataGetter(cta::rdbms::Conn & conn);
virtual ~CatalogueMetadataGetter();
std::string getCatalogueVersion();
SchemaVersion getCatalogueVersion();
virtual std::list<std::string> getIndexNames();
virtual std::list<std::string> getTableNames();
virtual std::map<std::string,std::string> getColumns(const std::string& tableName);
virtual std::list<std::string> getConstraintNames(const std::string& tableName);
virtual std::list<std::string> getParallelTableNames();
virtual cta::rdbms::Login::DbType getDbType() = 0;
};
/**
......@@ -70,6 +73,7 @@ public:
virtual ~SQLiteCatalogueMetadataGetter();
std::list<std::string> getIndexNames() override;
std::list<std::string> getTableNames() override;
cta::rdbms::Login::DbType getDbType() override;
};
/**
......@@ -78,6 +82,7 @@ public:
class OracleCatalogueMetadataGetter: public CatalogueMetadataGetter{
public:
OracleCatalogueMetadataGetter(cta::rdbms::Conn & conn);
cta::rdbms::Login::DbType getDbType() override;
virtual ~OracleCatalogueMetadataGetter();
};
......@@ -87,6 +92,7 @@ class OracleCatalogueMetadataGetter: public CatalogueMetadataGetter{
class MySQLCatalogueMetadataGetter: public CatalogueMetadataGetter{
public:
MySQLCatalogueMetadataGetter(cta::rdbms::Conn &conn);
cta::rdbms::Login::DbType getDbType() override;
virtual ~MySQLCatalogueMetadataGetter();
};
......@@ -96,6 +102,7 @@ class MySQLCatalogueMetadataGetter: public CatalogueMetadataGetter{
class PostgresCatalogueMetadataGetter: public CatalogueMetadataGetter{
public:
PostgresCatalogueMetadataGetter(cta::rdbms::Conn &conn);
cta::rdbms::Login::DbType getDbType() override;
virtual ~PostgresCatalogueMetadataGetter();
};
......
......@@ -468,7 +468,7 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->verifySchemaVersion();}, m_maxTriesToConnect);
}
std::map<std::string, uint64_t> getSchemaVersion() const override {
SchemaVersion getSchemaVersion() const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getSchemaVersion();}, m_maxTriesToConnect);
}
......
......@@ -43,6 +43,7 @@
#include "catalogue/UserSpecifiedAZeroCopyNb.hpp"
#include "catalogue/UserSpecifiedStorageClassUsedByArchiveFiles.hpp"
#include "catalogue/UserSpecifiedStorageClassUsedByArchiveRoutes.hpp"
#include "catalogue/SchemaVersion.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/UserError.hpp"
#include "common/make_unique.hpp"
......@@ -15388,16 +15389,9 @@ TEST_P(cta_catalogue_CatalogueTest, ping) {
TEST_P(cta_catalogue_CatalogueTest, getSchemaVersion) {
using namespace cta;
 
const std::map<std::string,uint64_t> schemaVersion = {
{"SCHEMA_VERSION_MAJOR", CTA_SCHEMA_VERSION_MAJOR},
{"SCHEMA_VERSION_MINOR", CTA_SCHEMA_VERSION_MINOR}
};
const auto schemaDbVersion = m_catalogue->getSchemaVersion();
for (const auto &schemaInfo : schemaVersion) {
ASSERT_NO_THROW(schemaDbVersion.at(schemaInfo.first));
ASSERT_EQ(schemaInfo.second, schemaDbVersion.at(schemaInfo.first));
}
ASSERT_EQ((uint64_t)CTA_CATALOGUE_SCHEMA_VERSION_MAJOR,schemaDbVersion.getSchemaVersion<catalogue::SchemaVersion::MajorMinor>().first);
ASSERT_EQ((uint64_t)CTA_CATALOGUE_SCHEMA_VERSION_MINOR,schemaDbVersion.getSchemaVersion<catalogue::SchemaVersion::MajorMinor>().second);
}
 
} // namespace unitTests
......@@ -120,7 +120,7 @@ public:
void noSpaceLeftOnTape(const std::string& vid) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void ping() override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void verifySchemaVersion() override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::map<std::string, uint64_t> getSchemaVersion() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
SchemaVersion getSchemaVersion() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
uint64_t checkAndGetNextArchiveFileId(const std::string &diskInstanceName, const std::string &storageClassName, const common::dataStructures::RequesterIdentity &user) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFileQueueCriteria getArchiveFileQueueCriteria(const std::string &diskInstanceName,
const std::string &storageClassName, const common::dataStructures::RequesterIdentity &user) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -58,6 +58,7 @@
#include "common/utils/utils.hpp"
#include "rdbms/AutoRollback.hpp"
#include "version.h"
#include "SchemaVersion.hpp"
#include <ctype.h>
#include <memory>
......@@ -6985,14 +6986,17 @@ void RdbmsCatalogue::ping() {
//------------------------------------------------------------------------------
void RdbmsCatalogue::verifySchemaVersion() {
try {
std::map<std::string, uint64_t> schemaVersion = getSchemaVersion();
uint64_t schemaVersionMajor = schemaVersion.at("SCHEMA_VERSION_MAJOR");
uint64_t schemaVersionMinor = schemaVersion.at("SCHEMA_VERSION_MINOR");
if(schemaVersionMajor != (uint64_t) CTA_CATALOGUE_SCHEMA_VERSION_MAJOR){
SchemaVersion schemaVersion = getSchemaVersion();
auto schemaVersionMajorMinor = schemaVersion.getSchemaVersion<SchemaVersion::MajorMinor>();
if(schemaVersionMajorMinor.first != (uint64_t) CTA_CATALOGUE_SCHEMA_VERSION_MAJOR){
std::ostringstream exceptionMsg;
exceptionMsg << "Catalogue schema MAJOR version differ : Database schema version is " << schemaVersionMajor << "." << schemaVersionMinor << ", CTA schema version is "<< CTA_CATALOGUE_SCHEMA_VERSION_MAJOR << "." << CTA_CATALOGUE_SCHEMA_VERSION_MINOR;
exceptionMsg << "Catalogue schema MAJOR version differ : Database schema version is " << schemaVersionMajorMinor.first << "." << schemaVersionMajorMinor.second << ", CTA schema version is "<< CTA_CATALOGUE_SCHEMA_VERSION_MAJOR << "." << CTA_CATALOGUE_SCHEMA_VERSION_MINOR;
throw WrongSchemaVersionException(exceptionMsg.str());
}
if(schemaVersion.getStatus<SchemaVersion::Status>() == SchemaVersion::Status::UPGRADING){
std::ostringstream exceptionMsg;
exceptionMsg << "Catalogue schema is in status "+schemaVersion.getStatus<std::string>()+", next schema version is "<<schemaVersion.getSchemaVersionNext<std::string>();
}
} catch (exception::UserError &ex) {
throw;
} catch (exception::Exception &ex) {
......@@ -7004,13 +7008,16 @@ void RdbmsCatalogue::verifySchemaVersion() {
//------------------------------------------------------------------------------
// getSchemaVersion
//------------------------------------------------------------------------------
std::map<std::string, uint64_t> RdbmsCatalogue::getSchemaVersion() const {
SchemaVersion RdbmsCatalogue::getSchemaVersion() const {
try {
std::map<std::string, uint64_t> schemaVersion;
const char *const sql =
"SELECT "
"CTA_CATALOGUE.SCHEMA_VERSION_MAJOR AS SCHEMA_VERSION_MAJOR,"
"CTA_CATALOGUE.SCHEMA_VERSION_MINOR AS SCHEMA_VERSION_MINOR "
"CTA_CATALOGUE.SCHEMA_VERSION_MINOR AS SCHEMA_VERSION_MINOR,"
"CTA_CATALOGUE.NEXT_SCHEMA_VERSION_MAJOR AS NEXT_SCHEMA_VERSION_MAJOR,"
"CTA_CATALOGUE.NEXT_SCHEMA_VERSION_MINOR AS NEXT_SCHEMA_VERSION_MINOR,"
"CTA_CATALOGUE.STATUS AS STATUS "
"FROM "
"CTA_CATALOGUE";
......@@ -7019,11 +7026,19 @@ std::map<std::string, uint64_t> RdbmsCatalogue::getSchemaVersion() const {
auto rset = stmt.executeQuery();
if(rset.next()) {
schemaVersion.insert(std::make_pair("SCHEMA_VERSION_MAJOR", rset.columnUint64("SCHEMA_VERSION_MAJOR")));
schemaVersion.insert(std::make_pair("SCHEMA_VERSION_MINOR", rset.columnUint64("SCHEMA_VERSION_MINOR")));
return schemaVersion;
SchemaVersion::Builder schemaVersionBuilder;
schemaVersionBuilder.schemaVersionMajor(rset.columnUint64("SCHEMA_VERSION_MAJOR"))
.schemaVersionMinor(rset.columnUint64("SCHEMA_VERSION_MINOR"))
.status(rset.columnString("STATUS"));
auto schemaVersionMajorNext = rset.columnOptionalUint64("NEXT_SCHEMA_VERSION_MAJOR");
auto schemaVersionMinorNext = rset.columnOptionalUint64("NEXT_SCHEMA_VERSION_MINOR");
if(schemaVersionMajorNext && schemaVersionMinorNext){
schemaVersionBuilder.nextSchemaVersionMajor(schemaVersionMajorNext.value())
.nextSchemaVersionMinor(schemaVersionMinorNext.value());
}
return schemaVersionBuilder.build();
} else {
throw exception::Exception("SCHEMA_VERSION_MAJOR,SCHEMA_VERSION_MINOR not found in the CTA_CATALOGUE");
throw exception::Exception("CTA_CATALOGUE does not contain any row");
}
} catch(exception::UserError &) {
throw;
......
......@@ -746,15 +746,22 @@ public:
*/
void ping() override;
/**
* Checks that the online database schema MAJOR version number matches the schema MAJOR version number defined in version.h
*/
void verifySchemaVersion() override;
/**
* Returns the map of strings to uint64 for the SCHEMA_VERSION_MAJOR
* and SCHEMA_VERSION_MINOR.
* Returns the SchemaVersion object corresponding to the catalogue schema version:
* - SCHEMA_VERSION_MAJOR
* - SCHEMA_VERSION_MINOR
* - SCHEMA_VERSION_MAJOR_NEXT (future major version number of the schema in case of upgrade)
* - SCHEMA_VERSION_MINOR_NEXT (future minor version number of the schema in case of upgrade)
* - STATUS (UPGRADING or COMPLETE)
*
* @return The map for SCHEMA_VERSION_MAJOR and SCHEMA_VERSION_MINOR values.
* @return The SchemaVersion object corresponding to the catalogue schema version
*/
std::map<std::string, uint64_t> getSchemaVersion() const override;
SchemaVersion getSchemaVersion() const override;
/**
* Returns the names of all the tables in the database schema in alphabetical
......
......@@ -25,7 +25,7 @@
namespace cta {
namespace catalogue {
SQLiteSchemaComparer::SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn): SchemaComparer(catalogueDbType,catalogueConn) {
SQLiteSchemaComparer::SQLiteSchemaComparer(CatalogueMetadataGetter &catalogueMetadataGetter): SchemaComparer(catalogueMetadataGetter) {
log::DummyLogger dl("dummy","dummy");
auto login = rdbms::Login::parseString("in_memory");
//Create SQLite connection
......@@ -34,7 +34,7 @@ SQLiteSchemaComparer::SQLiteSchemaComparer(const cta::rdbms::Login::DbType &cata
//Create the Metadata getter
std::unique_ptr<SQLiteCatalogueMetadataGetter> sqliteCatalogueMetadataGetter(new SQLiteCatalogueMetadataGetter(m_sqliteConn));
//Create the Schema Metadata Getter that will filter the SQLite schema metadata according to the catalogue database type we would like to compare
m_schemaMetadataGetter.reset(new SchemaMetadataGetter(std::move(sqliteCatalogueMetadataGetter),catalogueDbType));
m_schemaMetadataGetter.reset(new SchemaMetadataGetter(std::move(sqliteCatalogueMetadataGetter),catalogueMetadataGetter.getDbType()));
}
SQLiteSchemaComparer::~SQLiteSchemaComparer() {
......@@ -53,7 +53,7 @@ SchemaComparerResult SQLiteSchemaComparer::compareAll(){
SchemaComparerResult SQLiteSchemaComparer::compareTables(){
insertSchemaInSQLite();
std::list<std::string> catalogueTables = m_catalogueMetadataGetter->getTableNames();
std::list<std::string> catalogueTables = m_catalogueMetadataGetter.getTableNames();
std::list<std::string> schemaTables = m_schemaMetadataGetter->getTableNames();
SchemaComparerResult res = compareTables(catalogueTables,schemaTables);
return res;
......@@ -73,7 +73,7 @@ void SQLiteSchemaComparer::insertSchemaInSQLite() {
SchemaComparerResult SQLiteSchemaComparer::compareIndexes(){
insertSchemaInSQLite();
std::list<std::string> catalogueIndexes = m_catalogueMetadataGetter->getIndexNames();
std::list<std::string> catalogueIndexes = m_catalogueMetadataGetter.getIndexNames();
std::list<std::string> schemaIndexes = m_schemaMetadataGetter->getIndexNames();
return compareItems("INDEX", catalogueIndexes, schemaIndexes);
}
......@@ -101,8 +101,8 @@ SchemaComparerResult SQLiteSchemaComparer::compareTables(const std::list<std::st
std::map<std::string, std::list<std::string>> schemaTableConstraints;
for(auto &catalogueTable: catalogueTables){
catalogueTableColumns[catalogueTable] = m_catalogueMetadataGetter->getColumns(catalogueTable);
catalogueTableConstraints[catalogueTable] = m_catalogueMetadataGetter->getConstraintNames(catalogueTable);
catalogueTableColumns[catalogueTable] = m_catalogueMetadataGetter.getColumns(catalogueTable);
catalogueTableConstraints[catalogueTable] = m_catalogueMetadataGetter.getConstraintNames(catalogueTable);
}
for(auto &schemaTable: schemaTables){
......
......@@ -29,10 +29,10 @@ class SQLiteSchemaComparer: public SchemaComparer {
public:
/**
* Constructs a SQLiteSchemaComparer
* @param catalogueDbType
* @param catalogueConn
* @param catalogueMetadataGetter the catalogue metadata getter to compare the catalogue schema content with the SQLite
* database one
*/
SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn);
SQLiteSchemaComparer(CatalogueMetadataGetter &catalogueMetadataGetter);
/**
* Compare the catalogue schema against the InMemory SQLite catalogue schema
* @return a SchemaComparerResult object that will contain the differences if there are some
......
......@@ -23,18 +23,19 @@ namespace cta{
namespace catalogue{
SchemaChecker::SchemaChecker(rdbms::Login::DbType dbType,cta::rdbms::Conn &conn):m_dbType(dbType),m_catalogueConn(conn) {
m_catalogueMetadataGetter.reset(CatalogueMetadataGetterFactory::create(m_dbType,m_catalogueConn));
}
SchemaChecker::~SchemaChecker() {
}
void SchemaChecker::useSQLiteSchemaComparer(const cta::optional<std::string> allSchemasVersionsDirectory){
m_schemaComparer.reset(new SQLiteSchemaComparer(m_dbType,m_catalogueConn));
m_schemaComparer.reset(new SQLiteSchemaComparer(*m_catalogueMetadataGetter));
std::unique_ptr<SchemaSqlStatementsReader> schemaSqlStatementsReader;
if(allSchemasVersionsDirectory){
schemaSqlStatementsReader.reset(new DirectoryVersionsSqlStatementsReader(m_dbType,m_schemaComparer->getCatalogueVersion(),allSchemasVersionsDirectory.value()));
schemaSqlStatementsReader.reset(new DirectoryVersionsSqlStatementsReader(m_dbType,m_catalogueMetadataGetter->getCatalogueVersion().getSchemaVersion<std::string>(),allSchemasVersionsDirectory.value()));
} else {
schemaSqlStatementsReader.reset(new MapSqlStatementsReader(m_dbType,m_schemaComparer->getCatalogueVersion()));
schemaSqlStatementsReader.reset(new MapSqlStatementsReader(m_dbType,m_catalogueMetadataGetter->getCatalogueVersion().getSchemaVersion<std::string>()));
}
m_schemaComparer->setSchemaSqlStatementsReader(std::move(schemaSqlStatementsReader));
}
......@@ -44,7 +45,7 @@ SchemaChecker::Status SchemaChecker::compareSchema(){
throw cta::exception::Exception("No schema comparer used. Please specify the schema comparer by using the methods useXXXXSchemaComparer()");
}
SchemaComparerResult totalResult;
std::cout << "Schema version : " << m_schemaComparer->getCatalogueVersion() << std::endl;
std::cout << "Schema version : " << m_catalogueMetadataGetter->getCatalogueVersion().getSchemaVersion<std::string>() << std::endl;
std::cout << "Checking indexes..." << std::endl;
cta::catalogue::SchemaComparerResult resIndex = m_schemaComparer->compareIndexes();
totalResult += resIndex;
......@@ -67,10 +68,17 @@ SchemaChecker::Status SchemaChecker::compareSchema(){
}
void SchemaChecker::checkNoParallelTables(){
std::list<std::string> parallelTables = m_catalogueConn.getParallelTableNames();
std::list<std::string> parallelTables = m_catalogueMetadataGetter->getParallelTableNames();
for(auto& table:parallelTables) {
std::cout << "WARNING : TABLE " << table << " is set as PARALLEL" << std::endl;
}
}
void SchemaChecker::checkSchemaNotUpgrading(){
SchemaVersion catalogueVersion = m_catalogueMetadataGetter->getCatalogueVersion();
if(catalogueVersion.getStatus<SchemaVersion::Status>() == SchemaVersion::Status::UPGRADING){
std::cout << "WARNING : The status of the schema is " << catalogueVersion.getStatus<std::string>() << ", the future version is " << catalogueVersion.getSchemaVersionNext<std::string>() << std::endl;
}
}
}}
\ No newline at end of file
......@@ -75,6 +75,12 @@ public:
* It will display a warning with the table name if this is the case
*/
void checkNoParallelTables();
/**
* Checks if the catalogue database schema is upgrading or not
*/
void checkSchemaNotUpgrading();
private:
/**
* Catalogue-to-check database type
......@@ -88,6 +94,12 @@ private:
* SchemaComparer class to compare the database schema
*/
std::unique_ptr<SchemaComparer> m_schemaComparer;
/**
* Catalogue metadata getter that allows to query the
* metadatas of the catalogue database
*/
std::unique_ptr<CatalogueMetadataGetter> m_catalogueMetadataGetter;
};
}}
......
......@@ -26,14 +26,7 @@
namespace cta {
namespace catalogue {
SchemaComparer::SchemaComparer(const cta::rdbms::Login::DbType &dbType, rdbms::Conn &conn): m_dbType(dbType),m_catalogueConn(conn),m_compareTableConstraints((m_dbType != cta::rdbms::Login::DBTYPE_MYSQL)){
m_catalogueMetadataGetter.reset(CatalogueMetadataGetterFactory::create(dbType,m_catalogueConn));
m_catalogueSchemaVersion = m_catalogueMetadataGetter->getCatalogueVersion();
}
std::string SchemaComparer::getCatalogueVersion(){
return m_catalogueSchemaVersion;
}
SchemaComparer::SchemaComparer(CatalogueMetadataGetter &catalogueMetadataGetter): m_catalogueMetadataGetter(catalogueMetadataGetter),m_compareTableConstraints((m_catalogueMetadataGetter.getDbType() != cta::rdbms::Login::DBTYPE_MYSQL)){}
void SchemaComparer::setSchemaSqlStatementsReader(std::unique_ptr<SchemaSqlStatementsReader> schemaSqlStatementsReader){
m_schemaSqlStatementsReader = std::move(schemaSqlStatementsReader);
......
......@@ -40,10 +40,9 @@ class SchemaComparer {
public:
/**
* Constructs a SchemaComparer
* @param catalogueDbType the database type of the database to compare
* @param conn the connection of the database to compare the schema
* @param catalogueMetadataGetter the catalogue metadata getter to compare the catalogue schema content
*/
SchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType,cta::rdbms::Conn &conn);
SchemaComparer(CatalogueMetadataGetter &catalogueMetadataGetter);
/**
* Destructor
*/
......@@ -63,12 +62,7 @@ public:
* @return a SchemaComparerResult that will contain the differences if there are some
*/
virtual SchemaComparerResult compareIndexes() = 0;
/**
* Return the catalogue version of the schema located in the database to compare
* @return the catalogue version of the schema located in the database to compare
*/
std::string getCatalogueVersion();
/**
* Sets the way the schema sql statements will be read to do the schemas comparison
* @param schemaSqlStatementsReader the reader used to get the schema sql statements in order to do schema comparison
......@@ -76,10 +70,7 @@ public:
void setSchemaSqlStatementsReader(std::unique_ptr<SchemaSqlStatementsReader> schemaSqlStatementsReader);
protected:
const cta::rdbms::Login::DbType &m_dbType;
std::string m_catalogueSchemaVersion;
cta::rdbms::Conn &m_catalogueConn;
std::unique_ptr<cta::catalogue::CatalogueMetadataGetter> m_catalogueMetadataGetter;
cta::catalogue::CatalogueMetadataGetter & m_catalogueMetadataGetter;
std::unique_ptr<SchemaSqlStatementsReader> m_schemaSqlStatementsReader;
bool m_compareTableConstraints;
};
......
/**
* The CERN Tape Archive (CTA) project
* Copyright © 2018 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SchemaVersion.hpp"
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
namespace cta { namespace catalogue {
SchemaVersion::SchemaVersion(){}
SchemaVersion::SchemaVersion(const uint64_t schemaVersionMajor, const uint64_t schemaVersionMinor, const cta::optional<uint64_t> schemaVersionMajorNext, const cta::optional<uint64_t> schemaVersionMinorNext, const Status status):m_schemaVersionMajor(schemaVersionMajor), m_schemaVersionMinor(schemaVersionMinor), m_nextSchemaVersionMajor(schemaVersionMajorNext), m_nextSchemaVersionMinor(schemaVersionMinorNext), m_status(status) {
}
SchemaVersion::SchemaVersion(const SchemaVersion& orig) {
if(this != &orig){
m_schemaVersionMajor = orig.m_schemaVersionMajor;
m_schemaVersionMinor = orig.m_schemaVersionMinor;
m_nextSchemaVersionMajor = orig.m_nextSchemaVersionMajor;
m_nextSchemaVersionMinor = orig.m_nextSchemaVersionMinor;
m_status = orig.m_status;
}
}
SchemaVersion & SchemaVersion::operator =(const SchemaVersion& other){
if(this != &other){
m_schemaVersionMajor = other.m_schemaVersionMajor;
m_schemaVersionMinor = other.m_schemaVersionMinor;
m_nextSchemaVersionMajor = other.m_nextSchemaVersionMajor;
m_nextSchemaVersionMinor = other.m_nextSchemaVersionMinor;
m_status = other.m_status;
}
return *this;
}
SchemaVersion::~SchemaVersion() {
}
template<>
std::string SchemaVersion::getSchemaVersion() const {
return std::to_string(m_schemaVersionMajor)+"."+std::to_string(m_schemaVersionMinor);
}
template<>
SchemaVersion::MajorMinor SchemaVersion::getSchemaVersion() const {
return std::make_pair(m_schemaVersionMajor,m_schemaVersionMinor);
}
template<>
std::string SchemaVersion::getSchemaVersionNext() const {
std::string schemaVersionNext;
if(m_nextSchemaVersionMajor && m_nextSchemaVersionMinor){
schemaVersionNext = std::to_string(m_nextSchemaVersionMajor.value())+"."+std::to_string(m_nextSchemaVersionMinor.value());
}