diff --git a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt index 7f229d96d158f358b06fc879bb635e3a217fdce5..0975b4760e86465777365fd49d534180918fdd4f 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt @@ -128,7 +128,7 @@ add_library(castortapeserverdaemonunittests SHARED # TapeDaemon.cpp # TapeDaemonTest.cpp -# TaskWatchDogTest.cpp + TaskWatchDogTest.cpp ) target_link_libraries(castortapeserverdaemonunittests diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeReadTask.hpp b/tapeserver/castor/tape/tapeserver/daemon/TapeReadTask.hpp index fe11903607d6a3a729caa2099d108d981e83b080..2f35b6063fb7ec3dbfed88f0a8094e0ae91ddd83 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeReadTask.hpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeReadTask.hpp @@ -101,7 +101,7 @@ public: lc.log(LOG_INFO, "Successfully positioned for reading"); localStats.positionTime += timer.secs(castor::utils::Timer::resetCounter); - watchdog.notifyBeginNewJob(); + watchdog.notifyBeginNewJob(m_retrieveJob->archiveFile.path, m_retrieveJob->archiveFile.fileId, m_retrieveJob->tapeFileLocation.fSeq); localStats.waitReportingTime += timer.secs(castor::utils::Timer::resetCounter); currentErrorToCount = "Error_tapeReadData"; while (stillReading) { diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp index 558b169dfaf129848f857bade92b27cd1376389a..e7dc415c3562402f91fe80b9eb4958b358fc8c30 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp @@ -94,7 +94,7 @@ namespace daemon { try { //try to open the session currentErrorToCount = "Error_tapeWriteHeader"; - watchdog.notifyBeginNewJob(); + watchdog.notifyBeginNewJob(m_archiveJob->archiveFile.path, m_archiveJob->archiveFile.fileId, m_archiveJob->tapeFileLocation.fSeq); std::unique_ptr<castor::tape::tapeFile::WriteFile> output(openWriteFile(session,lc)); m_taskStats.readWriteTime += timer.secs(castor::utils::Timer::resetCounter); m_taskStats.headerVolume += TapeSessionStats::headerVolumePerFile; diff --git a/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDog.hpp b/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDog.hpp index 38db3f6adbcab2c55fbedf57711e65cc83809db4..33906f6ff4b294860bd087fc44a216305537ae4e 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDog.hpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDog.hpp @@ -372,25 +372,25 @@ protected: * Implementation of TaskWatchDog for recalls */ class RecallWatchDog: public TaskWatchDog { + private: - /** Our file type */ - //typedef cta::RetrieveJob FileStruct; + /** The file we are working on */ - //FileStruct m_file; + std::string m_path; + uint64_t m_fileId; + uint64_t m_fSeq; virtual void logStuckFile() { -// This code is commented out pending the implementation of a more complete -// watchdog involving disk side too (CASTOR-4773 tapeserverd's internal watchdog -// improvement: track disk transfers as well) -// -// castor::log::ScopedParamContainer params(m_lc); -// params.addTiming("TimeSinceLastBlockMove", m_blockMovementTimer.secs()) -// .add("Path",m_file.path()) -// .add("FILEID",m_file.fileid()) -// .add("fSeq",m_file.fseq()); -// m_lc.log(LOG_WARNING, "No tape block movement for too long"); + castor::log::ScopedParamContainer params(m_lc); + params.add("TimeSinceLastBlockMove", m_blockMovementTimer.secs()) + .add("path",m_path) + .add("NSFILEID",m_fileId) + .add("fSeq",m_fSeq); + m_lc.log(LOG_WARNING, "No tape block movement for too long"); } + public: + /** Pass through constructor */ RecallWatchDog(double periodToReport,double stuckPeriod, messages::TapeserverProxy& initialProcess, @@ -398,13 +398,16 @@ public: log::LogContext lc, double pollPeriod = 0.1): TaskWatchDog(periodToReport, stuckPeriod, initialProcess, driveUnitName, lc, pollPeriod) {} + /** * Notify the watchdog which file we are operating * @param file */ - void notifyBeginNewJob(/*const FileStruct& file*/){ + void notifyBeginNewJob(const std::string path, const uint64_t fileId, uint64_t fSeq) { castor::server::MutexLocker locker(&m_mutex); - //m_file=file; + m_path=path; + m_fileId=fileId; + m_fSeq=fSeq; m_fileBeingMoved=true; } @@ -414,7 +417,9 @@ public: void fileFinished(){ castor::server::MutexLocker locker(&m_mutex); m_fileBeingMoved=false; - //m_file=FileStruct(); + m_path=""; + m_fileId=0; + m_fSeq=0; } }; @@ -422,19 +427,25 @@ public: * Implementation of TaskWatchDog for migrations */ class MigrationWatchDog: public TaskWatchDog { + private: + /** The file we are working on */ -// cta::ArchiveJob m_file; -// + std::string m_path; + uint64_t m_fileId; + uint64_t m_fSeq; + virtual void logStuckFile() { -// castor::log::ScopedParamContainer params(m_lc); -// params.add("TimeSinceLastBlockMove", m_blockMovementTimer.secs()) -// .add("path",m_file.path()) -// .add("NSFILEID",m_file.fileid()) -// .add("fSeq",m_file.fseq()); -// m_lc.log(LOG_WARNING, "No tape block movement for too long"); + castor::log::ScopedParamContainer params(m_lc); + params.add("TimeSinceLastBlockMove", m_blockMovementTimer.secs()) + .add("path",m_path) + .add("NSFILEID",m_fileId) + .add("fSeq",m_fSeq); + m_lc.log(LOG_WARNING, "No tape block movement for too long"); } + public: + /** Pass through constructor */ MigrationWatchDog(double periodToReport,double stuckPeriod, messages::TapeserverProxy& initialProcess, @@ -442,13 +453,16 @@ public: log::LogContext lc, double pollPeriod = 0.1): TaskWatchDog(periodToReport, stuckPeriod, initialProcess, driveUnitName, lc, pollPeriod) {} + /** * Notify the watchdog which file we are operating * @param file */ - void notifyBeginNewJob(/*const cta::ArchiveJob file*/){ + void notifyBeginNewJob(const std::string path, const uint64_t fileId, uint64_t fSeq){ castor::server::MutexLocker locker(&m_mutex); -// m_file=file; + m_path=path; + m_fileId=fileId; + m_fSeq=fSeq; m_fileBeingMoved=true; } @@ -458,7 +472,9 @@ public: void fileFinished(){ castor::server::MutexLocker locker(&m_mutex); m_fileBeingMoved=false; -// m_file=FileStruct(); + m_path=""; + m_fileId=0; + m_fSeq=0; } }; diff --git a/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDogTest.cpp b/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDogTest.cpp index f342fa3dc4f508e66f370bf667fc9dc5eda6692e..a0dd3859584896ad5491be510f0071a3470d4b15 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDogTest.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TaskWatchDogTest.cpp @@ -23,27 +23,17 @@ #include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp" #include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp" -#include "castor/tape/tapeserver/client/FakeClient.hpp" #include "castor/messages/TapeserverProxyDummy.hpp" #include "castor/log/StringLogger.hpp" + +#include <gmock/gmock.h> #include <gtest/gtest.h> + namespace unitTests { using namespace castor::tape; using ::testing::_; - struct MockReportPacker : - public tapeserver::daemon::ReportPackerInterface<tapeserver::daemon::detail::Recall> { - // TODO MOCK_METHOD1(reportStuckOn, void(FileStruct& file)); - - MockReportPacker(tapeserver::client::ClientInterface & tg, castor::log::LogContext lc): - tapeserver::daemon::ReportPackerInterface<castor::tape::tapeserver::daemon::detail::Recall>(lc){ - - } - }; - - - TEST(castor_tape_tapeserver_daemon, WatchdogTestStuckWithNothing) { const double periodToReport = 10; // We wont report in practice const double stuckPeriod = 0.01; @@ -52,10 +42,8 @@ TEST(castor_tape_tapeserver_daemon, WatchdogTestStuckWithNothing) { castor::log::StringLogger log("castor_tape_tapeserver_daemon_WatchdogTestStuck"); castor::log::LogContext lc(log); - MockClient mockClient; castor::messages::TapeserverProxyDummy dummyInitialProcess; - tapeserver::daemon::RecallWatchDog watchdog(periodToReport, stuckPeriod,dummyInitialProcess,"testTapeDrive",lc,pollPeriod); @@ -75,7 +63,6 @@ TEST(castor_tape_tapeserver_daemon, MigrationWatchdogTestStuck) { castor::log::StringLogger log("castor_tape_tapeserver_daemon_WatchdogTestStuck"); castor::log::LogContext lc(log); - MockClient mockClient; castor::messages::TapeserverProxyDummy dummyInitialProcess; // We will poll for a @@ -83,8 +70,7 @@ TEST(castor_tape_tapeserver_daemon, MigrationWatchdogTestStuck) { dummyInitialProcess,"testTapeDrive", lc, pollPeriod); watchdog.startThread(); - tapegateway::FileToMigrateStruct file; - watchdog.notifyBeginNewJob(file); + watchdog.notifyBeginNewJob("/hey/ho/lets/go", 64, 64); usleep(100000); watchdog.stopAndWaitThread(); // This time the internal watchdog should have triggered