Commit f4c2830b authored by Cedric Caffy's avatar Cedric Caffy
Browse files

WIP - CI might fail

parent 32648d3f
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -11790,11 +11790,6 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_1_archive_file_2_tape_cop
ASSERT_EQ(file2Written.diskFileOwnerUid, archiveFile.diskFileInfo.owner_uid);
ASSERT_EQ(file2Written.diskFileGid, archiveFile.diskFileInfo.gid);
 
// If there are two or more tape copies with the same copy number then
// only one of them will be active (<=> supersededByVid.empty()).
ASSERT_EQ(1, std::count_if(archiveFile.tapeFiles.begin(), archiveFile.tapeFiles.end(),
[](const cta::common::dataStructures::TapeFile &tf){ return tf.supersededByVid.empty();}));
const auto &tapeFile = *archiveFile.tapeFiles.begin();
 
ASSERT_TRUE(file1Written.vid == tapeFile.vid || file2Written.vid == tapeFile.vid);
......@@ -11970,11 +11965,6 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_1_archive_file_2_tape_cop
ASSERT_EQ(file2Written.diskFileOwnerUid, archiveFile.diskFileInfo.owner_uid);
ASSERT_EQ(file2Written.diskFileGid, archiveFile.diskFileInfo.gid);
 
// If there are two or more tape copies with the same copy number then
// only one of them will be active (<=> supersededByVid.empty()).
ASSERT_EQ(1, std::count_if(archiveFile.tapeFiles.begin(), archiveFile.tapeFiles.end(),
[](const cta::common::dataStructures::TapeFile &tf){ return tf.supersededByVid.empty();}));
const auto &tapeFile = *archiveFile.tapeFiles.begin();
 
ASSERT_TRUE(file1Written.fSeq == tapeFile.fSeq || file2Written.fSeq == tapeFile.fSeq);
......@@ -14745,183 +14735,6 @@ TEST_P(cta_catalogue_CatalogueTest, checkTapeForLabel_one_tape_file_reclaimed_ta
ASSERT_NO_THROW(m_catalogue->checkTapeForLabel(m_tape1.vid));
}
 
TEST_P(cta_catalogue_CatalogueTest, checkTapeForLabel_one_tape_file_superseded) {
using namespace cta;
const std::string diskInstanceName1 = "disk_instance_1";
const bool logicalLibraryIsDisabled= false;
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
m_catalogue->createMediaType(m_admin, m_mediaType);
m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
m_catalogue->createVirtualOrganization(m_admin, m_vo);
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
m_catalogue->createTape(m_admin, m_tape1);
m_catalogue->createTape(m_admin, m_tape2);
m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(2, vidToTape.size());
auto it = vidToTape.find(m_tape1.vid);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(m_tape1.vid, tape.vid);
ASSERT_EQ(m_tape1.mediaType, tape.mediaType);
ASSERT_EQ(m_tape1.vendor, tape.vendor);
ASSERT_EQ(0, tape.dataOnTapeInBytes);
ASSERT_EQ(0, tape.lastFSeq);
ASSERT_EQ(m_tape1.logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(m_tape1.tapePoolName, tape.tapePoolName);
ASSERT_EQ(m_vo.name, tape.vo);
ASSERT_EQ(m_mediaType.capacityInBytes, tape.capacityInBytes);
ASSERT_EQ(m_tape1.disabled, tape.disabled);
ASSERT_EQ(m_tape1.full, tape.full);
ASSERT_EQ(m_tape1.readOnly, tape.readOnly);
ASSERT_FALSE(tape.isFromCastor);
ASSERT_EQ(m_tape1.comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
// Record initial tape file
const uint64_t archiveFileId = 1234;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
ASSERT_THROW(m_catalogue->getArchiveFileById(archiveFileId), exception::Exception);
const uint64_t archiveFileSize = 1;
const std::string tapeDrive = "tape_drive";
auto file1WrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & file1Written = *file1WrittenUP;
std::set<cta::catalogue::TapeItemWrittenPointer> file1WrittenSet;
file1WrittenSet.insert(file1WrittenUP.release());
file1Written.archiveFileId = archiveFileId;
file1Written.diskInstance = diskInstanceName1;
file1Written.diskFileId = "5678";
file1Written.diskFileOwnerUid = PUBLIC_DISK_USER;
file1Written.diskFileGid = PUBLIC_DISK_GROUP;
file1Written.size = archiveFileSize;
file1Written.checksumBlob.insert(checksum::ADLER32, "1234");
file1Written.storageClassName = m_storageClassSingleCopy.name;
file1Written.vid = m_tape1.vid;
file1Written.fSeq = 1;
file1Written.blockId = 4321;
file1Written.size = 1;
file1Written.copyNb = 1;
file1Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file1WrittenSet);
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file1Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(file1Written.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(file1Written.size, archiveFile.fileSize);
ASSERT_EQ(file1Written.checksumBlob, archiveFile.checksumBlob);
ASSERT_EQ(file1Written.storageClassName, archiveFile.storageClass);
ASSERT_EQ(file1Written.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(file1Written.diskFileOwnerUid, archiveFile.diskFileInfo.owner_uid);
ASSERT_EQ(file1Written.diskFileGid, archiveFile.diskFileInfo.gid);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
auto copyNbToTapeFile1Itor = archiveFile.tapeFiles.find(1);
ASSERT_FALSE(copyNbToTapeFile1Itor == archiveFile.tapeFiles.end());
const common::dataStructures::TapeFile &tapeFile1 = *copyNbToTapeFile1Itor;
ASSERT_EQ(file1Written.vid, tapeFile1.vid);
ASSERT_EQ(file1Written.fSeq, tapeFile1.fSeq);
ASSERT_EQ(file1Written.blockId, tapeFile1.blockId);
ASSERT_EQ(file1Written.size, tapeFile1.fileSize);
ASSERT_EQ(file1Written.checksumBlob, tapeFile1.checksumBlob);
ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb);
}
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(2, vidToTape.size());
auto it = vidToTape.find(m_tape1.vid);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(m_tape1.vid, tape.vid);
ASSERT_EQ(m_tape1.mediaType, tape.mediaType);
ASSERT_EQ(m_tape1.vendor, tape.vendor);
ASSERT_EQ(file1Written.size, tape.dataOnTapeInBytes);
ASSERT_EQ(1, tape.lastFSeq);
ASSERT_EQ(m_tape1.logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(m_tape1.tapePoolName, tape.tapePoolName);
ASSERT_EQ(m_vo.name, tape.vo);
ASSERT_EQ(m_mediaType.capacityInBytes, tape.capacityInBytes);
ASSERT_EQ(m_tape1.disabled, tape.disabled);
ASSERT_EQ(m_tape1.full, tape.full);
ASSERT_EQ(m_tape1.readOnly, tape.readOnly);
ASSERT_FALSE(tape.isFromCastor);
ASSERT_EQ(m_tape1.comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_TRUE((bool)tape.lastWriteLog);
ASSERT_EQ(tapeDrive, tape.lastWriteLog.value().drive);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
m_catalogue->setTapeFull(m_admin, m_tape1.vid, true);
// Record superseding tape file
file1WrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & file1WrittenAgain = *file1WrittenUP;
std::set<cta::catalogue::TapeItemWrittenPointer> file1WrittenAgainSet;
file1WrittenAgainSet.insert(file1WrittenUP.release());
file1WrittenAgain.archiveFileId = archiveFileId;
file1WrittenAgain.diskInstance = diskInstanceName1;
file1WrittenAgain.diskFileId = "5678";
file1WrittenAgain.diskFileOwnerUid = PUBLIC_DISK_USER;
file1WrittenAgain.diskFileGid = PUBLIC_DISK_GROUP;
file1WrittenAgain.size = archiveFileSize;
file1WrittenAgain.checksumBlob.insert(checksum::ADLER32, "1234");
file1WrittenAgain.storageClassName = m_storageClassSingleCopy.name;
file1WrittenAgain.vid = m_tape2.vid;
file1WrittenAgain.fSeq = 1;
file1WrittenAgain.blockId = 4321;
file1WrittenAgain.size = 1;
file1WrittenAgain.copyNb = 1;
file1WrittenAgain.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file1WrittenAgainSet);
common::dataStructures::ArchiveFile repackedFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(2, repackedFile.tapeFiles.size());
for (auto &tf: repackedFile.tapeFiles) {
if (tf.vid == m_tape1.vid)
ASSERT_EQ(m_tape2.vid, tf.supersededByVid);
else
ASSERT_EQ("", tf.supersededByVid);
}
ASSERT_THROW(m_catalogue->checkTapeForLabel(m_tape1.vid), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, checkTapeForLabel_not_in_the_catalogue) {
using namespace cta;
......@@ -15417,208 +15230,6 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file) {
ASSERT_THROW(m_catalogue->reclaimTape(m_admin, m_tape1.vid, dummyLc), exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file_superseded) {
using namespace cta;
log::LogContext dummyLc(m_dummyLog);
const std::string diskInstanceName1 = "disk_instance_1";
const bool logicalLibraryIsDisabled= false;
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
m_catalogue->createMediaType(m_admin, m_mediaType);
m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
m_catalogue->createVirtualOrganization(m_admin, m_vo);
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
m_catalogue->createTape(m_admin, m_tape1);
m_catalogue->createTape(m_admin, m_tape2);
m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(2, vidToTape.size());
auto it = vidToTape.find(m_tape1.vid);
ASSERT_TRUE(it != vidToTape.end());
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(m_tape1.vid, tape.vid);
ASSERT_EQ(m_tape1.mediaType, tape.mediaType);
ASSERT_EQ(m_tape1.vendor, tape.vendor);
ASSERT_EQ(0, tape.dataOnTapeInBytes);
ASSERT_EQ(0, tape.lastFSeq);
ASSERT_EQ(m_tape1.logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(m_tape1.tapePoolName, tape.tapePoolName);
ASSERT_EQ(m_vo.name, tape.vo);
ASSERT_EQ(m_mediaType.capacityInBytes, tape.capacityInBytes);
ASSERT_EQ(m_tape1.disabled, tape.disabled);
ASSERT_EQ(m_tape1.full, tape.full);
ASSERT_EQ(m_tape1.readOnly, tape.readOnly);
ASSERT_FALSE(tape.isFromCastor);
ASSERT_EQ(m_tape1.comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
// Record initial tape file
const uint64_t archiveFileId = 1234;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
ASSERT_THROW(m_catalogue->getArchiveFileById(archiveFileId), exception::Exception);
const uint64_t archiveFileSize = 1;
const std::string tapeDrive = "tape_drive";
auto file1WrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & file1Written = *file1WrittenUP;
std::set<cta::catalogue::TapeItemWrittenPointer> file1WrittenSet;
file1WrittenSet.insert(file1WrittenUP.release());
file1Written.archiveFileId = archiveFileId;
file1Written.diskInstance = diskInstanceName1;
file1Written.diskFileId = "5678";
file1Written.diskFileOwnerUid = PUBLIC_DISK_USER;
file1Written.diskFileGid = PUBLIC_DISK_GROUP;
file1Written.size = archiveFileSize;
file1Written.checksumBlob.insert(checksum::ADLER32, "1234");
file1Written.storageClassName = m_storageClassSingleCopy.name;
file1Written.vid = m_tape1.vid;
file1Written.fSeq = 1;
file1Written.blockId = 4321;
file1Written.size = 1;
file1Written.copyNb = 1;
file1Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file1WrittenSet);
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file1Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(file1Written.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(file1Written.size, archiveFile.fileSize);
ASSERT_EQ(file1Written.checksumBlob, archiveFile.checksumBlob);
ASSERT_EQ(file1Written.storageClassName, archiveFile.storageClass);
ASSERT_EQ(file1Written.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(file1Written.diskFileOwnerUid, archiveFile.diskFileInfo.owner_uid);
ASSERT_EQ(file1Written.diskFileGid, archiveFile.diskFileInfo.gid);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
auto copyNbToTapeFile1Itor = archiveFile.tapeFiles.find(1);
ASSERT_FALSE(copyNbToTapeFile1Itor == archiveFile.tapeFiles.end());
const common::dataStructures::TapeFile &tapeFile1 = *copyNbToTapeFile1Itor;
ASSERT_EQ(file1Written.vid, tapeFile1.vid);
ASSERT_EQ(file1Written.fSeq, tapeFile1.fSeq);
ASSERT_EQ(file1Written.blockId, tapeFile1.blockId);
ASSERT_EQ(file1Written.size, tapeFile1.fileSize);
ASSERT_EQ(file1Written.checksumBlob, tapeFile1.checksumBlob);
ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb);
}
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(2, vidToTape.size());
auto it = vidToTape.find(m_tape1.vid);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(m_tape1.vid, tape.vid);
ASSERT_EQ(m_tape1.mediaType, tape.mediaType);
ASSERT_EQ(m_tape1.vendor, tape.vendor);
ASSERT_EQ(file1Written.size, tape.dataOnTapeInBytes);
ASSERT_EQ(1, tape.lastFSeq);
ASSERT_EQ(m_tape1.logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(m_tape1.tapePoolName, tape.tapePoolName);
ASSERT_EQ(m_vo.name, tape.vo);
ASSERT_EQ(m_mediaType.capacityInBytes, tape.capacityInBytes);
ASSERT_EQ(m_tape1.disabled, tape.disabled);
ASSERT_EQ(m_tape1.full, tape.full);
ASSERT_EQ(m_tape1.readOnly, tape.readOnly);
ASSERT_FALSE(tape.isFromCastor);
ASSERT_EQ(m_tape1.comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_TRUE((bool)tape.lastWriteLog);
ASSERT_EQ(tapeDrive, tape.lastWriteLog.value().drive);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
m_catalogue->setTapeFull(m_admin, m_tape1.vid, true);
// Record superseding tape file
file1WrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & file1WrittenAgain = *file1WrittenUP;
std::set<cta::catalogue::TapeItemWrittenPointer> file1WrittenAgainSet;
file1WrittenAgainSet.insert(file1WrittenUP.release());
file1WrittenAgain.archiveFileId = archiveFileId;
file1WrittenAgain.diskInstance = diskInstanceName1;
file1WrittenAgain.diskFileId = "5678";
file1WrittenAgain.diskFileOwnerUid = PUBLIC_DISK_USER;
file1WrittenAgain.diskFileGid = PUBLIC_DISK_GROUP;
file1WrittenAgain.size = archiveFileSize;
file1WrittenAgain.checksumBlob.insert(checksum::ADLER32, "1234");
file1WrittenAgain.storageClassName = m_storageClassSingleCopy.name;
file1WrittenAgain.vid = m_tape2.vid;
file1WrittenAgain.fSeq = 1;
file1WrittenAgain.blockId = 4321;
file1WrittenAgain.size = 1;
file1WrittenAgain.copyNb = 1;
file1WrittenAgain.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file1WrittenAgainSet);
common::dataStructures::ArchiveFile repackedFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(2, repackedFile.tapeFiles.size());
for (auto &tf: repackedFile.tapeFiles) {
if (tf.vid == m_tape1.vid)
ASSERT_EQ(m_tape2.vid, tf.supersededByVid);
else
ASSERT_EQ("", tf.supersededByVid);
}
ASSERT_NO_THROW(m_catalogue->reclaimTape(m_admin, m_tape1.vid, dummyLc));
{
//Test that the tape with vid1 is reclaimed
common::dataStructures::Tape tape = m_catalogue->getTapes().front();
ASSERT_EQ(m_tape1.vid, tape.vid);
ASSERT_EQ(m_tape1.mediaType, tape.mediaType);
ASSERT_EQ(m_tape1.vendor, tape.vendor);
ASSERT_EQ(0, tape.dataOnTapeInBytes);
ASSERT_EQ(0, tape.lastFSeq);
ASSERT_EQ(m_tape1.logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(m_tape1.tapePoolName, tape.tapePoolName);
ASSERT_EQ(m_vo.name, tape.vo);
ASSERT_EQ(m_mediaType.capacityInBytes, tape.capacityInBytes);
ASSERT_EQ(m_tape1.disabled, tape.disabled);
ASSERT_FALSE(tape.full);
ASSERT_EQ(m_tape1.readOnly, tape.readOnly);
ASSERT_FALSE(tape.isFromCastor);
ASSERT_EQ(m_tape1.comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_TRUE((bool)tape.lastWriteLog);
ASSERT_EQ(tapeDrive, tape.lastWriteLog.value().drive);
}
}
TEST_P(cta_catalogue_CatalogueTest, createModifyDeleteActivityWeight) {
using namespace cta;
 
......@@ -16146,8 +15757,6 @@ TEST_P(cta_catalogue_CatalogueTest, moveFilesToRecycleBin) {
ASSERT_EQ(i * 100,tapeFile.blockId);
ASSERT_EQ(1, tapeFile.copyNb);
ASSERT_EQ(archiveFileSize,tapeFile.fileSize);
ASSERT_TRUE(tapeFile.supersededByVid.empty());
ASSERT_EQ(0,tapeFile.supersededByFSeq);
}
//Let's try the deletion of the files from the recycle-bin.
......
......@@ -333,6 +333,47 @@ uint64_t MysqlCatalogue::getNextTapePoolId(rdbms::Conn &conn) {
}
}
//------------------------------------------------------------------------------
// getNextFileRecyleLogId
//------------------------------------------------------------------------------
uint64_t MysqlCatalogue::getNextFileRecyleLogId(rdbms::Conn& conn) {
try {
rdbms::AutoRollback autoRollback(conn);
conn.executeNonQuery("START TRANSACTION");
{
const char *const sql =
"UPDATE FILE_RECYCLE_LOG_ID SET ID = LAST_INSERT_ID(ID + 1)";
auto stmt = conn.createStmt(sql);
stmt.executeNonQuery();
}
uint64_t fileRecycleLogId = 0;
{
const char *const sql =
"SELECT LAST_INSERT_ID() AS ID ";
auto stmt = conn.createStmt(sql);
auto rset = stmt.executeQuery();
if(!rset.next()) {
throw exception::Exception("FILE_RECYCLE_LOG_ID table is empty");
}
fileRecycleLogId = rset.columnUint64("ID");
if(rset.next()) {
throw exception::Exception("Found more than one ID counter in the FILE_RECYCLE_LOG_ID table");
}
}
conn.commit();
return fileRecycleLogId;
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// selectTapeForUpdateAndGetLastFSeq
//------------------------------------------------------------------------------
......@@ -517,9 +558,7 @@ void MysqlCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string &
"TAPE_FILE.BLOCK_ID AS BLOCK_ID,"
"TAPE_FILE.LOGICAL_SIZE_IN_BYTES AS LOGICAL_SIZE_IN_BYTES,"
"TAPE_FILE.COPY_NB AS COPY_NB,"
"TAPE_FILE.CREATION_TIME AS TAPE_FILE_CREATION_TIME,"
"TAPE_FILE.SUPERSEDED_BY_VID AS SSBY_VID,"
"TAPE_FILE.SUPERSEDED_BY_FSEQ AS SSBY_FSEQ "
"TAPE_FILE.CREATION_TIME AS TAPE_FILE_CREATION_TIME "
"FROM "
"ARCHIVE_FILE "
"INNER JOIN STORAGE_CLASS ON "
......@@ -568,10 +607,6 @@ void MysqlCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string &
tapeFile.fileSize = selectRset.columnUint64("LOGICAL_SIZE_IN_BYTES");
tapeFile.copyNb = selectRset.columnUint64("COPY_NB");
tapeFile.creationTime = selectRset.columnUint64("TAPE_FILE_CREATION_TIME");
if (!selectRset.columnIsNull("SSBY_VID")) {
tapeFile.supersededByVid = selectRset.columnString("SSBY_VID");
tapeFile.supersededByFSeq = selectRset.columnUint64("SSBY_FSEQ");
}
tapeFile.checksumBlob = archiveFile->checksumBlob; // Duplicated for convenience
archiveFile->tapeFiles.push_back(tapeFile);
......@@ -610,9 +645,7 @@ void MysqlCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string &
<< " creationTime: " << it->creationTime
<< " fileSize: " << it->fileSize
<< " checksumBlob: " << it->checksumBlob //this shouldn't be here: repeated field
<< " copyNb: " << it->copyNb //this shouldn't be here: repeated field
<< " supersededByVid: " << it->supersededByVid
<< " supersededByFSeq: " << it->supersededByFSeq;
<< " copyNb: " << it->copyNb;
spc.add("TAPE FILE", tapeCopyLogStream.str());
}
lc.log(log::WARNING, "Failed to delete archive file because the disk instance of the request does not match that "
......@@ -681,9 +714,7 @@ void MysqlCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string &
<< " creationTime: " << it->creationTime
<< " fileSize: " << it->fileSize
<< " checksumBlob: " << it->checksumBlob //this shouldn't be here: repeated field
<< " copyNb: " << static_cast<int>(it->copyNb) //this shouldn't be here: repeated field
<< " supersededByVid: " << it->supersededByVid
<< " supersededByFSeq: " << it->supersededByFSeq;
<< " copyNb: " << static_cast<int>(it->copyNb); //this shouldn't be here: repeated field
spc.add("TAPE FILE", tapeCopyLogStream.str());
}
lc.log(log::INFO, "Archive file deleted from CTA catalogue");
......
......@@ -149,6 +149,20 @@ protected:
* the catalogue.
*/
uint64_t getNextTapePoolId(rdbms::Conn &conn) override;
/**
* Returns a unique file recycle log ID that can be used by a new entry of file recycle log within
* the catalogue.
*
* This method must be implemented by the sub-classes of RdbmsCatalogue
* because different database technologies propose different solution to the
* problem of generating ever increasing numeric identifiers.
*
* @param conn The database connection.
* @return a unique file recycle log ID that can be used by a new entry of file recycle log within
* the catalogue.
*/
uint64_t getNextFileRecyleLogId(rdbms::Conn & conn) override;
/**
* Notifies the catalogue that the specified files have been written to tape.
......
......@@ -329,6 +329,31 @@ uint64_t OracleCatalogue::getNextTapePoolId(rdbms::Conn &conn) {
}
}
//------------------------------------------------------------------------------
// getNextFileRecyleLogId
//------------------------------------------------------------------------------
uint64_t OracleCatalogue::getNextFileRecyleLogId(rdbms::Conn &conn) {
try {
const char *const sql =
"SELECT "
"FILE_RECYCLE_LOG_ID_SEQ.NEXTVAL AS FILE_RECYCLE_LOG_ID "
"FROM "
"DUAL";
auto stmt = conn.createStmt(sql);
auto rset = stmt.executeQuery();
if (!rset.next()) {
throw exception::Exception(std::string("Result set is unexpectedly empty"));
}
return rset.columnUint64("FILE_RECYCLE_LOG_ID");
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// selectTapeForUpdateAndGetLastFSeq
//------------------------------------------------------------------------------
......@@ -555,10 +580,28 @@ void OracleCatalogue::filesWrittenToTape(const std::set<TapeItemWrittenPointer>
auto stmt = conn.createStmt(sql);
stmt.executeNonQuery();
}
insertOldCopiesOfFilesIfAnyOnFileRecycleLog(conn, fileEvents);
{
const char *const sql =
"MERGE INTO" "\n"
//DELETE the TAPE_FILEs that come from a tape to repack
/*const char *const sql =
"DELETE FROM TAPE_FILE WHERE (ARCHIVE_FILE_ID, COPY_NB, VID) IN "
"("
"SELECT "
"TF.ARCHIVE_FILE_ID,"
"TF.COPY_NB,"
"TF.VID "
// Using MAX(FSEQ) to cover the same tape copy being written more than
// once. The last one written supersedes the previous ones.
"FROM "
"TAPE_FILE TF JOIN "
"TEMP_TAPE_FILE_INSERTION_BATCH TTFIB "
"ON TF.ARCHIVE_FILE_ID = TTFIB.ARCHIVE_FILE_ID AND TF.COPY_NB = TTFIB.COPY_NB "
"WHERE "
"TF.VID != TTFIB.VID "
")";*/
const char * const sql = "MERGE INTO" "\n"
"TAPE_FILE" "\n"
"USING(" "\n"
"SELECT" "\n"
......@@ -746,6 +789,10 @@ void OracleCatalogue::idempotentBatchInsertArchiveFiles(rdbms::Conn &conn, const
}
}
void OracleCatalogue::insertOldCopiesOfFilesIfAnyOnFileRecycleLog(rdbms::Conn& conn, const std::set<TapeFileWritten>& events) {
//TODO: A CONTINUER
}
//------------------------------------------------------------------------------
// selectArchiveFileSizeAndChecksum
//------------------------------------------------------------------------------
......@@ -819,9 +866,7 @@ void OracleCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string
"TAPE_FILE.BLOCK_ID AS BLOCK_ID,"
"TAPE_FILE.LOGICAL_SIZE_IN_BYTES AS LOGICAL_SIZE_IN_BYTES,"
"TAPE_FILE.COPY_NB AS COPY_NB,"
"TAPE_FILE.CREATION_TIME AS TAPE_FILE_CREATION_TIME,"
"TAPE_FILE.SUPERSEDED_BY_VID AS SSBY_VID,"
"TAPE_FILE.SUPERSEDED_BY_FSEQ AS SSBY_FSEQ "
"TAPE_FILE.CREATION_TIME AS TAPE_FILE_CREATION_TIME "
"FROM "