diff --git a/catalogue/ArchiveFileBuilder.cpp b/catalogue/ArchiveFileBuilder.cpp index 56b187c4e85fc906506183f77d4f7c188599db5d..12ad96d3e8ee6d38c8b5108860ced87af12cec21 100644 --- a/catalogue/ArchiveFileBuilder.cpp +++ b/catalogue/ArchiveFileBuilder.cpp @@ -24,6 +24,13 @@ namespace cta { namespace catalogue { +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +ArchiveFileBuilder::ArchiveFileBuilder(log::Logger &log): + m_log(log) { +} + //------------------------------------------------------------------------------ // append //------------------------------------------------------------------------------ @@ -77,6 +84,9 @@ std::unique_ptr<common::dataStructures::ArchiveFile> ArchiveFileBuilder::append( // Append the tape file const auto tapeFileMapItor = tapeFile.tapeFiles.begin(); + const auto vid = tapeFileMapItor->second.vid; + const auto fSeq = tapeFileMapItor->second.fSeq; + const auto blockId = tapeFileMapItor->second.blockId; const auto copyNbOfTapeFileToAppend = tapeFileMapItor->first; if(m_archiveFile->tapeFiles.find(copyNbOfTapeFileToAppend) != m_archiveFile->tapeFiles.end()) { // Found two tape files for the same archive file with the same copy @@ -88,13 +98,25 @@ std::unique_ptr<common::dataStructures::ArchiveFile> ArchiveFileBuilder::append( // " numbers: archiveFileID=" << tapeFile.archiveFileID << " copyNb=" << copyNbOfTapeFileToAppend; // throw ex; + // Create a unique copy number to replace the original duplicate uint64_t maxCopyNb = 0; for(const auto maplet: m_archiveFile->tapeFiles) { if(maplet.first > maxCopyNb) { maxCopyNb = maplet.first; } } - m_archiveFile->tapeFiles[maxCopyNb + 1] = tapeFileMapItor->second; + const uint64_t workaroundCopyNb = maxCopyNb + 1; + { + std::list<cta::log::Param> params; + params.push_back(cta::log::Param("archiveFileID", tapeFile.archiveFileID)); + params.push_back(cta::log::Param("duplicateCopyNb", copyNbOfTapeFileToAppend)); + params.push_back(cta::log::Param("workaroundCopyNb", workaroundCopyNb)); + params.push_back(cta::log::Param("vid", vid)); + params.push_back(cta::log::Param("fSeq", fSeq)); + params.push_back(cta::log::Param("blockId", blockId)); + m_log(cta::log::WARNING, "Found a duplicate tape copy number when listing archive files", params); + } + m_archiveFile->tapeFiles[workaroundCopyNb] = tapeFileMapItor->second; } else { m_archiveFile->tapeFiles[copyNbOfTapeFileToAppend] = tapeFileMapItor->second; } diff --git a/catalogue/ArchiveFileBuilder.hpp b/catalogue/ArchiveFileBuilder.hpp index 6b4c4f1f6c5fbef4a5707f77717b4c73a4f5bf77..f05f1b191fef028fd8eec3fe5ce5b672b2f28d50 100644 --- a/catalogue/ArchiveFileBuilder.hpp +++ b/catalogue/ArchiveFileBuilder.hpp @@ -19,6 +19,7 @@ #pragma once #include "common/dataStructures/ArchiveFile.hpp" +#include "common/log/Logger.hpp" #include <memory> @@ -32,6 +33,13 @@ namespace catalogue { class ArchiveFileBuilder { public: + /** + * Constructor. + * + * @param log Object representing the API to the CTA logging system. + */ + ArchiveFileBuilder(log::Logger &log); + /** * Appends the specified tape file to the ArchiveFile object currently * construction. @@ -76,6 +84,11 @@ public: private: + /** + * Object representing the API to the CTA logging system. + */ + log::Logger &m_log; + /** * The Archivefile object currently under construction. */ diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index 6525a8ff78882d9d97e93cb588e11a2623fce82b..5ffe565396abaf715601ad9f9602765b3a5f1c00 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -535,7 +535,7 @@ public: */ virtual bool tapeExists(const std::string &vid) const = 0; -private: +protected: /** * Object representing the API to the CTA logging system. diff --git a/catalogue/RdbmsArchiveFileItorImpl.cpp b/catalogue/RdbmsArchiveFileItorImpl.cpp index 74b9c62074f5c5e5531a94ef4c801a75b75f6069..ed8d1bf70eac4c1a0f089db9b49078df486abd19 100644 --- a/catalogue/RdbmsArchiveFileItorImpl.cpp +++ b/catalogue/RdbmsArchiveFileItorImpl.cpp @@ -75,12 +75,15 @@ namespace { // constructor //------------------------------------------------------------------------------ RdbmsArchiveFileItorImpl::RdbmsArchiveFileItorImpl( + log::Logger &log, rdbms::ConnPool &connPool, const TapeFileSearchCriteria &searchCriteria): + m_log(log), m_connPool(connPool), m_searchCriteria(searchCriteria), m_rsetIsEmpty(true), - m_hasMoreHasBeenCalled(false) { + m_hasMoreHasBeenCalled(false), + m_archiveFileBuilder(log) { try { std::string sql = "SELECT " diff --git a/catalogue/RdbmsArchiveFileItorImpl.hpp b/catalogue/RdbmsArchiveFileItorImpl.hpp index 6184567641e423958fdfd4af78352739218f76c2..059dbc038fc26fd80ed5d146e6ed99f4d53e85e4 100644 --- a/catalogue/RdbmsArchiveFileItorImpl.hpp +++ b/catalogue/RdbmsArchiveFileItorImpl.hpp @@ -21,6 +21,7 @@ #include "catalogue/ArchiveFileBuilder.hpp" #include "catalogue/ArchiveFileItorImpl.hpp" #include "catalogue/TapeFileSearchCriteria.hpp" +#include "common/log/Logger.hpp" #include "rdbms/ConnPool.hpp" #include "rdbms/Rset.hpp" #include "rdbms/Stmt.hpp" @@ -37,8 +38,15 @@ public: /** * Constructor. * + * @param log Object representing the API to the CTA logging system. + * @param connPool The database connection pool. + * @param searchCriteria The search criteria to be used when listing archive + * files. */ - RdbmsArchiveFileItorImpl(rdbms::ConnPool &connPool, const TapeFileSearchCriteria &searchCriteria); + RdbmsArchiveFileItorImpl( + log::Logger &log, + rdbms::ConnPool &connPool, + const TapeFileSearchCriteria &searchCriteria); /** * Destructor. @@ -57,8 +65,19 @@ public: private: + /** + * Object representing the API to the CTA logging system. + */ + log::Logger &m_log; + + /** + * The database connection pool. + */ rdbms::ConnPool &m_connPool; + /** + * The search criteria to be used when listing archive files. + */ TapeFileSearchCriteria m_searchCriteria; /** diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 6becf607e6a25677d8907db39083446bf6998570..6e831e2532268eca95dbef996c2bfb1a41f3d05d 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -3564,7 +3564,7 @@ ArchiveFileItor RdbmsCatalogue::getArchiveFiles(const TapeFileSearchCriteria &se checkTapeFileSearchCriteria(searchCriteria); try { - auto impl = new RdbmsArchiveFileItorImpl(m_archiveFileListingConnPool, searchCriteria); + auto impl = new RdbmsArchiveFileItorImpl(m_log, m_archiveFileListingConnPool, searchCriteria); return ArchiveFileItor(impl); } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());