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

The catalogue.ping() method now checks the equality between the MAJOR version...

The catalogue.ping() method now checks the equality between the MAJOR version number of the CTA schema version and the MAJOR version number in the database
parent a4df3296
......@@ -73,6 +73,8 @@
namespace cta {
namespace catalogue {
CTA_GENERATE_EXCEPTION_CLASS(WrongSchemaVersionException);
/**
* Abstract class defining the interface to the CTA catalogue responsible for
......@@ -720,6 +722,11 @@ public:
*/
virtual void ping() = 0;
/**
* Checks that the online database schema MAJOR version number matches the schema MAJOR version number defined in version.h
*/
virtual void verifySchemaVersion() = 0;
/**
* Returns the map of strings to uint64 for the SCHEMA_VERSION_MAJOR
* and SCHEMA_VERSION_MINOR.
......
......@@ -461,6 +461,10 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->ping();}, m_maxTriesToConnect);
}
void verifySchemaVersion() override{
return retryOnLostConnection(m_log, [&]{return m_catalogue->verifySchemaVersion();}, m_maxTriesToConnect);
}
std::map<std::string, uint64_t> getSchemaVersion() const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getSchemaVersion();}, m_maxTriesToConnect);
}
......
......@@ -118,6 +118,7 @@ public:
void modifyTapeTapePoolName(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string& tapePoolName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
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"); }
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,
......
......@@ -57,6 +57,7 @@
#include "common/Timer.hpp"
#include "common/utils/utils.hpp"
#include "rdbms/AutoRollback.hpp"
#include "version.h"
#include <ctype.h>
#include <memory>
......@@ -6839,10 +6840,9 @@ std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveF
//------------------------------------------------------------------------------
void RdbmsCatalogue::ping() {
try {
const char *const sql = "SELECT COUNT(*) FROM CTA_CATALOGUE";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
auto rset = stmt.executeQuery();
verifySchemaVersion();
} catch (WrongSchemaVersionException &){
throw;
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......@@ -6851,6 +6851,27 @@ void RdbmsCatalogue::ping() {
}
}
//------------------------------------------------------------------------------
// verifySchemaVersion
//------------------------------------------------------------------------------
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){
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;
throw WrongSchemaVersionException(exceptionMsg.str());
}
} catch (exception::UserError &ex) {
throw;
} catch (exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// getSchemaVersion
//------------------------------------------------------------------------------
......
......@@ -727,6 +727,8 @@ public:
*/
void ping() override;
void verifySchemaVersion() override;
/**
* Returns the map of strings to uint64 for the SCHEMA_VERSION_MAJOR
* and SCHEMA_VERSION_MINOR.
......@@ -734,7 +736,7 @@ public:
* @return The map for SCHEMA_VERSION_MAJOR and SCHEMA_VERSION_MINOR values.
*/
std::map<std::string, uint64_t> getSchemaVersion() const override;
/**
* Returns the names of all the tables in the database schema in alphabetical
* order.
......
......@@ -936,6 +936,12 @@ int DriveHandler::runChild() {
lc.log(log::DEBUG, "In DriveHandler::runChild(): will ping scheduler.");
try {
scheduler.ping(lc);
} catch (const cta::catalogue::WrongSchemaVersionException &ex) {
log::ScopedParamContainer param (lc);
param.add("errorMessage", ex.getMessageValue());
lc.log(log::CRIT, "In DriveHandler::runChild(): catalogue MAJOR version mismatch. Reporting fatal error.");
driveHandlerProxy.reportState(tape::session::SessionState::Fatal, tape::session::SessionType::Undetermined, "");
return castor::tape::tapeserver::daemon::Session::MARK_DRIVE_AS_DOWN;
} catch (cta::exception::Exception &ex) {
log::ScopedParamContainer param (lc);
param.add("errorMessage", ex.getMessageValue());
......
......@@ -123,6 +123,7 @@ void XrdSsiCtaServiceProvider::ExceptionThrowingInit(XrdSsiLogger *logP, XrdSsiC
auto catalogueFactory = catalogue::CatalogueFactoryFactory::create(*m_log, catalogueLogin,
catalogue_numberofconnections.second, nbArchiveFileListingConns);
m_catalogue = catalogueFactory->create();
m_catalogue->ping();
}
// Initialise the Backend
......
Supports Markdown
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