xrootd
XrdFileCachePrefetch.hh
Go to the documentation of this file.
1 #ifndef __XRDFILECACHE_PREFETCH_HH__
2 #define __XRDFILECACHE_PREFETCH_HH__
3 //----------------------------------------------------------------------------------
4 // Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
5 // Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
6 //----------------------------------------------------------------------------------
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //----------------------------------------------------------------------------------
20 
21 #include <string>
22 #include <queue>
23 
24 #include "XrdCl/XrdClDefaultEnv.hh"
25 
26 #include "XrdFileCacheInfo.hh"
27 #include "XrdFileCacheStats.hh"
28 
29 class XrdOucIOVec;
30 namespace XrdCl
31 {
32  class Log;
33 }
34 
35 namespace XrdFileCache
36 {
37  //----------------------------------------------------------------------------
39  //----------------------------------------------------------------------------
40  class Prefetch
41  {
42  friend class IOEntireFile;
43  friend class IOFileBlock;
45 
46  struct Task;
47  public:
48  //------------------------------------------------------------------------
50  //------------------------------------------------------------------------
51  Prefetch(XrdOucCacheIO& inputFile, std::string& path,
52  long long offset, long long fileSize);
53 
54  //------------------------------------------------------------------------
56  //------------------------------------------------------------------------
57  ~Prefetch();
58 
59  //---------------------------------------------------------------------
61  //---------------------------------------------------------------------
62  void Run();
63 
64  //----------------------------------------------------------------------
66  //----------------------------------------------------------------------
67  Stats& GetStats() { return m_stats; }
68 
69  //----------------------------------------------------------------------
71  //----------------------------------------------------------------------
72  void WriteBlockToDisk(int ramIdx, size_t size);
73 
74  //----------------------------------------------------------------------
76  //----------------------------------------------------------------------
77  void DecRamBlockRefCount(int ramIdx);
78 
79  //----------------------------------------------------------------------
82  //----------------------------------------------------------------------
83  bool InitiateClose();
84 
85  protected:
87  ssize_t Read(char * buff, off_t offset, size_t size);
88 
90  int ReadV (const XrdOucIOVec *readV, int n);
91 
94 
95  private:
96  //----------------------------------------------------------------------
98  //----------------------------------------------------------------------
99  struct Task
100  {
102  size_t size;
104 
105  Task(): ramBlockIdx(-1), size(0), condVar(0) {}
106  Task(int r, size_t s, XrdSysCondVar *cv):
107  ramBlockIdx(r), size(s), condVar(cv) {}
108  ~Task() {}
109  };
110 
111  struct RAMBlock {
113  int refCount;
114  bool fromRead;
116  int readErrno;
117 
119  };
120 
121  struct RAM
122  {
124  char* m_buffer;
127 
128  RAM();
129  ~RAM();
130  };
131 
133  void CloseCleanly();
134 
136  Task* GetNextTask();
137 
139  bool Open();
140 
142  void RecordDownloadInfo();
143 
145  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
146 
148  ssize_t ReadInBlocks( char* buff, off_t offset, size_t size);
149 
152 
154  bool ReadFromTask(int bIdx, char* buff, long long off, size_t size);
155 
157  void DoTask(Task* task);
158 
160 
165 
166  std::string m_temp_filename;
167  long long m_offset;
168  long long m_fileSize;
169 
170  bool m_started;
171  bool m_failed;
172  bool m_stopping;
173  bool m_stopped;
175 
177 
178  std::deque<Task*> m_tasks_queue;
180 
182  };
183 }
184 #endif
int ReadV(const XrdOucIOVec *readV, int n)
Vector read from disk if block is already downloaded, else ReadV from client.
bool m_started
state of run thread
Definition: XrdFileCachePrefetch.hh:170
std::deque< Task * > m_tasks_queue
download queue
Definition: XrdFileCachePrefetch.hh:178
int m_numBlocks
number of in memory blocks
Definition: XrdFileCachePrefetch.hh:123
Downloads original file into multiple files, chunked into blocks. Only blocks that are asked for are ...
Definition: XrdFileCacheIOFileBlock.hh:39
Task * CreateTaskForFirstUndownloadedBlock()
Prefetch block.
Statistics of disk cache utilisation.
Definition: XrdFileCacheStats.hh:30
char * m_buffer
buffer m_numBlocks x size_of_block
Definition: XrdFileCachePrefetch.hh:124
XrdSysCondVar m_writeMutex
write mutex
Definition: XrdFileCachePrefetch.hh:126
Definition: XrdFileCachePrefetch.hh:121
long long m_fileSize
size of cached disk file for block-based operation
Definition: XrdFileCachePrefetch.hh:168
RAMBlock()
Definition: XrdFileCachePrefetch.hh:118
void DoTask(Task *task)
Read from client into in memory cache, queue ram buffer for disk write.
bool InitiateClose()
Initiate close. Return true if still IO active. Used in XrdPosixXrootd::Close()
Stats & GetStats()
Reference to prefetch statistics.
Definition: XrdFileCachePrefetch.hh:67
Definition: XrdOucCache.hh:158
A prefetching task – a file region that requires preferential treatment.
Definition: XrdFileCachePrefetch.hh:99
Definition: XrdFileCachePrefetch.hh:111
void AppendIOStatToFileInfo()
Write cache statistics in *cinfo file.
Definition: XrdFileCachePrefetch.hh:44
Definition: XrdFileCachePrefetch.hh:44
Status of cached file. Can be read from and written into a binary file.
Definition: XrdFileCacheInfo.hh:44
bool Open()
Open file handle for data file and info file on local disk.
XrdSysCondVar * condVar
signal when complete
Definition: XrdFileCachePrefetch.hh:103
void WriteBlockToDisk(int ramIdx, size_t size)
Write block to file on disk. Called from Cache.
size_t size
cached, used for the end file block
Definition: XrdFileCachePrefetch.hh:102
XrdSysCondVar m_stateCond
state condition variable
Definition: XrdFileCachePrefetch.hh:174
void Run()
Thread function for file prefetching.
Task * GetNextTask()
Get blocks to prefetch.
Downloads data into a file on local disk and handles IO read requests.
Definition: XrdFileCachePrefetch.hh:40
~Task()
Definition: XrdFileCachePrefetch.hh:108
Definition: XrdFileCachePrefetch.hh:44
static Log * GetLog()
Get default log.
Definition: XrdSysPthread.hh:140
Task(int r, size_t s, XrdSysCondVar *cv)
Definition: XrdFileCachePrefetch.hh:106
void RecordDownloadInfo()
Write download state into cinfo file.
Definition: XrdSysPthread.hh:53
bool m_stopping
run thread should be stopped
Definition: XrdFileCachePrefetch.hh:172
Definition: XrdOucIOVec.hh:40
XrdOucCacheIO & m_input
original data source
Definition: XrdFileCachePrefetch.hh:164
Downloads original file into a single file on local disk. Handles read requests as they come along...
Definition: XrdFileCacheIOEntireFile.hh:39
Task()
Definition: XrdFileCachePrefetch.hh:105
int refCount
read and write reference count
Definition: XrdFileCachePrefetch.hh:113
XrdSysMutex m_downloadStatusMutex
mutex locking access to m_cfi object
Definition: XrdFileCachePrefetch.hh:176
ssize_t ReadInBlocks(char *buff, off_t offset, size_t size)
Split read in blocks.
~Prefetch()
Destructor.
int ramBlockIdx
idx in the in-memory buffer
Definition: XrdFileCachePrefetch.hh:101
bool m_failed
reading from original source or writing to disk has failed
Definition: XrdFileCachePrefetch.hh:171
void DecRamBlockRefCount(int ramIdx)
Decrease block reference count.
XrdSysCondVar m_queueCond
m_tasks_queue condition variable
Definition: XrdFileCachePrefetch.hh:179
std::string m_temp_filename
filename of data file on disk
Definition: XrdFileCachePrefetch.hh:166
long long m_offset
offset of cached file for block-based operation
Definition: XrdFileCachePrefetch.hh:167
ReadRamState_t
Definition: XrdFileCachePrefetch.hh:44
Definition: XrdOss.hh:59
int readErrno
posix error on read fail
Definition: XrdFileCachePrefetch.hh:116
ssize_t Read(char *buff, off_t offset, size_t size)
Read from disk, RAM, task, or client.
bool m_stopped
prefetch is stopped
Definition: XrdFileCachePrefetch.hh:173
int fileBlockIdx
offset in output file
Definition: XrdFileCachePrefetch.hh:112
Stats m_stats
cache statistics, used in IO detach
Definition: XrdFileCachePrefetch.hh:181
bool ReadFromTask(int bIdx, char *buff, long long off, size_t size)
Create task from read request and wait its completed.
XrdOssDF * m_infoFile
file handle for data-info file on disk
Definition: XrdFileCachePrefetch.hh:162
RAM m_ram
in memory cache
Definition: XrdFileCachePrefetch.hh:159
bool fromRead
is ram requested from prefetch or read
Definition: XrdFileCachePrefetch.hh:114
XrdOssDF * m_output
file handle for data file on disk
Definition: XrdFileCachePrefetch.hh:161
void CloseCleanly()
Stop Run thread.
ReadRamState_t status
read from client status
Definition: XrdFileCachePrefetch.hh:115
XrdCl::Log * clLog() const
Short log alias.
Definition: XrdFileCachePrefetch.hh:145
Info m_cfi
download status of file blocks and access statistics
Definition: XrdFileCachePrefetch.hh:163
Prefetch(XrdOucCacheIO &inputFile, std::string &path, long long offset, long long fileSize)
Constructor.
RAMBlock * m_blockStates
referenced structure
Definition: XrdFileCachePrefetch.hh:125