DiskReadTask.hpp 3.52 KB
Newer Older
1
2
/*
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        This program is free software: you can redistribute it and/or modify
 *                 it under the terms of the GNU General Public License as published by
 *                 the Free Software Foundation, either version 3 of the License, or
 *                 (at your option) any later version.
8
 *
9
10
11
12
 *                 This program is distributed in the hope that it will be useful,
 *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                 GNU General Public License for more details.
13
 *
14
15
16
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17
18
19

#pragma once

David COME's avatar
David COME committed
20
#include "castor/tape/tapeserver/daemon/DataPipeline.hpp"
21
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
22
#include "castor/tape/tapeserver/daemon/DiskStats.hpp"
23
#include "castor/tape/tapeserver/daemon/ErrorFlag.hpp"
24
#include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp"
25
#include "common/threading/AtomicFlag.hpp"
Victor Kotlyar's avatar
Victor Kotlyar committed
26
#include "common/log/LogContext.hpp"
27
#include "disk/DiskFile.hpp"
28

David COME's avatar
David COME committed
29
30
31
32
33
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
34
class DiskReadTask {
35
public:
36
37
38
39
40
  /**
   * @param destination The task that will consume data block we fill up
   * @param file the file we are migrating. We acquire the ownership of the pointer
   * @param numberOfBlock number of memory block we need read the whole file
   */
41
  DiskReadTask(DataConsumer & destination, 
42
          cta::ArchiveJob *archiveJob,size_t numberOfBlock,
43
          cta::threading::AtomicFlag& errorFlag);
44
  
45
  void execute(cta::log::LogContext&  lc, cta::disk::DiskFileFactory & fileFactory,
46
47
    MigrationWatchDog & watchdog, const int threadID);
  /**
48
49
50
51
52
   * Return the stats of the tasks. Should be call after execute 
   * (otherwise, it is pointless)
   * @return 
   */
  const DiskStats getTaskStats() const;
53
private:
54
55
56
57
58
59
60
61
62
  
  /**
   * Stats to measue how long it takes to write on disk
   */
  DiskStats m_stats;
  
  /**
   * Throws an exception if m_errorFlag is set
   */
63
  void checkMigrationFailing() const {
64
65
    //if a task has signaled an error, we stop our job
    if(m_errorFlag){
66
      throw  castor::tape::tapeserver::daemon::ErrorFlag();
67
68
    }
  }
69
  
70
  /**
71
72
73
74
75
   * log into lc all m_stats parameters with the given message at the 
   * given level
   * @param level
   * @param message
   */
Victor Kotlyar's avatar
Victor Kotlyar committed
76
  void logWithStat(int level,const std::string& msg, cta::log::LogContext&  lc) ;
77
  
78
79
80
81
82
  /**
   * Circulate the remaining free blocks after an error
   * @param fromBlockId the number of already processed
   * @param mb pointer to a possible already popped free block (NULL otherwise)
   */
83
  void circulateAllBlocks(size_t fromBlockId, MemBlock * mb);
84
85
86
  /**
   * The task (a TapeWriteTask) that will handle the read blocks
   */
87
  DataConsumer & m_nextTask;
88
89
90
91
  
  /**
   * All we need to know about the file we are migrating
   */
92
  cta::ArchiveJob *m_archiveJob;
93
  
94
95
96
97
98
99
100
101
102
103
  /**
   * Information about the archive job we will cache as it is needed
   * after the archive job is going to be potentially deleted by the 
   * writer
   */
  struct {
    std::string remotePath;
    uint64_t fileId;
  } m_archiveJobCachedInfo;
  
104
105
106
  /**
   * The number of memory block we will need to read the whole file
   */
107
  size_t m_numberOfBlock;
108
  
109
  cta::threading::AtomicFlag& m_errorFlag;
110
};
David COME's avatar
David COME committed
111
112

}}}}
113