xrootd
XrdFileCacheInfo.hh
Go to the documentation of this file.
1 #ifndef __XRDFILECACHE_INFO_HH__
2 #define __XRDFILECACHE_INFO_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 <stdio.h>
22 #include <time.h>
23 #include <assert.h>
24 
25 #include "XrdSys/XrdSysPthread.hh"
26 #include "XrdCl/XrdClLog.hh"
27 #include "XrdCl/XrdClConstants.hh"
28 #include "XrdCl/XrdClDefaultEnv.hh"
29 
30 class XrdOssDF;
31 
32 namespace XrdCl
33 {
34  class Log;
35 }
36 
37 namespace XrdFileCache
38 {
39  class Stats;
40 
41  //----------------------------------------------------------------------------
43  //----------------------------------------------------------------------------
44  class Info
45  {
46  private:
47  static unsigned char cfiBIT(int n) { return 1 << n; }
48 
49  public:
50  // !Access statistics
51  struct AStat
52  {
53  time_t DetachTime;
54  long long BytesDisk;
55  long long BytesRam;
56  long long BytesMissed;
57  };
58 
59  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  Info(long long bufferSize);
63 
64  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
67  ~Info();
68 
69  //---------------------------------------------------------------------
73  //---------------------------------------------------------------------
74  void SetBitFetched(int i);
75 
79  //---------------------------------------------------------------------
80  void SetBitWriteCalled(int i);
81 
82  //---------------------------------------------------------------------
86  //---------------------------------------------------------------------
87  void ResizeBits(int n);
88 
89  //---------------------------------------------------------------------
95  //---------------------------------------------------------------------
96  int Read(XrdOssDF* fp);
97 
98  //---------------------------------------------------------------------
100  //---------------------------------------------------------------------
101  void WriteHeader(XrdOssDF* fp);
102 
103  //---------------------------------------------------------------------
105  //---------------------------------------------------------------------
106  void AppendIOStat(AStat& stat, XrdOssDF* fp);
107 
108  //---------------------------------------------------------------------
110  //---------------------------------------------------------------------
111  bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const;
112 
113  //---------------------------------------------------------------------
115  //---------------------------------------------------------------------
116  int GetSizeInBytes() const;
117 
118  //---------------------------------------------------------------------
120  //---------------------------------------------------------------------
121  int GetSizeInBits() const;
122 
123  //----------------------------------------------------------------------
125  //----------------------------------------------------------------------
126  int GetHeaderSize() const;
127 
128  //---------------------------------------------------------------------
130  //---------------------------------------------------------------------
131  bool GetLatestDetachTime(time_t& t, XrdOssDF* fp) const;
132 
133  //---------------------------------------------------------------------
135  //---------------------------------------------------------------------
136  long long GetBufferSize() const;
137 
138  //---------------------------------------------------------------------
140  //---------------------------------------------------------------------
141  bool TestBit(int i) const;
142 
143  //---------------------------------------------------------------------
145  //---------------------------------------------------------------------
146  bool IsComplete() const;
147 
148  //---------------------------------------------------------------------
150  //---------------------------------------------------------------------
151  int GetNDownloadedBlocks() const;
152 
153  //---------------------------------------------------------------------
155  //---------------------------------------------------------------------
156  long long GetNDownloadedBytes() const;
157 
158  //---------------------------------------------------------------------
160  //---------------------------------------------------------------------
161  void CheckComplete();
162 
163  //---------------------------------------------------------------------
165  //---------------------------------------------------------------------
166  int GetAccessCnt() { return m_accessCnt; }
167 
168  //---------------------------------------------------------------------
170  //---------------------------------------------------------------------
171  int GetVersion() { return m_version; }
172 
173 
174  const static char* m_infoExtension;
175 
176  protected:
177 
178  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
179 
180  //---------------------------------------------------------------------
182  //---------------------------------------------------------------------
183 
184  int m_version;
185  long long m_bufferSize;
187  unsigned char *m_buff_fetched;
188  unsigned char *m_buff_write_called;
190  bool m_complete;
191  };
192 
193  inline bool Info::TestBit(int i) const
194  {
195  int cn = i/8;
196  assert(cn < GetSizeInBytes());
197 
198  int off = i - cn*8;
199  return (m_buff_fetched[cn] & cfiBIT(off)) == cfiBIT(off);
200  }
201 
202 
203  inline int Info::GetNDownloadedBlocks() const
204  {
205  int cntd = 0;
206  for (int i = 0; i < m_sizeInBits; ++i)
207  if (TestBit(i)) cntd++;
208 
209  return cntd;
210  }
211 
212  inline long long Info::GetNDownloadedBytes() const
213  {
215  }
216 
217  inline int Info::GetSizeInBytes() const
218  {
219  return ((m_sizeInBits -1)/8 + 1);
220  }
221 
222  inline int Info::GetSizeInBits() const
223  {
224  return m_sizeInBits;
225  }
226 
227  inline bool Info::IsComplete() const
228  {
229  return m_complete;
230  }
231 
232  inline bool Info::IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
233  {
234  for (int i = firstIdx; i <= lastIdx; ++i)
235  if (!TestBit(i)) return true;
236 
237  return false;
238  }
239 
240  inline void Info::CheckComplete()
241  {
243  }
244 
245  inline void Info::SetBitWriteCalled(int i)
246  {
247  int cn = i/8;
248  assert(cn < GetSizeInBytes());
249 
250  int off = i - cn*8;
251  m_buff_write_called[cn] |= cfiBIT(off);
252  }
253 
254  inline void Info::SetBitFetched(int i)
255  {
256  int cn = i/8;
257  assert(cn < GetSizeInBytes());
258 
259  int off = i - cn*8;
260  m_buff_fetched[cn] |= cfiBIT(off);
261  }
262 
263  inline long long Info::GetBufferSize() const
264  {
265  return m_bufferSize;
266  }
267 }
268 #endif
bool GetLatestDetachTime(time_t &t, XrdOssDF *fp) const
Get latest detach time.
Definition: XrdFileCache.hh:30
int GetVersion()
Get version.
Definition: XrdFileCacheInfo.hh:171
static const char * m_infoExtension
Definition: XrdFileCacheInfo.hh:174
long long GetBufferSize() const
Get prefetch buffer size.
Definition: XrdFileCacheInfo.hh:263
long long GetNDownloadedBytes() const
Get number of downloaded bytes.
Definition: XrdFileCacheInfo.hh:212
int GetSizeInBits() const
Get number of blocks represented in download-state bit-vector.
Definition: XrdFileCacheInfo.hh:222
time_t DetachTime
Definition: XrdFileCacheInfo.hh:53
bool IsComplete() const
Get complete status.
Definition: XrdFileCacheInfo.hh:227
long long BytesDisk
close time
Definition: XrdFileCacheInfo.hh:54
Status of cached file. Can be read from and written into a binary file.
Definition: XrdFileCacheInfo.hh:44
void ResizeBits(int n)
Reserve buffer for fileSize/bufferSize bytes.
void AppendIOStat(AStat &stat, XrdOssDF *fp)
Append access time, and cache statistics.
int m_version
Cache statistics and time of access.
Definition: XrdFileCacheInfo.hh:184
static unsigned char cfiBIT(int n)
Definition: XrdFileCacheInfo.hh:47
static Log * GetLog()
Get default log.
unsigned char * m_buff_fetched
download state vector
Definition: XrdFileCacheInfo.hh:187
Info(long long bufferSize)
Constructor.
void CheckComplete()
Update complete status.
Definition: XrdFileCacheInfo.hh:240
unsigned char * m_buff_write_called
disk written state vector
Definition: XrdFileCacheInfo.hh:188
Definition: XrdFileCacheInfo.hh:51
bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
Check download status in given block range.
Definition: XrdFileCacheInfo.hh:232
int GetHeaderSize() const
Get header size.
Definition: XrdClEnv.hh:28
int Read(XrdOssDF *fp)
Rea load content from cinfo file into this object.
bool m_complete
cached
Definition: XrdFileCacheInfo.hh:190
int GetAccessCnt()
Get number of accesses.
Definition: XrdFileCacheInfo.hh:166
void SetBitWriteCalled(int i)
Mark block as disk written.
Definition: XrdFileCacheInfo.hh:245
int m_sizeInBits
number of file blocks
Definition: XrdFileCacheInfo.hh:186
int GetSizeInBytes() const
Get size of download-state bit-vector in bytes.
Definition: XrdFileCacheInfo.hh:217
long long BytesMissed
read from ram
Definition: XrdFileCacheInfo.hh:56
int GetNDownloadedBlocks() const
Get number of downloaded blocks.
Definition: XrdFileCacheInfo.hh:203
Definition: XrdOss.hh:59
long long BytesRam
read from disk
Definition: XrdFileCacheInfo.hh:55
XrdCl::Log * clLog() const
Definition: XrdFileCacheInfo.hh:178
~Info()
Destructor.
void WriteHeader(XrdOssDF *fp)
Write number of blocks and prefetch buffer size.
void SetBitFetched(int i)
Mark block as downloaded.
Definition: XrdFileCacheInfo.hh:254
long long m_bufferSize
prefetch buffer size
Definition: XrdFileCacheInfo.hh:185
bool TestBit(int i) const
Test if block at the given index is downlaoded.
Definition: XrdFileCacheInfo.hh:193
int m_accessCnt
number of written AStat structs
Definition: XrdFileCacheInfo.hh:189