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