42 const char *f_tpf, *f_tdir, *f_tfile , *f_tmsg;
45 TraceHeader(
const char *tpf,
const char *tdir,
const char *tfile = 0,
const char *tmsg = 0) :
46 f_tpf(tpf), f_tdir(tdir), f_tfile(tfile), f_tmsg(tmsg) {}
51 s << th.f_tpf <<
" " << th.f_tdir;
52 if (th.f_tfile) s << th.f_tfile;
53 if (th.f_tmsg) s <<
" " << th.f_tmsg;
63 const char *m_traceID;
64 const TraceHeader &f_trace_hdr;
66 XrdSysTrace*
GetTrace()
const {
return f_trace; }
68 FpHelper(XrdOssDF* fp, off_t off, XrdSysTrace *trace,
const char *tid,
const TraceHeader &thdr) :
69 f_fp(fp), f_off(off), f_trace(trace), m_traceID(tid), f_trace_hdr(thdr)
73 bool ReadRaw(
void *buf, ssize_t size,
bool warnp =
true)
75 ssize_t ret = f_fp->Read(buf, f_off, size);
80 TRACE(Warning, f_trace_hdr <<
"Oss Read failed at off=" << f_off <<
" size=" << size
81 <<
" ret=" << ret <<
" error=" << ((ret < 0) ?
XrdSysE2T(-ret) :
"<no error>"));
89 template<
typename T>
bool Read(T &loc,
bool warnp =
true)
91 return ReadRaw(&loc,
sizeof(T), warnp);
95 bool WriteRaw(
const void *buf, ssize_t size)
97 ssize_t ret = f_fp->Write(buf, f_off, size);
100 TRACE(Warning, f_trace_hdr <<
"Oss Write failed at off=" << f_off <<
" size=" << size
101 <<
" ret=" << ret <<
" error=" << ((ret < 0) ?
XrdSysE2T(ret) :
"<no error>"));
108 template<
typename T>
bool Write(
const T &loc)
110 return WriteRaw(&loc,
sizeof(T));
155 for (
int i = 0; i < nb; ++i)
169 m_store.m_creationTime = time(0);
211 m_store.m_noCkSumTime = time(0);
221 m_store.m_noCkSumTime = time(0);
243 m_cksCalcMd5->Init();
248 memcpy(digest, m_cksCalcMd5->Final(), 16);
253 switch (
m_store.m_status.f_cksum_check) {
258 default :
return "unknown";
270 TraceHeader trace_pfx(
"Write()", dname, fname);
301 TraceHeader trace_pfx(
"Read()", dname, fname);
311 return ReadV2(fp, r.f_off, dname, fname);
315 return ReadV3(fp, r.f_off, dname, fname);
319 TRACE(Warning, trace_pfx <<
"File version " <<
m_version <<
" not supported.");
326 if (r.Read(
m_store) || r.Read(cksum))
return false;
330 TRACE(
Error, trace_pfx <<
"Checksum Store mismatch.");
346 TRACE(
Error, trace_pfx <<
"Checksum Synced or AStats mismatch.");
383 time_t now = time(0);
387 for (
int i = 0; i < (int) v.size() - 1; ++i)
389 if (v[i].DetachTime == 0)
390 v[i].DetachTime = std::min(v[i].AttachTime + v[i].Duration / v[i].NumIos, v[i+1].AttachTime);
398 int M = (int) v.size() - 2;
399 for (
int i = 0; i < M; ++i)
401 AStat &a = v[i], &b = v[i + 1];
403 time_t t = std::max((time_t) 1, (now - b.AttachTime) / 2 + (now - a.
DetachTime) / 2);
404 double s = (double) (b.AttachTime - a.
DetachTime) / t;
414 v[min_i].MergeWith(v[min_i + 1]);
416 v.erase(v.begin() + (min_i + 1));
442 m_astats.back().DetachTime = time(0);
500bool Info::ReadV3(
XrdOssDF* fp, off_t off,
const char *dname,
const char *fname)
502 TraceHeader trace_pfx(
"ReadV3()", dname, fname);
513 char fileCksum[16], tmpCksum[16];
514 if (r.ReadRaw(&fileCksum[0], 16))
return false;
517 if (memcmp(&fileCksum[0], &tmpCksum[0], 16))
519 TRACE(
Error, trace_pfx <<
"buffer cksum and saved cksum don't match.");
535 while ( ! r.Read(as,
false))
538 if (as.NumIos <= 0 || as.AttachTime < 3600*24*365 ||
539 (as.DetachTime != 0 && (as.DetachTime < 3600*24*365 || as.DetachTime < as.AttachTime)))
541 TRACE(Warning, trace_pfx <<
"Corrupted access record, skipping.");
555bool Info::ReadV2(XrdOssDF* fp, off_t off,
const char *dname,
const char *fname)
562 long long BytesMissed;
563 long long BytesBypassed;
566 TraceHeader trace_pfx(
"ReadV2()", dname, fname);
570 if (r.Read(
m_store.m_buffer_size))
return false;
571 if (r.Read(
m_store.m_file_size))
return false;
577 char fileCksum[16], tmpCksum[16];
578 if (r.ReadRaw(&fileCksum[0], 16))
return false;
581 if (memcmp(&fileCksum[0], &tmpCksum[0], 16))
583 TRACE(
Error, trace_pfx <<
"buffer cksum and saved cksum don't match.");
591 if (r.Read(
m_store.m_creationTime))
return false;
599 while ( ! r.ReadRaw(&av2,
sizeof(AStatV2),
false))
603 as.DetachTime = av2.DetachTime;
605 as.Duration = av2.DetachTime - av2.AttachTime;
608 as.BytesHit = av2.BytesHit;
609 as.BytesMissed = av2.BytesMissed;
610 as.BytesBypassed = av2.BytesBypassed;
613 if (as.AttachTime < 3600*24*365 ||
614 (as.DetachTime != 0 && (as.DetachTime < 3600*24*365 || as.DetachTime < as.AttachTime)))
616 TRACE(Warning, trace_pfx <<
"Corrupted access record, skipping.");
630#ifdef XRDPFC_CKSUM_TEST
632void Info::TestCksumStuff()
634 static const char* names[] = {
"--",
"-C",
"N-",
"NC" };
638 printf(
"Doing cksum tests for config %s\n", names[conf.
m_cs_Chk]);
641 printf(
"cksum %d, raw %x\n", cfi.m_store.m_status.f_cksum_check, cfi.m_store.m_status._raw_);
644 printf(
"cksum %d, raw %x\n", cfi.m_store.m_status.f_cksum_check, cfi.m_store.m_status._raw_);
646 cfi.m_store.m_status._raw_ |= 0xff0000;
647 printf(
"cksum %d, raw %x\n", cfi.m_store.m_status.f_cksum_check, cfi.m_store.m_status._raw_);
649 cfi.ResetCkSumCache();
650 printf(
"cksum %d, raw %x\n", cfi.m_store.m_status.f_cksum_check, cfi.m_store.m_status._raw_);
653 printf(
"cksum %d, raw %x\n", cfi.m_store.m_status.f_cksum_check, cfi.m_store.m_status._raw_);
660 printf(
"-- File conf %s -- does_cschk_have_missing_bits:%d, downgraded_state:%s\n",
661 names[cs], hasmb, names[cfi.GetCkSumState()]);
uint32_t crc32c(uint32_t crc, void const *buf, size_t len)
std::ostream & operator<<(std::ostream &os, const XrdOucString s)
const char * XrdSysE2T(int errcode)
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
static Cache & GetInstance()
Singleton access.
void UpdateDownloadCompleteStatus()
Update complete status.
static const char * s_infoExtension
uint32_t CalcCksumStore()
Get cksum, MD5 is for backward compatibility with V2 and V3.
void ResizeBits()
Reserve bit vectors for file_size / buffer_size bytes.
static const int s_defaultVersion
void WriteIOStatSingle(long long bytes_disk)
Write single open/close time for given bytes read from disk.
Info(XrdSysTrace *trace, bool prefetchBuffer=false)
Constructor.
int GetBitvecSizeInBytes() const
Get size of download-state bit-vector in bytes.
unsigned char * m_buff_prefetch
prefetch statistics
static const size_t s_infoExtensionLen
const AStat * GetLastAccessStats() const
Get latest access stats.
void WriteIOStatAttach()
Write open time in the last entry of access statistics.
bool GetLatestDetachTime(time_t &t) const
Get latest detach time.
bool Write(XrdOssDF *fp, const char *dname, const char *fname=0)
void CompactifyAccessRecords()
Compactify access records to the configured maximum.
uint32_t CalcCksumSyncedAndAStats()
unsigned char * m_buff_written
download state vector
unsigned char * m_buff_synced
disk written state vector
bool m_complete
cached; if false, set to true when missingBlocks hit zero
void ResetAllAccessStats()
Reset IO Stats.
bool IsCkSumCache() const
int m_missingBlocks
cached, updated in SetBitWritten()
void WriteIOStat(Stats &s)
Write bytes missed, hits, and disk.
int m_bitvecSizeInBits
cached
std::vector< AStat > m_astats
access records
void SetAllBitsSynced()
Mark all blocks as synced to disk.
bool Read(XrdOssDF *fp, const char *dname, const char *fname=0)
Read content of cinfo file into this object.
const char * GetCkSumStateAsText() const
void SetBufferSizeFileSizeAndCreationTime(long long bs, long long fs)
void WriteIOStatDetach(Stats &s)
Write close time together with bytes missed, hits, and disk.
static size_t s_maxNumAccess
static const char * m_traceID
void CalcCksumMd5(unsigned char *buff, char *digest)
bool m_hasPrefetchBuffer
constains current prefetch score
bool HasNoCkSumTime() const
Statistics of cache utilisation by a File object.
long long m_BytesMissed
number of bytes served from remote and cached
long long m_BytesBypassed
number of bytes served directly through XrdCl
int m_Duration
total duration of all IOs attached
int m_NumIos
number of IO objects attached during this access
long long m_BytesHit
number of bytes served from disk
ReadImpl< false > Read(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
WriteImpl< false > Write(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating WriteImpl objects.
bool does_cschk_have_missing_bits(CkSumCheck_e cks_on_file) const
CkSumCheck_e get_cs_Chk() const
int m_cs_Chk
Checksum check.
long long BytesHit
read from cache
long long BytesBypassed
read from remote and dropped
void MergeWith(const AStat &a)
int Duration
total duration of all IOs attached
int NumIos
number of IO objects attached during this access
time_t DetachTime
close time
long long BytesMissed
read from remote and cached
time_t AttachTime
open time
int NumMerged
number of times the record has been merged
long long m_buffer_size
buffer / block size
size_t m_accessCnt
total access count for the file
long long m_file_size
size of file in bytes
time_t m_creationTime
time the info file was created