Commit dbe439cf authored by Steven Murray's avatar Steven Murray
Browse files

Removed the 'LEFT OUTER JOIN' based method RdbmsCatalogue::getArchiveFileByArchiveFileId()

parent cac7c88c
......@@ -26,7 +26,9 @@ namespace catalogue {
//------------------------------------------------------------------------------
ArchiveFileRow::ArchiveFileRow() :
archiveFileId(0),
size(0) {
size(0),
creationTime(0),
reconciliationTime(0) {
}
//------------------------------------------------------------------------------
......
......@@ -93,6 +93,16 @@ struct ArchiveFileRow {
*/
std::string storageClassName;
/**
* Creation time in seconds since the Unix epoch.
*/
time_t creationTime;
/**
* Reconciliation time in seconds since the Unix epoch.
*/
time_t reconciliationTime;
}; // struct ArchiveFileRow
/**
......
......@@ -885,10 +885,13 @@ public:
* This method assumes that the archive file being requested exists and will
* therefore throw an exception if it does not.
*
* Please note that an archive file with no associated tape files is
* considered not to exist by this method.
*
* @param id The unique identifier of the archive file.
* @return The archive file.
*/
virtual common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) = 0;
virtual common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) const = 0;
/**
* !!!!!!!!!!!!!!!!!!! THIS METHOD SHOULD NOT BE USED !!!!!!!!!!!!!!!!!!!!!!!
......
......@@ -532,7 +532,7 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->getTapeFileSummary(searchCriteria);}, m_maxTriesToConnect);
}
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) override {
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getArchiveFileById(id);}, m_maxTriesToConnect);
}
......
......@@ -79,7 +79,7 @@ public:
void modifyDiskSystemSleepTime(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const uint64_t sleepTime) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");}
void modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");}
std::list<common::dataStructures::AdminUser> getAdminUsers() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
ArchiveFileItor getArchiveFilesItor(const TapeFileSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
DeletedArchiveFileItor getDeletedArchiveFilesItor() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void deleteFileFromRecycleBin(const uint64_t archiveFileId, log::LogContext &lc) {throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");}
......
......@@ -453,9 +453,9 @@ void MysqlCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten
}
const time_t now = time(nullptr);
const auto archiveFile = getArchiveFileByArchiveFileId(conn, event.archiveFileId);
const auto archiveFileRow = getArchiveFileRowById(conn, event.archiveFileId);
if(nullptr == archiveFile) {
if(nullptr == archiveFileRow) {
// This should never happen
exception::Exception ex;
ex.getMessage() << "Failed to find archive file: archiveFileId=" << event.archiveFileId;
......@@ -466,14 +466,14 @@ void MysqlCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten
fileContext << "archiveFileId=" << event.archiveFileId << ", diskInstanceName=" << event.diskInstance <<
", diskFileId=" << event.diskFileId;
if(archiveFile->fileSize != event.size) {
if(archiveFileRow->size != event.size) {
catalogue::FileSizeMismatch ex;
ex.getMessage() << "File size mismatch: expected=" << archiveFile->fileSize << ", actual=" << event.size << ": "
ex.getMessage() << "File size mismatch: expected=" << archiveFileRow->size << ", actual=" << event.size << ": "
<< fileContext.str();
throw ex;
}
archiveFile->checksumBlob.validate(event.checksumBlob);
archiveFileRow->checksumBlob.validate(event.checksumBlob);
// Insert the tape file
common::dataStructures::TapeFile tapeFile;
......
......@@ -6789,10 +6789,10 @@ common::dataStructures::ArchiveFileSummary RdbmsCatalogue::getTapeFileSummary(
//------------------------------------------------------------------------------
// getArchiveFileById
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFile RdbmsCatalogue::getArchiveFileById(const uint64_t id) {
common::dataStructures::ArchiveFile RdbmsCatalogue::getArchiveFileById(const uint64_t id) const {
try {
auto conn = m_connPool.getConn();
std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile(getArchiveFileByArchiveFileId(conn, id));
const auto archiveFile = getArchiveFileById(conn, id);
// Throw an exception if the archive file does not exist
if(nullptr == archiveFile.get()) {
......@@ -6810,6 +6810,92 @@ common::dataStructures::ArchiveFile RdbmsCatalogue::getArchiveFileById(const uin
}
}
//------------------------------------------------------------------------------
// getArchiveFileById
//------------------------------------------------------------------------------
std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveFileById(rdbms::Conn &conn,
const uint64_t id) const {
try {
const char *const sql =
"SELECT "
"ARCHIVE_FILE.ARCHIVE_FILE_ID AS ARCHIVE_FILE_ID,"
"ARCHIVE_FILE.DISK_INSTANCE_NAME AS DISK_INSTANCE_NAME,"
"ARCHIVE_FILE.DISK_FILE_ID AS DISK_FILE_ID,"
"ARCHIVE_FILE.DISK_FILE_UID AS DISK_FILE_UID,"
"ARCHIVE_FILE.DISK_FILE_GID AS DISK_FILE_GID,"
"ARCHIVE_FILE.SIZE_IN_BYTES AS SIZE_IN_BYTES,"
"ARCHIVE_FILE.CHECKSUM_BLOB AS CHECKSUM_BLOB,"
"ARCHIVE_FILE.CHECKSUM_ADLER32 AS CHECKSUM_ADLER32,"
"STORAGE_CLASS.STORAGE_CLASS_NAME AS STORAGE_CLASS_NAME,"
"ARCHIVE_FILE.CREATION_TIME AS ARCHIVE_FILE_CREATION_TIME,"
"ARCHIVE_FILE.RECONCILIATION_TIME AS RECONCILIATION_TIME,"
"TAPE_FILE.VID AS VID,"
"TAPE_FILE.FSEQ AS FSEQ,"
"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 "
"FROM "
"ARCHIVE_FILE "
"INNER JOIN STORAGE_CLASS ON "
"ARCHIVE_FILE.STORAGE_CLASS_ID = STORAGE_CLASS.STORAGE_CLASS_ID "
"INNER JOIN TAPE_FILE ON "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = TAPE_FILE.ARCHIVE_FILE_ID "
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID "
"ORDER BY "
"TAPE_FILE.CREATION_TIME ASC";
auto stmt = conn.createStmt(sql);
stmt.bindUint64(":ARCHIVE_FILE_ID", id);
auto rset = stmt.executeQuery();
std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile;
while (rset.next()) {
if(nullptr == archiveFile.get()) {
archiveFile = cta::make_unique<common::dataStructures::ArchiveFile>();
archiveFile->archiveFileID = rset.columnUint64("ARCHIVE_FILE_ID");
archiveFile->diskInstance = rset.columnString("DISK_INSTANCE_NAME");
archiveFile->diskFileId = rset.columnString("DISK_FILE_ID");
archiveFile->diskFileInfo.owner_uid = rset.columnUint64("DISK_FILE_UID");
archiveFile->diskFileInfo.gid = rset.columnUint64("DISK_FILE_GID");
archiveFile->fileSize = rset.columnUint64("SIZE_IN_BYTES");
archiveFile->checksumBlob.deserializeOrSetAdler32(rset.columnBlob("CHECKSUM_BLOB"), rset.columnUint64("CHECKSUM_ADLER32"));
archiveFile->storageClass = rset.columnString("STORAGE_CLASS_NAME");
archiveFile->creationTime = rset.columnUint64("ARCHIVE_FILE_CREATION_TIME");
archiveFile->reconciliationTime = rset.columnUint64("RECONCILIATION_TIME");
}
// If there is a tape file
if(!rset.columnIsNull("VID")) {
// Add the tape file to the archive file's in-memory structure
common::dataStructures::TapeFile tapeFile;
tapeFile.vid = rset.columnString("VID");
tapeFile.fSeq = rset.columnUint64("FSEQ");
tapeFile.blockId = rset.columnUint64("BLOCK_ID");
tapeFile.fileSize = rset.columnUint64("LOGICAL_SIZE_IN_BYTES");
tapeFile.copyNb = rset.columnUint64("COPY_NB");
tapeFile.creationTime = rset.columnUint64("TAPE_FILE_CREATION_TIME");
tapeFile.checksumBlob = archiveFile->checksumBlob; // Duplicated for convenience
if (!rset.columnIsNull("SSBY_VID")) {
tapeFile.supersededByVid = rset.columnString("SSBY_VID");
tapeFile.supersededByFSeq = rset.columnUint64("SSBY_FSEQ");
}
archiveFile->tapeFiles.push_back(tapeFile);
}
}
return archiveFile;
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// tapeLabelled
//------------------------------------------------------------------------------
......@@ -7501,84 +7587,50 @@ uint64_t RdbmsCatalogue::getTapeLastFSeq(rdbms::Conn &conn, const std::string &v
}
//------------------------------------------------------------------------------
// getArchiveFileByArchiveId
// getArchiveFileRowByArchiveId
//------------------------------------------------------------------------------
std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveFileByArchiveFileId(
rdbms::Conn &conn,
const uint64_t archiveFileId) const {
std::unique_ptr<ArchiveFileRow> RdbmsCatalogue::getArchiveFileRowById(rdbms::Conn &conn, const uint64_t id) const {
try {
const char *const sql =
"SELECT "
"ARCHIVE_FILE.ARCHIVE_FILE_ID AS ARCHIVE_FILE_ID,"
"ARCHIVE_FILE.DISK_INSTANCE_NAME AS DISK_INSTANCE_NAME,"
"ARCHIVE_FILE.DISK_FILE_ID AS DISK_FILE_ID,"
"ARCHIVE_FILE.DISK_FILE_UID AS DISK_FILE_UID,"
"ARCHIVE_FILE.DISK_FILE_GID AS DISK_FILE_GID,"
"ARCHIVE_FILE.SIZE_IN_BYTES AS SIZE_IN_BYTES,"
"ARCHIVE_FILE.CHECKSUM_BLOB AS CHECKSUM_BLOB,"
"ARCHIVE_FILE.CHECKSUM_ADLER32 AS CHECKSUM_ADLER32,"
"STORAGE_CLASS.STORAGE_CLASS_NAME AS STORAGE_CLASS_NAME,"
"ARCHIVE_FILE.CREATION_TIME AS ARCHIVE_FILE_CREATION_TIME,"
"ARCHIVE_FILE.RECONCILIATION_TIME AS RECONCILIATION_TIME,"
"TAPE_FILE.VID AS VID,"
"TAPE_FILE.FSEQ AS FSEQ,"
"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 "
"FROM "
"ARCHIVE_FILE "
"INNER JOIN STORAGE_CLASS ON "
"ARCHIVE_FILE.STORAGE_CLASS_ID = STORAGE_CLASS.STORAGE_CLASS_ID "
"LEFT OUTER JOIN TAPE_FILE ON "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = TAPE_FILE.ARCHIVE_FILE_ID "
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID "
"ORDER BY "
"TAPE_FILE.CREATION_TIME ASC";
"SELECT" "\n"
"ARCHIVE_FILE.ARCHIVE_FILE_ID AS ARCHIVE_FILE_ID," "\n"
"ARCHIVE_FILE.DISK_INSTANCE_NAME AS DISK_INSTANCE_NAME," "\n"
"ARCHIVE_FILE.DISK_FILE_ID AS DISK_FILE_ID," "\n"
"ARCHIVE_FILE.DISK_FILE_UID AS DISK_FILE_UID," "\n"
"ARCHIVE_FILE.DISK_FILE_GID AS DISK_FILE_GID," "\n"
"ARCHIVE_FILE.SIZE_IN_BYTES AS SIZE_IN_BYTES," "\n"
"ARCHIVE_FILE.CHECKSUM_BLOB AS CHECKSUM_BLOB," "\n"
"ARCHIVE_FILE.CHECKSUM_ADLER32 AS CHECKSUM_ADLER32," "\n"
"STORAGE_CLASS.STORAGE_CLASS_NAME AS STORAGE_CLASS_NAME," "\n"
"ARCHIVE_FILE.CREATION_TIME AS ARCHIVE_FILE_CREATION_TIME," "\n"
"ARCHIVE_FILE.RECONCILIATION_TIME AS RECONCILIATION_TIME" "\n"
"FROM" "\n"
"ARCHIVE_FILE" "\n"
"INNER JOIN STORAGE_CLASS ON" "\n"
"ARCHIVE_FILE.STORAGE_CLASS_ID = STORAGE_CLASS.STORAGE_CLASS_ID" "\n"
"WHERE" "\n"
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
auto stmt = conn.createStmt(sql);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt.bindUint64(":ARCHIVE_FILE_ID", id);
auto rset = stmt.executeQuery();
std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile;
while (rset.next()) {
if(nullptr == archiveFile.get()) {
archiveFile = cta::make_unique<common::dataStructures::ArchiveFile>();
archiveFile->archiveFileID = rset.columnUint64("ARCHIVE_FILE_ID");
archiveFile->diskInstance = rset.columnString("DISK_INSTANCE_NAME");
archiveFile->diskFileId = rset.columnString("DISK_FILE_ID");
archiveFile->diskFileInfo.owner_uid = rset.columnUint64("DISK_FILE_UID");
archiveFile->diskFileInfo.gid = rset.columnUint64("DISK_FILE_GID");
archiveFile->fileSize = rset.columnUint64("SIZE_IN_BYTES");
archiveFile->checksumBlob.deserializeOrSetAdler32(rset.columnBlob("CHECKSUM_BLOB"), rset.columnUint64("CHECKSUM_ADLER32"));
archiveFile->storageClass = rset.columnString("STORAGE_CLASS_NAME");
archiveFile->creationTime = rset.columnUint64("ARCHIVE_FILE_CREATION_TIME");
archiveFile->reconciliationTime = rset.columnUint64("RECONCILIATION_TIME");
}
std::unique_ptr<ArchiveFileRow> row;
if (rset.next()) {
row = cta::make_unique<ArchiveFileRow>();
// If there is a tape file
if(!rset.columnIsNull("VID")) {
// Add the tape file to the archive file's in-memory structure
common::dataStructures::TapeFile tapeFile;
tapeFile.vid = rset.columnString("VID");
tapeFile.fSeq = rset.columnUint64("FSEQ");
tapeFile.blockId = rset.columnUint64("BLOCK_ID");
tapeFile.fileSize = rset.columnUint64("LOGICAL_SIZE_IN_BYTES");
tapeFile.copyNb = rset.columnUint64("COPY_NB");
tapeFile.creationTime = rset.columnUint64("TAPE_FILE_CREATION_TIME");
tapeFile.checksumBlob = archiveFile->checksumBlob; // Duplicated for convenience
if (!rset.columnIsNull("SSBY_VID")) {
tapeFile.supersededByVid = rset.columnString("SSBY_VID");
tapeFile.supersededByFSeq = rset.columnUint64("SSBY_FSEQ");
}
archiveFile->tapeFiles.push_back(tapeFile);
}
row->archiveFileId = rset.columnUint64("ARCHIVE_FILE_ID");
row->diskInstance = rset.columnString("DISK_INSTANCE_NAME");
row->diskFileId = rset.columnString("DISK_FILE_ID");
row->diskFileOwnerUid = rset.columnUint64("DISK_FILE_UID");
row->diskFileGid = rset.columnUint64("DISK_FILE_GID");
row->size = rset.columnUint64("SIZE_IN_BYTES");
row->checksumBlob.deserializeOrSetAdler32(rset.columnBlob("CHECKSUM_BLOB"), rset.columnUint64("CHECKSUM_ADLER32"));
row->storageClassName = rset.columnString("STORAGE_CLASS_NAME");
row->creationTime = rset.columnUint64("ARCHIVE_FILE_CREATION_TIME");
row->reconciliationTime = rset.columnUint64("RECONCILIATION_TIME");
}
return archiveFile;
return row;
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......
......@@ -874,10 +874,13 @@ public:
* This method assumes that the archive file being requested exists and will
* therefore throw an exception if it does not.
*
* Please note that an archive file with no associated tape files is
* considered not to exist by this method.
*
* @param id The unique identifier of the archive file.
* @return The archive file.
*/
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) override;
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) const override;
/**
* Returns true if the specified user has administrator privileges.
......@@ -1410,21 +1413,27 @@ protected:
const std::string &tapeDrive);
/**
* Returns the specified archive file. A nullptr pointer is returned if
* there is no corresponding row in the ARCHIVE_FILE table. Please note that
* a non-nullptr is returned if there is a row in the ARCHIVE_FILE table and
* there are no rows in the TAPE_FILE table.
* Returns the archive file with the specified unique identifier or nullptr if
* it does not exist.
*
* Please note that this method performs a LEFT OUTER JOIN from the
* ARCHIVE_FILE table to the TAPE_FILE table.
* Please note that an archive file with no associated tape files is
* considered not to exist by this method.
*
* @param conn The database connection.
* @param archiveFileId The identifier of the archive file.
* @return The archive file or nullptr.
* @param id The unique identifier of the archive file.
* @return The archive file.
*/
std::unique_ptr<common::dataStructures::ArchiveFile> getArchiveFileByArchiveFileId(
rdbms::Conn &conn,
const uint64_t archiveFileId) const;
std::unique_ptr<common::dataStructures::ArchiveFile> getArchiveFileById(rdbms::Conn &conn, const uint64_t archiveFileId) const;
/**
* Returns the specified archive file row. A nullptr pointer is returned if
* there is no corresponding row in the ARCHIVE_FILE table.
*
* @param conn The database connection.
* @param id The identifier of the archive file.
* @return The archive file row or nullptr.
*/
std::unique_ptr<ArchiveFileRow> getArchiveFileRowById(rdbms::Conn &conn, const uint64_t id) const;
/**
* Returns the specified archive file. A nullptr pointer is returned if
......
......@@ -65,7 +65,7 @@ void SqliteCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string
const auto getConnTime = t.secs();
rdbms::AutoRollback autoRollback(conn);
t.reset();
const auto archiveFile = getArchiveFileByArchiveFileId(conn, archiveFileId);
const auto archiveFile = getArchiveFileById(conn, archiveFileId);
const auto getArchiveFileTime = t.secs();
if(nullptr == archiveFile.get()) {
......@@ -522,12 +522,12 @@ void SqliteCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten
}
const time_t now = time(nullptr);
const auto archiveFile = getArchiveFileByArchiveFileId(conn, event.archiveFileId);
const auto archiveFileRow = getArchiveFileRowById(conn, event.archiveFileId);
if(nullptr == archiveFile) {
if(nullptr == archiveFileRow) {
// This should never happen
exception::Exception ex;
ex.getMessage() << "Failed to find archive file: archiveFileId=" << event.archiveFileId;
ex.getMessage() << "Failed to find archive file row: archiveFileId=" << event.archiveFileId;
throw ex;
}
......@@ -535,14 +535,14 @@ void SqliteCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten
fileContext << "archiveFileId=" << event.archiveFileId << ", diskInstanceName=" << event.diskInstance <<
", diskFileId=" << event.diskFileId;
if(archiveFile->fileSize != event.size) {
if(archiveFileRow->size != event.size) {
catalogue::FileSizeMismatch ex;
ex.getMessage() << "File size mismatch: expected=" << archiveFile->fileSize << ", actual=" << event.size << ": "
ex.getMessage() << "File size mismatch: expected=" << archiveFileRow->size << ", actual=" << event.size << ": "
<< fileContext.str();
throw ex;
}
archiveFile->checksumBlob.validate(event.checksumBlob);
archiveFileRow->checksumBlob.validate(event.checksumBlob);
// Insert the tape file
common::dataStructures::TapeFile tapeFile;
......
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