1 #ifndef XRD_READCACHE_H
2 #define XRD_READCACHE_H
36 #include "XrdSys/XrdSysHeaders.hh"
51 class XrdClientReadCacheItem {
56 long long fBeginOffset;
62 XrdClientReadCacheItem(
const void *buffer,
long long begin_offs,
63 long long end_offs,
long long ticksnow,
64 bool placeholder=
false);
65 ~XrdClientReadCacheItem();
67 inline long long BeginOffset() {
return fBeginOffset; }
68 inline long long EndOffset() {
return fEndOffset; }
71 inline bool ContainedInInterval(
long long begin_offs,
long long end_offs) {
72 return ( (end_offs >= begin_offs) &&
73 (fBeginOffset >= begin_offs) &&
74 (fEndOffset <= end_offs) );
78 inline bool ContainsInterval(
long long begin_offs,
long long end_offs) {
79 return ( (end_offs > begin_offs) &&
80 (fBeginOffset <= begin_offs) && (fEndOffset >= end_offs) );
84 inline bool IntersectInterval(
long long begin_offs,
long long end_offs) {
85 if ( ContainsOffset( begin_offs ) || ContainsOffset( end_offs ) )
return true;
86 if ( (fBeginOffset >= begin_offs) && (fBeginOffset <= end_offs) )
return true;
91 inline bool ContainsOffset(
long long offs) {
92 return (fBeginOffset <= offs) && (fEndOffset >= offs);
95 void *GetData() {
return fData; }
98 inline bool GetInterval(
const void *buffer,
long long begin_offs,
100 if (!ContainsInterval(begin_offs, end_offs))
102 memcpy((
void *)buffer, ((
char *)fData)+(begin_offs - fBeginOffset),
103 end_offs - begin_offs + 1);
109 inline long GetPartialInterval(
const void *buffer,
long long begin_offs,
110 long long end_offs) {
112 long long b = -1, e, l;
114 if (begin_offs > end_offs)
return 0;
117 if ( (begin_offs >= fBeginOffset) &&
118 (begin_offs <= fEndOffset) )
124 e = xrdmin(end_offs, fEndOffset);
129 memcpy((
void *)buffer, ((
char *)fData)+(b - fBeginOffset), l);
134 inline long long GetTimestampTicks() {
return(fTimestampTicks); }
136 inline bool IsPlaceholder() {
return fIsPlaceholder; }
138 long Size() {
return (fEndOffset - fBeginOffset + 1); }
140 inline void Touch(
long long ticksnow) { fTimestampTicks = ticksnow; }
151 typedef XrdClientVector<XrdClientReadCacheItem *> ItemVect;
154 struct XrdClientCacheInterval {
159 typedef XrdClientVector<XrdClientCacheInterval> XrdClientIntvList;
161 class XrdClientReadCache {
165 long long fBytesSubmitted;
166 float fBytesUsefulness;
168 long long fMaxCacheSize;
169 long long fMissCount;
171 XrdSysRecMutex fMutex;
172 long long fReadsCounter;
174 long long fTimestampTickCounter;
175 long long fTotalByteCount;
177 long long GetTimestampTick();
178 bool MakeFreeSpace(
long long bytes);
181 bool RemoveLRUItem();
182 bool RemoveFirstItem();
184 inline void UpdatePerfCounters() {
185 if (fReadsCounter > 0)
186 fMissRate = (float)fMissCount / fReadsCounter;
187 if (fBytesSubmitted > 0)
188 fBytesUsefulness = (float)fBytesHit / fBytesSubmitted;
191 int FindInsertionApprox(
long long begin_offs);
192 int FindInsertionApprox_rec(
int startidx,
int endidx,
193 long long begin_offs);
203 XrdClientReadCache();
204 ~XrdClientReadCache();
206 long GetDataIfPresent(
const void *buffer,
long long begin_offs,
207 long long end_offs,
bool PerfCalc,
208 XrdClientIntvList &missingblks,
long &outstandingblks);
215 long long &bytessubmitted,
222 long long &misscount,
228 long long &readreqcnt,
231 float &bytesusefulness
234 inline long long GetTotalByteCount() {
235 XrdSysMutexHelper m(fMutex);
236 return fTotalByteCount;
239 void PutPlaceholder(
long long begin_offs,
long long end_offs);
241 inline void PrintPerfCounters() {
242 XrdSysMutexHelper m(fMutex);
244 cout <<
"Low level caching info:" << endl;
245 cout <<
" StallsRate=" << fMissRate << endl;
246 cout <<
" StallsCount=" << fMissCount << endl;
247 cout <<
" ReadsCounter=" << fReadsCounter << endl;
248 cout <<
" BytesUsefulness=" << fBytesUsefulness << endl;
249 cout <<
" BytesSubmitted=" << fBytesSubmitted <<
" BytesHit=" <<
250 fBytesHit << endl << endl;
256 void SubmitXMessage(XrdClientMessage *xmsg,
long long begin_offs,
259 bool SubmitRawData(
const void *buffer,
long long begin_offs,
260 long long end_offs,
bool pinned=
false);
262 void RemoveItems(
bool leavepinned=
true);
263 void RemoveItems(
long long begin_offs,
long long end_offs,
bool remove_overlapped =
false);
264 void RemovePlaceholders();
267 void SetSize(
int sz) {
271 void SetBlkRemovalPolicy(
int p) {
275 void UnPinCacheBlk(
long long begin_offs,
long long end_offs);
276 void *FindBlk(
long long begin_offs,
long long end_offs);
279 inline bool WillFit(
long long bc) {
280 XrdSysMutexHelper m(fMutex);
281 return (bc < fMaxCacheSize);