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 ()
 
Stats DeltaStatsFromLastCall ()
 
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 Info::AStatGetLastAccessStats () const
 
std::string & GetLocalPath ()
 
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 213 of file XrdPfcFile.hh.

Constructor & Destructor Documentation

◆ ~File()

File::~File ( )

Destructor.

Definition at line 77 of file XrdPfcFile.cc.

78 {
79  if (m_info_file)
80  {
81  TRACEF(Debug, "~File() close info ");
82  m_info_file->Close();
83  delete m_info_file;
84  m_info_file = NULL;
85  }
86 
87  if (m_data_file)
88  {
89  TRACEF(Debug, "~File() close output ");
90  m_data_file->Close();
91  delete m_data_file;
92  m_data_file = NULL;
93  }
94 
95  TRACEF(Debug, "~File() ended, prefetch score = " << m_prefetch_score);
96 }
#define TRACEF(act, x)
Definition: XrdPfcTrace.hh:67
bool Debug
virtual int Close(long long *retsz=0)=0

References XrdOssDF::Close(), Debug, and TRACEF.

+ Here is the call graph for this function:

Member Function Documentation

◆ AddIO()

void File::AddIO ( IO io)

Definition at line 296 of file XrdPfcFile.cc.

297 {
298  // Called from Cache::GetFile() when a new IO asks for the file.
299 
300  TRACEF(Debug, "AddIO() io = " << (void*)io);
301 
302  time_t now = time(0);
303  std::string loc(io->GetLocation());
304 
305  m_state_cond.Lock();
306 
307  IoSet_i mi = m_io_set.find(io);
308 
309  if (mi == m_io_set.end())
310  {
311  m_io_set.insert(io);
312  io->m_attach_time = now;
313  m_stats.IoAttach();
314 
315  insert_remote_location(loc);
316 
317  if (m_prefetch_state == kStopped)
318  {
319  m_prefetch_state = kOn;
320  cache()->RegisterPrefetchFile(this);
321  }
322  }
323  else
324  {
325  TRACEF(Error, "AddIO() io = " << (void*)io << " already registered.");
326  }
327 
328  m_state_cond.UnLock();
329 }
@ Error
const char * GetLocation()
Definition: XrdPfcIO.hh:46
void IoAttach()
Definition: XrdPfcStats.hh:83

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

159 {
160  TRACEF(Dump, "BlockRemovedFromWriteQ() block = " << (void*) b << " idx= " << b->m_offset/m_block_size);
161 
162  XrdSysCondVarHelper _lck(m_state_cond);
163  dec_ref_count(b);
164 }
long long m_offset
Definition: XrdPfcFile.hh:125

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

167 {
168  TRACEF(Dump, "BlocksRemovedFromWriteQ() n_blocks = " << blocks.size());
169 
170  XrdSysCondVarHelper _lck(m_state_cond);
171 
172  for (std::list<Block*>::iterator i = blocks.begin(); i != blocks.end(); ++i)
173  {
174  dec_ref_count(*i);
175  }
176 }

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

303 { return --m_ref_cnt; }

◆ DeltaStatsFromLastCall()

Stats File::DeltaStatsFromLastCall ( )

Definition at line 143 of file XrdPfcFile.cc.

144 {
145  // Not locked, only used from Cache / Purge thread.
146 
147  Stats delta = m_last_stats;
148 
149  m_last_stats = m_stats.Clone();
150 
151  delta.DeltaToReference(m_last_stats);
152 
153  return delta;
154 }
Statistics of cache utilisation by a File object.
Definition: XrdPfcStats.hh:31
Stats Clone()
Definition: XrdPfcStats.hh:97
void DeltaToReference(const Stats &ref)
Definition: XrdPfcStats.hh:106

References XrdPfc::Stats::Clone(), and XrdPfc::Stats::DeltaToReference().

+ Here is the call graph for this function:

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

101 {
102  File *file = new File(path, offset, fileSize);
103  if ( ! file->Open())
104  {
105  delete file;
106  file = 0;
107  }
108  return file;
109 }

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

273 {
274  // Returns true if sync is required.
275  // This method is called after corresponding IO is detached from PosixCache.
276 
277  XrdSysCondVarHelper _lck(m_state_cond);
278  if ( ! m_in_shutdown)
279  {
280  if ( ! m_writes_during_sync.empty() || m_non_flushed_cnt > 0 || ! m_detach_time_logged)
281  {
282  Stats loc_stats = m_stats.Clone();
283  m_cfi.WriteIOStatDetach(loc_stats);
284  m_detach_time_logged = true;
285  m_in_sync = true;
286  TRACEF(Debug, "FinalizeSyncBeforeExit requesting sync to write detach stats");
287  return true;
288  }
289  }
290  TRACEF(Debug, "FinalizeSyncBeforeExit sync not required");
291  return false;
292 }
void WriteIOStatDetach(Stats &s)
Write close time together with bytes missed, hits, and disk.
Definition: XrdPfcInfo.cc:440

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

+ Here is the call graph for this function:

◆ Fstat()

int File::Fstat ( struct stat sbuff)

Definition at line 491 of file XrdPfcFile.cc.

492 {
493  // Stat on an open file.
494  // Corrects size to actual full size of the file.
495  // Sets atime to 0 if the file is only partially downloaded, in accordance
496  // with pfc.onlyifcached settings.
497  // Called from IO::Fstat() and Cache::Stat() when the file is active.
498  // Returns 0 on success, -errno on error.
499 
500  int res;
501 
502  if ((res = m_data_file->Fstat(&sbuff))) return res;
503 
504  sbuff.st_size = m_file_size;
505 
506  bool is_cached = cache()->DecideIfConsideredCached(m_file_size, sbuff.st_blocks * 512ll);
507  if ( ! is_cached)
508  sbuff.st_atime = 0;
509 
510  return 0;
511 }
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 301 of file XrdPfcFile.hh.

301 { return m_ref_cnt; }

◆ GetAccessCnt()

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

Definition at line 291 of file XrdPfcFile.hh.

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

References XrdPfc::Info::GetAccessCnt().

+ Here is the call graph for this function:

◆ GetBlockSize()

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

Definition at line 292 of file XrdPfcFile.hh.

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

References XrdPfc::Info::GetBufferSize().

+ Here is the call graph for this function:

◆ GetFileSize()

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

Definition at line 280 of file XrdPfcFile.hh.

280 { 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 290 of file XrdPfcFile.hh.

290 { 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()

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

Definition at line 275 of file XrdPfcFile.hh.

275 { 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 1540 of file XrdPfcFile.cc.

1541 {
1542  return Cache::GetInstance().GetLog();
1543 }
XrdSysError * GetLog()
Definition: XrdPfc.hh:401
static Cache & GetInstance()
Singleton access.
Definition: XrdPfc.cc:163

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

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

References XrdPfc::Info::GetNBlocks().

+ Here is the call graph for this function:

◆ GetNDownloadedBlocks()

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

Definition at line 294 of file XrdPfcFile.hh.

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

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

295 { return m_prefetch_bytes; }

◆ GetPrefetchScore()

float File::GetPrefetchScore ( ) const

Definition at line 1535 of file XrdPfcFile.cc.

1536 {
1537  return m_prefetch_score;
1538 }

◆ GetRemoteLocations()

std::string File::GetRemoteLocations ( ) const

Definition at line 1559 of file XrdPfcFile.cc.

1560 {
1561  std::string s;
1562  if ( ! m_remote_locations.empty())
1563  {
1564  size_t sl = 0;
1565  int nl = 0;
1566  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++nl)
1567  {
1568  sl += i->size();
1569  }
1570  s.reserve(2 + sl + 2*nl + nl - 1 + 1);
1571  s = '[';
1572  int j = 1;
1573  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++j)
1574  {
1575  s += '"'; s += *i; s += '"';
1576  if (j < nl) s += ',';
1577  }
1578  s += ']';
1579  }
1580  else
1581  {
1582  s = "[]";
1583  }
1584  return s;
1585 }

◆ GetTrace()

XrdSysTrace * File::GetTrace ( )

Definition at line 1545 of file XrdPfcFile.cc.

1546 {
1547  return Cache::GetInstance().GetTrace();
1548 }
XrdSysTrace * GetTrace()
Definition: XrdPfc.hh:402

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

302 { return ++m_ref_cnt; }

◆ initiate_emergency_shutdown()

void File::initiate_emergency_shutdown ( )

Definition at line 113 of file XrdPfcFile.cc.

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

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

190 {
191  // Returns true if delay is needed.
192 
193  TRACEF(Debug, "ioActive start for io " << io);
194 
195  std::string loc(io->GetLocation());
196 
197  {
198  XrdSysCondVarHelper _lck(m_state_cond);
199 
200  IoSet_i mi = m_io_set.find(io);
201 
202  if (mi != m_io_set.end())
203  {
204  unsigned int n_active_reads = io->m_active_read_reqs;
205 
206  TRACE(Info, "ioActive for io " << io <<
207  ", active_reads " << n_active_reads <<
208  ", active_prefetches " << io->m_active_prefetches <<
209  ", allow_prefetching " << io->m_allow_prefetching <<
210  ", ios_in_detach " << m_ios_in_detach);
211  TRACEF(Info,
212  "\tio_map.size() " << m_io_set.size() <<
213  ", block_map.size() " << m_block_map.size() << ", file");
214 
215  insert_remote_location(loc);
216 
217  io->m_allow_prefetching = false;
218  io->m_in_detach = true;
219 
220  // Check if any IO is still available for prfetching. If not, stop it.
221  if (m_prefetch_state == kOn || m_prefetch_state == kHold)
222  {
223  if ( ! select_current_io_or_disable_prefetching(false) )
224  {
225  TRACEF(Debug, "ioActive stopping prefetching after io " << io << " retreat.");
226  }
227  }
228 
229  // On last IO, consider write queue blocks. Note, this also contains
230  // blocks being prefetched.
231 
232  bool io_active_result;
233 
234  if (n_active_reads > 0)
235  {
236  io_active_result = true;
237  }
238  else if (m_io_set.size() - m_ios_in_detach == 1)
239  {
240  io_active_result = ! m_block_map.empty();
241  }
242  else
243  {
244  io_active_result = io->m_active_prefetches > 0;
245  }
246 
247  if ( ! io_active_result)
248  {
249  ++m_ios_in_detach;
250  }
251 
252  TRACEF(Info, "ioActive for io " << io << " returning " << io_active_result << ", file");
253 
254  return io_active_result;
255  }
256  else
257  {
258  TRACEF(Error, "ioActive io " << io <<" not found in IoSet. This should not happen.");
259  return false;
260  }
261  }
262 }
#define TRACE(act, x)
Definition: XrdTrace.hh:63
RAtomic_int m_active_read_reqs
number of active read requests
Definition: XrdPfcIO.hh:72
Status of cached file. Can be read from and written into a binary file.
Definition: XrdPfcInfo.hh:45

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

181 {
182  std::string loc(io->GetLocation());
183  XrdSysCondVarHelper _lck(m_state_cond);
184  insert_remote_location(loc);
185 }

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

306 { return m_in_shutdown; }

◆ lPath()

const char * File::lPath ( ) const

Log path.

Definition at line 1447 of file XrdPfcFile.cc.

1448 {
1449  return m_filename.c_str();
1450 }

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

+ Here is the caller graph for this function:

◆ Prefetch()

void File::Prefetch ( )

Definition at line 1462 of file XrdPfcFile.cc.

1463 {
1464  // Check that block is not on disk and not in RAM.
1465  // TODO: Could prefetch several blocks at once!
1466  // blks_max could be an argument
1467 
1468  BlockList_t blks;
1469 
1470  TRACEF(DumpXL, "Prefetch() entering.");
1471  {
1472  XrdSysCondVarHelper _lck(m_state_cond);
1473 
1474  if (m_prefetch_state != kOn)
1475  {
1476  return;
1477  }
1478 
1479  if ( ! select_current_io_or_disable_prefetching(true) )
1480  {
1481  TRACEF(Error, "Prefetch no available IO object found, prefetching stopped. This should not happen, i.e., prefetching should be stopped before.");
1482  return;
1483  }
1484 
1485  // Select block(s) to fetch.
1486  for (int f = 0; f < m_num_blocks; ++f)
1487  {
1488  if ( ! m_cfi.TestBitWritten(f))
1489  {
1490  int f_act = f + m_offset / m_block_size;
1491 
1492  BlockMap_i bi = m_block_map.find(f_act);
1493  if (bi == m_block_map.end())
1494  {
1495  Block *b = PrepareBlockRequest(f_act, *m_current_io, nullptr, true);
1496  if (b)
1497  {
1498  TRACEF(Dump, "Prefetch take block " << f_act);
1499  blks.push_back(b);
1500  // Note: block ref_cnt not increased, it will be when placed into write queue.
1501 
1502  inc_prefetch_read_cnt(1);
1503  }
1504  else
1505  {
1506  // This shouldn't happen as prefetching stops when RAM is 70% full.
1507  TRACEF(Warning, "Prefetch allocation failed for block " << f_act);
1508  }
1509  break;
1510  }
1511  }
1512  }
1513 
1514  if (blks.empty())
1515  {
1516  TRACEF(Debug, "Prefetch file is complete, stopping prefetch.");
1517  m_prefetch_state = kComplete;
1518  cache()->DeRegisterPrefetchFile(this);
1519  }
1520  else
1521  {
1522  (*m_current_io)->m_active_prefetches += (int) blks.size();
1523  }
1524  }
1525 
1526  if ( ! blks.empty())
1527  {
1528  ProcessBlockRequests(blks);
1529  }
1530 }
bool TestBitWritten(int i) const
Test if block at the given index is written to disk.
Definition: XrdPfcInfo.hh:347
std::list< Block * > BlockList_t
Definition: XrdPfcFile.hh:177

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

677 {
678  // rrc_func is ONLY called from async processing.
679  // If this function returns anything other than -EWOULDBLOCK, rrc_func needs to be called by the caller.
680  // This streamlines implementation of synchronous IO::Read().
681 
682  TRACEF(Dump, "Read() sid: " << Xrd::hex1 << rh->m_seq_id << " size: " << iUserSize);
683 
684  m_state_cond.Lock();
685 
686  if (m_in_shutdown || io->m_in_detach)
687  {
688  m_state_cond.UnLock();
689  return m_in_shutdown ? -ENOENT : -EBADF;
690  }
691 
692  // Shortcut -- file is fully downloaded.
693 
694  if (m_cfi.IsComplete())
695  {
696  m_state_cond.UnLock();
697  int ret = m_data_file->Read(iUserBuff, iUserOff, iUserSize);
698  if (ret > 0) m_stats.AddBytesHit(ret);
699  return ret;
700  }
701 
702  XrdOucIOVec readV( { iUserOff, iUserSize, 0, iUserBuff } );
703 
704  return ReadOpusCoalescere(io, &readV, 1, rh, "Read() ");
705 }
virtual ssize_t Read(off_t offset, size_t size)
Definition: XrdOss.hh:281
bool IsComplete() const
Get complete status.
Definition: XrdPfcInfo.hh:451
void AddBytesHit(long long bh)
Definition: XrdPfcStats.hh:68
@ hex1
Definition: XrdSysTrace.hh:42
unsigned short m_seq_id
Definition: XrdPfcFile.hh:64

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

710 {
711  TRACEF(Dump, "ReadV() for " << readVnum << " chunks.");
712 
713  m_state_cond.Lock();
714 
715  if (m_in_shutdown || io->m_in_detach)
716  {
717  m_state_cond.UnLock();
718  return m_in_shutdown ? -ENOENT : -EBADF;
719  }
720 
721  // Shortcut -- file is fully downloaded.
722 
723  if (m_cfi.IsComplete())
724  {
725  m_state_cond.UnLock();
726  int ret = m_data_file->ReadV(const_cast<XrdOucIOVec*>(readV), readVnum);
727  if (ret > 0) m_stats.AddBytesHit(ret);
728  return ret;
729  }
730 
731  return ReadOpusCoalescere(io, readV, readVnum, rh, "ReadV() ");
732 }
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 296 of file XrdPfcFile.hh.

296 { return m_stats; }

◆ RemoveIO()

void File::RemoveIO ( IO io)

Definition at line 333 of file XrdPfcFile.cc.

334 {
335  // Called from Cache::ReleaseFile.
336 
337  TRACEF(Debug, "RemoveIO() io = " << (void*)io);
338 
339  time_t now = time(0);
340 
341  m_state_cond.Lock();
342 
343  IoSet_i mi = m_io_set.find(io);
344 
345  if (mi != m_io_set.end())
346  {
347  if (mi == m_current_io)
348  {
349  ++m_current_io;
350  }
351 
352  m_stats.IoDetach(now - io->m_attach_time);
353  m_io_set.erase(mi);
354  --m_ios_in_detach;
355 
356  if (m_io_set.empty() && m_prefetch_state != kStopped && m_prefetch_state != kComplete)
357  {
358  TRACEF(Error, "RemoveIO() io = " << (void*)io << " Prefetching is not stopped/complete -- it should be by now.");
359  m_prefetch_state = kStopped;
360  cache()->DeRegisterPrefetchFile(this);
361  }
362  }
363  else
364  {
365  TRACEF(Error, "RemoveIO() io = " << (void*)io << " is NOT registered.");
366  }
367 
368  m_state_cond.UnLock();
369 }
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 266 of file XrdPfcFile.cc.

267 {
268  XrdSysCondVarHelper _lck(m_state_cond);
269  m_detach_time_logged = false;
270 }

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

1071 {
1072  TRACEF(Dump, "Sync()");
1073 
1074  int ret = m_data_file->Fsync();
1075  bool errorp = false;
1076  if (ret == XrdOssOK)
1077  {
1078  Stats loc_stats = m_stats.Clone();
1079  m_cfi.WriteIOStat(loc_stats);
1080  m_cfi.Write(m_info_file, m_filename.c_str());
1081  int cret = m_info_file->Fsync();
1082  if (cret != XrdOssOK)
1083  {
1084  TRACEF(Error, "Sync cinfo file sync error " << cret);
1085  errorp = true;
1086  }
1087  }
1088  else
1089  {
1090  TRACEF(Error, "Sync data file sync error " << ret << ", cinfo file has not been updated");
1091  errorp = true;
1092  }
1093 
1094  if (errorp)
1095  {
1096  TRACEF(Error, "Sync failed, unlinking local files and initiating shutdown of File object");
1097 
1098  // Unlink will also call this->initiate_emergency_shutdown()
1099  Cache::GetInstance().UnlinkFile(m_filename, false);
1100 
1101  XrdSysCondVarHelper _lck(&m_state_cond);
1102 
1103  m_writes_during_sync.clear();
1104  m_in_sync = false;
1105 
1106  return;
1107  }
1108 
1109  int written_while_in_sync;
1110  bool resync = false;
1111  {
1112  XrdSysCondVarHelper _lck(&m_state_cond);
1113  for (std::vector<int>::iterator i = m_writes_during_sync.begin(); i != m_writes_during_sync.end(); ++i)
1114  {
1115  m_cfi.SetBitSynced(*i);
1116  }
1117  written_while_in_sync = m_non_flushed_cnt = (int) m_writes_during_sync.size();
1118  m_writes_during_sync.clear();
1119 
1120  // If there were writes during sync and the file is now complete,
1121  // let us call Sync again without resetting the m_in_sync flag.
1122  if (written_while_in_sync > 0 && m_cfi.IsComplete() && ! m_in_shutdown)
1123  resync = true;
1124  else
1125  m_in_sync = false;
1126  }
1127  TRACEF(Dump, "Sync "<< written_while_in_sync << " blocks written during sync." << (resync ? " File is now complete - resyncing." : ""));
1128 
1129  if (resync)
1130  Sync();
1131 }
#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:1171
void Sync()
Sync file cache inf o and output data with disk.
Definition: XrdPfcFile.cc:1070
void SetBitSynced(int i)
Mark block as synced to disk.
Definition: XrdPfcInfo.hh:391
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

References XrdPfc::Stats::Clone(), 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 987 of file XrdPfcFile.cc.

988 {
989  // write block buffer into disk file
990  long long offset = b->m_offset - m_offset;
991  long long size = b->get_size();
992  ssize_t retval;
993 
994  if (m_cfi.IsCkSumCache())
995  if (b->has_cksums())
996  retval = m_data_file->pgWrite(b->get_buff(), offset, size, b->ref_cksum_vec().data(), 0);
997  else
998  retval = m_data_file->pgWrite(b->get_buff(), offset, size, 0, 0);
999  else
1000  retval = m_data_file->Write(b->get_buff(), offset, size);
1001 
1002  if (retval < size)
1003  {
1004  if (retval < 0)
1005  {
1006  GetLog()->Emsg("WriteToDisk()", -retval, "write block to disk", GetLocalPath().c_str());
1007  }
1008  else
1009  {
1010  TRACEF(Error, "WriteToDisk() incomplete block write ret=" << retval << " (should be " << size << ")");
1011  }
1012 
1013  XrdSysCondVarHelper _lck(m_state_cond);
1014 
1015  dec_ref_count(b);
1016 
1017  return;
1018  }
1019 
1020  const int blk_idx = (b->m_offset - m_offset) / m_block_size;
1021 
1022  // Set written bit.
1023  TRACEF(Dump, "WriteToDisk() success set bit for block " << b->m_offset << " size=" << size);
1024 
1025  bool schedule_sync = false;
1026  {
1027  XrdSysCondVarHelper _lck(m_state_cond);
1028 
1029  m_cfi.SetBitWritten(blk_idx);
1030 
1031  if (b->m_prefetch)
1032  {
1033  m_cfi.SetBitPrefetch(blk_idx);
1034  }
1035  if (b->req_cksum_net() && ! b->has_cksums() && m_cfi.IsCkSumNet())
1036  {
1037  m_cfi.ResetCkSumNet();
1038  }
1039 
1040  dec_ref_count(b);
1041 
1042  // Set synced bit or stash block index if in actual sync.
1043  // Synced state is only written out to cinfo file when data file is synced.
1044  if (m_in_sync)
1045  {
1046  m_writes_during_sync.push_back(blk_idx);
1047  }
1048  else
1049  {
1050  m_cfi.SetBitSynced(blk_idx);
1051  ++m_non_flushed_cnt;
1052  if ((m_cfi.IsComplete() || m_non_flushed_cnt >= Cache::GetInstance().RefConfiguration().m_flushCnt) &&
1053  ! m_in_shutdown)
1054  {
1055  schedule_sync = true;
1056  m_in_sync = true;
1057  m_non_flushed_cnt = 0;
1058  }
1059  }
1060  }
1061 
1062  if (schedule_sync)
1063  {
1064  cache()->ScheduleFileSync(this);
1065  }
1066 }
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:147
vCkSum_t & ref_cksum_vec()
Definition: XrdPfcFile.hh:172
char * get_buff() const
Definition: XrdPfcFile.hh:146
bool req_cksum_net() const
Definition: XrdPfcFile.hh:170
bool has_cksums() const
Definition: XrdPfcFile.hh:171
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
Definition: XrdPfc.hh:319
XrdSysError * GetLog()
Definition: XrdPfcFile.cc:1540
std::string & GetLocalPath()
Definition: XrdPfcFile.hh:275
void SetBitPrefetch(int i)
Mark block as obtained through prefetch.
Definition: XrdPfcInfo.hh:369
void ResetCkSumNet()
Definition: XrdPfcInfo.cc:215
bool IsCkSumNet() const
Definition: XrdPfcInfo.hh:294
bool IsCkSumCache() const
Definition: XrdPfcInfo.hh:293
void SetBitWritten(int i)
Mark block as written to disk.
Definition: XrdPfcInfo.hh:356
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:109

References XrdSysError::Emsg(), 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 215 of file XrdPfcFile.hh.

◆ DirectResponseHandler

friend class DirectResponseHandler
friend

Definition at line 216 of file XrdPfcFile.hh.


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