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  //------------------------------------------------------------------------
52  //------------------------------------------------------------------------
53  Info();
54 
55  //------------------------------------------------------------------------
57  //------------------------------------------------------------------------
58  ~Info();
59 
60  //---------------------------------------------------------------------
64  //---------------------------------------------------------------------
65  void SetBit(int i);
66 
67  //---------------------------------------------------------------------
71  //---------------------------------------------------------------------
72  void ResizeBits(int n);
73 
74  //---------------------------------------------------------------------
80  //---------------------------------------------------------------------
81  int Read(XrdOssDF* fp);
82 
83  //---------------------------------------------------------------------
85  //---------------------------------------------------------------------
86  void WriteHeader(XrdOssDF* fp);
87 
88  //---------------------------------------------------------------------
90  //---------------------------------------------------------------------
91  void AppendIOStat(const Stats* stat, XrdOssDF* fp);
92 
93  //---------------------------------------------------------------------
95  //---------------------------------------------------------------------
96  bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const;
97 
98  //---------------------------------------------------------------------
100  //---------------------------------------------------------------------
101  int GetSizeInBytes() const;
102 
103  //---------------------------------------------------------------------
105  //---------------------------------------------------------------------
106  int GetSizeInBits() const;
107 
108  //----------------------------------------------------------------------
110  //----------------------------------------------------------------------
111  int GetHeaderSize() const;
112 
113  //---------------------------------------------------------------------
115  //---------------------------------------------------------------------
116  bool GetLatestDetachTime(time_t& t, XrdOssDF* fp) const;
117 
118  //---------------------------------------------------------------------
120  //---------------------------------------------------------------------
121  long long GetBufferSize() const;
122 
123  //---------------------------------------------------------------------
125  //---------------------------------------------------------------------
126  bool TestBit(int i) const;
127 
128  //---------------------------------------------------------------------
130  //---------------------------------------------------------------------
131  bool IsComplete() const;
132 
133  //---------------------------------------------------------------------
135  //---------------------------------------------------------------------
136  void CheckComplete();
137 
138  const static char* m_infoExtension;
139 
140  private:
141 
142  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
143 
144  //---------------------------------------------------------------------
146  //---------------------------------------------------------------------
147  struct AStat
148  {
149  time_t DetachTime;
150  long long BytesDisk;
151  long long BytesRam;
152  long long BytesMissed;
153  };
154 
155  int m_version;
156  long long m_bufferSize;
158  unsigned char *m_buff;
160  bool m_complete;
161  };
162 
163  inline bool Info::TestBit(int i) const
164  {
165  int cn = i/8;
166  assert(cn < GetSizeInBytes());
167 
168  int off = i - cn*8;
169  return (m_buff[cn] & cfiBIT(off)) == cfiBIT(off);
170  }
171 
172  inline int Info::GetSizeInBytes() const
173  {
174  return ((m_sizeInBits -1)/8 + 1);
175  }
176 
177  inline int Info::GetSizeInBits() const
178  {
179  return m_sizeInBits;
180  }
181 
182  inline bool Info::IsComplete() const
183  {
184  return m_complete;
185  }
186 
187  inline bool Info::IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
188  {
189  for (int i = firstIdx; i <= lastIdx; ++i)
190  if (!TestBit(i)) return true;
191 
192  return false;
193  }
194 
195  inline void Info::CheckComplete()
196  {
198  }
199 
200  inline void Info::SetBit(int i)
201  {
202  int cn = i/8;
203  assert(cn < GetSizeInBytes());
204 
205  int off = i - cn*8;
206  m_buff[cn] |= cfiBIT(off);
207  }
208 
209  inline long long Info::GetBufferSize() const
210  {
211  return m_bufferSize;
212  }
213 }
214 #endif
bool GetLatestDetachTime(time_t &t, XrdOssDF *fp) const
Get latest detach time.
Statistics of disk cache utilisation.
Definition: XrdFileCacheStats.hh:30
Definition: XrdFileCache.hh:30
static const char * m_infoExtension
Definition: XrdFileCacheInfo.hh:138
long long GetBufferSize() const
Get prefetch buffer size.
Definition: XrdFileCacheInfo.hh:209
int GetSizeInBits() const
Get number of blocks represented in download-state bit-vector.
Definition: XrdFileCacheInfo.hh:177
time_t DetachTime
Definition: XrdFileCacheInfo.hh:149
bool IsComplete() const
Get complete status.
Definition: XrdFileCacheInfo.hh:182
long long BytesDisk
Definition: XrdFileCacheInfo.hh:150
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.
int m_version
info version
Definition: XrdFileCacheInfo.hh:155
void SetBit(int i)
Mark block as downloaded.
Definition: XrdFileCacheInfo.hh:200
Info()
Constructor.
static unsigned char cfiBIT(int n)
Definition: XrdFileCacheInfo.hh:47
void AppendIOStat(const Stats *stat, XrdOssDF *fp)
Append access time, and cache statistics.
static Log * GetLog()
Get default log.
void CheckComplete()
Update complete status.
Definition: XrdFileCacheInfo.hh:195
Cache statistics and time of access.
Definition: XrdFileCacheInfo.hh:147
bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
Check download status in given block range.
Definition: XrdFileCacheInfo.hh:187
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:160
int m_sizeInBits
number of file blocks
Definition: XrdFileCacheInfo.hh:157
int GetSizeInBytes() const
Get size of download-state bit-vector in bytes.
Definition: XrdFileCacheInfo.hh:172
long long BytesMissed
Definition: XrdFileCacheInfo.hh:152
Definition: XrdOss.hh:59
long long BytesRam
Definition: XrdFileCacheInfo.hh:151
XrdCl::Log * clLog() const
Definition: XrdFileCacheInfo.hh:142
~Info()
Destructor.
void WriteHeader(XrdOssDF *fp)
Write number of blocks and prefetch buffer size.
long long m_bufferSize
prefetch buffer size
Definition: XrdFileCacheInfo.hh:156
bool TestBit(int i) const
Test if block at the given index is downlaoded.
Definition: XrdFileCacheInfo.hh:163
int m_accessCnt
number of written AStat structs
Definition: XrdFileCacheInfo.hh:159
unsigned char * m_buff
download state vector
Definition: XrdFileCacheInfo.hh:158