From 9507b43cd208c44286fa432f263975223e1404fc Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Mon, 29 Jan 2018 17:36:34 +0100 Subject: [PATCH] cta/CTA#186 CTA should cope with idle database connections being dropped by the database server RdbmsCatalogue::noSpaceLeftOnTape() should re-connect to database if connection lost. --- catalogue/RdbmsCatalogue.cpp | 30 +++++++++++++++++++++++++++++- catalogue/RdbmsCatalogue.hpp | 8 ++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index b0ede92245..6aee3a9f63 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -2339,6 +2339,32 @@ void RdbmsCatalogue::setTapeFull(const common::dataStructures::SecurityIdentity // noSpaceLeftOnTape //------------------------------------------------------------------------------ void RdbmsCatalogue::noSpaceLeftOnTape(const std::string &vid) { + const uint32_t maxTries = 3; + + for(uint32_t tryNb = 1; tryNb <= maxTries; tryNb++) { + try { + return noSpaceLeftOnTapeInternal(vid); + } catch(exception::LostDatabaseConnection &lc) { + // Ignore lost connection + std::list<log::Param> params = { + {"maxTries", maxTries}, + {"tryNb", tryNb}, + {"msg", lc.getMessage()} + }; + m_log(cta::log::WARNING, "Lost database connection", params); + } + } + + exception::Exception ex; + ex.getMessage() << std::string(__FUNCTION__) << " failed: Lost the database connection after trying " << maxTries << + " times"; + throw ex; +} + +//------------------------------------------------------------------------------ +// noSpaceLeftOnTapeInternal +//------------------------------------------------------------------------------ +void RdbmsCatalogue::noSpaceLeftOnTapeInternal(const std::string &vid) { try { const char *const sql = "UPDATE TAPE SET " @@ -2350,9 +2376,11 @@ void RdbmsCatalogue::noSpaceLeftOnTape(const std::string &vid) { stmt.bindString(":VID", vid); stmt.executeNonQuery(); - if(0 == stmt.getNbAffectedRows()) { + if (0 == stmt.getNbAffectedRows()) { throw exception::Exception(std::string("Tape ") + vid + " does not exist"); } + } catch (exception::LostDatabaseConnection &) { + throw; } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 391cdea5e7..69747edf45 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -1035,6 +1035,14 @@ protected: */ void tapeMountedForRetrieveInternal(const std::string &vid, const std::string &drive); + /** + * This method notifies the CTA catalogue that there is no more free space on + * the specified tape. + * + * @param vid The volume identifier of the tape. + */ + void noSpaceLeftOnTapeInternal(const std::string &vid); + /** * Prepares the catalogue for a new archive file and returns the information * required to queue the associated archive request. -- GitLab