Commit 9ccbea4a authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[recycle-bin] Deleted files now go to the recycle-bin instead of being deleted from

the Catalogue
parent 281e1918
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -24,95 +24,7 @@
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveFileBuilder::ArchiveFileBuilder(log::Logger &log):
m_log(log) {
}
//------------------------------------------------------------------------------
// append
//------------------------------------------------------------------------------
std::unique_ptr<common::dataStructures::ArchiveFile> ArchiveFileBuilder::append(
const common::dataStructures::ArchiveFile &tapeFile) {
// If there is currently no ArchiveFile object under construction
if(nullptr == m_archiveFile.get()) {
// If the tape file represents an ArchiveFile object with no tape files
if(tapeFile.tapeFiles.empty()) {
// Archive file is already complete
return std::unique_ptr<common::dataStructures::ArchiveFile>(new common::dataStructures::ArchiveFile(tapeFile));
}
// If the tape file exists then it must be alone
if(tapeFile.tapeFiles.size() != 1) {
exception::Exception ex;
ex.getMessage() << __FUNCTION__ << " failed: Expected exactly one tape file to be appended at a time: actual=" <<
tapeFile.tapeFiles.size();
throw ex;
}
// Start constructing one
m_archiveFile.reset(new common::dataStructures::ArchiveFile(tapeFile));
// There could be more tape files so return incomplete
return std::unique_ptr<common::dataStructures::ArchiveFile>();
}
// If the tape file represents an ArchiveFile object with no tape files
if(tapeFile.tapeFiles.empty()) {
// The ArchiveFile object under construction is complete,
// therefore return it and start the construction of the next
std::unique_ptr<common::dataStructures::ArchiveFile> tmp;
tmp = std::move(m_archiveFile);
m_archiveFile.reset(new common::dataStructures::ArchiveFile(tapeFile));
return tmp;
}
// If the tape file to be appended belongs to the ArchiveFile object
// currently under construction
if(tapeFile.archiveFileID == m_archiveFile->archiveFileID) {
// The tape file must exist and must be alone
if(tapeFile.tapeFiles.size() != 1) {
exception::Exception ex;
ex.getMessage() << __FUNCTION__ << " failed: Expected exactly one tape file to be appended at a time: actual=" <<
tapeFile.tapeFiles.size() << " archiveFileID=" << tapeFile.archiveFileID;
throw ex;
}
// Append the tape file
m_archiveFile->tapeFiles.push_back(tapeFile.tapeFiles.front());
// There could be more tape files so return incomplete
return std::unique_ptr<common::dataStructures::ArchiveFile>();
}
// Reaching this point means the tape file to be appended belongs to the next
// ArchiveFile to be constructed.
// ArchiveFile object under construction is complete,
// therefore return it and start the construction of the next
std::unique_ptr<common::dataStructures::ArchiveFile> tmp;
tmp = std::move(m_archiveFile);
m_archiveFile.reset(new common::dataStructures::ArchiveFile(tapeFile));
return tmp;
}
//------------------------------------------------------------------------------
// getArchiveFile
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFile *ArchiveFileBuilder::getArchiveFile() {
return m_archiveFile.get();
}
//------------------------------------------------------------------------------
// clear
//------------------------------------------------------------------------------
void ArchiveFileBuilder::clear() {
m_archiveFile.reset();
}
} // namespace catalogue
} // namespace cta
......@@ -29,7 +29,9 @@ namespace catalogue {
/**
* Builds ArchiveFile objects from a stream of tape files ordered by archive ID
* and then copy number.
* The template T is an ArchiveFile or a DeletedArchiveFile
*/
template<typename T>
class ArchiveFileBuilder {
public:
......@@ -65,7 +67,7 @@ public:
* @param tapeFile The tape file to be appended or an archive file with no
* tape files at all.
*/
std::unique_ptr<common::dataStructures::ArchiveFile> append(const common::dataStructures::ArchiveFile &tapeFile);
std::unique_ptr<T> append(const T &tapeFile);
/**
* Returns a pointer to the ArchiveFile object currently under construction.
......@@ -75,7 +77,7 @@ public:
* @return The ArchiveFile object currently under construction or nullptr
* if there isn't one.
*/
common::dataStructures::ArchiveFile *getArchiveFile();
T *getArchiveFile();
/**
* If there is an ArchiveFile under construction then it is forgotten.
......@@ -92,9 +94,104 @@ private:
/**
* The Archivefile object currently under construction.
*/
std::unique_ptr<common::dataStructures::ArchiveFile> m_archiveFile;
std::unique_ptr<T> m_archiveFile;
}; // class ArchiveFileBuilder
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
template<typename T>
ArchiveFileBuilder<T>::ArchiveFileBuilder(log::Logger &log):
m_log(log) {
}
//------------------------------------------------------------------------------
// append
//------------------------------------------------------------------------------
template<typename T>
std::unique_ptr<T> ArchiveFileBuilder<T>::append(
const T &tapeFile) {
// If there is currently no ArchiveFile object under construction
if(nullptr == m_archiveFile.get()) {
// If the tape file represents an ArchiveFile object with no tape files
if(tapeFile.tapeFiles.empty()) {
// Archive file is already complete
return std::unique_ptr<T>(new T(tapeFile));
}
// If the tape file exists then it must be alone
if(tapeFile.tapeFiles.size() != 1) {
exception::Exception ex;
ex.getMessage() << __FUNCTION__ << " failed: Expected exactly one tape file to be appended at a time: actual=" <<
tapeFile.tapeFiles.size();
throw ex;
}
// Start constructing one
m_archiveFile.reset(new T(tapeFile));
// There could be more tape files so return incomplete
return std::unique_ptr<T>();
}
// If the tape file represents an ArchiveFile object with no tape files
if(tapeFile.tapeFiles.empty()) {
// The ArchiveFile object under construction is complete,
// therefore return it and start the construction of the next
std::unique_ptr<T> tmp;
tmp = std::move(m_archiveFile);
m_archiveFile.reset(new T(tapeFile));
return tmp;
}
// If the tape file to be appended belongs to the ArchiveFile object
// currently under construction
if(tapeFile.archiveFileID == m_archiveFile->archiveFileID) {
// The tape file must exist and must be alone
if(tapeFile.tapeFiles.size() != 1) {
exception::Exception ex;
ex.getMessage() << __FUNCTION__ << " failed: Expected exactly one tape file to be appended at a time: actual=" <<
tapeFile.tapeFiles.size() << " archiveFileID=" << tapeFile.archiveFileID;
throw ex;
}
// Append the tape file
m_archiveFile->tapeFiles.push_back(tapeFile.tapeFiles.front());
// There could be more tape files so return incomplete
return std::unique_ptr<T>();
}
// Reaching this point means the tape file to be appended belongs to the next
// ArchiveFile to be constructed.
// ArchiveFile object under construction is complete,
// therefore return it and start the construction of the next
std::unique_ptr<T> tmp;
tmp = std::move(m_archiveFile);
m_archiveFile.reset(new T(tapeFile));
return tmp;
}
//------------------------------------------------------------------------------
// getArchiveFile
//------------------------------------------------------------------------------
template<typename T>
T *ArchiveFileBuilder<T>::getArchiveFile() {
return m_archiveFile.get();
}
//------------------------------------------------------------------------------
// clear
//------------------------------------------------------------------------------
template<typename T>
void ArchiveFileBuilder<T>::clear() {
m_archiveFile.reset();
}
} // namespace catalogue
} // namespace cta
......@@ -36,6 +36,8 @@ set (CATALOGUE_LIB_SRC_FILES
CatalogueFactoryFactory.cpp
CatalogueSchema.cpp
CmdLineTool.cpp
DeletedArchiveFileItor.cpp
DeletedArchiveFileItorImpl.cpp
InMemoryCatalogue.cpp
InMemoryCatalogueFactory.cpp
MysqlCatalogue.cpp
......@@ -52,6 +54,7 @@ set (CATALOGUE_LIB_SRC_FILES
RdbmsCatalogue.cpp
RdbmsCatalogueGetArchiveFilesForRepackItor.cpp
RdbmsCatalogueGetArchiveFilesItor.cpp
RdbmsCatalogueGetDeletedArchiveFilesItor.cpp
SchemaCreatingSqliteCatalogue.cpp
SqliteCatalogue.cpp
SqliteCatalogueFactory.cpp
......@@ -172,6 +175,7 @@ add_custom_command (OUTPUT sqlite_catalogue_schema.sql mysql_catalogue_schema.sq
${CMAKE_CURRENT_SOURCE_DIR}/CreateAllSchemasCppFile.sh
${CMAKE_CURRENT_SOURCE_DIR}/AllCatalogueSchema.hpp.in
${CMAKE_CURRENT_SOURCE_DIR}/insert_cta_catalogue_version.sql.in
create_catalogue_schema_directory
)
add_custom_command(OUTPUT sqlite_catalogue_schema.cpp
......
......@@ -33,6 +33,7 @@
#include "common/dataStructures/ArchiveJob.hpp"
#include "common/dataStructures/ArchiveRoute.hpp"
#include "common/dataStructures/CancelRetrieveRequest.hpp"
#include "common/dataStructures/DeleteArchiveRequest.hpp"
#include "common/dataStructures/DiskFileInfo.hpp"
#include "common/dataStructures/DriveState.hpp"
#include "common/dataStructures/EntryLog.hpp"
......@@ -64,6 +65,7 @@
#include "common/log/Logger.hpp"
#include "common/optional.hpp"
#include "SchemaVersion.hpp"
#include "DeletedArchiveFileItor.hpp"
#include <list>
#include <map>
......@@ -420,8 +422,9 @@ public:
*
* @param admin The administrator.
* @param vid The volume identifier of the tape to be reclaimed.
* @param lc the logContext
*/
virtual void reclaimTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid) = 0;
virtual void reclaimTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, cta::log::LogContext & lc) = 0;
/**
* Checks the specified tape for the tape label command.
......@@ -684,6 +687,16 @@ public:
virtual ArchiveFileItor getArchiveFilesItor(
const TapeFileSearchCriteria &searchCriteria = TapeFileSearchCriteria()) const = 0;
/**
* Returns the specified deleted archive files. Please note that the list of files
* is ordered by archive file ID.
*
* @param searchCriteria The search criteria.
* @return The deleted archive files.
*/
virtual DeletedArchiveFileItor getDeletedArchiveFilesItor(
const TapeFileSearchCriteria &searchCriteria = TapeFileSearchCriteria()) const = 0;
/**
* Returns the specified files in tape file sequence order.
*
......@@ -822,6 +835,28 @@ public:
*/
virtual void updateDiskFileId(uint64_t archiveFileId, const std::string &diskInstance,
const std::string &diskFileId) = 0;
/**
* Insert the tape files and ArchiveFiles entries in the recycle-bin and delete
* them from the TAPE_FILE and ARCHIVE_FILE tables
* @param request the DeleteRequest object that holds information about the file to delete.
* @param lc the logContext
*/
virtual void moveArchiveFileToRecycleBin(const common::dataStructures::DeleteArchiveRequest &request,
log::LogContext & lc) = 0;
/**
*
* Deletes the specified archive file and its associated tape copies from the
* recycle-bin
*
* Please note that this method is idempotent. If the file to be deleted does
* not exist in the CTA catalogue then this method returns without error.
*
* @param archiveFileId The unique identifier of the archive file.
* @param lc The log context.
*/
virtual void deleteFileFromRecycleBin(const uint64_t archiveFileId, log::LogContext &lc) = 0;
}; // class Catalogue
......
......@@ -268,8 +268,8 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->getAllTapes();}, m_maxTriesToConnect);
}
void reclaimTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->reclaimTape(admin, vid);}, m_maxTriesToConnect);
void reclaimTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, cta::log::LogContext & lc) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->reclaimTape(admin, vid,lc);}, m_maxTriesToConnect);
}
void checkTapeForLabel(const std::string &vid) override {
......@@ -463,6 +463,14 @@ public:
ArchiveFileItor getArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getArchiveFilesItor(searchCriteria);}, m_maxTriesToConnect);
}
DeletedArchiveFileItor getDeletedArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getDeletedArchiveFilesItor(searchCriteria);}, m_maxTriesToConnect);
}
void deleteFileFromRecycleBin(const uint64_t archiveFileId, log::LogContext &lc){
return retryOnLostConnection(m_log,[&]{return m_catalogue->deleteFileFromRecycleBin(archiveFileId,lc);},m_maxTriesToConnect);
}
std::list<common::dataStructures::ArchiveFile> getFilesForRepack(const std::string &vid, const uint64_t startFSeq, const uint64_t maxNbFiles) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getFilesForRepack(vid, startFSeq, maxNbFiles);}, m_maxTriesToConnect);
......@@ -515,6 +523,11 @@ public:
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);
}
void moveArchiveFileToRecycleBin(const common::dataStructures::DeleteArchiveRequest &request,
log::LogContext & lc) override {
return retryOnLostConnection(m_log,[&]{return m_catalogue->moveArchiveFileToRecycleBin(request,lc);},m_maxTriesToConnect);
}
protected:
......
......@@ -53,6 +53,7 @@
#include "common/threading/Thread.hpp"
#include "common/threading/Mutex.hpp"
#include "common/threading/MutexLocker.hpp"
#include "DeletedArchiveFileItor.hpp"
 
#include <algorithm>
#include <gtest/gtest.h>
......@@ -144,6 +145,19 @@ void cta_catalogue_CatalogueTest::SetUp() {
m_catalogue->deleteArchiveFile(archiveFile.diskInstance, archiveFile.archiveFileID, dummyLc);
}
}
{
//Delete all the entries from the recycle bin
auto itor = m_catalogue->getDeletedArchiveFilesItor();
std::list<common::dataStructures::DeletedArchiveFile> deletedArchiveFiles;
while(itor.hasMore()){
deletedArchiveFiles.push_back(itor.next());
}
for(const auto &deletedArchiveFile: deletedArchiveFiles){
log::LogContext dummyLc(m_dummyLog);
m_catalogue->deleteFileFromRecycleBin(deletedArchiveFile.archiveFileID,dummyLc);
}
}
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
for(auto &tape: tapes) {
......@@ -14490,7 +14504,7 @@ TEST_P(cta_catalogue_CatalogueTest, checkTapeForLabel_one_tape_file_reclaimed_ta
m_catalogue->deleteArchiveFile(diskInstanceName1, archiveFileId, dummyLc);
m_catalogue->setTapeFull(m_admin, vid1, true);
m_catalogue->reclaimTape(m_admin, vid1);
m_catalogue->reclaimTape(m_admin, vid1,dummyLc);
ASSERT_NO_THROW(m_catalogue->checkTapeForLabel(vid1));
}
......@@ -14720,6 +14734,7 @@ TEST_P(cta_catalogue_CatalogueTest, checkTapeForLabel_empty_vid) {
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_0_no_tape_files) {
using namespace cta;
 
log::LogContext dummyLc(m_dummyLog);
ASSERT_TRUE(m_catalogue->getTapes().empty());
 
const std::string mediaType = "media_type";
......@@ -14776,7 +14791,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_0_no_tape_files) {
}
 
m_catalogue->setTapeFull(m_admin, vid, true);
m_catalogue->reclaimTape(m_admin, vid);
m_catalogue->reclaimTape(m_admin, vid, dummyLc);
 
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
......@@ -14811,6 +14826,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_0_no_tape_files) {
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_not_full_lastFSeq_0_no_tape_files) {
using namespace cta;
 
log::LogContext dummyLc(m_dummyLog);
ASSERT_TRUE(m_catalogue->getTapes().empty());
 
const std::string mediaType = "media_type";
......@@ -14866,15 +14882,15 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_not_full_lastFSeq_0_no_tape_file
const common::dataStructures::EntryLog lastModificationLog = tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
ASSERT_THROW(m_catalogue->reclaimTape(m_admin, vid), exception::UserError);
ASSERT_THROW(m_catalogue->reclaimTape(m_admin, vid, dummyLc), exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_no_tape_files) {
using namespace cta;
 
log::LogContext dummyLc(m_dummyLog);
const std::string diskInstanceName1 = "disk_instance_1";
ASSERT_TRUE(m_catalogue->getTapes().empty());
 
const std::string vid1 = "VID123";
......@@ -15028,7 +15044,6 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_no_tape_files) {
}
 
{
log::LogContext dummyLc(m_dummyLog);
m_catalogue->deleteArchiveFile(diskInstanceName1, file1Written.archiveFileId, dummyLc);
}
 
......@@ -15067,7 +15082,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_no_tape_files) {
}
 
m_catalogue->setTapeFull(m_admin, vid1, true);
m_catalogue->reclaimTape(m_admin, vid1);
m_catalogue->reclaimTape(m_admin, vid1, dummyLc);
 
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
......@@ -15102,6 +15117,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_no_tape_files) {
 
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file) {
using namespace cta;
log::LogContext dummyLc(m_dummyLog);
 
const std::string diskInstanceName1 = "disk_instance_1";
 
......@@ -15259,12 +15275,13 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file) {
}
 
m_catalogue->setTapeFull(m_admin, vid1, true);
ASSERT_THROW(m_catalogue->reclaimTape(m_admin, vid1), exception::UserError);
ASSERT_THROW(m_catalogue->reclaimTape(m_admin, vid1, dummyLc), exception::UserError);
}
 
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file_superseded) {
using namespace cta;
 
log::LogContext dummyLc(m_dummyLog);
const std::string diskInstanceName1 = "disk_instance_1";
 
ASSERT_TRUE(m_catalogue->getTapes().empty());
......@@ -15460,7 +15477,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file_su
ASSERT_EQ("", tf.supersededByVid);
}
ASSERT_NO_THROW(m_catalogue->reclaimTape(m_admin, vid1));
ASSERT_NO_THROW(m_catalogue->reclaimTape(m_admin, vid1, dummyLc));
{
//Test that the tape with vid1 is reclaimed
......@@ -15928,4 +15945,262 @@ TEST_P(cta_catalogue_CatalogueTest, updateDiskFileId) {
}
}
 
TEST_P(cta_catalogue_CatalogueTest, moveFilesToRecycleBin) {
using namespace cta;
const std::string vid1 = "VID123";
const std::string vid2 = "VID456";
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 tapePoolName1 = "tape_pool_name_1";
const std::string tapePoolName2 = "tape_pool_name_2";
const std::string vo = "vo";
const uint64_t nbPartialTapes = 1;
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, tapePoolName1, vo, nbPartialTapes, isEncrypted, supply, "Create tape pool");
common::dataStructures::StorageClass storageClass;
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
storageClass.vo.name = vo;
m_catalogue->createStorageClass(m_admin, storageClass);
const std::string tapeDrive = "tape_drive";
m_catalogue->createTapePool(m_admin, tapePoolName2, vo, nbPartialTapes, isEncrypted, supply, "Create tape pool");
m_catalogue->createTape(m_admin, vid1, mediaType, vendor, logicalLibraryName, tapePoolName1, capacityInBytes,
disabledValue, fullValue, readOnlyValue, comment);
m_catalogue->createTape(m_admin, vid2, mediaType, vendor, logicalLibraryName, tapePoolName2, capacityInBytes,
disabledValue, fullValue, readOnlyValue, comment);
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
const uint64_t nbArchiveFiles = 10; // Must be a multiple of 2 for this test
const uint64_t archiveFileSize = 2 * 1000 * 1000 * 1000;
std::set<catalogue::TapeItemWrittenPointer> tapeFilesWrittenCopy1;
for(uint64_t i = 1; i <= nbArchiveFiles; i++) {
std::ostringstream diskFileId;
diskFileId << (12345677 + i);
std::ostringstream diskFilePath;
diskFilePath << "/test/file"<<i;
// Tape copy 1 written to tape
auto fileWrittenUP=cta::make_unique<cta::catalogue::TapeFileWritten>();
auto & fileWritten = *fileWrittenUP;
fileWritten.archiveFileId = i;
fileWritten.diskInstance = diskInstance;
fileWritten.diskFileId = diskFileId.str();
fileWritten.diskFilePath = diskFilePath.str();
fileWritten.diskFileOwnerUid = PUBLIC_DISK_USER;
fileWritten.diskFileGid = PUBLIC_DISK_GROUP;
fileWritten.size = archiveFileSize;
fileWritten.checksumBlob.insert(checksum::ADLER32, "1357");
fileWritten.storageClassName = storageClass.name;
fileWritten.vid = vid1;
fileWritten.fSeq = i;
fileWritten.blockId = i * 100;
fileWritten.copyNb = 1;
fileWritten.tapeDrive = tapeDrive;
tapeFilesWrittenCopy1.emplace(fileWrittenUP.release());
}
m_catalogue->filesWrittenToTape(tapeFilesWrittenCopy1);
{
ASSERT_TRUE(m_catalogue->getArchiveFilesItor().hasMore());
}
log::LogContext dummyLc(m_dummyLog);
for(auto & tapeItemWritten: tapeFilesWrittenCopy1){
cta::catalogue::TapeFileWritten * tapeItem = static_cast<cta::catalogue::TapeFileWritten *>(tapeItemWritten.get());
cta::common::dataStructures::DeleteArchiveRequest req;
req.archiveFileID = tapeItem->archiveFileId;
req.diskFileId = tapeItem->diskFileId;
req.diskFilePath = tapeItem->diskFilePath;
req.diskInstance = tapeItem->diskInstance;
ASSERT_NO_THROW(m_catalogue->moveArchiveFileToRecycleBin(req,dummyLc));
}
ASSERT_FALSE(m_catalogue->getArchiveFilesItor().hasMore());
std::vector<common::dataStructures::DeletedArchiveFile> deletedArchiveFiles;
{
cta::catalogue::DeletedArchiveFileItor itor = m_catalogue->getDeletedArchiveFilesItor();
while(itor.hasMore()){
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());
for(uint64_t i = 1; i <= nbArchiveFiles; i++) {
auto deletedArchiveFile = deletedArchiveFiles[i-1];
std::ostringstream diskFileId;
diskFileId << (12345677 + i);
std::ostringstream diskFilePath;
diskFilePath << "/test/file"<<i;
ASSERT_EQ(i,deletedArchiveFile.archiveFileID);
ASSERT_EQ(diskInstance,deletedArchiveFile.diskInstance);
ASSERT_EQ(diskFileId.str(),deletedArchiveFile.diskFileId);
ASSERT_EQ(diskFilePath.str(),deletedArchiveFile.diskFilePath);
ASSERT_EQ(PUBLIC_DISK_USER,deletedArchiveFile.diskFileInfo.owner_uid);
ASSERT_EQ(PUBLIC_DISK_GROUP,deletedArchiveFile.diskFileInfo.gid);
ASSERT_EQ(archiveFileSize,deletedArchiveFile.fileSize);
ASSERT_EQ(cta::checksum::ChecksumBlob(checksum::ADLER32, "1357"),deletedArchiveFile.checksumBlob);
ASSERT_EQ(storageClass.name,deletedArchiveFile.storageClass);
ASSERT_EQ(diskFileId.str(),deletedArchiveFile.diskFileIdWhenDeleted);
auto tapeFile = deletedArchiveFile.tapeFiles.at(1);
ASSERT_EQ(vid1,tapeFile.vid);
ASSERT_EQ(i,tapeFile.fSeq);