DiskWriteTask.hpp 4.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/******************************************************************************
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * 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 2
 * of the License, or (at your option) any later version.
 * 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.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/

#pragma once

David COME's avatar
David COME committed
26
#include "castor/tape/tapeserver/daemon/DataPipeline.hpp"
27
#include "castor/tape/tapeserver/daemon/RecallMemoryManager.hpp"
28
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
29
#include "castor/tape/tapeserver/file/File.hpp"
30
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
31
#include "castor/tape/tapeserver/daemon/DiskStats.hpp"
32
#include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp"
33

34
#include <memory>
35

David COME's avatar
David COME committed
36
37
38
39
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
40
  class MemBlock;
41
/**
42
43
44
 * 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?).
45
 */
46
class DiskWriteTask: public DataConsumer {
47
public:
48
49
  /**
   * Constructor
50
   * @param file: All we need to know about the file we  are recalling
51
52
   * @param mm: memory manager of the session
   */
53
54
  DiskWriteTask(cta::RetrieveJob *retrieveJob, RecallMemoryManager& mm);
  
55
  /**
56
   * Main routine: takes each memory block in the fifo and writes it to disk
57
   * @return true if the file has been successfully written false otherwise.
58
   */
Victor Kotlyar's avatar
Victor Kotlyar committed
59
  virtual bool execute(RecallReportPacker& reporter,cta::log::LogContext&  lc,
60
    cta::disk::DiskFileFactory & fileFactory, RecallWatchDog & watchdog,
61
    const int threadID);
62
63
  
  /**
64
   * Allows client code to return a reusable memory block. Should not been called
65
66
   * @return the pointer to the memory block that can be reused
   */
67
  virtual MemBlock *getFreeBlock() ;
68
69
70
71
72
  
  /**
   * Function used to enqueue a new memory block holding data to be written to disk
   * @param mb: corresponding memory block
   */
73
  virtual void pushDataBlock(MemBlock *mb);
74

75
76
77
  /**
   * Destructor (also waiting for the end of the write operation)
   */
78
  virtual ~DiskWriteTask();
79
  
80
81
82
83
84
85
  /**
   * Return the stats of the tasks. Should be call after execute 
   * (otherwise, it is pointless)
   * @return 
   */
  const DiskStats getTaskStats() const;
86
private:
87
88
89
90
91
92
  
  /**
   * Stats to measue how long it takes to write on disk
   */
  DiskStats m_stats;
  
93
94
95
96
97
98
99
  /**
   * 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
100
  void checkErrors(MemBlock* mb,int blockId,cta::log::LogContext&  lc);
101
  
102
103
104
105
  /**
   * 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
   */
106
  void releaseAllBlock();
107
  
108
  /**
109
   * The fifo containing the memory blocks holding data to be written to disk
110
   */
111
  cta::threading::BlockingQueue<MemBlock *> m_fifo;
112
  
113
114
115
  /** 
   * All we need to know about the file we are currently recalling
   */
116
  std::unique_ptr<cta::RetrieveJob> m_retrieveJob;
117
    
118
  /**
119
   * Reference to the Memory Manager in use
120
   */
121
  RecallMemoryManager & m_memManager;
122
123
  
  /**
124
   * Mutex forcing serial access to the fifo
125
   */
126
  cta::threading::Mutex m_producerProtection;
127
  
128
129
130
131
132
133
  /**
   * 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
134
  void logWithStat(int level,const std::string& msg,cta::log::LogContext&  lc) ;
135
};
David COME's avatar
David COME committed
136
137

}}}}