XRootD
XrdPfc::File Class Reference

#include <XrdPfcFile.hh>

+ Collaboration diagram for XrdPfc::File:

Public Member Functions

void AddIO (IO *io)
 
void BlockRemovedFromWriteQ (Block *)
 Handle removal of a block from Cache's write queue. More...
 
void BlocksRemovedFromWriteQ (std::list< Block * > &)
 Handle removal of a set of blocks from Cache's write queue. More...
 
int dec_ref_cnt ()
 
bool FinalizeSyncBeforeExit ()
 Returns true if any of blocks need sync. Called from Cache::dec_ref_cnt on zero ref cnt. More...
 
int Fstat (struct stat &sbuff)
 
int get_ref_cnt ()
 
size_t GetAccessCnt () const
 
int GetBlockSize () const
 
long long GetFileSize () const
 
const Info::AStat * GetLastAccessStats () const
 
const std::string & GetLocalPath () const
 
XrdSysError * GetLog () const
 
int GetNBlocks () const
 
int GetNDownloadedBlocks () const
 
int GetPrefetchCountOnIO (IO *io)
 
long long GetPrefetchedBytes () const
 
float GetPrefetchScore () const
 
std::string GetRemoteLocations () const
 
XrdSysTrace * GetTrace () const
 
int inc_ref_cnt ()
 
long long initiate_emergency_shutdown ()
 
bool ioActive (IO *io)
 Initiate close. Return true if still IO active. Used in XrdPosixXrootd::Close() More...
 
void ioUpdated (IO *io)
 Notification from IO that it has been updated (remote open). More...
 
bool is_in_emergency_shutdown ()
 
const char * lPath () const
 Log path. More...
 
void Prefetch ()
 
int Read (IO *io, char *buff, long long offset, int size, ReadReqRH *rh)
 Normal read. More...
 
int ReadV (IO *io, const XrdOucIOVec *readV, int readVnum, ReadReqRH *rh)
 Vector read. More...
 
const Stats & RefStats () const
 
void RemoveIO (IO *io)
 
void RequestSyncOfDetachStats ()
 Flags that detach stats should be written out in final sync. Called from CacheIO upon Detach. More...
 
void StopPrefetchingOnIO (IO *io)
 
void Sync ()
 Sync file cache inf o and output data with disk. More...
 
void WriteBlockToDisk (Block *b)
 

Static Public Member Functions

static File * FileOpen (const std::string &path, long long offset, long long fileSize, XrdOucCacheIO *inputIO)
 Static constructor that also does Open. Returns null ptr if Open fails. More...
 

Friends

class BlockResponseHandler
 
class Cache
 
class DirectResponseHandler
 

Detailed Description

Definition at line 209 of file XrdPfcFile.hh.

Member Function Documentation

◆ AddIO()

void File::AddIO ( IO *  io)

Definition at line 349 of file XrdPfcFile.cc.

350 {
351  // Called from Cache::GetFile() when a new IO asks for the file.
352 
353  TRACEF(Debug, "AddIO() io = " << (void*)io);
354 
355  time_t now = time(0);
356  std::string loc(io->GetLocation());
357 
358  m_state_cond.Lock();
359 
360  IoSet_i mi = m_io_set.find(io);
361 
362  if (mi == m_io_set.end())
363  {
364  m_io_set.insert(io);
365  io->m_attach_time = now;
366  m_delta_stats.IoAttach();
367 
368  insert_remote_location(loc);
369 
370  if (m_prefetch_state == kStopped)
371  {
372  m_prefetch_state = kOn;
373  cache()->RegisterPrefetchFile(this);
374  }
375  }
376  else
377  {
378  TRACEF(Error, "AddIO() io = " << (void*)io << " already registered.");
379  }
380 
381  m_state_cond.UnLock();
382 }
#define TRACEF(act, x)
Definition: XrdPfcTrace.hh:67
bool Debug
@ Error
const char * GetLocation()
Definition: XrdPfcIO.hh:44
void IoAttach()
Definition: XrdPfcStats.hh:85

References Debug, Error, XrdPfc::IO::GetLocation(), XrdPfc::Stats::IoAttach(), XrdSysCondVar::Lock(), TRACEF, and XrdSysCondVar::UnLock().

Referenced by XrdPfc::Cache::GetFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BlockRemovedFromWriteQ()

void File::BlockRemovedFromWriteQ ( Block *  b)

Handle removal of a block from Cache's write queue.

Definition at line 211 of file XrdPfcFile.cc.

212 {
213  TRACEF(Dump, "BlockRemovedFromWriteQ() block = " << (void*) b << " idx= " << b->m_offset/m_block_size);
214 
215  XrdSysCondVarHelper _lck(m_state_cond);
216  dec_ref_count(b);
217 }
long long m_offset
Definition: XrdPfcFile.hh:121

References XrdPfc::Block::m_offset, and TRACEF.

◆ BlocksRemovedFromWriteQ()

void File::BlocksRemovedFromWriteQ ( std::list< Block * > &  blocks)

Handle removal of a set of blocks from Cache's write queue.

Definition at line 219 of file XrdPfcFile.cc.

220 {
221  TRACEF(Dump, "BlocksRemovedFromWriteQ() n_blocks = " << blocks.size());
222 
223  XrdSysCondVarHelper _lck(m_state_cond);
224 
225  for (std::list<Block*>::iterator i = blocks.begin(); i != blocks.end(); ++i)
226  {
227  dec_ref_count(*i);
228  }
229 }

References TRACEF.

Referenced by XrdPfc::Cache::RemoveWriteQEntriesFor().

+ Here is the caller graph for this function:

◆ dec_ref_cnt()

int XrdPfc::File::dec_ref_cnt ( )
inline

Definition at line 295 of file XrdPfcFile.hh.

295 { return --m_ref_cnt; }

◆ FileOpen()

File * File::FileOpen ( const std::string &  path,
long long  offset,
long long  fileSize,
XrdOucCacheIO *  inputIO 
)
static

Static constructor that also does Open. Returns null ptr if Open fails.

Definition at line 141 of file XrdPfcFile.cc.

142 {
143  File *file = new File(path, offset, fileSize);
144  if ( ! file->Open(inputIO))
145  {
146  delete file;
147  file = 0;
148  }
149  return file;
150 }

References File.

Referenced by XrdPfc::Cache::GetFile().

+ Here is the caller graph for this function:

◆ FinalizeSyncBeforeExit()

bool File::FinalizeSyncBeforeExit ( )

Returns true if any of blocks need sync. Called from Cache::dec_ref_cnt on zero ref cnt.

Definition at line 325 of file XrdPfcFile.cc.

326 {
327  // Returns true if sync is required.
328  // This method is called after corresponding IO is detached from PosixCache.
329 
330  XrdSysCondVarHelper _lck(m_state_cond);
331  if ( ! m_in_shutdown)
332  {
333  if ( ! m_writes_during_sync.empty() || m_non_flushed_cnt > 0 || ! m_detach_time_logged)
334  {
335  report_and_merge_delta_stats();
336  m_cfi.WriteIOStatDetach(m_stats);
337  m_detach_time_logged = true;
338  m_in_sync = true;
339  TRACEF(Debug, "FinalizeSyncBeforeExit requesting sync to write detach stats");
340  return true;
341  }
342  }
343  TRACEF(Debug, "FinalizeSyncBeforeExit sync not required");
344  return false;
345 }
void WriteIOStatDetach(Stats &s)
Write close time together with bytes missed, hits, and disk.
Definition: XrdPfcInfo.cc:438

References Debug, TRACEF, and XrdPfc::Info::WriteIOStatDetach().

+ Here is the call graph for this function:

◆ Fstat()

int File::Fstat ( struct stat &  sbuff)

Definition at line 668 of file XrdPfcFile.cc.

669 {
670  // Stat on an open file.
671  // Corrects size to actual full size of the file.
672  // Sets atime to 0 if the file is only partially downloaded, in accordance
673  // with pfc.onlyifcached settings.
674  // Called from IO::Fstat() and Cache::Stat() when the file is active.
675  // Returns 0 on success, -errno on error.
676 
677  int res;
678 
679  if ((res = m_data_file->Fstat(&sbuff))) return res;
680 
681  sbuff.st_size = m_file_size;
682 
683  bool is_cached = cache()->DecideIfConsideredCached(m_file_size, sbuff.st_blocks * 512ll);
684  if ( ! is_cached)
685  sbuff.st_atime = 0;
686 
687  return 0;
688 }
virtual int Fstat(struct stat *buf)
Definition: XrdOss.hh:136

References XrdOssDF::Fstat().

Referenced by XrdPfc::Cache::ConsiderCached(), XrdPfc::IOFile::Fstat(), and XrdPfc::Cache::Stat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_ref_cnt()

int XrdPfc::File::get_ref_cnt ( )
inline

Definition at line 293 of file XrdPfcFile.hh.

293 { return m_ref_cnt; }

◆ GetAccessCnt()

size_t XrdPfc::File::GetAccessCnt ( ) const
inline

Definition at line 283 of file XrdPfcFile.hh.

283 { return m_cfi.GetAccessCnt(); }
size_t GetAccessCnt() const
Get number of accesses.
Definition: XrdPfcInfo.hh:261

References XrdPfc::Info::GetAccessCnt().

+ Here is the call graph for this function:

◆ GetBlockSize()

int XrdPfc::File::GetBlockSize ( ) const
inline

Definition at line 284 of file XrdPfcFile.hh.

284 { return m_cfi.GetBufferSize(); }
long long GetBufferSize() const
Get prefetch buffer size.
Definition: XrdPfcInfo.hh:469

References XrdPfc::Info::GetBufferSize().

+ Here is the call graph for this function:

◆ GetFileSize()

long long XrdPfc::File::GetFileSize ( ) const
inline

Definition at line 274 of file XrdPfcFile.hh.

274 { return m_file_size; }

Referenced by XrdPfc::IOFile::FSize().

+ Here is the caller graph for this function:

◆ GetLastAccessStats()

const Info::AStat* XrdPfc::File::GetLastAccessStats ( ) const
inline

Definition at line 282 of file XrdPfcFile.hh.

282 { return m_cfi.GetLastAccessStats(); }
const AStat * GetLastAccessStats() const
Get latest access stats.
Definition: XrdPfcInfo.cc:489

References XrdPfc::Info::GetLastAccessStats().

+ Here is the call graph for this function:

◆ GetLocalPath()

const std::string& XrdPfc::File::GetLocalPath ( ) const
inline

Definition at line 269 of file XrdPfcFile.hh.

269 { return m_filename; }

Referenced by XrdPfc::Cache::AddWriteTask(), and XrdPfc::Cache::ReleaseFile().

+ Here is the caller graph for this function:

◆ GetLog()

XrdSysError * File::GetLog ( ) const

Definition at line 1738 of file XrdPfcFile.cc.

1739 {
1740  return Cache::TheOne().GetLog();
1741 }
static const Cache & TheOne()
Definition: XrdPfc.cc:133
XrdSysError * GetLog() const
Definition: XrdPfc.hh:294

References XrdPfc::Cache::GetLog(), and XrdPfc::Cache::TheOne().

+ Here is the call graph for this function:

◆ GetNBlocks()

int XrdPfc::File::GetNBlocks ( ) const
inline

Definition at line 285 of file XrdPfcFile.hh.

285 { return m_cfi.GetNBlocks(); }
int GetNBlocks() const
Get number of blocks represented in download-state bit-vector.
Definition: XrdPfcInfo.hh:437

References XrdPfc::Info::GetNBlocks().

+ Here is the call graph for this function:

◆ GetNDownloadedBlocks()

int XrdPfc::File::GetNDownloadedBlocks ( ) const
inline

Definition at line 286 of file XrdPfcFile.hh.

286 { return m_cfi.GetNDownloadedBlocks(); }
int GetNDownloadedBlocks() const
Get number of downloaded blocks.
Definition: XrdPfcInfo.hh:398

References XrdPfc::Info::GetNDownloadedBlocks().

+ Here is the call graph for this function:

◆ GetPrefetchCountOnIO()

int XrdPfc::File::GetPrefetchCountOnIO ( IO *  io)

◆ GetPrefetchedBytes()

long long XrdPfc::File::GetPrefetchedBytes ( ) const
inline

Definition at line 287 of file XrdPfcFile.hh.

287 { return m_prefetch_bytes; }

◆ GetPrefetchScore()

float File::GetPrefetchScore ( ) const

Definition at line 1733 of file XrdPfcFile.cc.

1734 {
1735  return m_prefetch_score;
1736 }

◆ GetRemoteLocations()

std::string File::GetRemoteLocations ( ) const

Definition at line 1757 of file XrdPfcFile.cc.

1758 {
1759  std::string s;
1760  if ( ! m_remote_locations.empty())
1761  {
1762  size_t sl = 0;
1763  int nl = 0;
1764  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++nl)
1765  {
1766  sl += i->size();
1767  }
1768  s.reserve(2 + sl + 2*nl + nl - 1 + 1);
1769  s = '[';
1770  int j = 1;
1771  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++j)
1772  {
1773  s += '"'; s += *i; s += '"';
1774  if (j < nl) s += ',';
1775  }
1776  s += ']';
1777  }
1778  else
1779  {
1780  s = "[]";
1781  }
1782  return s;
1783 }

◆ GetTrace()

XrdSysTrace * File::GetTrace ( ) const

Definition at line 1743 of file XrdPfcFile.cc.

1744 {
1745  return Cache::TheOne().GetTrace();
1746 }
XrdSysTrace * GetTrace() const
Definition: XrdPfc.hh:295

References XrdPfc::Cache::GetTrace(), and XrdPfc::Cache::TheOne().

+ Here is the call graph for this function:

◆ inc_ref_cnt()

int XrdPfc::File::inc_ref_cnt ( )
inline

Definition at line 294 of file XrdPfcFile.hh.

294 { return ++m_ref_cnt; }

◆ initiate_emergency_shutdown()

long long File::initiate_emergency_shutdown ( )

Definition at line 154 of file XrdPfcFile.cc.

155 {
156  // Called from Cache::Unlink() when the file is currently open.
157  // Cache::Unlink is also called on FSync error and when wrong number of bytes
158  // is received from a remote read.
159  //
160  // From this point onward the file will not be written to, cinfo file will
161  // not be updated, and all new read requests will return -ENOENT.
162  //
163  // File's entry in the Cache's active map is set to nullptr and will be
164  // removed from there shortly, in any case, well before this File object
165  // shuts down. Cache::Unlink() also reports the appropriate purge event.
166 
167  XrdSysCondVarHelper _lck(m_state_cond);
168 
169  m_in_shutdown = true;
170 
171  if (m_prefetch_state != kStopped && m_prefetch_state != kComplete)
172  {
173  m_prefetch_state = kStopped;
174  cache()->DeRegisterPrefetchFile(this);
175  }
176 
177  report_and_merge_delta_stats();
178 
179  return m_st_blocks;
180 }

Referenced by XrdPfc::Cache::UnlinkFile().

+ Here is the caller graph for this function:

◆ ioActive()

bool File::ioActive ( IO *  io)

Initiate close. Return true if still IO active. Used in XrdPosixXrootd::Close()

Definition at line 242 of file XrdPfcFile.cc.

243 {
244  // Returns true if delay is needed.
245 
246  TRACEF(Debug, "ioActive start for io " << io);
247 
248  std::string loc(io->GetLocation());
249 
250  {
251  XrdSysCondVarHelper _lck(m_state_cond);
252 
253  IoSet_i mi = m_io_set.find(io);
254 
255  if (mi != m_io_set.end())
256  {
257  unsigned int n_active_reads = io->m_active_read_reqs;
258 
259  TRACE(Info, "ioActive for io " << io <<
260  ", active_reads " << n_active_reads <<
261  ", active_prefetches " << io->m_active_prefetches <<
262  ", allow_prefetching " << io->m_allow_prefetching <<
263  ", ios_in_detach " << m_ios_in_detach);
264  TRACEF(Info,
265  "\tio_map.size() " << m_io_set.size() <<
266  ", block_map.size() " << m_block_map.size() << ", file");
267 
268  insert_remote_location(loc);
269 
270  io->m_allow_prefetching = false;
271  io->m_in_detach = true;
272 
273  // Check if any IO is still available for prfetching. If not, stop it.
274  if (m_prefetch_state == kOn || m_prefetch_state == kHold)
275  {
276  if ( ! select_current_io_or_disable_prefetching(false) )
277  {
278  TRACEF(Debug, "ioActive stopping prefetching after io " << io << " retreat.");
279  }
280  }
281 
282  // On last IO, consider write queue blocks. Note, this also contains
283  // blocks being prefetched.
284 
285  bool io_active_result;
286 
287  if (n_active_reads > 0)
288  {
289  io_active_result = true;
290  }
291  else if (m_io_set.size() - m_ios_in_detach == 1)
292  {
293  io_active_result = ! m_block_map.empty();
294  }
295  else
296  {
297  io_active_result = io->m_active_prefetches > 0;
298  }
299 
300  if ( ! io_active_result)
301  {
302  ++m_ios_in_detach;
303  }
304 
305  TRACEF(Info, "ioActive for io " << io << " returning " << io_active_result << ", file");
306 
307  return io_active_result;
308  }
309  else
310  {
311  TRACEF(Error, "ioActive io " << io <<" not found in IoSet. This should not happen.");
312  return false;
313  }
314  }
315 }
#define TRACE(act, x)
Definition: XrdTrace.hh:63
RAtomic_int m_active_read_reqs
number of active read requests
Definition: XrdPfcIO.hh:70
Status of cached file. Can be read from and written into a binary file.
Definition: XrdPfcInfo.hh:41

References Debug, Error, XrdPfc::IO::GetLocation(), XrdPfc::IO::m_active_read_reqs, TRACE, and TRACEF.

Referenced by XrdPfc::IOFile::ioActive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ioUpdated()

void File::ioUpdated ( IO *  io)

Notification from IO that it has been updated (remote open).

Definition at line 233 of file XrdPfcFile.cc.

234 {
235  std::string loc(io->GetLocation());
236  XrdSysCondVarHelper _lck(m_state_cond);
237  insert_remote_location(loc);
238 }

References XrdPfc::IO::GetLocation().

Referenced by XrdPfc::IOFile::Update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_in_emergency_shutdown()

bool XrdPfc::File::is_in_emergency_shutdown ( )
inline

Definition at line 298 of file XrdPfcFile.hh.

298 { return m_in_shutdown; }

◆ lPath()

const char * File::lPath ( ) const

Log path.

Definition at line 1645 of file XrdPfcFile.cc.

1646 {
1647  return m_filename.c_str();
1648 }

Referenced by XrdPfc::Cache::ProcessWriteTasks(), and XrdPfc::Cache::RemoveWriteQEntriesFor().

+ Here is the caller graph for this function:

◆ Prefetch()

void File::Prefetch ( )

Definition at line 1660 of file XrdPfcFile.cc.

1661 {
1662  // Check that block is not on disk and not in RAM.
1663  // TODO: Could prefetch several blocks at once!
1664  // blks_max could be an argument
1665 
1666  BlockList_t blks;
1667 
1668  TRACEF(DumpXL, "Prefetch() entering.");
1669  {
1670  XrdSysCondVarHelper _lck(m_state_cond);
1671 
1672  if (m_prefetch_state != kOn)
1673  {
1674  return;
1675  }
1676 
1677  if ( ! select_current_io_or_disable_prefetching(true) )
1678  {
1679  TRACEF(Error, "Prefetch no available IO object found, prefetching stopped. This should not happen, i.e., prefetching should be stopped before.");
1680  return;
1681  }
1682 
1683  // Select block(s) to fetch.
1684  for (int f = 0; f < m_num_blocks; ++f)
1685  {
1686  if ( ! m_cfi.TestBitWritten(f))
1687  {
1688  int f_act = f + m_offset / m_block_size;
1689 
1690  BlockMap_i bi = m_block_map.find(f_act);
1691  if (bi == m_block_map.end())
1692  {
1693  Block *b = PrepareBlockRequest(f_act, *m_current_io, nullptr, true);
1694  if (b)
1695  {
1696  TRACEF(Dump, "Prefetch take block " << f_act);
1697  blks.push_back(b);
1698  // Note: block ref_cnt not increased, it will be when placed into write queue.
1699 
1700  inc_prefetch_read_cnt(1);
1701  }
1702  else
1703  {
1704  // This shouldn't happen as prefetching stops when RAM is 70% full.
1705  TRACEF(Warning, "Prefetch allocation failed for block " << f_act);
1706  }
1707  break;
1708  }
1709  }
1710  }
1711 
1712  if (blks.empty())
1713  {
1714  TRACEF(Debug, "Prefetch file is complete, stopping prefetch.");
1715  m_prefetch_state = kComplete;
1716  cache()->DeRegisterPrefetchFile(this);
1717  }
1718  else
1719  {
1720  (*m_current_io)->m_active_prefetches += (int) blks.size();
1721  }
1722  }
1723 
1724  if ( ! blks.empty())
1725  {
1726  ProcessBlockRequests(blks);
1727  }
1728 }
bool TestBitWritten(int i) const
Test if block at the given index is written to disk.
Definition: XrdPfcInfo.hh:343
@ Warning
std::list< Block * > BlockList_t
Definition: XrdPfcFile.hh:173

References Debug, Error, XrdPfc::Info::TestBitWritten(), TRACEF, and TPC::Warning.

Referenced by XrdPfc::Cache::Prefetch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Read()

int File::Read ( IO *  io,
char *  buff,
long long  offset,
int  size,
ReadReqRH *  rh 
)

Normal read.

Definition at line 853 of file XrdPfcFile.cc.

854 {
855  // rrc_func is ONLY called from async processing.
856  // If this function returns anything other than kReadPending, rrc_func needs to be called by the caller.
857  // This streamlines implementation of synchronous IO::Read().
858 
859  TRACEF(Dump, "Read() sid: " << Xrd::hex1 << rh->m_seq_id << " size: " << iUserSize);
860 
861  m_state_cond.Lock();
862 
863  if (m_in_shutdown || io->m_in_detach)
864  {
865  m_state_cond.UnLock();
866  return m_in_shutdown ? -ENOENT : -EBADF;
867  }
868 
869  // Shortcut -- file is fully downloaded.
870 
871  if (m_cfi.IsComplete())
872  {
873  m_state_cond.UnLock();
874  int ret = m_data_file->Read(iUserBuff, iUserOff, iUserSize);
875  if (ret > 0) {
876  XrdSysCondVarHelper _lck(m_state_cond);
877  m_delta_stats.AddBytesHit(ret);
878  check_delta_stats();
879  }
880  return ret;
881  }
882 
883  XrdOucIOVec readV( { iUserOff, iUserSize, 0, iUserBuff } );
884 
885  return ReadOpusCoalescere(io, &readV, 1, rh, "Read() ");
886 }
virtual ssize_t Read(off_t offset, size_t size)
Definition: XrdOss.hh:281
bool IsComplete() const
Get complete status.
Definition: XrdPfcInfo.hh:447
void AddBytesHit(long long bh)
Definition: XrdPfcStats.hh:74
@ hex1
Definition: XrdSysTrace.hh:42
unsigned short m_seq_id
Definition: XrdPfcFile.hh:60

References XrdPfc::Stats::AddBytesHit(), Xrd::hex1, XrdPfc::Info::IsComplete(), XrdSysCondVar::Lock(), XrdPfc::ReadReqRH::m_seq_id, XrdOssDF::Read(), TRACEF, and XrdSysCondVar::UnLock().

Referenced by XrdPfc::IOFileBlock::Read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadV()

int File::ReadV ( IO *  io,
const XrdOucIOVec *  readV,
int  readVnum,
ReadReqRH *  rh 
)

Vector read.

Definition at line 890 of file XrdPfcFile.cc.

891 {
892  TRACEF(Dump, "ReadV() for " << readVnum << " chunks.");
893 
894  m_state_cond.Lock();
895 
896  if (m_in_shutdown || io->m_in_detach)
897  {
898  m_state_cond.UnLock();
899  return m_in_shutdown ? -ENOENT : -EBADF;
900  }
901 
902  // Shortcut -- file is fully downloaded.
903 
904  if (m_cfi.IsComplete())
905  {
906  m_state_cond.UnLock();
907  int ret = m_data_file->ReadV(const_cast<XrdOucIOVec*>(readV), readVnum);
908  if (ret > 0) {
909  XrdSysCondVarHelper _lck(m_state_cond);
910  m_delta_stats.AddBytesHit(ret);
911  check_delta_stats();
912  }
913  return ret;
914  }
915 
916  return ReadOpusCoalescere(io, readV, readVnum, rh, "ReadV() ");
917 }
virtual ssize_t ReadV(XrdOucIOVec *readV, int rdvcnt)
Definition: XrdOss.cc:236

References XrdPfc::Stats::AddBytesHit(), XrdPfc::Info::IsComplete(), XrdSysCondVar::Lock(), XrdOssDF::ReadV(), TRACEF, and XrdSysCondVar::UnLock().

+ Here is the call graph for this function:

◆ RefStats()

const Stats& XrdPfc::File::RefStats ( ) const
inline

Definition at line 288 of file XrdPfcFile.hh.

288 { return m_stats; }

◆ RemoveIO()

void File::RemoveIO ( IO *  io)

Definition at line 386 of file XrdPfcFile.cc.

387 {
388  // Called from Cache::ReleaseFile.
389 
390  TRACEF(Debug, "RemoveIO() io = " << (void*)io);
391 
392  time_t now = time(0);
393 
394  m_state_cond.Lock();
395 
396  IoSet_i mi = m_io_set.find(io);
397 
398  if (mi != m_io_set.end())
399  {
400  if (mi == m_current_io)
401  {
402  ++m_current_io;
403  }
404 
405  m_delta_stats.IoDetach(now - io->m_attach_time);
406  m_io_set.erase(mi);
407  --m_ios_in_detach;
408 
409  if (m_io_set.empty() && m_prefetch_state != kStopped && m_prefetch_state != kComplete)
410  {
411  TRACEF(Error, "RemoveIO() io = " << (void*)io << " Prefetching is not stopped/complete -- it should be by now.");
412  m_prefetch_state = kStopped;
413  cache()->DeRegisterPrefetchFile(this);
414  }
415  }
416  else
417  {
418  TRACEF(Error, "RemoveIO() io = " << (void*)io << " is NOT registered.");
419  }
420 
421  m_state_cond.UnLock();
422 }
void IoDetach(int duration)
Definition: XrdPfcStats.hh:90

References Debug, Error, XrdPfc::Stats::IoDetach(), XrdSysCondVar::Lock(), TRACEF, and XrdSysCondVar::UnLock().

Referenced by XrdPfc::Cache::ReleaseFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RequestSyncOfDetachStats()

void File::RequestSyncOfDetachStats ( )

Flags that detach stats should be written out in final sync. Called from CacheIO upon Detach.

Definition at line 319 of file XrdPfcFile.cc.

320 {
321  XrdSysCondVarHelper _lck(m_state_cond);
322  m_detach_time_logged = false;
323 }

Referenced by XrdPfc::IOFile::DetachFinalize().

+ Here is the caller graph for this function:

◆ StopPrefetchingOnIO()

void XrdPfc::File::StopPrefetchingOnIO ( IO *  io)

◆ Sync()

void File::Sync ( )

Sync file cache inf o and output data with disk.

Definition at line 1259 of file XrdPfcFile.cc.

1260 {
1261  TRACEF(Dump, "Sync()");
1262 
1263  int ret = m_data_file->Fsync();
1264  bool errorp = false;
1265  if (ret == XrdOssOK)
1266  {
1267  Stats loc_stats;
1268  {
1269  XrdSysCondVarHelper _lck(&m_state_cond);
1270  report_and_merge_delta_stats();
1271  loc_stats = m_stats;
1272  }
1273  m_cfi.WriteIOStat(loc_stats);
1274  m_cfi.Write(m_info_file, m_filename.c_str());
1275  int cret = m_info_file->Fsync();
1276  if (cret != XrdOssOK)
1277  {
1278  TRACEF(Error, "Sync cinfo file sync error " << cret);
1279  errorp = true;
1280  }
1281  }
1282  else
1283  {
1284  TRACEF(Error, "Sync data file sync error " << ret << ", cinfo file has not been updated");
1285  errorp = true;
1286  }
1287 
1288  if (errorp)
1289  {
1290  TRACEF(Error, "Sync failed, unlinking local files and initiating shutdown of File object");
1291 
1292  // Unlink will also call this->initiate_emergency_shutdown()
1293  Cache::GetInstance().UnlinkFile(m_filename, false);
1294 
1295  XrdSysCondVarHelper _lck(&m_state_cond);
1296 
1297  m_writes_during_sync.clear();
1298  m_in_sync = false;
1299 
1300  return;
1301  }
1302 
1303  int written_while_in_sync;
1304  bool resync = false;
1305  {
1306  XrdSysCondVarHelper _lck(&m_state_cond);
1307  for (std::vector<int>::iterator i = m_writes_during_sync.begin(); i != m_writes_during_sync.end(); ++i)
1308  {
1309  m_cfi.SetBitSynced(*i);
1310  }
1311  written_while_in_sync = m_non_flushed_cnt = (int) m_writes_during_sync.size();
1312  m_writes_during_sync.clear();
1313 
1314  // If there were writes during sync and the file is now complete,
1315  // let us call Sync again without resetting the m_in_sync flag.
1316  if (written_while_in_sync > 0 && m_cfi.IsComplete() && ! m_in_shutdown)
1317  resync = true;
1318  else
1319  m_in_sync = false;
1320  }
1321  TRACEF(Dump, "Sync "<< written_while_in_sync << " blocks written during sync." << (resync ? " File is now complete - resyncing." : ""));
1322 
1323  if (resync)
1324  Sync();
1325 }
#define XrdOssOK
Definition: XrdOss.hh:50
virtual int Fsync()
Definition: XrdOss.hh:144
static Cache & GetInstance()
Singleton access.
Definition: XrdPfc.cc:132
int UnlinkFile(const std::string &f_name, bool fail_if_open)
Remove cinfo and data files from cache.
Definition: XrdPfc.cc:1191
void Sync()
Sync file cache inf o and output data with disk.
Definition: XrdPfcFile.cc:1259
void SetBitSynced(int i)
Mark block as synced to disk.
Definition: XrdPfcInfo.hh:387
bool Write(XrdOssDF *fp, const char *dname, const char *fname=0)
Definition: XrdPfcInfo.cc:266
void WriteIOStat(Stats &s)
Write bytes missed, hits, and disk.
Definition: XrdPfcInfo.cc:429
Statistics of cache utilisation by a File object.
Definition: XrdPfcStats.hh:35

References Error, XrdOssDF::Fsync(), XrdPfc::Cache::GetInstance(), XrdPfc::Info::IsComplete(), XrdPfc::Info::SetBitSynced(), TRACEF, XrdPfc::Cache::UnlinkFile(), XrdPfc::Info::Write(), XrdPfc::Info::WriteIOStat(), and XrdOssOK.

+ Here is the call graph for this function:

◆ WriteBlockToDisk()

void File::WriteBlockToDisk ( Block *  b)

Definition at line 1173 of file XrdPfcFile.cc.

1174 {
1175  // write block buffer into disk file
1176  long long offset = b->m_offset - m_offset;
1177  long long size = b->get_size();
1178  ssize_t retval;
1179 
1180  if (m_cfi.IsCkSumCache())
1181  if (b->has_cksums())
1182  retval = m_data_file->pgWrite(b->get_buff(), offset, size, b->ref_cksum_vec().data(), 0);
1183  else
1184  retval = m_data_file->pgWrite(b->get_buff(), offset, size, 0, 0);
1185  else
1186  retval = m_data_file->Write(b->get_buff(), offset, size);
1187 
1188  if (retval < size)
1189  {
1190  if (retval < 0) {
1191  TRACEF(Error, "WriteToDisk() write error " << retval);
1192  } else {
1193  TRACEF(Error, "WriteToDisk() incomplete block write ret=" << retval << " (should be " << size << ")");
1194  }
1195 
1196  XrdSysCondVarHelper _lck(m_state_cond);
1197 
1198  dec_ref_count(b);
1199 
1200  return;
1201  }
1202 
1203  const int blk_idx = (b->m_offset - m_offset) / m_block_size;
1204 
1205  // Set written bit.
1206  TRACEF(Dump, "WriteToDisk() success set bit for block " << b->m_offset << " size=" << size);
1207 
1208  bool schedule_sync = false;
1209  {
1210  XrdSysCondVarHelper _lck(m_state_cond);
1211 
1212  m_cfi.SetBitWritten(blk_idx);
1213 
1214  if (b->m_prefetch)
1215  {
1216  m_cfi.SetBitPrefetch(blk_idx);
1217  }
1218  if (b->req_cksum_net() && ! b->has_cksums() && m_cfi.IsCkSumNet())
1219  {
1220  m_cfi.ResetCkSumNet();
1221  }
1222 
1223  // Set synced bit or stash block index if in actual sync.
1224  // Synced state is only written out to cinfo file when data file is synced.
1225  if (m_in_sync)
1226  {
1227  m_writes_during_sync.push_back(blk_idx);
1228  }
1229  else
1230  {
1231  m_cfi.SetBitSynced(blk_idx);
1232  ++m_non_flushed_cnt;
1233  if ((m_cfi.IsComplete() || m_non_flushed_cnt >= Cache::GetInstance().RefConfiguration().m_flushCnt) &&
1234  ! m_in_shutdown)
1235  {
1236  schedule_sync = true;
1237  m_in_sync = true;
1238  m_non_flushed_cnt = 0;
1239  }
1240  }
1241  // As soon as the reference count is decreased on the block, the
1242  // file object may be deleted. Thus, to avoid holding both locks at a time,
1243  // we defer the ref count decrease until later if a sync is needed
1244  if (!schedule_sync) {
1245  dec_ref_count(b);
1246  }
1247  }
1248 
1249  if (schedule_sync)
1250  {
1251  cache()->ScheduleFileSync(this);
1252  XrdSysCondVarHelper _lck(m_state_cond);
1253  dec_ref_count(b);
1254  }
1255 }
virtual ssize_t pgWrite(void *buffer, off_t offset, size_t wrlen, uint32_t *csvec, uint64_t opts)
Definition: XrdOss.cc:198
virtual ssize_t Write(const void *buffer, off_t offset, size_t size)
Definition: XrdOss.hh:345
int get_size() const
Definition: XrdPfcFile.hh:143
vCkSum_t & ref_cksum_vec()
Definition: XrdPfcFile.hh:168
char * get_buff() const
Definition: XrdPfcFile.hh:142
bool req_cksum_net() const
Definition: XrdPfcFile.hh:166
bool has_cksums() const
Definition: XrdPfcFile.hh:167
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
Definition: XrdPfc.hh:215
void SetBitPrefetch(int i)
Mark block as obtained through prefetch.
Definition: XrdPfcInfo.hh:365
void ResetCkSumNet()
Definition: XrdPfcInfo.cc:213
bool IsCkSumNet() const
Definition: XrdPfcInfo.hh:290
bool IsCkSumCache() const
Definition: XrdPfcInfo.hh:289
void SetBitWritten(int i)
Mark block as written to disk.
Definition: XrdPfcInfo.hh:352
long long m_flushCnt
nuber of unsynced blcoks on disk before flush is called
Definition: XrdPfc.hh:122

References Error, XrdPfc::Block::get_buff(), XrdPfc::Block::get_size(), XrdPfc::Cache::GetInstance(), XrdPfc::Block::has_cksums(), XrdPfc::Info::IsCkSumCache(), XrdPfc::Info::IsCkSumNet(), XrdPfc::Info::IsComplete(), XrdPfc::Configuration::m_flushCnt, XrdPfc::Block::m_offset, XrdPfc::Block::m_prefetch, XrdOssDF::pgWrite(), XrdPfc::Block::ref_cksum_vec(), XrdPfc::Cache::RefConfiguration(), XrdPfc::Block::req_cksum_net(), XrdPfc::Info::ResetCkSumNet(), XrdPfc::Info::SetBitPrefetch(), XrdPfc::Info::SetBitSynced(), XrdPfc::Info::SetBitWritten(), TRACEF, and XrdOssDF::Write().

Referenced by XrdPfc::Cache::ProcessWriteTasks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ BlockResponseHandler

friend class BlockResponseHandler
friend

Definition at line 212 of file XrdPfcFile.hh.

◆ Cache

friend class Cache
friend

Definition at line 211 of file XrdPfcFile.hh.

◆ DirectResponseHandler

friend class DirectResponseHandler
friend

Definition at line 213 of file XrdPfcFile.hh.


The documentation for this class was generated from the following files: