Commit 539e58a4 authored by David COME's avatar David COME
Browse files

Added an initial check on the error flag

in order to no even move the little finger if a previous task failed
Also added some comments
parent c3b96b49
......@@ -58,16 +58,19 @@ namespace daemon {
size_t blockId=0;
size_t migratingFileSize=m_migratedFile->fileSize();
try{
//we first check here to not even try to open the disk if a previous task has failed
//because the disk could the very reason why the previous one failed,
//so dont do the same mistake twice !
hasAnotherTaskTailed();
tape::diskFile::ReadFile sourceFile(m_migratedFile->path());
log::LogContext::ScopedParam sp(lc, log::Param("filePath",m_migratedFile->path()));
lc.log(LOG_INFO,"Opened file on disk for migration ");
while(migratingFileSize>0){
//if a task has signaled an error, we stop our job
if(m_errorFlag){
throw castor::tape::exceptions::ErrorFlag();
}
hasAnotherTaskTailed();
MemBlock* const mb = m_nextTask.getFreeBlock();
AutoPushBlock push(mb,m_nextTask);
......
......@@ -47,7 +47,12 @@ public:
virtual void execute(log::LogContext& lc);
private:
void hasAnotherTaskTailed() const {
//if a task has signaled an error, we stop our job
if(m_errorFlag){
throw castor::tape::exceptions::ErrorFlag();
}
}
void circulateAllBlocks(size_t fromBlockId);
/**
* The task (a TapeWriteTask) that will handle the read blocks
......
......@@ -63,16 +63,23 @@ namespace daemon {
unsigned long ckSum = Payload::zeroAdler32();
int blockId = 0;
try {
//we first check here to not even try to move the tape if a previous task has failed
//because the tape- could the very reason why the previous one failed,
//so dont do the same mistake twice !
hasAnotherTaskTailed();
//try to open the session
std::auto_ptr<castor::tape::tapeFile::WriteFile> output(openWriteFile(session,lc));
while(!m_fifo.finished()) {
if(m_errorFlag){
throw castor::tape::exceptions::ErrorFlag();
}
//if someone screw somewhere else, we stop
hasAnotherTaskTailed();
MemBlock* const mb = m_fifo.popDataBlock();
AutoReleaseBlock<MemoryManager> releaser(mb,m_memManager);
if(/*m_migratingFile->fileid() != static_cast<unsigned int>(mb->m_fileid)
* || */blockId != mb->m_fileBlock || mb->m_failed ){
if(m_fileToMigrate->fileid() != static_cast<unsigned int>(mb->m_fileid)
|| blockId != mb->m_fileBlock || mb->m_failed ){
LogContext::ScopedParam sp[]={
LogContext::ScopedParam(lc, Param("received_NSFILEID", mb->m_fileid)),
LogContext::ScopedParam(lc, Param("expected_NSFBLOCKId", blockId)),
......@@ -84,11 +91,13 @@ namespace daemon {
throw castor::tape::Exception("received a bad block for writing");
}
ckSum = mb->m_payload.adler32(ckSum);
mb->m_payload.write(*output);
++blockId;
}
//finish the writing of the file on tape
//put the trailer
output->close();
reportPacker.reportCompletedJob(*m_fileToMigrate,ckSum);
}
......@@ -99,11 +108,15 @@ namespace daemon {
circulateMemBlocks();
}
catch(const castor::tape::Exception& e){
m_errorFlag.set();
//we can end up there because
//we failed to open the WriteFile
//we received a bad block or a block written failed
//close failed
//close failed
//first set the error flag
m_errorFlag.set();
//log and circulate blocks
LogContext::ScopedParam sp(lc, Param("exceptionCode",e.code()));
LogContext::ScopedParam sp1(lc, Param("exceptionMessage", e.getMessageValue()));
lc.log(LOG_ERR,"Circulating blocks into TapeWriteTask::execute");
......
......@@ -84,7 +84,13 @@ public:
virtual ~TapeWriteTask();
private:
void hasAnotherTaskTailed() const {
//if a task has signaled an error, we stop our job
if(m_errorFlag){
throw castor::tape::exceptions::ErrorFlag();
}
}
void circulateMemBlocks();
/**
* Function in charge of opening the WriteFile for m_fileToMigrate
......
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