From b4eb307d938e8ded23de8d2922adcdb5e5d35335 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Mon, 7 Sep 2015 12:19:53 +0200 Subject: [PATCH] The uncommented tests of DataTransferSessionTest now create tape file entries in the archive namespace --- common/Utils.cpp | 2 +- common/Utils.hpp | 2 +- common/UtilsTest.cpp | 2 +- common/archiveNS/TapeFileLocation.cpp | 10 ++- common/archiveNS/TapeFileLocation.hpp | 6 +- scheduler/OStoreDB/OStoreDB.cpp | 8 +- scheduler/SchedulerDatabaseTest.cpp | 8 +- .../daemon/DataTransferSessionTest.cpp | 82 ++++++++++++++----- 8 files changed, 83 insertions(+), 37 deletions(-) diff --git a/common/Utils.cpp b/common/Utils.cpp index e153643989..ce66236a67 100644 --- a/common/Utils.cpp +++ b/common/Utils.cpp @@ -477,7 +477,7 @@ bool cta::Utils::isValidUInt(const std::string &str) //------------------------------------------------------------------------------ // getAdler32 //------------------------------------------------------------------------------ -uint32_t cta::Utils::getAdler32(const char *buf, const uint32_t len) +uint32_t cta::Utils::getAdler32(const uint8_t *buf, const uint32_t len) throw() { const uint32_t checksum = adler32(0L, Z_NULL, 0); return adler32(checksum, (const Bytef*)buf, len); diff --git a/common/Utils.hpp b/common/Utils.hpp index b5c1504f46..ccad120e47 100644 --- a/common/Utils.hpp +++ b/common/Utils.hpp @@ -215,7 +215,7 @@ public: * @param len The length of the buffer in bytes. * @return the alder32 checksum of the specified buffer. */ - static uint32_t getAdler32(const char *buf, const uint32_t len) throw(); + static uint32_t getAdler32(const uint8_t *buf, const uint32_t len) throw(); }; // class Utils diff --git a/common/UtilsTest.cpp b/common/UtilsTest.cpp index 44e027e2fc..490cac80c1 100644 --- a/common/UtilsTest.cpp +++ b/common/UtilsTest.cpp @@ -462,7 +462,7 @@ TEST_F(cta_UtilsTest, adler32_empty_buf) { TEST_F(cta_UtilsTest, adler32_buf_of_character_1) { using namespace cta; - const char buf = '1'; + const uint8_t buf = '1'; ASSERT_EQ((uint32_t)0x320032, Utils::getAdler32(&buf, 1)); } diff --git a/common/archiveNS/TapeFileLocation.cpp b/common/archiveNS/TapeFileLocation.cpp index 9e0a4e4ba2..0bf2c646cb 100644 --- a/common/archiveNS/TapeFileLocation.cpp +++ b/common/archiveNS/TapeFileLocation.cpp @@ -25,15 +25,19 @@ cta::TapeFileLocation::TapeFileLocation(): fSeq(0), blockId(0), vid(""), - copyNumber(0) { + copyNb(0) { } //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -cta::TapeFileLocation::TapeFileLocation(const uint64_t fSeq, const uint64_t blockId, const std::string &vid, const uint8_t copyNumber): +cta::TapeFileLocation::TapeFileLocation( + const uint64_t fSeq, + const uint64_t blockId, + const std::string &vid, + const uint8_t copyNb): fSeq(fSeq), blockId(blockId), vid(vid), - copyNumber(copyNumber) { + copyNb(copyNb) { } diff --git a/common/archiveNS/TapeFileLocation.hpp b/common/archiveNS/TapeFileLocation.hpp index 848f627c0c..b8d6eeed0a 100644 --- a/common/archiveNS/TapeFileLocation.hpp +++ b/common/archiveNS/TapeFileLocation.hpp @@ -39,9 +39,9 @@ struct TapeFileLocation { * @param fSeq The sequence number of the file. * @param blockId The block identifier of the file. * @param vid The vid of the tape containing the file. TODO: to be put in the mount object in the future - * @param copyNumber The copy number of the tape file. TODO: to be put in the mount object in the future + * @param copyNb The copy number of the tape file. TODO: to be put in the mount object in the future */ - TapeFileLocation(const uint64_t fSeq, const uint64_t blockId, const std::string &vid, const uint8_t copyNumber); + TapeFileLocation(const uint64_t fSeq, const uint64_t blockId, const std::string &vid, const uint8_t copyNb); /** * The sequence number of the file. @@ -61,7 +61,7 @@ struct TapeFileLocation { /** * The copy number of the tape file. TODO: to be put in the mount object in the future */ - uint8_t copyNumber; + uint8_t copyNb; }; // struct TapeFileLocation diff --git a/scheduler/OStoreDB/OStoreDB.cpp b/scheduler/OStoreDB/OStoreDB.cpp index 5ccd1f6f30..24002756f5 100644 --- a/scheduler/OStoreDB/OStoreDB.cpp +++ b/scheduler/OStoreDB/OStoreDB.cpp @@ -969,14 +969,14 @@ void OStoreDB::queue(const cta::RetrieveToFileRequest& rqst) { // Now add all the candidate tape copies to the request. With validation for (auto tc=rqst.getTapeCopies().begin(); tc!=rqst.getTapeCopies().end(); tc++) { // Check the tape copy copynumber (range = [1 - copyCount] ) - if (tc->copyNumber > rqst.getTapeCopies().size() || tc->copyNumber < 1) { + if (tc->copyNb > rqst.getTapeCopies().size() || tc->copyNb < 1) { throw TapeCopyNumberOutOfRange("In OStoreDB::queue(RetrieveToFile): copy number out of range"); } } // Add all the tape copies to the request try { for (auto tc=rqst.getTapeCopies().begin(); tc!=rqst.getTapeCopies().end(); tc++) { - rtfr.addJob(tc->copyNumber, tc->vid, vidToAddress.at(tc->vid)); + rtfr.addJob(tc->copyNb, tc->vid, vidToAddress.at(tc->vid)); } } catch (std::out_of_range &) { throw NoSuchTape("In OStoreDB::queue(RetrieveToFile): tape not found"); @@ -990,7 +990,7 @@ void OStoreDB::queue(const cta::RetrieveToFileRequest& rqst) { { // First tape copy is always better than nothing. auto tc=rqst.getTapeCopies().begin(); - selectedCopyNumber = tc->copyNumber; + selectedCopyNumber = tc->copyNb; selectedVid = tc->vid; // Get info for the tape. { @@ -1007,7 +1007,7 @@ void OStoreDB::queue(const cta::RetrieveToFileRequest& rqst) { t.fetch(); if (t.getJobsSummary().bytes > bestTapeQueuedBytes) { bestTapeQueuedBytes = t.getJobsSummary().bytes; - selectedCopyNumber = tc->copyNumber; + selectedCopyNumber = tc->copyNb; selectedVid = tc->vid; } } diff --git a/scheduler/SchedulerDatabaseTest.cpp b/scheduler/SchedulerDatabaseTest.cpp index fbceda99b7..7aad0c5be3 100644 --- a/scheduler/SchedulerDatabaseTest.cpp +++ b/scheduler/SchedulerDatabaseTest.cpp @@ -482,12 +482,12 @@ TEST_P(SchedulerDatabaseTest, getMountInfo) { tcl.back().blockId = 666; tcl.back().fSeq = 10; tcl.back().vid = "Tape2"; - tcl.back().copyNumber = 1; + tcl.back().copyNb = 1; tcl.push_back(TapeFileLocation()); tcl.back().blockId = 111; tcl.back().fSeq = 5; tcl.back().vid = "Tape3"; - tcl.back().copyNumber = 2; + tcl.back().copyNb = 2; ASSERT_NO_THROW(db.queue(cta::RetrieveToFileRequest("cta:://cta/myfile", 1234, tcl, "eos://myeos/myeosfile", 10, cl))); mountCandidates.reset(NULL); ASSERT_NO_THROW(mountCandidates = db.getMountInfo()); @@ -526,12 +526,12 @@ TEST_P(SchedulerDatabaseTest, getMountInfo) { tcl2.back().blockId = 999; tcl2.back().fSeq = 11; tcl2.back().vid = "Tape3"; - tcl2.back().copyNumber = 1; + tcl2.back().copyNb = 1; tcl2.push_back(TapeFileLocation()); tcl2.back().blockId = 333; tcl2.back().fSeq = 3; tcl2.back().vid = "Tape2"; - tcl2.back().copyNumber = 2; + tcl2.back().copyNb = 2; db.queue(cta::RetrieveToFileRequest("cta:://cta/myfile2", 1234, tcl2, "eos://myeos/myeosfile2", 10, cl)); mountCandidates.reset(NULL); ASSERT_NO_THROW(mountCandidates = db.getMountInfo()); diff --git a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp index d4409b4e34..be899bca55 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp @@ -214,21 +214,17 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio remoteFilePath << "file:" << m_tmpDir << "/test" << fseq; remoteFilePaths.push_back(remoteFilePath.str()); - // Create an entry in the archive namespace + // Create an archive file entry in the archive namespace std::ostringstream archiveFilePath; archiveFilePath << "/test" << fseq; const mode_t archiveFileMode = 0655; const uint64_t archiveFileSize = 256*1024; - ns.createFile( + ASSERT_NO_THROW(ns.createFile( requester, archiveFilePath.str(), archiveFileMode, - archiveFileSize); - -// TODO -// We need to add the tape file entry to the name server - - + archiveFileSize)); + // Write the file to tape std::unique_ptr<cta::RetrieveJob> ftr(new MockRetrieveJob()); std::unique_ptr<cta::ArchiveJob> ftm(new MockArchiveJob()); @@ -244,6 +240,23 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio // Close the file wf.close(); + // Create tape file entry in the archive namespace + cta::NameServerTapeFile tapeFile; + tapeFile.copyNb = 1; + tapeFile.tapeFileLocation.fSeq = fseq; + tapeFile.tapeFileLocation.blockId = wf.getPosition(); + tapeFile.tapeFileLocation.vid = volInfo.vid; + tapeFile.tapeFileLocation.copyNb = 1; + tapeFile.size = archiveFileSize; + tapeFile.compressedSize = archiveFileSize; // No compression + cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, + cta::ByteArray(cta::Utils::getAdler32(data, sizeof data))); + tapeFile.checksum = tapeFileChecksum; + ASSERT_NO_THROW(ns.addTapeFile( + requester, + archiveFilePath.str(), + tapeFile)); + // Schedule the retrieval of the file std::list<std::string> archiveFilePaths; archiveFilePaths.push_back(archiveFilePath.str()); @@ -346,19 +359,16 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio remoteFilePath << "file:" << m_tmpDir << "/test" << fseq; remoteFilePaths.push_back(remoteFilePath.str()); - // Create an entry in the archive namespace + // Create an archive file entry in the archive namespace std::ostringstream archiveFilePath; archiveFilePath << "/test" << fseq; const mode_t archiveFileMode = 0655; const uint64_t archiveFileSize = 256*1024; - ns.createFile( + ASSERT_NO_THROW(ns.createFile( requester, archiveFilePath.str(), archiveFileMode, - archiveFileSize); -// TODO -// We need to add the tape file entry to the name server with at least one entry -// pointing beyond the end of data + archiveFileSize)); // Write the file to tape std::unique_ptr<cta::RetrieveJob> ftr(new MockRetrieveJob()); @@ -375,6 +385,24 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio // Close the file wf.close(); + // Create tape file entry in the archive namespace that is beyond the end + // of data + cta::NameServerTapeFile tapeFile; + tapeFile.copyNb = 1; + tapeFile.tapeFileLocation.fSeq = fseq + 10000; + tapeFile.tapeFileLocation.blockId = wf.getPosition() + 10000; + tapeFile.tapeFileLocation.vid = volInfo.vid; + tapeFile.tapeFileLocation.copyNb = 1; + tapeFile.size = archiveFileSize; + tapeFile.compressedSize = archiveFileSize; // No compression + cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, + cta::ByteArray(cta::Utils::getAdler32(data, sizeof data))); + tapeFile.checksum = tapeFileChecksum; + ASSERT_NO_THROW(ns.addTapeFile( + requester, + archiveFilePath.str(), + tapeFile)); + // Schedule the retrieval of the file std::list<std::string> archiveFilePaths; archiveFilePaths.push_back(archiveFilePath.str()); @@ -527,19 +555,16 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio remoteFilePath << "file:" << m_tmpDir << "/test" << fseq; remoteFilePaths.push_back(remoteFilePath.str()); - // Create an entry in the archive namespace + // Create an archive file entry in the archive namespace std::ostringstream archiveFilePath; archiveFilePath << "/test" << fseq; const mode_t archiveFileMode = 0655; const uint64_t archiveFileSize = 256*1024; - ns.createFile( + ASSERT_NO_THROW(ns.createFile( requester, archiveFilePath.str(), archiveFileMode, - archiveFileSize); -// TODO -// We need to add the tape file entry to the name server with at least one entry -// pointing beyond the end of data + archiveFileSize)); // Write the file to tape std::unique_ptr<cta::RetrieveJob> ftr(new MockRetrieveJob()); @@ -556,6 +581,23 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio // Close the file wf.close(); + // Create tape file entry in the archive namespace + cta::NameServerTapeFile tapeFile; + tapeFile.copyNb = 1; + tapeFile.tapeFileLocation.fSeq = fseq; + tapeFile.tapeFileLocation.blockId = wf.getPosition(); + tapeFile.tapeFileLocation.vid = volInfo.vid; + tapeFile.tapeFileLocation.copyNb = 1; + tapeFile.size = archiveFileSize; + tapeFile.compressedSize = archiveFileSize; // No compression + cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, + cta::ByteArray(cta::Utils::getAdler32(data, sizeof data))); + tapeFile.checksum = tapeFileChecksum; + ASSERT_NO_THROW(ns.addTapeFile( + requester, + archiveFilePath.str(), + tapeFile)); + // Schedule the retrieval of the file std::list<std::string> archiveFilePaths; archiveFilePaths.push_back(archiveFilePath.str()); -- GitLab