DiskWriteTask.hpp 3.73 KB
Newer Older
1
/******************************************************************************
2
 *                      DiskWriteFileTask.hpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * 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

27
#include "castor/tape/tapeserver/daemon/DiskWriteTaskInterface.hpp"
28
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
29
#include "castor/tape/tapeserver/daemon/RecallMemoryManager.hpp"
30
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
31
#include "castor/tape/tapeserver/file/File.hpp"
32
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
33
34
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"

35
#include <memory>
36
37
namespace {
  
38
  // TODO: merge with same function in File.hpp and move to tape/utils
39
40
41
42
  uint32_t blockID(const castor::tape::tapegateway::FileToRecallStruct& ftr)
  {
    return (ftr.blockId0() << 24) | (ftr.blockId1() << 16) |  (ftr.blockId2() << 8) | ftr.blockId3();
  }
43
 
44
}
David COME's avatar
David COME committed
45
46
47
48
49
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
50
/**
51
52
53
 * 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?).
54
 */
David COME's avatar
David COME committed
55
class DiskWriteTask: public DiskWriteTaskInterface, public DataConsumer {
56
public:
57
58
  /**
   * Constructor
59
   * @param file: All we need to know about the file we  are recalling
60
61
   * @param mm: memory manager of the session
   */
62
  DiskWriteTask(tape::tapegateway::FileToRecallStruct* file,RecallMemoryManager& mm);
63
  /**
64
   * Main routine: takes each memory block in the fifo and writes it to disk
65
   * @return true if the file has been successfully written false otherwise.
66
   */
67
  virtual bool execute(ReportPackerInterface<detail::Recall>& reporter,log::LogContext& lc) ;
68
69
  
  /**
70
   * Allows client code to return a reusable memory block. Should not been called
71
72
   * @return the pointer to the memory block that can be reused
   */
73
  virtual MemBlock *getFreeBlock() ;
74
75
76
77
78
  
  /**
   * Function used to enqueue a new memory block holding data to be written to disk
   * @param mb: corresponding memory block
   */
79
  virtual void pushDataBlock(MemBlock *mb);
80

81
82
83
  /**
   * Destructor (also waiting for the end of the write operation)
   */
84
  virtual ~DiskWriteTask();
85
86
  
private:
87

88
  void releaseAllBlock();
89
  /**
90
   * The fifo containing the memory blocks holding data to be written to disk
91
   */
92
  castor::tape::threading::BlockingQueue<MemBlock *> m_fifo;
93
94
95
  /** 
   * All we need to know about the file we are currently recalling
   */
96
  std::auto_ptr<tape::tapegateway::FileToRecallStruct> m_recallingFile;
97
    
98
  /**
99
   * Reference to the Memory Manager in use
100
   */
101
  RecallMemoryManager & m_memManager;
102
103
  
  /**
104
   * Mutex forcing serial access to the fifo
105
   */
106
  castor::tape::threading::Mutex m_producerProtection;
107
  
108
};
David COME's avatar
David COME committed
109
110

}}}}