Commit 498c9445 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[catalogue] Modified the tape deletion SQL query to look for files in the FILE_RECYCLE_LOG table

parent ab78c127
......@@ -4621,14 +4621,16 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_1_tape_with_write_log_1_tape_with
}
 
const uint64_t fileSize = 1234 * 1000000000UL;
const uint64_t archiveFileId = 1234;
const std::string diskFileId = "5678";
{
auto file1WrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & file1Written = *file1WrittenUP;
std::set<cta::catalogue::TapeItemWrittenPointer> file1WrittenSet;
file1WrittenSet.insert(file1WrittenUP.release());
file1Written.archiveFileId = 1234;
file1Written.archiveFileId = archiveFileId;
file1Written.diskInstance = diskInstance;
file1Written.diskFileId = "5678";
file1Written.diskFileId = diskFileId;
file1Written.diskFileOwnerUid = PUBLIC_DISK_USER;
file1Written.diskFileGid = PUBLIC_DISK_GROUP;
file1Written.size = fileSize;
......@@ -4767,6 +4769,8 @@ TEST_P(cta_catalogue_CatalogueTest, deleteTape) {
TEST_P(cta_catalogue_CatalogueTest, deleteNonEmptyTape) {
using namespace cta;
 
log::LogContext dummyLc(m_dummyLog);
m_catalogue->createVirtualOrganization(m_admin, m_vo);
m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
 
......@@ -4869,6 +4873,29 @@ TEST_P(cta_catalogue_CatalogueTest, deleteNonEmptyTape) {
 
ASSERT_THROW(m_catalogue->deleteTape(m_tape1.vid), catalogue::UserSpecifiedANonEmptyTape);
ASSERT_FALSE(m_catalogue->getTapes().empty());
//Put the files on the tape on the recycle log
cta::common::dataStructures::DeleteArchiveRequest deletedArchiveReq;
deletedArchiveReq.archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
deletedArchiveReq.diskInstance = diskInstance;
deletedArchiveReq.archiveFileID = archiveFileId;
deletedArchiveReq.diskFileId = diskFileId;
deletedArchiveReq.recycleTime = time(nullptr);
deletedArchiveReq.requester = cta::common::dataStructures::RequesterIdentity(m_admin.username,"group");
deletedArchiveReq.diskFilePath = "/path/";
m_catalogue->moveArchiveFileToRecycleLog(deletedArchiveReq,dummyLc);
//The ArchiveFilesItor should not have any file in it
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
//The tape should not be deleted
ASSERT_THROW(m_catalogue->deleteTape(m_tape1.vid), catalogue::UserSpecifiedANonEmptyTape);
ASSERT_FALSE(m_catalogue->getTapes().empty());
m_catalogue->setTapeFull(m_admin,m_tape1.vid,true);
//Reclaim it to delete the files from the recycle log
m_catalogue->reclaimTape(m_admin,m_tape1.vid,dummyLc);
//Deletion should be successful
ASSERT_NO_THROW(m_catalogue->deleteTape(m_tape1.vid));
ASSERT_TRUE(m_catalogue->getTapes().empty());
}
 
TEST_P(cta_catalogue_CatalogueTest, deleteTape_non_existent) {
......
......@@ -3362,18 +3362,20 @@ void RdbmsCatalogue::deleteTape(const std::string &vid) {
"TAPE "
"WHERE "
"VID = :DELETE_VID AND "
"NOT EXISTS (SELECT VID FROM TAPE_FILE WHERE VID = :SELECT_VID)";
"NOT EXISTS (SELECT VID FROM TAPE_FILE WHERE VID = :SELECT_VID) AND "
"NOT EXISTS (SELECT VID FROM FILE_RECYCLE_LOG WHERE VID = :SELECT_VID2)";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(delete_sql);
stmt.bindString(":DELETE_VID", vid);
stmt.bindString(":SELECT_VID", vid);
stmt.bindString(":SELECT_VID2", vid);
stmt.executeNonQuery();
// The delete statement will effect no rows and will not raise an error if
// either the tape does not exist or if it still has tape files
// either the tape does not exist or if it still has tape files or files in the recycle log
if(0 == stmt.getNbAffectedRows()) {
if(tapeExists(conn, vid)) {
throw UserSpecifiedANonEmptyTape(std::string("Cannot delete tape ") + vid + " because it contains one or more files");
throw UserSpecifiedANonEmptyTape(std::string("Cannot delete tape ") + vid + " because either it contains one or more files or the files that were in it are in the file recycle log.");
} else {
throw UserSpecifiedANonExistentTape(std::string("Cannot delete tape ") + vid + " because it does not exist");
}
......
......@@ -32,8 +32,8 @@ namespace common {
namespace dataStructures {
/**
* This is a request to delete an existing archive file or to cancel and ongoing
* archival
* This is a request to delete an existing archive file or to cancel an ongoing
* archival.
*/
struct DeleteArchiveRequest {
......
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