/* * @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/rdbms/RdbmsTapeFileCatalogue.hpp" namespace cta { namespace utils { class Timer; } namespace log { class TimingList; } namespace catalogue { class RdbmsCatalogue; class PostgresTapeFileCatalogue : public RdbmsTapeFileCatalogue { public: PostgresTapeFileCatalogue(log::Logger &log, std::shared_ptr connPool, RdbmsCatalogue *rdbmsCatalogue); ~PostgresTapeFileCatalogue() override = default; void filesWrittenToTape(const std::set &event) override; private: void copyTapeFileToFileRecyleLogAndDeleteTransaction(rdbms::Conn & conn, const cta::common::dataStructures::ArchiveFile &file, const std::string &reason, utils::Timer *timer, log::TimingList *timingList, log::LogContext & lc) const override; std::list insertOldCopiesOfFilesIfAnyOnFileRecycleLog(rdbms::Conn& conn); /** * Selects the specified tape for update and returns its last FSeq. * * @param conn The database connection. * @param vid The volume identifier of the tape. * @param The last FSeq of the tape. */ uint64_t selectTapeForUpdateAndGetLastFSeq(rdbms::Conn &conn, const std::string &vid) const; /** * Start a database transaction and then create the temporary * tables TEMP_ARCHIVE_FILE_BATCH and TEMP_TAPE_FILE_BATCH. * Sets deferred mode for one of the db constraints to avoid * violations during concurrent bulk insert. * * @parm conn The database connection. */ void beginCreateTemporarySetDeferred(rdbms::Conn &conn) const; /** * Batch inserts rows into the ARCHIVE_FILE table that correspond to the * specified TapeFileWritten events. * * This method has idempotent behaviour in the case where an ARCHIVE_FILE * already exists. Such a situation will occur when a file has more than one * copy on tape. The first tape copy will cause two successful inserts, one * into the ARCHIVE_FILE table and one into the TAPE_FILE table. The second * tape copy will try to do the same, but the insert into the ARCHIVE_FILE * table will fail or simply bounce as the row will already exists. The * insert into the TABLE_FILE table will succeed because the two TAPE_FILE * rows will be unique. * * @param conn The database connection. * @param events The tape file written events. */ void idempotentBatchInsertArchiveFiles(rdbms::Conn &conn, const std::set &events) const; /** * Batch inserts rows into the TAPE_FILE_BATCH temporary table that correspond * to the specified TapeFileWritten events. * * @param conn The database connection. * @param events The tape file written events. */ void insertTapeFileBatchIntoTempTable(rdbms::Conn &conn, const std::set &events) const; }; // class PostgresTapeFileCatalogue }} // namespace cta::catalogue