From 7504e732dd3ee389714d59d4b5eb2a932e78a66d Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Mon, 29 Jan 2018 11:07:55 +0100 Subject: [PATCH] Revert "cta/CTA#186 CTA should cope with idle database connections being dropped by the database server" This reverts commit 1be86a70285013b2bf53cf58bc0edd98e26f4668. --- catalogue/Catalogue.hpp | 1 - catalogue/RdbmsCatalogue.cpp | 79 +++++++++++++++--------------------- catalogue/RdbmsCatalogue.hpp | 14 ------- 3 files changed, 33 insertions(+), 61 deletions(-) diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index 790551652d..bdddd9746c 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -128,7 +128,6 @@ public: * disabled, not full and are in the specified logical library. * * @param logicalLibraryName The name of the logical library. - * @return The list of tapes for writing. */ virtual std::list<TapeForWriting> getTapesForWriting(const std::string &logicalLibraryName) const = 0; diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 3b14cb3999..26202f0a49 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -4216,10 +4216,42 @@ bool RdbmsCatalogue::hostIsAdmin(rdbms::Conn &conn, const std::string &hostName) //------------------------------------------------------------------------------ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string &logicalLibraryName) const { try { + std::list<TapeForWriting> tapes; + const char *const sql = + "SELECT " + "VID AS VID," + "TAPE_POOL_NAME AS TAPE_POOL_NAME," + "CAPACITY_IN_BYTES AS CAPACITY_IN_BYTES," + "DATA_IN_BYTES AS DATA_IN_BYTES," + "LAST_FSEQ AS LAST_FSEQ " + "FROM " + "TAPE " + "WHERE " +// "LBP_IS_ON IS NOT NULL AND " // Set when the tape has been labelled +// "LABEL_DRIVE IS NOT NULL AND " // Set when the tape has been labelled +// "LABEL_TIME IS NOT NULL AND " // Set when the tape has been labelled + "IS_DISABLED = 0 AND " + "IS_FULL = 0 AND " + "LOGICAL_LIBRARY_NAME = :LOGICAL_LIBRARY_NAME"; + const uint32_t maxTries = 3; for(uint32_t tryNb = 1; tryNb <= maxTries; tryNb++) { try { - return getTapesForWriting(logicalLibraryName); + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF); + stmt.bindString(":LOGICAL_LIBRARY_NAME", logicalLibraryName); + auto rset = stmt.executeQuery(); + while (rset.next()) { + TapeForWriting tape; + tape.vid = rset.columnString("VID"); + tape.tapePool = rset.columnString("TAPE_POOL_NAME"); + tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); + tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); + tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); + + tapes.push_back(tape); + } + return tapes; } catch(exception::LostDatabaseConnection &lc) { // Ignore lost connection std::list<log::Param> params = { @@ -4241,51 +4273,6 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string & } } -//------------------------------------------------------------------------------ -// getTapesForWritingInternal -//------------------------------------------------------------------------------ -std::list<TapeForWriting> RdbmsCatalogue::getTapesForWritingInternal(const std::string &logicalLibraryName) const { - try { - std::list<TapeForWriting> tapes; - const char *const sql = - "SELECT " - "VID AS VID," - "TAPE_POOL_NAME AS TAPE_POOL_NAME," - "CAPACITY_IN_BYTES AS CAPACITY_IN_BYTES," - "DATA_IN_BYTES AS DATA_IN_BYTES," - "LAST_FSEQ AS LAST_FSEQ " - "FROM " - "TAPE " - "WHERE " -// "LBP_IS_ON IS NOT NULL AND " // Set when the tape has been labelled -// "LABEL_DRIVE IS NOT NULL AND " // Set when the tape has been labelled -// "LABEL_TIME IS NOT NULL AND " // Set when the tape has been labelled - "IS_DISABLED = 0 AND " - "IS_FULL = 0 AND " - "LOGICAL_LIBRARY_NAME = :LOGICAL_LIBRARY_NAME"; - - auto conn = m_connPool.getConn(); - auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF); - stmt.bindString(":LOGICAL_LIBRARY_NAME", logicalLibraryName); - auto rset = stmt.executeQuery(); - while (rset.next()) { - TapeForWriting tape; - tape.vid = rset.columnString("VID"); - tape.tapePool = rset.columnString("TAPE_POOL_NAME"); - tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); - tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); - tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); - - tapes.push_back(tape); - } - return tapes; - } catch(exception::LostDatabaseConnection &) { - throw; - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // insertTapeFile //------------------------------------------------------------------------------ diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 34674a0389..9d3ceecfbd 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -123,7 +123,6 @@ public: * disabled, not full and are in the specified logical library. * * @param logicalLibraryName The name of the logical library. - * @return The list of tapes for writing. */ std::list<TapeForWriting> getTapesForWriting(const std::string &logicalLibraryName) const override; @@ -983,19 +982,6 @@ protected: */ bool isAdminInternal(const common::dataStructures::SecurityIdentity &admin) const; - /** - * Returns the list of tapes that can be written to by a tape drive in the - * specified logical library, in other words tapes that are labelled, not - * disabled, not full and are in the specified logical library. - * - * This internal method can be re-tried if it throws a LostDatabaseConnection - * exception. - * - * @param logicalLibraryName The name of the logical library. - * @return The list of tapes for writing. - */ - std::list<TapeForWriting> getTapesForWritingInternal(const std::string &logicalLibraryName) const; - }; // class RdbmsCatalogue } // namespace catalogue -- GitLab