00001 #ifndef __XRDFILECACHE_INFO_HH__
00002 #define __XRDFILECACHE_INFO_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <time.h>
00023 #include <assert.h>
00024 #include <vector>
00025
00026 #include "XrdSys/XrdSysPthread.hh"
00027 #include "XrdCl/XrdClConstants.hh"
00028 #include "XrdCl/XrdClDefaultEnv.hh"
00029
00030 class XrdOssDF;
00031 class XrdCksCalc;
00032 class XrdSysTrace;
00033
00034
00035 namespace XrdCl
00036 {
00037 class Log;
00038 }
00039
00040 namespace XrdFileCache
00041 {
00042 class Stats;
00043
00044
00046
00047
00048 class Info
00049 {
00050 public:
00051
00052 struct AStat
00053 {
00054 time_t AttachTime;
00055 time_t DetachTime;
00056 long long BytesDisk;
00057 long long BytesRam;
00058 long long BytesMissed;
00059
00060 AStat() : AttachTime(0), DetachTime(0), BytesDisk(0), BytesRam(0), BytesMissed(0) {}
00061 };
00062
00063 struct Store {
00064 int m_version;
00065 long long m_bufferSize;
00066 long long m_fileSize;
00067 unsigned char *m_buff_synced;
00068 char m_cksum[16];
00069 time_t m_creationTime;
00070 size_t m_accessCnt;
00071 std::vector<AStat> m_astats;
00072
00073 Store () : m_version(1), m_bufferSize(-1), m_fileSize(0), m_buff_synced(0),m_creationTime(0), m_accessCnt(0) {}
00074 };
00075
00076
00077
00079
00080 Info(XrdSysTrace* trace, bool prefetchBuffer = false);
00081
00082
00084
00085 ~Info();
00086
00087
00091
00092 void SetBitWritten(int i);
00093
00094
00098
00099 void SetBitSynced(int i);
00100
00101
00103
00104 void SetAllBitsSynced();
00105
00106
00110
00111 void SetBitPrefetch(int i);
00112
00113 void SetBufferSize(long long);
00114
00115 void SetFileSize(long long);
00116
00117
00121
00122 void ResizeBits(int n);
00123
00124
00131
00132 bool Read(XrdOssDF* fp, const std::string &fname = "<unknown>");
00133
00134
00137
00138 bool Write(XrdOssDF* fp, const std::string &fname = "<unknown>");
00139
00140
00142
00143 void DisableDownloadStatus();
00144
00145
00147
00148 void WriteIOStatAttach();
00149
00151
00152 void WriteIOStat(Stats& s);
00153
00154
00156
00157 void WriteIOStatDetach(Stats& s);
00158
00159
00161
00162 void WriteIOStatSingle(long long bytes_disk);
00163
00164
00166
00167 void WriteIOStatSingle(long long bytes_disk, time_t att, time_t dtc);
00168
00169
00171
00172 bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const;
00173
00174
00176
00177 int GetSizeInBytes() const;
00178
00179
00181
00182 int GetSizeInBits() const;
00183
00184
00186
00187 long long GetFileSize() const;
00188
00189
00191
00192 bool GetLatestDetachTime(time_t& t) const;
00193
00194
00196
00197 long long GetBufferSize() const;
00198
00199
00201
00202 bool TestBit(int i) const;
00203
00204
00206
00207 bool TestPrefetchBit(int i) const;
00208
00209
00211
00212 bool IsComplete() const;
00213
00214
00216
00217 int GetNDownloadedBlocks() const;
00218
00219
00221
00222 long long GetNDownloadedBytes() const;
00223
00224
00226
00227 void UpdateDownloadCompleteStatus();
00228
00229
00231
00232 size_t GetAccessCnt() { return m_store.m_accessCnt; }
00233
00234
00236
00237 int GetVersion() { return m_store.m_version; }
00238
00239
00241
00242 const Store& RefStoredData() const { return m_store; }
00243
00244
00246
00247 void GetCksum( unsigned char* buff, char* digest);
00248
00249 const static char* m_infoExtension;
00250 const static char* m_traceID;
00251 const static int m_defaultVersion;
00252 const static size_t m_maxNumAccess;
00253
00254 XrdSysTrace* GetTrace() const {return m_trace; }
00255
00256 static size_t GetMaxNumAccess() { return m_maxNumAccess; }
00257
00258 protected:
00259 XrdSysTrace* m_trace;
00260
00261 Store m_store;
00262 bool m_hasPrefetchBuffer;
00263 unsigned char *m_buff_written;
00264 unsigned char *m_buff_prefetch;
00265
00266 int m_sizeInBits;
00267 bool m_complete;
00268
00269 private:
00270 inline unsigned char cfiBIT(int n) const { return 1 << n; }
00271
00272
00273 bool ReadV1(XrdOssDF* fp, const std::string &fname);
00274 XrdCksCalc* m_cksCalc;
00275 };
00276
00277
00278
00279 inline bool Info::TestBit(int i) const
00280 {
00281 const int cn = i/8;
00282 assert(cn < GetSizeInBytes());
00283
00284 const int off = i - cn*8;
00285 return (m_buff_written[cn] & cfiBIT(off)) == cfiBIT(off);
00286 }
00287
00288 inline bool Info::TestPrefetchBit(int i) const
00289 {
00290 if (!m_buff_prefetch) return false;
00291
00292 const int cn = i/8;
00293 assert(cn < GetSizeInBytes());
00294
00295 const int off = i - cn*8;
00296 return (m_buff_prefetch[cn] & cfiBIT(off)) == cfiBIT(off);
00297 }
00298
00299 inline int Info::GetNDownloadedBlocks() const
00300 {
00301 int cntd = 0;
00302 for (int i = 0; i < m_sizeInBits; ++i)
00303 if (TestBit(i)) cntd++;
00304
00305 return cntd;
00306 }
00307
00308 inline long long Info::GetNDownloadedBytes() const
00309 {
00310 return m_store.m_bufferSize * GetNDownloadedBlocks();
00311 }
00312
00313 inline int Info::GetSizeInBytes() const
00314 {
00315 if (m_sizeInBits)
00316 return ((m_sizeInBits - 1)/8 + 1);
00317 else
00318 return 0;
00319 }
00320
00321 inline int Info::GetSizeInBits() const
00322 {
00323 return m_sizeInBits;
00324 }
00325
00326 inline long long Info::GetFileSize() const
00327 {
00328 return m_store.m_fileSize;
00329 }
00330
00331 inline bool Info::IsComplete() const
00332 {
00333 return m_complete;
00334 }
00335
00336 inline bool Info::IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
00337 {
00338
00339
00340 for (int i = firstIdx; i < lastIdx; ++i)
00341 if (! TestBit(i)) return true;
00342
00343 return false;
00344 }
00345
00346 inline void Info::UpdateDownloadCompleteStatus()
00347 {
00348 m_complete = ! IsAnythingEmptyInRng(0, m_sizeInBits);
00349 }
00350
00351 inline void Info::SetBitSynced(int i)
00352 {
00353 const int cn = i/8;
00354 assert(cn < GetSizeInBytes());
00355
00356 const int off = i - cn*8;
00357 m_store.m_buff_synced[cn] |= cfiBIT(off);
00358 }
00359
00360 inline void Info::SetBitWritten(int i)
00361 {
00362 const int cn = i/8;
00363 assert(cn < GetSizeInBytes());
00364
00365 const int off = i - cn*8;
00366 m_buff_written[cn] |= cfiBIT(off);
00367 }
00368
00369 inline void Info::SetBitPrefetch(int i)
00370 {
00371 if (!m_buff_prefetch) return;
00372
00373 const int cn = i/8;
00374 assert(cn < GetSizeInBytes());
00375
00376 const int off = i - cn*8;
00377 m_buff_prefetch[cn] |= cfiBIT(off);
00378 }
00379
00380 inline long long Info::GetBufferSize() const
00381 {
00382 return m_store.m_bufferSize;
00383 }
00384
00385 }
00386 #endif