Commit 46eba24f authored by Michael Davis's avatar Michael Davis
Browse files

Merge branch 'tapefile_ls'

parents f2897a0e 229dd427
......@@ -8677,68 +8677,15 @@ TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existance_archiveFileId)
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_disk_file_group_without_instance) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskFileGid = DISK_FILE_GID;
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existent_disk_file_group) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = "non_existent_disk_instance";
searchCriteria.diskFileGid = NON_EXISTENT_DISK_FILE_GID;
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_disk_file_id_without_instance) {
using namespace cta;
 
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
 
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskFileId = "disk_file_id";
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existent_disk_file_id) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = "non_existent_disk_instance";
searchCriteria.diskFileId = "non_existent_disk_file_id";
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_disk_file_user_without_instance) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskFileOwnerUid = DISK_FILE_OWNER_UID;
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existent_disk_file_user) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = "non_existent_disk_instance";
searchCriteria.diskFileOwnerUid = NON_EXISTENT_DISK_FILE_OWNER_UID;
std::vector<std::string> diskFileIds;
diskFileIds.push_back("disk_file_id");
searchCriteria.diskFileIds = diskFileIds;
 
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
......@@ -8769,34 +8716,6 @@ TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_existent_storage_class_witho
}
 
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.storageClass = m_storageClassSingleCopy.name;
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existent_storage_class) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = "non_existent_disk_instance";
searchCriteria.storageClass = "non_existent_storage_class";
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existent_tape_pool) {
using namespace cta;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = "non_existent_tape_pool";
ASSERT_THROW(m_catalogue->getArchiveFilesItor(searchCriteria), exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, getArchiveFiles_non_existent_vid) {
......@@ -9093,13 +9012,10 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.archiveFileId = 1;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileId = std::to_string(12345678);
searchCriteria.diskFileOwnerUid = PUBLIC_DISK_USER;
searchCriteria.diskFileGid = PUBLIC_DISK_GROUP;
searchCriteria.storageClass = m_storageClassDualCopy.name;
std::vector<std::string> diskFileIds;
diskFileIds.push_back("12345678");
searchCriteria.diskFileIds = diskFileIds;
searchCriteria.vid = tape1.vid;
searchCriteria.tapeFileCopyNb = 1;
searchCriteria.tapePool = tapePoolName1;
 
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
std::map<uint64_t, common::dataStructures::ArchiveFile> m = archiveFileItorToMap(archiveFileItor);
......@@ -9110,10 +9026,7 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
const common::dataStructures::ArchiveFile archiveFile = idAndFile->second;
ASSERT_EQ(searchCriteria.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(searchCriteria.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(searchCriteria.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(searchCriteria.diskFileOwnerUid, static_cast<uint64_t>(archiveFile.diskFileInfo.owner_uid));
ASSERT_EQ(searchCriteria.diskFileGid, static_cast<uint64_t>(archiveFile.diskFileInfo.gid));
ASSERT_EQ(searchCriteria.storageClass, archiveFile.storageClass);
ASSERT_EQ(searchCriteria.diskFileIds->front(), archiveFile.diskFileId);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
ASSERT_EQ(searchCriteria.vid, archiveFile.tapeFiles.begin()->vid);
}
......@@ -9458,7 +9371,9 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileId = "12345687";
std::vector<std::string> diskFileIds;
diskFileIds.push_back("12345687");
searchCriteria.diskFileIds = diskFileIds;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(1, m.size());
......@@ -9469,45 +9384,6 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
ASSERT_EQ(m_storageClassDualCopy.nbCopies, summary.totalFiles);
}
 
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileOwnerUid = PUBLIC_DISK_USER;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * m_storageClassDualCopy.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * m_storageClassDualCopy.nbCopies, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileGid = PUBLIC_DISK_GROUP;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * m_storageClassDualCopy.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * m_storageClassDualCopy.nbCopies, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.storageClass = m_storageClassDualCopy.name;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * m_storageClassDualCopy.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * m_storageClassDualCopy.nbCopies, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
......@@ -9531,42 +9407,6 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
 
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapeFileCopyNb = 1;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = tapePoolName1;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = tapePoolName2;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.archiveFileId = nbArchiveFiles + 1234;
......@@ -9975,13 +9815,10 @@ TEST_P(cta_catalogue_CatalogueTest, DISABLED_concurrent_filesWrittenToTape_many_
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.archiveFileId = 1;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileId = std::to_string(12345678);
searchCriteria.diskFileOwnerUid = PUBLIC_DISK_USER;
searchCriteria.diskFileGid = PUBLIC_DISK_GROUP;
searchCriteria.storageClass = storageClass.name;
std::vector<std::string> diskFileIds;
diskFileIds.push_back("12345678");
searchCriteria.diskFileIds = diskFileIds;
searchCriteria.vid = tape1.vid;
searchCriteria.tapeFileCopyNb = 1;
searchCriteria.tapePool = tapePoolName1;
 
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
std::map<uint64_t, common::dataStructures::ArchiveFile> m = archiveFileItorToMap(archiveFileItor);
......@@ -9992,10 +9829,7 @@ TEST_P(cta_catalogue_CatalogueTest, DISABLED_concurrent_filesWrittenToTape_many_
const common::dataStructures::ArchiveFile archiveFile = idAndFile->second;
ASSERT_EQ(searchCriteria.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(searchCriteria.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(searchCriteria.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(searchCriteria.diskFileOwnerUid, static_cast<uint64_t>(archiveFile.diskFileInfo.owner_uid));
ASSERT_EQ(searchCriteria.diskFileGid, static_cast<uint64_t>(archiveFile.diskFileInfo.gid));
ASSERT_EQ(searchCriteria.storageClass, archiveFile.storageClass);
ASSERT_EQ(searchCriteria.diskFileIds->front(), archiveFile.diskFileId);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
ASSERT_EQ(searchCriteria.vid, archiveFile.tapeFiles.begin()->vid);
}
......@@ -10369,7 +10203,9 @@ TEST_P(cta_catalogue_CatalogueTest, DISABLED_concurrent_filesWrittenToTape_many_
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileId = "12345687";
std::vector<std::string> diskFileIds;
diskFileIds.push_back("12345687");
searchCriteria.diskFileIds = diskFileIds;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(1, m.size());
......@@ -10393,45 +10229,6 @@ TEST_P(cta_catalogue_CatalogueTest, DISABLED_concurrent_filesWrittenToTape_many_
ASSERT_EQ(storageClass.nbCopies, summary.totalFiles);
}
 
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileOwnerUid = PUBLIC_DISK_USER;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.diskFileGid = PUBLIC_DISK_GROUP;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = diskInstance;
searchCriteria.storageClass = storageClass.name;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
......@@ -10455,42 +10252,6 @@ TEST_P(cta_catalogue_CatalogueTest, DISABLED_concurrent_filesWrittenToTape_many_
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
 
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapeFileCopyNb = 1;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = tapePoolName1;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = tapePoolName2;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.archiveFileId = nbArchiveFiles + 1234;
......
......@@ -56,6 +56,38 @@ MysqlCatalogue::MysqlCatalogue(
MysqlCatalogue::~MysqlCatalogue() {
}
//------------------------------------------------------------------------------
// createAndPopulateTempTableFxid
//------------------------------------------------------------------------------
std::string MysqlCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const {
const std::string tempTableName = "TEMP_DISK_FXIDS";
if(tapeFileSearchCriteria.diskFileIds) {
try {
std::string sql = "CREATE TEMPORARY TABLE " + tempTableName + "(DISK_FILE_ID VARCHAR(100))";
try {
conn.executeNonQuery(sql);
} catch(exception::Exception &ex) {
// MySQL does not drop temporary tables until the end of the session; trying to create another
// temporary table in the same unit test will fail. If this happens, truncate the table and carry on.
sql = "TRUNCATE TABLE " + tempTableName;
conn.executeNonQuery(sql);
}
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
auto stmt = conn.createStmt(sql);
for(auto &diskFileId : tapeFileSearchCriteria.diskFileIds.value()) {
stmt.bindString(":DISK_FILE_ID", diskFileId);
stmt.executeNonQuery();
}
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
return tempTableName;
}
//------------------------------------------------------------------------------
// getNextArchiveFileId
//------------------------------------------------------------------------------
......
......@@ -57,6 +57,15 @@ public:
protected:
/**
* Creates a temporary table from the list of disk file IDs provided in the search criteria.
*
* @param conn The database connection.
* @param tapeFileSearchCriteria Search criteria containing a list of disk file IDs (fxid).
* @return Name of the temporary table
*/
std::string createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const override;
/**
* Returns a unique archive ID that can be used by a new archive file within
* the catalogue.
......
......@@ -151,6 +151,34 @@ OracleCatalogue::OracleCatalogue(
OracleCatalogue::~OracleCatalogue() {
}
//------------------------------------------------------------------------------
// createAndPopulateTempTableFxid
//------------------------------------------------------------------------------
std::string OracleCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const {
const std::string tempTableName = "ORA$PTT_DISK_FXIDS";
try {
if(tapeFileSearchCriteria.diskFileIds) {
conn.setAutocommitMode(rdbms::AutocommitMode::AUTOCOMMIT_OFF);
std::string sql = "CREATE PRIVATE TEMPORARY TABLE " + tempTableName +
"(DISK_FILE_ID VARCHAR2(100))";
conn.executeNonQuery(sql);
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
auto stmt = conn.createStmt(sql);
for(auto &diskFileId : tapeFileSearchCriteria.diskFileIds.value()) {
stmt.bindString(":DISK_FILE_ID", diskFileId);
stmt.executeNonQuery();
}
}
return tempTableName;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// getNextArchiveFileId
//------------------------------------------------------------------------------
......
......@@ -57,6 +57,15 @@ public:
*/
~OracleCatalogue() override;
/**
* Creates a temporary table from the list of disk file IDs provided in the search criteria.
*
* @param conn The database connection.
* @param tapeFileSearchCriteria Search criteria containing a list of disk file IDs (fxid).
* @return Name of the temporary table
*/
std::string createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const override;
/**
* Returns a unique archive ID that can be used by a new archive file within
* the catalogue.
......
......@@ -149,6 +149,38 @@ PostgresCatalogue::PostgresCatalogue(
PostgresCatalogue::~PostgresCatalogue() {
}
//------------------------------------------------------------------------------
// createAndPopulateTempTableFxid
//------------------------------------------------------------------------------
std::string PostgresCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const {
const std::string tempTableName = "TEMP_DISK_FXIDS";
if(tapeFileSearchCriteria.diskFileIds) {
try {
std::string sql = "CREATE TEMPORARY TABLE " + tempTableName + "(DISK_FILE_ID VARCHAR(100))";
try {
conn.executeNonQuery(sql);
} catch(exception::Exception &ex) {
// Postgres does not drop temporary tables until the end of the session; trying to create another
// temporary table in the same unit test will fail. If this happens, truncate the table and carry on.
sql = "TRUNCATE TABLE " + tempTableName;
conn.executeNonQuery(sql);
}
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
auto stmt = conn.createStmt(sql);
for(auto &diskFileId : tapeFileSearchCriteria.diskFileIds.value()) {
stmt.bindString(":DISK_FILE_ID", diskFileId);
stmt.executeNonQuery();
}
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
return tempTableName;
}
//------------------------------------------------------------------------------
// getNextArchiveFileId
//------------------------------------------------------------------------------
......
......@@ -84,6 +84,15 @@ public:
*/
void filesWrittenToTape(const std::set<TapeItemWrittenPointer> &events) override;
/**
* Creates a temporary table from the list of disk file IDs provided in the search criteria.
*
* @param conn The database connection.
* @param tapeFileSearchCriteria Search criteria containing a list of disk file IDs (fxid).
* @return Name of the temporary table
*/
std::string createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const override;
/**
* Returns a unique archive ID that can be used by a new archive file within
* the catalogue.
......
......@@ -6530,58 +6530,8 @@ void RdbmsCatalogue::checkTapeFileSearchCriteria(const TapeFileSearchCriteria &s
}
}
if(searchCriteria.diskFileGid && !searchCriteria.diskInstance) {
throw exception::UserError(std::string("Disk file group ") + std::to_string(searchCriteria.diskFileGid.value()) +
" is ambiguous without disk instance name");
}
if(searchCriteria.diskInstance && searchCriteria.diskFileGid) {
if(!diskFileGroupExists(conn, searchCriteria.diskInstance.value(), searchCriteria.diskFileGid.value())) {
throw exception::UserError(std::string("Disk file group ") + searchCriteria.diskInstance.value() + "::" +
std::to_string(searchCriteria.diskFileGid.value()) + " does not exist");
}
}
if(searchCriteria.diskFileId && !searchCriteria.diskInstance) {
throw exception::UserError(std::string("Disk file ID ") + searchCriteria.diskFileId.value() + " is ambiguous "
"without disk instance name");
}
if(searchCriteria.diskInstance && searchCriteria.diskFileId) {
if(!diskFileIdExists(conn, searchCriteria.diskInstance.value(), searchCriteria.diskFileId.value())) {
throw exception::UserError(std::string("Disk file ID ") + searchCriteria.diskInstance.value() + "::" +
searchCriteria.diskFileId.value() + " does not exist");
}
}
if(searchCriteria.diskFileOwnerUid && !searchCriteria.diskInstance) {
throw exception::UserError(std::string("Disk file user ") + std::to_string(searchCriteria.diskFileOwnerUid.value()) +
" is ambiguous without disk instance name");
}
if(searchCriteria.diskInstance && searchCriteria.diskFileOwnerUid) {
if(!diskFileUserExists(conn, searchCriteria.diskInstance.value(), searchCriteria.diskFileOwnerUid.value())) {
throw exception::UserError(std::string("Disk file user ") + searchCriteria.diskInstance.value() + "::" +
std::to_string(searchCriteria.diskFileOwnerUid.value()) + " does not exist");
}
}
if(searchCriteria.storageClass && !searchCriteria.diskInstance) {
throw exception::UserError(std::string("Storage class ") + searchCriteria.storageClass.value() + " is ambiguous "
"without disk instance name");
}
if(searchCriteria.diskInstance && searchCriteria.storageClass) {
if(!storageClassExists(conn, searchCriteria.storageClass.value())) {
throw exception::UserError(std::string("Storage class ") + "::" +
searchCriteria.storageClass.value() + " does not exist");
}
}
if(searchCriteria.tapePool) {
if(!tapePoolExists(conn, searchCriteria.tapePool.value())) {
throw exception::UserError(std::string("Tape pool ") + searchCriteria.tapePool.value() + " does not exist");
}
if(searchCriteria.diskFileIds && !searchCriteria.diskInstance) {
throw exception::UserError(std::string("Disk file IDs are ambiguous without disk instance name"));
}
if(searchCriteria.vid) {
......@@ -6599,7 +6549,11 @@ ArchiveFileItor RdbmsCatalogue::getArchiveFilesItor(const TapeFileSearchCriteria
checkTapeFileSearchCriteria(searchCriteria);
try {
auto impl = new RdbmsCatalogueGetArchiveFilesItor(m_log, m_archiveFileListingConnPool, searchCriteria);
// Create a connection to populate the temporary table (specialised by database type)
auto conn = m_archiveFileListingConnPool.getConn();
const auto tempDiskFxidsTableName = createAndPopulateTempTableFxid(conn, searchCriteria);
// Pass ownership of the connection to the Iterator object
auto impl = new RdbmsCatalogueGetArchiveFilesItor(m_log, std::move(conn), searchCriteria, tempDiskFxidsTableName);
return ArchiveFileItor(impl);
} catch(exception::UserError &) {
throw;
......@@ -6739,10 +6693,17 @@ ArchiveFileItor RdbmsCatalogue::getArchiveFilesForRepackItor(const std::string &
//------------------------------------------------------------------------------
// getTapeFileSummary
//
// NOTE: As "archivefile ls" has been deprecated, there is no longer a way for
// operators to request a tape file summary. (Use "tape ls" instead).
// This method is used exclusively by the unit tests.
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFileSummary RdbmsCatalogue::getTapeFileSummary(
const TapeFileSearchCriteria &searchCriteria) const {
const TapeFileSearchCriteria &searchCriteria) const
{
try {
auto conn = m_connPool.getConn();
std::string sql =
"SELECT "
"COALESCE(SUM(ARCHIVE_FILE.SIZE_IN_BYTES), 0) AS TOTAL_BYTES,"
......@@ -6758,16 +6719,15 @@ common::dataStructures::ArchiveFileSummary RdbmsCatalogue::getTapeFileSummary(
"INNER JOIN TAPE_POOL ON "
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID";
if(
const bool hideSuperseded = searchCriteria.showSuperseded ? !*searchCriteria.showSuperseded : false;
const bool thereIsAtLeastOneSearchCriteria =