XRootD
XrdPfc::File Class Reference

#include <XrdPfcFile.hh>

+ Collaboration diagram for XrdPfc::File:

Public Member Functions

 ~File ()
 Destructor. More...
 
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::AStatGetLastAccessStats () const
 
const std::string & GetLocalPath () const
 
XrdSysErrorGetLog ()
 
int GetNBlocks () const
 
int GetNDownloadedBlocks () const
 
int GetPrefetchCountOnIO (IO *io)
 
long long GetPrefetchedBytes () const
 
float GetPrefetchScore () const
 
std::string GetRemoteLocations () const
 
XrdSysTraceGetTrace ()
 
int inc_ref_cnt ()
 
void 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 StatsRefStats () 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 FileFileOpen (const std::string &path, long long offset, long long fileSize)
 Static constructor that also does Open. Returns null ptr if Open fails. More...
 

Friends

class BlockResponseHandler
 
class DirectResponseHandler
 

Detailed Description

Definition at line 208 of file XrdPfcFile.hh.

Constructor & Destructor Documentation

◆ ~File()

File::~File ( )

Destructor.

Definition at line 80 of file XrdPfcFile.cc.

81 {
82  if (m_info_file)
83  {
84  TRACEF(Debug, "~File() close info ");
85  m_info_file->Close();
86  delete m_info_file;
87  m_info_file = nullptr;
88  }
89 
90  if (m_data_file)
91  {
92  TRACEF(Debug, "~File() close output ");
93  m_data_file->Close();
94  delete m_data_file;
95  m_data_file = nullptr;
96  }
97 
98  if (m_resmon_token >= 0)
99  {
100  // Last update of file stats has been sent from the final Sync.
101  Cache::ResMon().register_file_close(m_resmon_token, time(0), m_stats);
102  }
103 
104  TRACEF(Debug, "~File() ended, prefetch score = " << m_prefetch_score);
105 }
#define TRACEF(act, x)
Definition: XrdPfcTrace.hh:67
virtual int Close(long long *retsz=0)=0
static ResourceMonitor & ResMon()
Definition: XrdPfc.cc:136
void register_file_close(int token_id, time_t close_timestamp, const Stats &full_stats)

References XrdOssDF::Close(), Macaroons::Debug, XrdPfc::ResourceMonitor::register_file_close(), XrdPfc::Cache::ResMon(), and TRACEF.

+ Here is the call graph for this function:

Member Function Documentation

◆ AddIO()

void File::AddIO ( IO io)

Definition at line 311 of file XrdPfcFile.cc.

312 {
313  // Called from Cache::GetFile() when a new IO asks for the file.
314 
315  TRACEF(Debug, "AddIO() io = " << (void*)io);
316 
317  time_t now = time(0);
318  std::string loc(io->GetLocation());
319 
320  m_state_cond.Lock();
321 
322  IoSet_i mi = m_io_set.find(io);
323 
324  if (mi == m_io_set.end())
325  {
326  m_io_set.insert(io);
327  io->m_attach_time = now;
328  m_delta_stats.IoAttach();
329 
330  insert_remote_location(loc);
331 
332  if (m_prefetch_state == kStopped)
333  {
334  m_prefetch_state = kOn;
335  cache()->RegisterPrefetchFile(this);
336  }
337  }
338  else
339  {
340  TRACEF(Error, "AddIO() io = " << (void*)io << " already registered.");
341  }
342 
343  m_state_cond.UnLock();
344 }
const char * GetLocation()
Definition: XrdPfcIO.hh:44
void IoAttach()
Definition: XrdPfcStats.hh:85

References Macaroons::Debug, Macaroons::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 173 of file XrdPfcFile.cc.

174 {
175  TRACEF(Dump, "BlockRemovedFromWriteQ() block = " << (void*) b << " idx= " << b->m_offset/m_block_size);
176 
177  XrdSysCondVarHelper _lck(m_state_cond);
178  dec_ref_count(b);
179 }
long long m_offset
Definition: XrdPfcFile.hh:120

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 181 of file XrdPfcFile.cc.

182 {
183  TRACEF(Dump, "BlocksRemovedFromWriteQ() n_blocks = " << blocks.size());
184 
185  XrdSysCondVarHelper _lck(m_state_cond);
186 
187  for (std::list<Block*>::iterator i = blocks.begin(); i != blocks.end(); ++i)
188  {
189  dec_ref_count(*i);
190  }
191 }

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 296 of file XrdPfcFile.hh.

296 { return --m_ref_cnt; }

◆ FileOpen()

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

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

Definition at line 109 of file XrdPfcFile.cc.

110 {
111  File *file = new File(path, offset, fileSize);
112  if ( ! file->Open())
113  {
114  delete file;
115  file = 0;
116  }
117  return file;
118 }

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 287 of file XrdPfcFile.cc.

288 {
289  // Returns true if sync is required.
290  // This method is called after corresponding IO is detached from PosixCache.
291 
292  XrdSysCondVarHelper _lck(m_state_cond);
293  if ( ! m_in_shutdown)
294  {
295  if ( ! m_writes_during_sync.empty() || m_non_flushed_cnt > 0 || ! m_detach_time_logged)
296  {
297  report_and_merge_delta_stats();
298  m_cfi.WriteIOStatDetach(m_stats);
299  m_detach_time_logged = true;
300  m_in_sync = true;
301  TRACEF(Debug, "FinalizeSyncBeforeExit requesting sync to write detach stats");
302  return true;
303  }
304  }
305  TRACEF(Debug, "FinalizeSyncBeforeExit sync not required");
306  return false;
307 }
void WriteIOStatDetach(Stats &s)
Write close time together with bytes missed, hits, and disk.
Definition: XrdPfcInfo.cc:440

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

+ Here is the call graph for this function:

◆ Fstat()

int File::Fstat ( struct stat sbuff)

Definition at line 527 of file XrdPfcFile.cc.

528 {
529  // Stat on an open file.
530  // Corrects size to actual full size of the file.
531  // Sets atime to 0 if the file is only partially downloaded, in accordance
532  // with pfc.onlyifcached settings.
533  // Called from IO::Fstat() and Cache::Stat() when the file is active.
534  // Returns 0 on success, -errno on error.
535 
536  int res;
537 
538  if ((res = m_data_file->Fstat(&sbuff))) return res;
539 
540  sbuff.st_size = m_file_size;
541 
542  bool is_cached = cache()->DecideIfConsideredCached(m_file_size, sbuff.st_blocks * 512ll);
543  if ( ! is_cached)
544  sbuff.st_atime = 0;
545 
546  return 0;
547 }
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 294 of file XrdPfcFile.hh.

294 { return m_ref_cnt; }

◆ GetAccessCnt()

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

Definition at line 284 of file XrdPfcFile.hh.

284 { 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 285 of file XrdPfcFile.hh.

285 { 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 275 of file XrdPfcFile.hh.

275 { 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 283 of file XrdPfcFile.hh.

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

References XrdPfc::Info::GetLastAccessStats().

+ Here is the call graph for this function:

◆ GetLocalPath()

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

Definition at line 270 of file XrdPfcFile.hh.

270 { return m_filename; }

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

+ Here is the caller graph for this function:

◆ GetLog()

XrdSysError * File::GetLog ( )

Definition at line 1594 of file XrdPfcFile.cc.

1595 {
1596  return Cache::GetInstance().GetLog();
1597 }
XrdSysError * GetLog()
Definition: XrdPfc.hh:281
static Cache & GetInstance()
Singleton access.
Definition: XrdPfc.cc:133

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

Referenced by WriteBlockToDisk().

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

◆ GetNBlocks()

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

Definition at line 286 of file XrdPfcFile.hh.

286 { 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 287 of file XrdPfcFile.hh.

287 { 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 288 of file XrdPfcFile.hh.

288 { return m_prefetch_bytes; }

◆ GetPrefetchScore()

float File::GetPrefetchScore ( ) const

Definition at line 1589 of file XrdPfcFile.cc.

1590 {
1591  return m_prefetch_score;
1592 }

◆ GetRemoteLocations()

std::string File::GetRemoteLocations ( ) const

Definition at line 1613 of file XrdPfcFile.cc.

1614 {
1615  std::string s;
1616  if ( ! m_remote_locations.empty())
1617  {
1618  size_t sl = 0;
1619  int nl = 0;
1620  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++nl)
1621  {
1622  sl += i->size();
1623  }
1624  s.reserve(2 + sl + 2*nl + nl - 1 + 1);
1625  s = '[';
1626  int j = 1;
1627  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++j)
1628  {
1629  s += '"'; s += *i; s += '"';
1630  if (j < nl) s += ',';
1631  }
1632  s += ']';
1633  }
1634  else
1635  {
1636  s = "[]";
1637  }
1638  return s;
1639 }

◆ GetTrace()

XrdSysTrace * File::GetTrace ( )

Definition at line 1599 of file XrdPfcFile.cc.

1600 {
1601  return Cache::GetInstance().GetTrace();
1602 }
XrdSysTrace * GetTrace()
Definition: XrdPfc.hh:282

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

+ Here is the call graph for this function:

◆ inc_ref_cnt()

int XrdPfc::File::inc_ref_cnt ( )
inline

Definition at line 295 of file XrdPfcFile.hh.

295 { return ++m_ref_cnt; }

◆ initiate_emergency_shutdown()

void File::initiate_emergency_shutdown ( )

Definition at line 122 of file XrdPfcFile.cc.

123 {
124  // Called from Cache::Unlink() when the file is currently open.
125  // Cache::Unlink is also called on FSync error and when wrong number of bytes
126  // is received from a remote read.
127  //
128  // From this point onward the file will not be written to, cinfo file will
129  // not be updated, and all new read requests will return -ENOENT.
130  //
131  // File's entry in the Cache's active map is set to nullptr and will be
132  // removed from there shortly, in any case, well before this File object
133  // shuts down. So we do not communicate to Cache about our destruction when
134  // it happens.
135 
136  {
137  XrdSysCondVarHelper _lck(m_state_cond);
138 
139  m_in_shutdown = true;
140 
141  if (m_prefetch_state != kStopped && m_prefetch_state != kComplete)
142  {
143  m_prefetch_state = kStopped;
144  cache()->DeRegisterPrefetchFile(this);
145  }
146  }
147 }

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 204 of file XrdPfcFile.cc.

205 {
206  // Returns true if delay is needed.
207 
208  TRACEF(Debug, "ioActive start for io " << io);
209 
210  std::string loc(io->GetLocation());
211 
212  {
213  XrdSysCondVarHelper _lck(m_state_cond);
214 
215  IoSet_i mi = m_io_set.find(io);
216 
217  if (mi != m_io_set.end())
218  {
219  unsigned int n_active_reads = io->m_active_read_reqs;
220 
221  TRACE(Info, "ioActive for io " << io <<
222  ", active_reads " << n_active_reads <<
223  ", active_prefetches " << io->m_active_prefetches <<
224  ", allow_prefetching " << io->m_allow_prefetching <<
225  ", ios_in_detach " << m_ios_in_detach);
226  TRACEF(Info,
227  "\tio_map.size() " << m_io_set.size() <<
228  ", block_map.size() " << m_block_map.size() << ", file");
229 
230  insert_remote_location(loc);
231 
232  io->m_allow_prefetching = false;
233  io->m_in_detach = true;
234 
235  // Check if any IO is still available for prfetching. If not, stop it.
236  if (m_prefetch_state == kOn || m_prefetch_state == kHold)
237  {
238  if ( ! select_current_io_or_disable_prefetching(false) )
239  {
240  TRACEF(Debug, "ioActive stopping prefetching after io " << io << " retreat.");
241  }
242  }
243 
244  // On last IO, consider write queue blocks. Note, this also contains
245  // blocks being prefetched.
246 
247  bool io_active_result;
248 
249  if (n_active_reads > 0)
250  {
251  io_active_result = true;
252  }
253  else if (m_io_set.size() - m_ios_in_detach == 1)
254  {
255  io_active_result = ! m_block_map.empty();
256  }
257  else
258  {
259  io_active_result = io->m_active_prefetches > 0;
260  }
261 
262  if ( ! io_active_result)
263  {
264  ++m_ios_in_detach;
265  }
266 
267  TRACEF(Info, "ioActive for io " << io << " returning " << io_active_result << ", file");
268 
269  return io_active_result;
270  }
271  else
272  {
273  TRACEF(Error, "ioActive io " << io <<" not found in IoSet. This should not happen.");
274  return false;
275  }
276  }
277 }
#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 Macaroons::Debug, Macaroons::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 195 of file XrdPfcFile.cc.

196 {
197  std::string loc(io->GetLocation());
198  XrdSysCondVarHelper _lck(m_state_cond);
199  insert_remote_location(loc);
200 }

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 299 of file XrdPfcFile.hh.

299 { return m_in_shutdown; }

◆ lPath()

const char * File::lPath ( ) const

Log path.

Definition at line 1501 of file XrdPfcFile.cc.

1502 {
1503  return m_filename.c_str();
1504 }

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

+ Here is the caller graph for this function:

◆ Prefetch()

void File::Prefetch ( )

Definition at line 1516 of file XrdPfcFile.cc.

1517 {
1518  // Check that block is not on disk and not in RAM.
1519  // TODO: Could prefetch several blocks at once!
1520  // blks_max could be an argument
1521 
1522  BlockList_t blks;
1523 
1524  TRACEF(DumpXL, "Prefetch() entering.");
1525  {
1526  XrdSysCondVarHelper _lck(m_state_cond);
1527 
1528  if (m_prefetch_state != kOn)
1529  {
1530  return;
1531  }
1532 
1533  if ( ! select_current_io_or_disable_prefetching(true) )
1534  {
1535  TRACEF(Error, "Prefetch no available IO object found, prefetching stopped. This should not happen, i.e., prefetching should be stopped before.");
1536  return;
1537  }
1538 
1539  // Select block(s) to fetch.
1540  for (int f = 0; f < m_num_blocks; ++f)
1541  {
1542  if ( ! m_cfi.TestBitWritten(f))
1543  {
1544  int f_act = f + m_offset / m_block_size;
1545 
1546  BlockMap_i bi = m_block_map.find(f_act);
1547  if (bi == m_block_map.end())
1548  {
1549  Block *b = PrepareBlockRequest(f_act, *m_current_io, nullptr, true);
1550  if (b)
1551  {
1552  TRACEF(Dump, "Prefetch take block " << f_act);
1553  blks.push_back(b);
1554  // Note: block ref_cnt not increased, it will be when placed into write queue.
1555 
1556  inc_prefetch_read_cnt(1);
1557  }
1558  else
1559  {
1560  // This shouldn't happen as prefetching stops when RAM is 70% full.
1561  TRACEF(Warning, "Prefetch allocation failed for block " << f_act);
1562  }
1563  break;
1564  }
1565  }
1566  }
1567 
1568  if (blks.empty())
1569  {
1570  TRACEF(Debug, "Prefetch file is complete, stopping prefetch.");
1571  m_prefetch_state = kComplete;
1572  cache()->DeRegisterPrefetchFile(this);
1573  }
1574  else
1575  {
1576  (*m_current_io)->m_active_prefetches += (int) blks.size();
1577  }
1578  }
1579 
1580  if ( ! blks.empty())
1581  {
1582  ProcessBlockRequests(blks);
1583  }
1584 }
@ Warning
bool TestBitWritten(int i) const
Test if block at the given index is written to disk.
Definition: XrdPfcInfo.hh:343
std::list< Block * > BlockList_t
Definition: XrdPfcFile.hh:172

References Macaroons::Debug, Macaroons::Error, XrdPfc::Info::TestBitWritten(), TRACEF, and 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 712 of file XrdPfcFile.cc.

713 {
714  // rrc_func is ONLY called from async processing.
715  // If this function returns anything other than -EWOULDBLOCK, rrc_func needs to be called by the caller.
716  // This streamlines implementation of synchronous IO::Read().
717 
718  TRACEF(Dump, "Read() sid: " << Xrd::hex1 << rh->m_seq_id << " size: " << iUserSize);
719 
720  m_state_cond.Lock();
721 
722  if (m_in_shutdown || io->m_in_detach)
723  {
724  m_state_cond.UnLock();
725  return m_in_shutdown ? -ENOENT : -EBADF;
726  }
727 
728  // Shortcut -- file is fully downloaded.
729 
730  if (m_cfi.IsComplete())
731  {
732  m_state_cond.UnLock();
733  int ret = m_data_file->Read(iUserBuff, iUserOff, iUserSize);
734  if (ret > 0) {
735  XrdSysCondVarHelper _lck(m_state_cond);
736  m_delta_stats.AddBytesHit(ret);
737  check_delta_stats();
738  }
739  return ret;
740  }
741 
742  XrdOucIOVec readV( { iUserOff, iUserSize, 0, iUserBuff } );
743 
744  return ReadOpusCoalescere(io, &readV, 1, rh, "Read() ");
745 }
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:59

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 749 of file XrdPfcFile.cc.

750 {
751  TRACEF(Dump, "ReadV() for " << readVnum << " chunks.");
752 
753  m_state_cond.Lock();
754 
755  if (m_in_shutdown || io->m_in_detach)
756  {
757  m_state_cond.UnLock();
758  return m_in_shutdown ? -ENOENT : -EBADF;
759  }
760 
761  // Shortcut -- file is fully downloaded.
762 
763  if (m_cfi.IsComplete())
764  {
765  m_state_cond.UnLock();
766  int ret = m_data_file->ReadV(const_cast<XrdOucIOVec*>(readV), readVnum);
767  if (ret > 0) {
768  XrdSysCondVarHelper _lck(m_state_cond);
769  m_delta_stats.AddBytesHit(ret);
770  check_delta_stats();
771  }
772  return ret;
773  }
774 
775  return ReadOpusCoalescere(io, readV, readVnum, rh, "ReadV() ");
776 }
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 289 of file XrdPfcFile.hh.

289 { return m_stats; }

◆ RemoveIO()

void File::RemoveIO ( IO io)

Definition at line 348 of file XrdPfcFile.cc.

349 {
350  // Called from Cache::ReleaseFile.
351 
352  TRACEF(Debug, "RemoveIO() io = " << (void*)io);
353 
354  time_t now = time(0);
355 
356  m_state_cond.Lock();
357 
358  IoSet_i mi = m_io_set.find(io);
359 
360  if (mi != m_io_set.end())
361  {
362  if (mi == m_current_io)
363  {
364  ++m_current_io;
365  }
366 
367  m_delta_stats.IoDetach(now - io->m_attach_time);
368  m_io_set.erase(mi);
369  --m_ios_in_detach;
370 
371  if (m_io_set.empty() && m_prefetch_state != kStopped && m_prefetch_state != kComplete)
372  {
373  TRACEF(Error, "RemoveIO() io = " << (void*)io << " Prefetching is not stopped/complete -- it should be by now.");
374  m_prefetch_state = kStopped;
375  cache()->DeRegisterPrefetchFile(this);
376  }
377  }
378  else
379  {
380  TRACEF(Error, "RemoveIO() io = " << (void*)io << " is NOT registered.");
381  }
382 
383  m_state_cond.UnLock();
384 }
void IoDetach(int duration)
Definition: XrdPfcStats.hh:90

References Macaroons::Debug, Macaroons::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 281 of file XrdPfcFile.cc.

282 {
283  XrdSysCondVarHelper _lck(m_state_cond);
284  m_detach_time_logged = false;
285 }

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 1115 of file XrdPfcFile.cc.

1116 {
1117  TRACEF(Dump, "Sync()");
1118 
1119  int ret = m_data_file->Fsync();
1120  bool errorp = false;
1121  if (ret == XrdOssOK)
1122  {
1123  Stats loc_stats;
1124  {
1125  XrdSysCondVarHelper _lck(&m_state_cond);
1126  report_and_merge_delta_stats();
1127  loc_stats = m_stats;
1128  }
1129  m_cfi.WriteIOStat(loc_stats);
1130  m_cfi.Write(m_info_file, m_filename.c_str());
1131  int cret = m_info_file->Fsync();
1132  if (cret != XrdOssOK)
1133  {
1134  TRACEF(Error, "Sync cinfo file sync error " << cret);
1135  errorp = true;
1136  }
1137  }
1138  else
1139  {
1140  TRACEF(Error, "Sync data file sync error " << ret << ", cinfo file has not been updated");
1141  errorp = true;
1142  }
1143 
1144  if (errorp)
1145  {
1146  TRACEF(Error, "Sync failed, unlinking local files and initiating shutdown of File object");
1147 
1148  // Unlink will also call this->initiate_emergency_shutdown()
1149  Cache::GetInstance().UnlinkFile(m_filename, false);
1150 
1151  XrdSysCondVarHelper _lck(&m_state_cond);
1152 
1153  m_writes_during_sync.clear();
1154  m_in_sync = false;
1155 
1156  return;
1157  }
1158 
1159  int written_while_in_sync;
1160  bool resync = false;
1161  {
1162  XrdSysCondVarHelper _lck(&m_state_cond);
1163  for (std::vector<int>::iterator i = m_writes_during_sync.begin(); i != m_writes_during_sync.end(); ++i)
1164  {
1165  m_cfi.SetBitSynced(*i);
1166  }
1167  written_while_in_sync = m_non_flushed_cnt = (int) m_writes_during_sync.size();
1168  m_writes_during_sync.clear();
1169 
1170  // If there were writes during sync and the file is now complete,
1171  // let us call Sync again without resetting the m_in_sync flag.
1172  if (written_while_in_sync > 0 && m_cfi.IsComplete() && ! m_in_shutdown)
1173  resync = true;
1174  else
1175  m_in_sync = false;
1176  }
1177  TRACEF(Dump, "Sync "<< written_while_in_sync << " blocks written during sync." << (resync ? " File is now complete - resyncing." : ""));
1178 
1179  if (resync)
1180  Sync();
1181 }
#define XrdOssOK
Definition: XrdOss.hh:50
virtual int Fsync()
Definition: XrdOss.hh:144
int UnlinkFile(const std::string &f_name, bool fail_if_open)
Remove cinfo and data files from cache.
Definition: XrdPfc.cc:1163
void Sync()
Sync file cache inf o and output data with disk.
Definition: XrdPfcFile.cc:1115
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:268
void WriteIOStat(Stats &s)
Write bytes missed, hits, and disk.
Definition: XrdPfcInfo.cc:431
Statistics of cache utilisation by a File object.
Definition: XrdPfcStats.hh:35

References Macaroons::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 1032 of file XrdPfcFile.cc.

1033 {
1034  // write block buffer into disk file
1035  long long offset = b->m_offset - m_offset;
1036  long long size = b->get_size();
1037  ssize_t retval;
1038 
1039  if (m_cfi.IsCkSumCache())
1040  if (b->has_cksums())
1041  retval = m_data_file->pgWrite(b->get_buff(), offset, size, b->ref_cksum_vec().data(), 0);
1042  else
1043  retval = m_data_file->pgWrite(b->get_buff(), offset, size, 0, 0);
1044  else
1045  retval = m_data_file->Write(b->get_buff(), offset, size);
1046 
1047  if (retval < size)
1048  {
1049  if (retval < 0)
1050  {
1051  GetLog()->Emsg("WriteToDisk()", -retval, "write block to disk", GetLocalPath().c_str());
1052  }
1053  else
1054  {
1055  TRACEF(Error, "WriteToDisk() incomplete block write ret=" << retval << " (should be " << size << ")");
1056  }
1057 
1058  XrdSysCondVarHelper _lck(m_state_cond);
1059 
1060  dec_ref_count(b);
1061 
1062  return;
1063  }
1064 
1065  const int blk_idx = (b->m_offset - m_offset) / m_block_size;
1066 
1067  // Set written bit.
1068  TRACEF(Dump, "WriteToDisk() success set bit for block " << b->m_offset << " size=" << size);
1069 
1070  bool schedule_sync = false;
1071  {
1072  XrdSysCondVarHelper _lck(m_state_cond);
1073 
1074  m_cfi.SetBitWritten(blk_idx);
1075 
1076  if (b->m_prefetch)
1077  {
1078  m_cfi.SetBitPrefetch(blk_idx);
1079  }
1080  if (b->req_cksum_net() && ! b->has_cksums() && m_cfi.IsCkSumNet())
1081  {
1082  m_cfi.ResetCkSumNet();
1083  }
1084 
1085  dec_ref_count(b);
1086 
1087  // Set synced bit or stash block index if in actual sync.
1088  // Synced state is only written out to cinfo file when data file is synced.
1089  if (m_in_sync)
1090  {
1091  m_writes_during_sync.push_back(blk_idx);
1092  }
1093  else
1094  {
1095  m_cfi.SetBitSynced(blk_idx);
1096  ++m_non_flushed_cnt;
1097  if ((m_cfi.IsComplete() || m_non_flushed_cnt >= Cache::GetInstance().RefConfiguration().m_flushCnt) &&
1098  ! m_in_shutdown)
1099  {
1100  schedule_sync = true;
1101  m_in_sync = true;
1102  m_non_flushed_cnt = 0;
1103  }
1104  }
1105  }
1106 
1107  if (schedule_sync)
1108  {
1109  cache()->ScheduleFileSync(this);
1110  }
1111 }
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:142
vCkSum_t & ref_cksum_vec()
Definition: XrdPfcFile.hh:167
char * get_buff() const
Definition: XrdPfcFile.hh:141
bool req_cksum_net() const
Definition: XrdPfcFile.hh:165
bool has_cksums() const
Definition: XrdPfcFile.hh:166
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
Definition: XrdPfc.hh:203
XrdSysError * GetLog()
Definition: XrdPfcFile.cc:1594
const std::string & GetLocalPath() const
Definition: XrdPfcFile.hh:270
void SetBitPrefetch(int i)
Mark block as obtained through prefetch.
Definition: XrdPfcInfo.hh:365
void ResetCkSumNet()
Definition: XrdPfcInfo.cc:215
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
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
long long m_flushCnt
nuber of unsynced blcoks on disk before flush is called
Definition: XrdPfc.hh:115

References XrdSysError::Emsg(), Macaroons::Error, XrdPfc::Block::get_buff(), XrdPfc::Block::get_size(), XrdPfc::Cache::GetInstance(), GetLocalPath(), GetLog(), 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 210 of file XrdPfcFile.hh.

◆ DirectResponseHandler

friend class DirectResponseHandler
friend

Definition at line 211 of file XrdPfcFile.hh.


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