Commit 3ff9b962 authored by Steven Murray's avatar Steven Murray
Browse files

CTA front-end now logs duplicate tape copy numbers

If the "cta af ls" command is executed and the listing
encounters duplicate tape copy numbers then the listing
continues with "workaround" number displayed in place
of the duplicates and inow with this commit a log
message is alseo written to

    /var/log/cta/cta-frontent.log

An example log:

2017-07-12T18:04:40.691236+02:00 itdssbuild01 cta-frontend: LVL="Warn" PID="9423" TID="9436" MSG="Found a duplicate tape copy number when listing archive files" archiveFileID="5" duplicateCopyNb="1" workaroundCopyNb="2" vid="V41001" fSeq="5" blockId="41"
parent 581d90db
......@@ -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;
}
......
......@@ -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.
*/
......
......@@ -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.
......
......@@ -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 "
......
......@@ -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;
/**
......
......@@ -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());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment