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

[catalogue] Added Catalogue::updateDiskFileId()

parent 09245363
......@@ -810,6 +810,19 @@ public:
*/
virtual bool diskSystemExists(const std::string &name) const = 0;
/**
* Updates the disk file ID of the specified archive file.
*
* @param archiveFileId The unique identifier of the archive file.
* @param diskInstance The instance name of the source disk system.
* @param diskFileId The identifier of the source disk file which is unique
* within it's host disk system. Two files from different disk systems may
* have the same identifier. The combination of diskInstance and diskFileId
* must be globally unique, in other words unique within the CTA catalogue.
*/
virtual void updateDiskFileId(uint64_t archiveFileId, const std::string &diskInstance,
const std::string &diskFileId) = 0;
}; // class Catalogue
CTA_GENERATE_USER_EXCEPTION_CLASS(UserSpecifiedAnEmptyStringActivity);
......
......@@ -510,7 +510,11 @@ public:
bool diskSystemExists(const std::string &name) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->diskSystemExists(name);}, m_maxTriesToConnect);
};
}
void updateDiskFileId(uint64_t archiveFileId, const std::string &diskInstance, const std::string &diskFileId) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->updateDiskFileId(archiveFileId, diskInstance, diskFileId);}, m_maxTriesToConnect);
}
protected:
......
......@@ -15766,4 +15766,166 @@ TEST_P(cta_catalogue_CatalogueTest, modifyVirtualOrganizationComment) {
ASSERT_THROW(m_catalogue->modifyVirtualOrganizationComment(m_admin,"DOES not exists","COMMENT_DOES_NOT_EXIST"),cta::exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, updateDiskFileId) {
using namespace cta;
const std::string vid1 = "VID123";
const std::string mediaType = "media_type";
const std::string vendor = "vendor";
const std::string logicalLibraryName = "logical_library_name";
const bool logicalLibraryIsDisabled= false;
const std::string tapePoolName = "tape_pool_name";
const std::string vo = "vo";
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
const cta::optional<std::string> supply("value for the supply pool mechanism");
const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
const bool readOnlyValue = true;
const std::string comment = "Create tape";
const std::string diskInstance = "disk_instance";
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
createVo(vo);
m_catalogue->createTapePool(m_admin, tapePoolName, vo, nbPartialTapes, isEncrypted, supply, "Create tape pool");
m_catalogue->createTape(m_admin, vid1, mediaType, vendor, logicalLibraryName, tapePoolName, capacityInBytes,
disabledValue, fullValue, readOnlyValue, comment);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
ASSERT_EQ(1, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
{
auto it = vidToTape.find(vid1);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(vid1, tape.vid);
ASSERT_EQ(mediaType, tape.mediaType);
ASSERT_EQ(vendor, tape.vendor);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(vo, tape.vo);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_TRUE(readOnlyValue == tape.readOnly);
ASSERT_FALSE(tape.isFromCastor);
ASSERT_EQ(0, tape.readMountCount);
ASSERT_EQ(0, tape.writeMountCount);
ASSERT_EQ(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);
}
}
const uint64_t archiveFileId = 1234;
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
ASSERT_THROW(m_catalogue->getArchiveFileById(archiveFileId), exception::Exception);
common::dataStructures::StorageClass storageClass;
storageClass.name = "storage_class";
storageClass.nbCopies = 1;
storageClass.vo.name = vo;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
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 = diskInstance;
file1Written.diskFileId = "5678";
file1Written.diskFileOwnerUid = PUBLIC_DISK_USER;
file1Written.diskFileGid = PUBLIC_DISK_GROUP;
file1Written.size = archiveFileSize;
file1Written.checksumBlob.insert(checksum::ADLER32, "1234");
file1Written.storageClassName = storageClass.name;
file1Written.vid = vid1;
file1Written.fSeq = 1;
file1Written.blockId = 4321;
file1Written.copyNb = 1;
file1Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(file1WrittenSet);
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = file1Written.vid;
std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape &tape = tapes.front();
ASSERT_EQ(1, tape.lastFSeq);
}
{
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.checksumBlob, tapeFile1.checksumBlob);
ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb);
}
const std::string newDiskFileId = "9012";
m_catalogue->updateDiskFileId(file1Written.archiveFileId, file1Written.diskInstance, newDiskFileId);
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file1Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(newDiskFileId, 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.checksumBlob, tapeFile1.checksumBlob);
ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb);
}
}
} // namespace unitTests
......@@ -148,6 +148,7 @@ public:
void tapeMountedForArchive(const std::string& vid, const std::string& drive) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void tapeMountedForRetrieve(const std::string& vid, const std::string& drive) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
bool tapePoolExists(const std::string& tapePoolName) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void updateDiskFileId(uint64_t archiveFileId, const std::string &diskInstance, const std::string &diskFileId) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
// Special functions for unit tests.
void addEnabledTape(const std::string & vid) {
......
......@@ -7518,5 +7518,38 @@ optional<uint64_t> RdbmsCatalogue::getTapePoolId(rdbms::Conn &conn, const std::s
}
}
//------------------------------------------------------------------------------
// updateDiskFileId
//------------------------------------------------------------------------------
void RdbmsCatalogue::updateDiskFileId(const uint64_t archiveFileId, const std::string &diskInstance,
const std::string &diskFileId) {
try {
const char *const sql =
"UPDATE ARCHIVE_FILE SET" "\n"
"DISK_INSTANCE_NAME = :DISK_INSTANCE_NAME," "\n"
"DISK_FILE_ID = :DISK_FILE_ID" "\n"
"WHERE" "\n"
"ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
stmt.bindString(":DISK_INSTANCE_NAME", diskInstance);
stmt.bindString(":DISK_FILE_ID", diskFileId);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt.executeNonQuery();
if(0 == stmt.getNbAffectedRows()) {
std::ostringstream msg;
msg << "Cannot update the disk file ID of the archive file with archive file ID " << archiveFileId <<
" because the archive file does not exist";
throw exception::UserError(msg.str());
}
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
} // namespace catalogue
} // namespace cta
......@@ -1605,6 +1605,19 @@ protected:
*/
optional<uint64_t> getTapePoolId(rdbms::Conn &conn, const std::string &name) const;
/**
* Updates the disk file ID of the specified archive file.
*
* @param archiveFileId The unique identifier of the archive file.
* @param diskInstance The instance name of the source disk system.
* @param diskFileId The identifier of the source disk file which is unique
* within it's host disk system. Two files from different disk systems may
* have the same identifier. The combination of diskInstance and diskFileId
* must be globally unique, in other words unique within the CTA catalogue.
*/
void updateDiskFileId(uint64_t archiveFileId, const std::string &diskInstance,
const std::string &diskFileId) override;
/**
* Cached versions of tape copy to tape tape pool mappings for specific
* storage classes.
......
Markdown is supported
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