TapeReadSingleThread.hpp 5.51 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

20
#include "castor/tape/tapeserver/daemon/TapeSingleThreadInterface.hpp"
21
#include "common/threading/BlockingQueue.hpp"
22
#include "castor/tape/tapeserver/daemon/TapeReadTask.hpp"
23
#include "common/threading/Thread.hpp"
24
#include "castor/tape/tapeserver/drive/DriveInterface.hpp"
25
#include "castor/tape/tapeserver/file/File.hpp"
26
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
27
#include "castor/tape/tapeserver/daemon/RecallTaskInjector.hpp"
28
#include "castor/tape/tapeserver/daemon/TapeServerReporter.hpp"
29
#include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp"
30
#include "castor/tape/tapeserver/daemon/VolumeInfo.hpp"
Victor Kotlyar's avatar
Victor Kotlyar committed
31
#include "common/Timer.hpp"
32
33
34
35
36

#include <iostream>
#include <memory>
#include <stdio.h>

37
38
39
40
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
41
42

//forward declaration
43
class TapeServerReporter;
44

45
46
47
48
  /**
   * This class will execute the different tape read tasks.
   * 
   */
49
class TapeReadSingleThread : public TapeSingleThreadInterface<TapeReadTask>{
50
public:
51
  /**
52
   * Constructor:
53
   */
54
  TapeReadSingleThread(castor::tape::tapeserver::drive::DriveInterface & drive,
55
          cta::mediachanger::MediaChangerFacade &mc,
56
          TapeServerReporter & initialProcess,
57
          const VolumeInfo& volInfo, 
58
          uint64_t maxFilesRequest,
59
          cta::server::ProcessCap &capUtils,
60
          RecallWatchDog& watchdog,
Victor Kotlyar's avatar
Victor Kotlyar committed
61
          cta::log::LogContext & lc,
62
          RecallReportPacker &rrp,
63
          const bool useLbp,
64
          const bool useRAO,
65
          const std::string & externalEncryptionKeyScript,
66
67
          const cta::RetrieveMount &retrieveMount,
          const uint32_t tapeLoadTimeout);
68
   
69
70
71
72
73
74
75
76
  /**
   * Set the task injector. Has to be done that way (and not in the constructor)
   *  because there is a dependency
   * @param ti the task injector
   */
  void setTaskInjector(RecallTaskInjector * ti) {
    m_taskInjector = ti;
  }
77

78
79
80
81
82
private:  
  
  /**
   * Returns the string representation of the specified mount type
   */
83
  const char *mountTypeToString(const cta::common::dataStructures::MountType mountType) const
84
85
    throw();
  
86
  //RAII class for cleaning tape stuff
87
88
  class TapeCleaning{
    TapeReadSingleThread& m_this;
89
    // As we are living in the single thread of tape, we can borrow the timer
Victor Kotlyar's avatar
Victor Kotlyar committed
90
    cta::utils::Timer & m_timer;
91
  public:
Victor Kotlyar's avatar
Victor Kotlyar committed
92
    TapeCleaning(TapeReadSingleThread& parent, cta::utils::Timer & timer):
93
      m_this(parent), m_timer(timer){}
94
    ~TapeCleaning();
95
  };
96
  /**
97
   * Pop a task from its tasks and if there is not enough tasks left, it will 
98
99
100
   * ask the task injector for more 
   * @return m_tasks.pop();
   */
101
  TapeReadTask * popAndRequestMoreJobs();
102
103
104
    
    /**
     * Try to open an tapeFile::ReadSession, if it fails, we got an exception.
105
106
     * Return an std::unique_ptr will ensure the callee will have the ownershipe 
     * of the object through unique_ptr's copy constructor
107
108
     * @return 
     */
109
  std::unique_ptr<castor::tape::tapeFile::ReadSession> openReadSession();
110

111
112
113
  /**
   * This function is from Thread, it is the function that will do all the job
   */
114
  virtual void run();
115
116
117
118
119
120
121

  /**
   * Log msg with the given level, Session time is the time taken by the action 
   * @param level
   * @param msg
   * @param sessionTime
   */
122
  void logWithStat(int level,const std::string& msg,
Victor Kotlyar's avatar
Victor Kotlyar committed
123
    cta::log::ScopedParamContainer& params);
124
  
125
126
127
128
129
  /**
   * Number of files a single request to the client might give us.
   * Used in the loop-back function to ask the task injector to request more job
   */
  const uint64_t m_maxFilesRequest;
130
  
131
  ///a pointer to task injector, thus we can ask him for more tasks
132
  castor::tape::tapeserver::daemon::RecallTaskInjector * m_taskInjector;
133
  
134
  /// Reference to the watchdog, used in run()
135
  RecallWatchDog& m_watchdog;
136
  
137
138
139
  /// Reference to the RecallReportPacker, used to update tape/drive state during recall
  RecallReportPacker & m_rrp;
  
140
141
142
143
144
145
  /**
   * The boolean variable describing to use on not to use Logical
   * Block Protection.
   */
  const bool m_useLbp;

146
147
148
149
150
  /**
   * The boolean variable describing to use on not to use Recommended
   * Access Order
   */
  bool m_useRAO;
151
152
153
154
155
156
157
  
  /**
   * The retrieve mount object to get the VO, the tape pool and the density of the tape
   * on which we are reading
   */
  const cta::RetrieveMount& m_retrieveMount;
  
158
159
160
161
  /// Helper virtual function to access the watchdog from parent class
  virtual void countTapeLogError(const std::string & error) { 
    m_watchdog.addToErrorCount(error);
  }
162
  
163
164
165
166
167
protected:
  /**
   * Logs SCSI metrics for read session.
   */
  virtual void logSCSIMetrics();
168
169
170
171
172
173
}; // class TapeReadSingleThread

} // namespace daemon
} // namespace tapeserver
} // namespace tape
} // namespace castor