Commit 8babacb5 authored by David COME's avatar David COME
Browse files

(WIP) DiskReadTask execute is in progress

parent 839d5168
......@@ -27,6 +27,7 @@
#include "castor/tape/tapeserver/daemon/DiskReadTaskInterface.hpp"
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
#include "castor/tape/tapegateway/FileToMigrateStruct.hpp"
namespace castor {
namespace tape {
......@@ -35,23 +36,51 @@ namespace daemon {
class DiskReadTask :public DiskReadTaskInterface {
public:
DiskReadTask(DataConsumer & destination, int fileId, int nbBlocks): m_fileId(fileId),
m_nbBlocks(nbBlocks), m_fifo(destination) {}
DiskReadTask(DataConsumer & destination, tape::tapegateway::FileToMigrateStruct* file):
m_nextTask(destination),m_migratedFile(file) {}
virtual void execute() {
for (int blockId=0; blockId < m_nbBlocks; blockId++) {
MemBlock * mb = m_fifo.getFreeBlock();
mb->m_fileid = m_fileId;
mb->m_fileBlock = blockId;
//TODO fill mb. Somehow we need a disk
m_fifo.pushDataBlock(mb);
virtual void execute(log::LogContext& lc) {
size_t blockId=0;
size_t migratingFileSize=m_migratedFile->fileSize();
try{
tape::diskFile::ReadFile sourceFile(m_migratedFile->path());
while(migratingFileSize>0){
blockId++;
MemBlock * mb = m_nextTask.getFreeBlock();
mb->m_fileid = m_migratedFile->fileid();
//mb->m_fileBlock = blockId;
mb->m_payload.read(sourceFile);
migratingFileSize-= mb->m_payload.size();
//we either read at full capacity (ie size=capacity) or if there different,
//it should be the end => migratingFileSize should be 0. If it not, error
if(mb->m_payload.size() != mb->m_payload.capacity() && migratingFileSize>0){
throw castor::tape::Exception("Error while reading a file. Did not read at full capacity but the file is not fully read");
}
m_nextTask.pushDataBlock(mb);
} //end of while(migratingFileSize>0)
}
catch(const castor::tape::Exception& e){
//we have to pump block anyway, mark them failed and then pass them to TapeWrite
//Otherwise they would be stuck into TapeWriteTask free block fifo
using log::LogContext;
using log::Param;
LogContext::ScopedParam sp(lc, Param("blockID",blockId));
lc.log(LOG_ERR,e.getMessageValue());
while(migratingFileSize>0) {
MemBlock * mb = m_nextTask.getFreeBlock();
mb->m_failled=true;
m_nextTask.pushDataBlock(mb);
} //end of while
} //end of catch
}
private:
int m_fileId;
int m_nbBlocks;
DataConsumer & m_fifo;
//TW ; tape write
DataConsumer & m_nextTask;
std::auto_ptr<tape::tapegateway::FileToMigrateStruct> m_migratedFile;
};
}}}}
......
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