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

Tape is dirty when an ArchiveFile is moved to the recycle-bin

parent 0cd9de17
......@@ -17004,6 +17004,7 @@ TEST_P(cta_catalogue_CatalogueTest, moveFilesToRecycleBin) {
deletedArchiveFiles.push_back(itor.next());
}
}
//And test that these files are there.
//Run the unit test for all the databases
ASSERT_EQ(nbArchiveFiles,deletedArchiveFiles.size());
......@@ -17151,6 +17152,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTapeRemovesFilesFromRecycleBin) {
deletedArchiveFiles.push_back(itor.next());
}
}
//And test that these files are there.
//Run the unit test for all the databases
ASSERT_EQ(nbArchiveFiles,deletedArchiveFiles.size());
......
......@@ -662,6 +662,9 @@ void MysqlCatalogue::deleteArchiveFile(const std::string &diskInstanceName, cons
}
}
//------------------------------------------------------------------------------
// copyArchiveFileToRecycleBinAndDelete
//------------------------------------------------------------------------------
void MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, const common::dataStructures::DeleteArchiveRequest &request, log::LogContext & lc){
try {
utils::Timer t;
......@@ -671,8 +674,12 @@ void MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, co
conn.executeNonQuery("START TRANSACTION");
copyArchiveFileToRecycleBin(conn,request);
tl.insertAndReset("insertToRecycleBinTime",t);
deleteArchiveFileAndTapeFiles(conn,request);
tl.insertAndReset("deleteArchiveFileAndTapeFilesTime",t);
setTapeDirty(conn,request.archiveFileID);
tl.insertAndReset("setTapeDirtyTime",t);
deleteTapeFiles(conn,request);
tl.insertAndReset("deleteTapeFilesTime",t);
RdbmsCatalogue::deleteArchiveFile(conn,request);
tl.insertAndReset("deleteArchiveFileTime",t);
conn.commit();
tl.insertAndReset("commitTime",t);
log::ScopedParamContainer spc(lc);
......@@ -681,7 +688,7 @@ void MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, co
spc.add("diskFilePath",request.diskFilePath);
spc.add("diskInstance",request.diskInstance);
tl.addToLog(spc);
lc.log(log::INFO,"In MysqlCatalogue::moveArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
lc.log(log::INFO,"In MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......@@ -690,6 +697,9 @@ void MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, co
}
}
//------------------------------------------------------------------------------
// deleteTapeFilesAndArchiveFileFromRecycleBin
//------------------------------------------------------------------------------
void MysqlCatalogue::deleteTapeFilesAndArchiveFileFromRecycleBin(rdbms::Conn & conn, const uint64_t archiveFileId, log::LogContext &lc) {
try {
utils::Timer t;
......
......@@ -982,21 +982,25 @@ void OracleCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, c
try {
utils::Timer t;
log::TimingList tl;
//We currently do an INSERT INTO and a DELETE FROM
//We currently do an INSERT INTO, update and two DELETE FROM
//in a single transaction
conn.setAutocommitMode(rdbms::AutocommitMode::AUTOCOMMIT_OFF);
copyArchiveFileToRecycleBin(conn,request);
tl.insertAndReset("insertToRecycleBinTime",t);
setTapeDirty(conn,request.archiveFileID);
tl.insertAndReset("setTapeDirtyTime",t);
deleteTapeFiles(conn,request);
tl.insertAndReset("deleteTapeFilesTime",t);
conn.setAutocommitMode(rdbms::AutocommitMode::AUTOCOMMIT_ON);
deleteArchiveFileAndTapeFiles(conn,request);
tl.insertAndReset("deleteArchiveFileAndTapeFilesTime",t);
RdbmsCatalogue::deleteArchiveFile(conn,request);
tl.insertAndReset("deleteArchiveFileTime",t);
log::ScopedParamContainer spc(lc);
spc.add("archiveFileId",request.archiveFileID);
spc.add("diskFileId",request.diskFileId);
spc.add("diskFilePath",request.diskFilePath);
spc.add("diskInstance",request.diskInstance);
tl.addToLog(spc);
lc.log(log::INFO,"In OracleCatalogue::moveArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
lc.log(log::INFO,"In OracleCatalogue::copyArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......
......@@ -930,8 +930,12 @@ void PostgresCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn,
conn.executeNonQuery("BEGIN");
copyArchiveFileToRecycleBin(conn,request);
tl.insertAndReset("insertToRecycleBinTime",t);
deleteArchiveFileAndTapeFiles(conn,request);
tl.insertAndReset("deleteArchiveFileAndTapeFilesTime",t);
setTapeDirty(conn,request.archiveFileID);
tl.insertAndReset("setTapeDirtyTime",t);
deleteTapeFiles(conn,request);
tl.insertAndReset("deleteTapeFilesTime",t);
RdbmsCatalogue::deleteArchiveFile(conn,request);
tl.insertAndReset("deleteArchiveFileTime",t);
conn.commit();
tl.insertAndReset("commitTime",t);
log::ScopedParamContainer spc(lc);
......@@ -940,7 +944,7 @@ void PostgresCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn,
spc.add("diskFilePath",request.diskFilePath);
spc.add("diskInstance",request.diskInstance);
tl.addToLog(spc);
lc.log(log::INFO,"In MysqlCatalogue::moveArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
lc.log(log::INFO,"In MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......
......@@ -3754,6 +3754,9 @@ uint64_t RdbmsCatalogue::getNbFilesOnTape(rdbms::Conn& conn, const std::string&
}
}
//------------------------------------------------------------------------------
//deleteTapeFiles
//------------------------------------------------------------------------------
void RdbmsCatalogue::deleteTapeFiles(rdbms::Conn& conn, const std::string& vid) const {
try {
const char * const sql =
......@@ -3770,6 +3773,9 @@ void RdbmsCatalogue::deleteTapeFiles(rdbms::Conn& conn, const std::string& vid)
}
}
//------------------------------------------------------------------------------
//setTapeDirty
//------------------------------------------------------------------------------
void RdbmsCatalogue::setTapeDirty(rdbms::Conn& conn, const std::string& vid) const {
try {
const char * const sql =
......@@ -3783,7 +3789,27 @@ void RdbmsCatalogue::setTapeDirty(rdbms::Conn& conn, const std::string& vid) con
}
}
//------------------------------------------------------------------------------
//setTapeDirty
//------------------------------------------------------------------------------
void RdbmsCatalogue::setTapeDirty(rdbms::Conn& conn, const uint64_t & archiveFileId) const {
try {
const char * const sql =
"UPDATE TAPE SET DIRTY='1' "
"WHERE VID IN "
" (SELECT DISTINCT TAPE_FILE.VID AS VID FROM TAPE_FILE WHERE TAPE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID)";
auto stmt = conn.createStmt(sql);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt.executeNonQuery();
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
//resetTapeCounters
//------------------------------------------------------------------------------
void RdbmsCatalogue::resetTapeCounters(rdbms::Conn& conn, const common::dataStructures::SecurityIdentity& admin, const std::string& vid) const {
try {
const time_t now = time(nullptr);
......@@ -8388,11 +8414,9 @@ void RdbmsCatalogue::copyArchiveFileToRecycleBin(rdbms::Conn & conn, const commo
}
}
//------------------------------------------------------------------------------
// deleteArchiveFileAndTapeFiles
//------------------------------------------------------------------------------
void RdbmsCatalogue::deleteArchiveFileAndTapeFiles(rdbms::Conn& conn, const common::dataStructures::DeleteArchiveRequest& request) {
try {
void RdbmsCatalogue::deleteTapeFiles(rdbms::Conn & conn, const common::dataStructures::DeleteArchiveRequest& request){
try {
//Delete the tape files after.
const char *const deleteTapeFilesSql =
"DELETE FROM "
"TAPE_FILE "
......@@ -8401,7 +8425,16 @@ void RdbmsCatalogue::deleteArchiveFileAndTapeFiles(rdbms::Conn& conn, const comm
auto deleteTapeFilesStmt = conn.createStmt(deleteTapeFilesSql);
deleteTapeFilesStmt.bindUint64(":ARCHIVE_FILE_ID",request.archiveFileID);
deleteTapeFilesStmt.executeNonQuery();
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
void RdbmsCatalogue::deleteArchiveFile(rdbms::Conn& conn, const common::dataStructures::DeleteArchiveRequest& request){
try{
const char *const deleteArchiveFileSql =
"DELETE FROM "
"ARCHIVE_FILE "
......
......@@ -1795,13 +1795,27 @@ protected:
*/
void copyArchiveFileToRecycleBin(rdbms::Conn & conn, const common::dataStructures::DeleteArchiveRequest & request);
/**
* Deletes the ArchiveFile from the ARCHIVE_FILE table
* @param conn the database connection
* @param request the DeleteArchiveRequest that contains the archiveFileId to delete
*/
void deleteArchiveFile(rdbms::Conn & conn, const common::dataStructures::DeleteArchiveRequest & request);
/**
* Delete the TAPE_FILE and ARCHIVE_FILE entries from the Catalogue
* Delete the TapeFile from the TAPE_FILE table
* @param conn the database connection
* @param request the request that contains the necessary informations to identify the archiveFile to copy to the recycle-bin
* @param request the DeleteArchiveRequest that contains the archiveFileId to delete the corresponding tape files
*/
void deleteTapeFiles(rdbms::Conn & conn, const common::dataStructures::DeleteArchiveRequest & request);
/**
* Set the DIRTY flag to true
* @param conn the database connection
* @param archiveFileId the ArchiveFile that is going to be deleted and hence dirty the tape because
* the tape files will be removed from this tape
*/
void deleteArchiveFileAndTapeFiles(rdbms::Conn & conn, const common::dataStructures::DeleteArchiveRequest & request);
void setTapeDirty(rdbms::Conn & conn, const uint64_t & archiveFileId) const;
/**
* Delete the archiveFile and the associated tape files from the recycle-bin
......
......@@ -548,8 +548,12 @@ void SqliteCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, c
conn.executeNonQuery("BEGIN TRANSACTION");
copyArchiveFileToRecycleBin(conn,request);
tl.insertAndReset("insertToRecycleBinTime",t);
deleteArchiveFileAndTapeFiles(conn,request);
tl.insertAndReset("deleteArchiveFileAndTapeFilesTime",t);
setTapeDirty(conn,request.archiveFileID);
tl.insertAndReset("setTapeDirtyTime",t);
deleteTapeFiles(conn,request);
tl.insertAndReset("deleteTapeFilesTime",t);
RdbmsCatalogue::deleteArchiveFile(conn,request);
tl.insertAndReset("deleteArchiveFileTime",t);
conn.commit();
tl.insertAndReset("commitTime",t);
log::ScopedParamContainer spc(lc);
......@@ -558,7 +562,7 @@ void SqliteCatalogue::copyArchiveFileToRecycleBinAndDelete(rdbms::Conn & conn, c
spc.add("diskFilePath",request.diskFilePath);
spc.add("diskInstance",request.diskInstance);
tl.addToLog(spc);
lc.log(log::INFO,"In MysqlCatalogue::moveArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
lc.log(log::INFO,"In MysqlCatalogue::copyArchiveFileToRecycleBinAndDelete: ArchiveFile moved to the recycle-bin.");
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......
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