Commit 8506e55b authored by David COME's avatar David COME
Browse files

Added an adler32 checksum

Compute it on DiskWriteTask and report it to the Client. Tests and interfaces have changed consequently
parent 98ab557d
......@@ -61,7 +61,7 @@ add_library(tapeserver
TapeWriteTask.cpp
DiskReadTask.cpp
DiskWriteTask.cpp
MigrationTaskInjector.cpp)
MigrationTaskInjector.cpp)
add_library(tapeserverdTest
......
......@@ -25,6 +25,11 @@
#include "castor/tape/tapeserver/daemon/DiskWriteTask.hpp"
namespace {
//todo : merge it with one of TapeWriteTask and put is somewhere
unsigned long initAdler32Checksum() {
return adler32(0L,Z_NULL,0);
}
/*Use RAII to make sure the memory block is released
*(ie pushed back to the memory manager) in any case (exception or not)
*/
......@@ -65,7 +70,7 @@ namespace daemon {
try{
tape::diskFile::WriteFile ourFile(m_recallingFile->path());
int blockId = 0;
unsigned long checksum = initAdler32Checksum();
while(1) {
if(MemBlock* const mb = m_fifo.pop()) {
AutoReleaseBlock releaser(mb,m_memManager);
......@@ -84,14 +89,15 @@ namespace daemon {
throw castor::tape::Exception("received a bad block for writing");
}
mb->m_payload.write(ourFile);
checksum = mb->m_payload.adler32(checksum);
blockId++;
}
else
break;
} //end of while(1)
reporter.reportCompletedJob(*m_recallingFile);
reporter.reportCompletedJob(*m_recallingFile,checksum);
return true;
}
} //end of try
catch(const castor::exception::Exception& e){
/*
*We might end up there with some blocks into m_fifo
......
......@@ -15,7 +15,7 @@ namespace unitTests{
using namespace castor::tape::tapeserver::daemon;
using namespace castor::tape::tapeserver::client;
struct MockRecallReportPacker : public ReportPackerInterface<detail::Recall>{
MOCK_METHOD1(reportCompletedJob,void(const FileStruct&));
MOCK_METHOD2(reportCompletedJob,void(const FileStruct&,unsigned long));
MOCK_METHOD3(reportFailedJob, void(const FileStruct& ,const std::string&,int));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
......
......@@ -15,7 +15,7 @@ namespace unitTests{
using namespace castor::tape::tapeserver::daemon;
using namespace castor::tape::tapeserver::client;
struct MockRecallReportPacker : public ReportPackerInterface<detail::Recall>{
MOCK_METHOD1(reportCompletedJob,void(const FileStruct&));
MOCK_METHOD2(reportCompletedJob,void(const FileStruct&,unsigned long));
MOCK_METHOD3(reportFailedJob, void(const FileStruct& ,const std::string&,int));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
......@@ -34,7 +34,7 @@ namespace unitTests{
castor::log::LogContext lc(log);
MockRecallReportPacker report(client,lc);
EXPECT_CALL(report,reportCompletedJob(_)).Times(5);
EXPECT_CALL(report,reportCompletedJob(_,_)).Times(5);
//EXPECT_CALL(tskInjectorl,requestInjection(_,_,_)).Times(2);
EXPECT_CALL(report,reportEndOfSession()).Times(1);
......
......@@ -51,8 +51,9 @@ MigrationReportPacker::~MigrationReportPacker(){
castor::tape::threading::MutexLocker ml(&m_producterProtection);
}
void MigrationReportPacker::reportCompletedJob(const tapegateway::FileToMigrateStruct& migratedFile) {
std::auto_ptr<Report> rep(new ReportSuccessful(migratedFile));
void MigrationReportPacker::reportCompletedJob(
const tapegateway::FileToMigrateStruct& migratedFile,unsigned long checksum) {
std::auto_ptr<Report> rep(new ReportSuccessful(migratedFile,checksum));
castor::tape::threading::MutexLocker ml(&m_producterProtection);
m_fifo.push(rep.release());
}
......@@ -85,6 +86,10 @@ void MigrationReportPacker::ReportSuccessful::execute(MigrationReportPacker& _th
successMigration->setId(m_migratedFile.id());
successMigration->setNshost(m_migratedFile.nshost());
successMigration->setFileid(m_migratedFile.fileid());
successMigration->setChecksum(m_checksum);
//WARNING; Ad-hoc name of the ChecksumName !!
successMigration->setChecksumName("adler32");
_this.m_listReports->addSuccessfulMigrations(successMigration.release());
}
......
......@@ -52,7 +52,8 @@ public:
* of migratedFile
* @param migratedFile the file successfully migrated
*/
void reportCompletedJob(const tapegateway::FileToMigrateStruct& migratedFile);
void reportCompletedJob(const tapegateway::FileToMigrateStruct& migratedFile,
unsigned long checksum);
/**
* Create into the MigrationReportPacker a report for the failled migration
......@@ -89,9 +90,10 @@ private:
};
class ReportSuccessful : public Report {
const FileStruct m_migratedFile;
const unsigned long m_checksum;
public:
ReportSuccessful(const FileStruct& file):
m_migratedFile(file){}
ReportSuccessful(const FileStruct& file,unsigned long checksum):
m_migratedFile(file),m_checksum(checksum){}
virtual void execute(MigrationReportPacker& _this);
};
class ReportFlush : public Report {
......
......@@ -44,8 +44,8 @@ TEST(castor_tape_tapeserver_daemon, MigrationReportPackerNominal) {
tapegateway::FileToMigrateStruct migratedFile;
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportFlush();
mrp.reportEndOfSession();
mrp.waitThread();
......@@ -68,9 +68,9 @@ TEST(castor_tape_tapeserver_daemon, MigrationReportPackerFaillure) {
tapegateway::FileToMigrateStruct migratedFile;
tapegateway::FileToMigrateStruct failed;
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportFailedJob(failed,error,-1);
mrp.reportFlush();
mrp.reportEndOfSessionWithErrors(error,-1);
......@@ -93,9 +93,9 @@ TEST(castor_tape_tapeserver_daemon, MigrationReportPackerFaillureGoodEnd) {
tapegateway::FileToMigrateStruct migratedFile;
tapegateway::FileToMigrateStruct failed;
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportFailedJob(failed,error,-1);
mrp.reportFlush();
mrp.reportEndOfSession();
......@@ -120,9 +120,9 @@ TEST(castor_tape_tapeserver_daemon, MigrationReportPackerGoodBadEnd) {
tapegateway::FileToMigrateStruct migratedFile;
tapegateway::FileToMigrateStruct failed;
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportCompletedJob(migratedFile,0);
mrp.reportFlush();
mrp.reportEndOfSessionWithErrors(error,-1);
......
......@@ -49,8 +49,8 @@ ReportPackerInterface<detail::Recall>(tg,lc),
RecallReportPacker::~RecallReportPacker(){
}
void RecallReportPacker::reportCompletedJob(const tapegateway::FileToRecallStruct& recalledFile){
std::auto_ptr<Report> rep(new ReportSuccessful(recalledFile));
void RecallReportPacker::reportCompletedJob(const tapegateway::FileToRecallStruct& recalledFile,unsigned long checksum){
std::auto_ptr<Report> rep(new ReportSuccessful(recalledFile,checksum));
castor::tape::threading::MutexLocker ml(&m_producterProtection);
m_fifo.push(rep.release());
}
......@@ -82,7 +82,10 @@ void RecallReportPacker::ReportSuccessful::execute(RecallReportPacker& _this){
successRecall->setId(m_migratedFile.id());
successRecall->setNshost(m_migratedFile.nshost());
successRecall->setFileid(m_migratedFile.fileid());
successRecall->setChecksum(m_checksum);
//WARNING : ad hoc name of checksum algorithm
successRecall->setChecksumName("adler32");
_this.m_listReports->addSuccessfulRecalls(successRecall.release());
}
......
......@@ -46,7 +46,8 @@ public:
* of migratedFile
* @param migratedFile the file successfully migrated
*/
void reportCompletedJob(const tapegateway::FileToRecallStruct& recalledFile);
void reportCompletedJob(const tapegateway::FileToRecallStruct& recalledFile,
unsigned long checksum);
/**
* Create into the MigrationReportPacker a report for the failled migration
......@@ -81,9 +82,10 @@ private:
};
class ReportSuccessful : public Report {
const FileStruct m_migratedFile;
unsigned long m_checksum;
public:
ReportSuccessful(const FileStruct& file):
Report(false),m_migratedFile(file){}
ReportSuccessful(const FileStruct& file,unsigned long checksum):
Report(false),m_migratedFile(file),m_checksum(checksum){}
virtual void execute(RecallReportPacker& _this);
};
class ReportError : public Report {
......
......@@ -40,8 +40,8 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerNominal) {
rrp.startThreads();
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportEndOfSession();
rrp.waitThread();
......@@ -62,9 +62,9 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerCumulated) {
rrp.startThreads();
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportEndOfSession();
rrp.waitThread();
......@@ -88,9 +88,9 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerBadBadEnd) {
rrp.startThreads();
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportFailedJob(recalledFiled,error_msg,error_code);
rrp.reportEndOfSessionWithErrors(error_msg,error_code);
rrp.waitThread();
......@@ -118,9 +118,9 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerBadGoodEnd) {
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportFailedJob(recalledFiled,error_msg,-1);
rrp.reportEndOfSession();
rrp.waitThread();
......@@ -147,8 +147,8 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerGoodBadEnd) {
rrp.startThreads();
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportEndOfSessionWithErrors(error_msg,error_code);
rrp.waitThread();
......@@ -175,8 +175,8 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerFaillure) {
rrp.startThreads();
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportCompletedJob(recalledFiled,0);
rrp.reportEndOfSessionWithErrors(error_msg,error_code);
rrp.waitThread();
......
......@@ -82,7 +82,7 @@ public:
* of migratedFile
* @param migratedFile the file successfully migrated
*/
virtual void reportCompletedJob(const FileStruct&) =0;
virtual void reportCompletedJob(const FileStruct&,unsigned long checksum) =0;
/**
* Create into the MigrationReportPacker a report for the failled migration
......
......@@ -30,7 +30,7 @@
#include "castor/tape/tapeserver/utils/suppressUnusedVariable.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
namespace {
namespace {
unsigned long initAdler32Checksum() {
return adler32(0L,Z_NULL,0);
}
......@@ -97,7 +97,7 @@ namespace daemon {
mb->m_payload.write(*output);
++blockId;
}
reportPacker.reportCompletedJob(*m_fileToMigrate);
reportPacker.reportCompletedJob(*m_fileToMigrate,ckSum);
}
catch(const castor::tape::Exception& e){
//we can end up there because
......
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