DiskWriteTask.hpp 4.22 KB
Newer Older
1
2
3
4
5
6
7
/*
 * @project        The CERN Tape Archive (CTA)
 * @copyright      Copyright(C) 2021 CERN
 * @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/RecallMemoryManager.hpp"
22
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
23
#include "castor/tape/tapeserver/file/File.hpp"
24
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
25
#include "castor/tape/tapeserver/daemon/DiskStats.hpp"
26
#include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp"
27

28
#include <memory>
29

David COME's avatar
David COME committed
30
31
32
33
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
34
  class MemBlock;
35
/**
36
37
38
 * The DiskWriteFileTask is responsible to write a single file onto disk as part of a recall
 * session. Being a consumer of memory blocks, it inherits from the DataConsumer class. It also
 * inherits several methods from the DiskWriteTask (TODO: do we really need this base class?).
39
 */
40
class DiskWriteTask: public DataConsumer {
41
public:
42
43
  /**
   * Constructor
44
   * @param file: All we need to know about the file we  are recalling
45
46
   * @param mm: memory manager of the session
   */
47
48
  DiskWriteTask(cta::RetrieveJob *retrieveJob, RecallMemoryManager& mm);
  
49
  /**
50
   * Main routine: takes each memory block in the fifo and writes it to disk
51
   * @return true if the file has been successfully written false otherwise.
52
   */
Victor Kotlyar's avatar
Victor Kotlyar committed
53
  virtual bool execute(RecallReportPacker& reporter,cta::log::LogContext&  lc,
54
    cta::disk::DiskFileFactory & fileFactory, RecallWatchDog & watchdog,
55
    const int threadID);
56
57
  
  /**
58
   * Allows client code to return a reusable memory block. Should not been called
59
60
   * @return the pointer to the memory block that can be reused
   */
61
  virtual MemBlock *getFreeBlock() ;
62
63
64
65
66
  
  /**
   * Function used to enqueue a new memory block holding data to be written to disk
   * @param mb: corresponding memory block
   */
67
  virtual void pushDataBlock(MemBlock *mb);
68

69
70
71
  /**
   * Destructor (also waiting for the end of the write operation)
   */
72
  virtual ~DiskWriteTask();
73
  
74
75
76
77
78
79
  /**
   * Return the stats of the tasks. Should be call after execute 
   * (otherwise, it is pointless)
   * @return 
   */
  const DiskStats getTaskStats() const;
80
private:
81
82
83
84
85
86
  
  /**
   * Stats to measue how long it takes to write on disk
   */
  DiskStats m_stats;
  
87
88
89
90
91
92
93
  /**
   * This function will check the consistency of the mem block and 
   * throw exception is something goes wrong
   * @param mb The mem block to check
   * @param blockId The block id the mem blopck should be at
   * @param lc FOr logging
   */
Victor Kotlyar's avatar
Victor Kotlyar committed
94
  void checkErrors(MemBlock* mb,int blockId,cta::log::LogContext&  lc);
95
  
96
97
98
99
  /**
   * In case of error, it will spin on the blocks until we reach the end
   * in order to push them back into the memory manager
   */
100
  void releaseAllBlock();
101
  
102
  /**
103
   * The fifo containing the memory blocks holding data to be written to disk
104
   */
105
  cta::threading::BlockingQueue<MemBlock *> m_fifo;
106
  
107
108
109
  /** 
   * All we need to know about the file we are currently recalling
   */
110
  std::unique_ptr<cta::RetrieveJob> m_retrieveJob;
111
    
112
  /**
113
   * Reference to the Memory Manager in use
114
   */
115
  RecallMemoryManager & m_memManager;
116
117
  
  /**
118
   * Mutex forcing serial access to the fifo
119
   */
120
  cta::threading::Mutex m_producerProtection;
121
  
122
123
124
125
126
127
  /**
   * 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
128
  void logWithStat(int level,const std::string& msg,cta::log::LogContext&  lc) ;
129
};
David COME's avatar
David COME committed
130
131

}}}}