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  void CheckComplete();
157 
158  //---------------------------------------------------------------------
160  //---------------------------------------------------------------------
161  int GetAccessCnt() { return m_accessCnt; }
162 
163  //---------------------------------------------------------------------
165  //---------------------------------------------------------------------
166  int GetVersion() { return m_version; }
167 
168 
169  const static char* m_infoExtension;
170 
171  protected:
172 
173  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
174 
175  //---------------------------------------------------------------------
177  //---------------------------------------------------------------------
178 
179  int m_version;
180  long long m_bufferSize;
182  unsigned char *m_buff_fetched;
183  unsigned char *m_buff_write_called;
185  bool m_complete;
186  };
187 
188  inline bool Info::TestBit(int i) const
189  {
190  int cn = i/8;
191  assert(cn < GetSizeInBytes());
192 
193  int off = i - cn*8;
194  return (m_buff_fetched[cn] & cfiBIT(off)) == cfiBIT(off);
195  }
196 
197 
198  inline int Info::GetNDownloadedBlocks() const
199  {
200  int cntd = 0;
201  for (int i = 0; i < m_sizeInBits; ++i)
202  if (TestBit(i)) cntd++;
203 
204  return cntd;
205  }
206 
207  inline int Info::GetSizeInBytes() const
208  {
209  return ((m_sizeInBits -1)/8 + 1);
210  }
211 
212  inline int Info::GetSizeInBits() const
213  {
214  return m_sizeInBits;
215  }
216 
217  inline bool Info::IsComplete() const
218  {
219  return m_complete;
220  }
221 
222  inline bool Info::IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
223  {
224  for (int i = firstIdx; i <= lastIdx; ++i)
225  if (!TestBit(i)) return true;
226 
227  return false;
228  }
229 
230  inline void Info::CheckComplete()
231  {
233  }
234 
235  inline void Info::SetBitWriteCalled(int i)
236  {
237  int cn = i/8;
238  assert(cn < GetSizeInBytes());
239 
240  int off = i - cn*8;
241  m_buff_write_called[cn] |= cfiBIT(off);
242  }
243 
244  inline void Info::SetBitFetched(int i)
245  {
246  int cn = i/8;
247  assert(cn < GetSizeInBytes());
248 
249  int off = i - cn*8;
250  m_buff_fetched[cn] |= cfiBIT(off);
251  }
252 
253  inline long long Info::GetBufferSize() const
254  {
255  return m_bufferSize;
256  }
257 }
258 #endif
bool GetLatestDetachTime(time_t &t, XrdOssDF *fp) const
Get latest detach time.
Definition: XrdFileCache.hh:30
int GetVersion()
Get version.
Definition: XrdFileCacheInfo.hh:166
static const char * m_infoExtension
Definition: XrdFileCacheInfo.hh:169
long long GetBufferSize() const
Get prefetch buffer size.
Definition: XrdFileCacheInfo.hh:253
int GetSizeInBits() const
Get number of blocks represented in download-state bit-vector.
Definition: XrdFileCacheInfo.hh:212
time_t DetachTime
Definition: XrdFileCacheInfo.hh:53
bool IsComplete() const
Get complete status.
Definition: XrdFileCacheInfo.hh:217
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:179
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:182
Info(long long bufferSize)
Constructor.
void CheckComplete()
Update complete status.
Definition: XrdFileCacheInfo.hh:230
unsigned char * m_buff_write_called
disk written state vector
Definition: XrdFileCacheInfo.hh:183
Definition: XrdFileCacheInfo.hh:51
bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
Check download status in given block range.
Definition: XrdFileCacheInfo.hh:222
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:185
int GetAccessCnt()
Get number of accesses.
Definition: XrdFileCacheInfo.hh:161
void SetBitWriteCalled(int i)
Mark block as disk written.
Definition: XrdFileCacheInfo.hh:235
int m_sizeInBits
number of file blocks
Definition: XrdFileCacheInfo.hh:181
int GetSizeInBytes() const
Get size of download-state bit-vector in bytes.
Definition: XrdFileCacheInfo.hh:207
long long BytesMissed
read from ram
Definition: XrdFileCacheInfo.hh:56
int GetNDownloadedBlocks() const
Get number of downloaded blocks.
Definition: XrdFileCacheInfo.hh:198
Definition: XrdOss.hh:59
long long BytesRam
read from disk
Definition: XrdFileCacheInfo.hh:55
XrdCl::Log * clLog() const
Definition: XrdFileCacheInfo.hh:173
~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:244
long long m_bufferSize
prefetch buffer size
Definition: XrdFileCacheInfo.hh:180
bool TestBit(int i) const
Test if block at the given index is downlaoded.
Definition: XrdFileCacheInfo.hh:188
int m_accessCnt
number of written AStat structs
Definition: XrdFileCacheInfo.hh:184