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

The RdbmsCatalogue::getArchiveFileToRetrieveByArchiveFileId() method has been...

The RdbmsCatalogue::getArchiveFileToRetrieveByArchiveFileId() method has been modified to return only active (non superseded) files for retrieval
parent 35a032e4
......@@ -8722,6 +8722,131 @@ TEST_P(cta_catalogue_CatalogueTest, prepareToRetrieveFileUsingArchiveFileId_disa
exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, prepareToRetrieveFileUsingArchiveFileId_returnNonSupersededFiles) {
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);
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
const uint64_t archiveFileId = 1234;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
ASSERT_THROW(m_catalogue->getArchiveFileById(archiveFileId), exception::Exception);
m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
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.copyNb = 1;
file1Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file1WrittenSet);
//Create a superseded file
auto file2WrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & file2Written = *file2WrittenUP;
std::set<cta::catalogue::TapeItemWrittenPointer> file2WrittenSet;
file2WrittenSet.insert(file2WrittenUP.release());
file2Written.archiveFileId = file1Written.archiveFileId;
file2Written.diskInstance = file1Written.diskInstance;
file2Written.diskFileId = file1Written.diskFileId;
file2Written.diskFileOwnerUid = file1Written.diskFileOwnerUid;
file2Written.diskFileGid = file1Written.diskFileGid;
file2Written.size = archiveFileSize;
file2Written.checksumBlob = file1Written.checksumBlob;
file2Written.storageClassName = m_storageClassSingleCopy.name;
file2Written.vid = m_tape2.vid;
file2Written.fSeq = 1;
file2Written.blockId = 4331;
file2Written.copyNb = 1;
file2Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file2WrittenSet);
const std::string mountPolicyName = "mount_policy";
const uint64_t archivePriority = 1;
const uint64_t minArchiveRequestAge = 2;
const uint64_t retrievePriority = 3;
const uint64_t minRetrieveRequestAge = 4;
const uint64_t maxDrivesAllowed = 5;
m_catalogue->createMountPolicy(
m_admin,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"Create mount policy");
const std::string comment = "Create mount rule for requester";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_admin, mountPolicyName, diskInstanceName1, requesterName, comment);
log::LogContext dummyLc(m_dummyLog);
common::dataStructures::RequesterIdentity requesterIdentity;
requesterIdentity.name = requesterName;
requesterIdentity.group = "group";
{
const common::dataStructures::RetrieveFileQueueCriteria queueCriteria =
m_catalogue->prepareToRetrieveFile(diskInstanceName1, archiveFileId, requesterIdentity, cta::nullopt, dummyLc);
ASSERT_EQ(archivePriority, queueCriteria.mountPolicy.archivePriority);
ASSERT_EQ(minArchiveRequestAge, queueCriteria.mountPolicy.archiveMinRequestAge);
ASSERT_EQ(maxDrivesAllowed, queueCriteria.mountPolicy.maxDrivesAllowed);
ASSERT_EQ(1, queueCriteria.archiveFile.tapeFiles.size());
const auto copyNbToTapeFile1Itor = queueCriteria.archiveFile.tapeFiles.find(1);
ASSERT_FALSE(copyNbToTapeFile1Itor == queueCriteria.archiveFile.tapeFiles.end());
const common::dataStructures::TapeFile &tapeFile1 = *copyNbToTapeFile1Itor;
ASSERT_EQ(file2Written.vid, tapeFile1.vid);
ASSERT_EQ(file2Written.fSeq, tapeFile1.fSeq);
ASSERT_EQ(file2Written.blockId, tapeFile1.blockId);
ASSERT_EQ(file2Written.checksumBlob, tapeFile1.checksumBlob);
ASSERT_EQ(file2Written.copyNb, tapeFile1.copyNb);
}
m_catalogue->setTapeDisabled(m_admin, m_tape2.vid, true);
ASSERT_THROW(m_catalogue->prepareToRetrieveFile(diskInstanceName1, archiveFileId, requesterIdentity, cta::nullopt, dummyLc),
exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existance_archiveFileId) {
using namespace cta;
 
......
......@@ -7710,7 +7710,9 @@ std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveF
"TAPE_FILE.VID = TAPE.VID "
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID AND "
"TAPE.IS_DISABLED = '0' "
"TAPE.IS_DISABLED = '0' AND "
"TAPE_FILE.SUPERSEDED_BY_VID IS NULL AND "
"TAPE_FILE.SUPERSEDED_BY_FSEQ IS NULL "
"ORDER BY "
"TAPE_FILE.CREATION_TIME ASC";
auto stmt = conn.createStmt(sql);
......
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