/* * @project The CERN Tape Archive (CTA) * @copyright Copyright © 2022 CERN * @license This program is free software, distributed under the terms of the GNU General Public * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can * redistribute it and/or modify it under the terms of the GPL Version 3, 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. * * In applying this licence, CERN does not waive the privileges and immunities * granted to it by virtue of its status as an Intergovernmental Organization or * submit itself to any jurisdiction. */ #pragma once #include #include "catalogue/interfaces/TapeCatalogue.hpp" #include "common/log/Logger.hpp" #include "common/threading/Mutex.hpp" namespace cta { namespace rdbms { class Conn; class ConnPool; class Rset; class Stmt; } namespace catalogue { class RdbmsCatalogue; class TapeItemWritten; class RdbmsTapeCatalogue : public TapeCatalogue { public: ~RdbmsTapeCatalogue() override = default; void createTape(const common::dataStructures::SecurityIdentity &admin, const CreateTapeAttributes & tape) override; void deleteTape(const std::string &vid) override; std::list getTapes(const TapeSearchCriteria &searchCriteria) const override; common::dataStructures::VidToTapeMap getTapesByVid(const std::string& vid) const override; common::dataStructures::VidToTapeMap getTapesByVid(const std::set &vids) const override; common::dataStructures::VidToTapeMap getTapesByVid(const std::set &vids, bool ignoreMissingVids) const override; std::map getVidToLogicalLibrary(const std::set &vids) const override; void reclaimTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, cta::log::LogContext & lc) override; void checkTapeForLabel(const std::string &vid) override; void tapeLabelled(const std::string &vid, const std::string &drive) override; uint64_t getNbFilesOnTape(const std::string &vid) const override; void modifyTapeMediaType(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &mediaType) override; void modifyTapeVendor(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &vendor) override; void modifyTapeLogicalLibraryName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &logicalLibraryName) override; void modifyTapeTapePoolName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &tapePoolName) override; void modifyTapeEncryptionKeyName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &encryptionKeyName) override; void modifyPurchaseOrder(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &purchaseOrder) override; void modifyTapeVerificationStatus(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &verificationStatus) override; void modifyTapeState(const common::dataStructures::SecurityIdentity &admin,const std::string &vid, const common::dataStructures::Tape::State & state, const std::optional & prev_state, const std::optional & stateReason) override; bool tapeExists(const std::string &vid) const override; void setTapeFull(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool fullValue) override; void setTapeDirty(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool dirtyValue) override; void setTapeIsFromCastorInUnitTests(const std::string &vid) override; void setTapeDirty(const std::string & vid) override; void modifyTapeComment(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::optional &comment) override; void tapeMountedForArchive(const std::string &vid, const std::string &drive) override; void tapeMountedForRetrieve(const std::string &vid, const std::string &drive) override; void noSpaceLeftOnTape(const std::string &vid) override; std::list getTapesForWriting(const std::string &logicalLibraryName) const override; common::dataStructures::Label::Format getTapeLabelFormat(const std::string& vid) const override; protected: RdbmsTapeCatalogue(log::Logger &log, std::shared_ptr connPool, RdbmsCatalogue *rdbmsCatalogue); /** * Gets the last FSeq of the specified tape. * * @param conn The database connection. * @param vid The volume identifier of the tape. * @return The last FSeq of the tape. */ virtual uint64_t getTapeLastFSeq(rdbms::Conn &conn, const std::string &vid) const = 0; private: log::Logger &m_log; std::shared_ptr m_connPool; RdbmsCatalogue* m_rdbmsCatalogue; std::list getTapes(rdbms::Conn &conn, const TapeSearchCriteria &searchCriteria) const; std::string getSelectTapesBy100VidsSql() const; void executeGetTapesByVidStmtAndCollectResults(rdbms::Stmt &stmt, common::dataStructures::VidToTapeMap &vidToTapeMap) const; std::string getSelectVidToLogicalLibraryBy100Sql() const; void executeGetVidToLogicalLibraryBy100StmtAndCollectResults(rdbms::Stmt &stmt, std::map &vidToLogicalLibrary) const; /** * Returns the number of any files contained in the tape identified by its vid * @param conn the database connection * @param vid the vid in which we will count the number of files * @return the number of files on the tape */ uint64_t getNbFilesOnTape(rdbms::Conn &conn, const std::string &vid) const; /** * Reset the counters of a tape * @param conn the database connection * @param admin the administrator * @param vid the vid to reset the counters */ void resetTapeCounters(rdbms::Conn &conn, const common::dataStructures::SecurityIdentity &admin, const std::string& vid) const; /** * Delete all the tape files of the VID passed in parameter * @param conn the database connection * @param vid the vid in which we want to remove all the tape files */ void deleteTapeFiles(rdbms::Conn &conn, const std::string& vid) const; std::optional getTapeLogFromRset(const rdbms::Rset &rset, const std::string &driveColName, const std::string &timeColName) const; /** * Sets the last FSeq of the specified tape to the specified value. * * @param conn The database connection. * @param vid The volume identifier of the tape. * @param lastFseq The new value of the last FSeq. */ void setTapeLastFSeq(rdbms::Conn &conn, const std::string &vid, const uint64_t lastFSeq); }; }} // namespace cta::catalogue