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

Constructor & Destructor Documentation

◆ ~File()

File::~File ( )

Destructor.

Definition at line 79 of file XrdPfcFile.cc.

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

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

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

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

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

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

292 { 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 108 of file XrdPfcFile.cc.

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

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

287 {
288  // Returns true if sync is required.
289  // This method is called after corresponding IO is detached from PosixCache.
290 
291  XrdSysCondVarHelper _lck(m_state_cond);
292  if ( ! m_in_shutdown)
293  {
294  if ( ! m_writes_during_sync.empty() || m_non_flushed_cnt > 0 || ! m_detach_time_logged)
295  {
296  report_and_merge_delta_stats();
297  m_cfi.WriteIOStatDetach(m_stats);
298  m_detach_time_logged = true;
299  m_in_sync = true;
300  TRACEF(Debug, "FinalizeSyncBeforeExit requesting sync to write detach stats");
301  return true;
302  }
303  }
304  TRACEF(Debug, "FinalizeSyncBeforeExit sync not required");
305  return false;
306 }
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:

◆ get_ref_cnt()

int XrdPfc::File::get_ref_cnt ( )
inline

Definition at line 290 of file XrdPfcFile.hh.

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

269 { 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 1563 of file XrdPfcFile.cc.

1564 {
1565  return Cache::GetInstance().GetLog();
1566 }
XrdSysError * GetLog()
Definition: XrdPfc.hh:277
static Cache & GetInstance()
Singleton access.
Definition: XrdPfc.cc:130

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 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)

◆ GetPrefetchScore()

float File::GetPrefetchScore ( ) const

Definition at line 1558 of file XrdPfcFile.cc.

1559 {
1560  return m_prefetch_score;
1561 }

◆ GetRemoteLocations()

std::string File::GetRemoteLocations ( ) const

Definition at line 1582 of file XrdPfcFile.cc.

1583 {
1584  std::string s;
1585  if ( ! m_remote_locations.empty())
1586  {
1587  size_t sl = 0;
1588  int nl = 0;
1589  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++nl)
1590  {
1591  sl += i->size();
1592  }
1593  s.reserve(2 + sl + 2*nl + nl - 1 + 1);
1594  s = '[';
1595  int j = 1;
1596  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++j)
1597  {
1598  s += '"'; s += *i; s += '"';
1599  if (j < nl) s += ',';
1600  }
1601  s += ']';
1602  }
1603  else
1604  {
1605  s = "[]";
1606  }
1607  return s;
1608 }

◆ GetTrace()

XrdSysTrace * File::GetTrace ( )

Definition at line 1568 of file XrdPfcFile.cc.

1569 {
1570  return Cache::GetInstance().GetTrace();
1571 }
XrdSysTrace * GetTrace()
Definition: XrdPfc.hh:278

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

291 { return ++m_ref_cnt; }

◆ initiate_emergency_shutdown()

void File::initiate_emergency_shutdown ( )

Definition at line 121 of file XrdPfcFile.cc.

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

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

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

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

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

295 { return m_in_shutdown; }

◆ lPath()

const char * File::lPath ( ) const

Log path.

Definition at line 1470 of file XrdPfcFile.cc.

1471 {
1472  return m_filename.c_str();
1473 }

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

+ Here is the caller graph for this function:

◆ Prefetch()

void File::Prefetch ( )

Definition at line 1485 of file XrdPfcFile.cc.

1486 {
1487  // Check that block is not on disk and not in RAM.
1488  // TODO: Could prefetch several blocks at once!
1489  // blks_max could be an argument
1490 
1491  BlockList_t blks;
1492 
1493  TRACEF(DumpXL, "Prefetch() entering.");
1494  {
1495  XrdSysCondVarHelper _lck(m_state_cond);
1496 
1497  if (m_prefetch_state != kOn)
1498  {
1499  return;
1500  }
1501 
1502  if ( ! select_current_io_or_disable_prefetching(true) )
1503  {
1504  TRACEF(Error, "Prefetch no available IO object found, prefetching stopped. This should not happen, i.e., prefetching should be stopped before.");
1505  return;
1506  }
1507 
1508  // Select block(s) to fetch.
1509  for (int f = 0; f < m_num_blocks; ++f)
1510  {
1511  if ( ! m_cfi.TestBitWritten(f))
1512  {
1513  int f_act = f + m_offset / m_block_size;
1514 
1515  BlockMap_i bi = m_block_map.find(f_act);
1516  if (bi == m_block_map.end())
1517  {
1518  Block *b = PrepareBlockRequest(f_act, *m_current_io, nullptr, true);
1519  if (b)
1520  {
1521  TRACEF(Dump, "Prefetch take block " << f_act);
1522  blks.push_back(b);
1523  // Note: block ref_cnt not increased, it will be when placed into write queue.
1524 
1525  inc_prefetch_read_cnt(1);
1526  }
1527  else
1528  {
1529  // This shouldn't happen as prefetching stops when RAM is 70% full.
1530  TRACEF(Warning, "Prefetch allocation failed for block " << f_act);
1531  }
1532  break;
1533  }
1534  }
1535  }
1536 
1537  if (blks.empty())
1538  {
1539  TRACEF(Debug, "Prefetch file is complete, stopping prefetch.");
1540  m_prefetch_state = kComplete;
1541  cache()->DeRegisterPrefetchFile(this);
1542  }
1543  else
1544  {
1545  (*m_current_io)->m_active_prefetches += (int) blks.size();
1546  }
1547  }
1548 
1549  if ( ! blks.empty())
1550  {
1551  ProcessBlockRequests(blks);
1552  }
1553 }
@ 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:171

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

690 {
691  // rrc_func is ONLY called from async processing.
692  // If this function returns anything other than -EWOULDBLOCK, rrc_func needs to be called by the caller.
693  // This streamlines implementation of synchronous IO::Read().
694 
695  TRACEF(Dump, "Read() sid: " << Xrd::hex1 << rh->m_seq_id << " size: " << iUserSize);
696 
697  m_state_cond.Lock();
698 
699  if (m_in_shutdown || io->m_in_detach)
700  {
701  m_state_cond.UnLock();
702  return m_in_shutdown ? -ENOENT : -EBADF;
703  }
704 
705  // Shortcut -- file is fully downloaded.
706 
707  if (m_cfi.IsComplete())
708  {
709  m_state_cond.UnLock();
710  int ret = m_data_file->Read(iUserBuff, iUserOff, iUserSize);
711  if (ret > 0) {
712  XrdSysCondVarHelper _lck(m_state_cond);
713  m_delta_stats.AddBytesHit(ret);
714  check_delta_stats();
715  }
716  return ret;
717  }
718 
719  XrdOucIOVec readV( { iUserOff, iUserSize, 0, iUserBuff } );
720 
721  return ReadOpusCoalescere(io, &readV, 1, rh, "Read() ");
722 }
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 726 of file XrdPfcFile.cc.

727 {
728  TRACEF(Dump, "ReadV() for " << readVnum << " chunks.");
729 
730  m_state_cond.Lock();
731 
732  if (m_in_shutdown || io->m_in_detach)
733  {
734  m_state_cond.UnLock();
735  return m_in_shutdown ? -ENOENT : -EBADF;
736  }
737 
738  // Shortcut -- file is fully downloaded.
739 
740  if (m_cfi.IsComplete())
741  {
742  m_state_cond.UnLock();
743  int ret = m_data_file->ReadV(const_cast<XrdOucIOVec*>(readV), readVnum);
744  if (ret > 0) {
745  XrdSysCondVarHelper _lck(m_state_cond);
746  m_delta_stats.AddBytesHit(ret);
747  check_delta_stats();
748  }
749  return ret;
750  }
751 
752  return ReadOpusCoalescere(io, readV, readVnum, rh, "ReadV() ");
753 }
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 287 of file XrdPfcFile.hh.

287 { return m_stats; }

◆ RemoveIO()

void File::RemoveIO ( IO io)

Definition at line 347 of file XrdPfcFile.cc.

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

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

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

1092 {
1093  TRACEF(Dump, "Sync()");
1094 
1095  int ret = m_data_file->Fsync();
1096  bool errorp = false;
1097  if (ret == XrdOssOK)
1098  {
1099  Stats loc_stats;
1100  {
1101  XrdSysCondVarHelper _lck(&m_state_cond);
1102  report_and_merge_delta_stats();
1103  loc_stats = m_stats;
1104  }
1105  m_cfi.WriteIOStat(loc_stats);
1106  m_cfi.Write(m_info_file, m_filename.c_str());
1107  int cret = m_info_file->Fsync();
1108  if (cret != XrdOssOK)
1109  {
1110  TRACEF(Error, "Sync cinfo file sync error " << cret);
1111  errorp = true;
1112  }
1113  }
1114  else
1115  {
1116  TRACEF(Error, "Sync data file sync error " << ret << ", cinfo file has not been updated");
1117  errorp = true;
1118  }
1119 
1120  if (errorp)
1121  {
1122  TRACEF(Error, "Sync failed, unlinking local files and initiating shutdown of File object");
1123 
1124  // Unlink will also call this->initiate_emergency_shutdown()
1125  Cache::GetInstance().UnlinkFile(m_filename, false);
1126 
1127  XrdSysCondVarHelper _lck(&m_state_cond);
1128 
1129  m_writes_during_sync.clear();
1130  m_in_sync = false;
1131 
1132  return;
1133  }
1134 
1135  int written_while_in_sync;
1136  bool resync = false;
1137  {
1138  XrdSysCondVarHelper _lck(&m_state_cond);
1139  for (std::vector<int>::iterator i = m_writes_during_sync.begin(); i != m_writes_during_sync.end(); ++i)
1140  {
1141  m_cfi.SetBitSynced(*i);
1142  }
1143  written_while_in_sync = m_non_flushed_cnt = (int) m_writes_during_sync.size();
1144  m_writes_during_sync.clear();
1145 
1146  // If there were writes during sync and the file is now complete,
1147  // let us call Sync again without resetting the m_in_sync flag.
1148  if (written_while_in_sync > 0 && m_cfi.IsComplete() && ! m_in_shutdown)
1149  resync = true;
1150  else
1151  m_in_sync = false;
1152  }
1153  TRACEF(Dump, "Sync "<< written_while_in_sync << " blocks written during sync." << (resync ? " File is now complete - resyncing." : ""));
1154 
1155  if (resync)
1156  Sync();
1157 }
#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:1120
void Sync()
Sync file cache inf o and output data with disk.
Definition: XrdPfcFile.cc:1091
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 1008 of file XrdPfcFile.cc.

1009 {
1010  // write block buffer into disk file
1011  long long offset = b->m_offset - m_offset;
1012  long long size = b->get_size();
1013  ssize_t retval;
1014 
1015  if (m_cfi.IsCkSumCache())
1016  if (b->has_cksums())
1017  retval = m_data_file->pgWrite(b->get_buff(), offset, size, b->ref_cksum_vec().data(), 0);
1018  else
1019  retval = m_data_file->pgWrite(b->get_buff(), offset, size, 0, 0);
1020  else
1021  retval = m_data_file->Write(b->get_buff(), offset, size);
1022 
1023  if (retval < size)
1024  {
1025  if (retval < 0)
1026  {
1027  GetLog()->Emsg("WriteToDisk()", -retval, "write block to disk", GetLocalPath().c_str());
1028  }
1029  else
1030  {
1031  TRACEF(Error, "WriteToDisk() incomplete block write ret=" << retval << " (should be " << size << ")");
1032  }
1033 
1034  XrdSysCondVarHelper _lck(m_state_cond);
1035 
1036  dec_ref_count(b);
1037 
1038  return;
1039  }
1040 
1041  const int blk_idx = (b->m_offset - m_offset) / m_block_size;
1042 
1043  // Set written bit.
1044  TRACEF(Dump, "WriteToDisk() success set bit for block " << b->m_offset << " size=" << size);
1045 
1046  bool schedule_sync = false;
1047  {
1048  XrdSysCondVarHelper _lck(m_state_cond);
1049 
1050  m_cfi.SetBitWritten(blk_idx);
1051 
1052  if (b->m_prefetch)
1053  {
1054  m_cfi.SetBitPrefetch(blk_idx);
1055  }
1056  if (b->req_cksum_net() && ! b->has_cksums() && m_cfi.IsCkSumNet())
1057  {
1058  m_cfi.ResetCkSumNet();
1059  }
1060 
1061  dec_ref_count(b);
1062 
1063  // Set synced bit or stash block index if in actual sync.
1064  // Synced state is only written out to cinfo file when data file is synced.
1065  if (m_in_sync)
1066  {
1067  m_writes_during_sync.push_back(blk_idx);
1068  }
1069  else
1070  {
1071  m_cfi.SetBitSynced(blk_idx);
1072  ++m_non_flushed_cnt;
1073  if ((m_cfi.IsComplete() || m_non_flushed_cnt >= Cache::GetInstance().RefConfiguration().m_flushCnt) &&
1074  ! m_in_shutdown)
1075  {
1076  schedule_sync = true;
1077  m_in_sync = true;
1078  m_non_flushed_cnt = 0;
1079  }
1080  }
1081  }
1082 
1083  if (schedule_sync)
1084  {
1085  cache()->ScheduleFileSync(this);
1086  }
1087 }
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:141
vCkSum_t & ref_cksum_vec()
Definition: XrdPfcFile.hh:166
char * get_buff() const
Definition: XrdPfcFile.hh:140
bool req_cksum_net() const
Definition: XrdPfcFile.hh:164
bool has_cksums() const
Definition: XrdPfcFile.hh:165
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
Definition: XrdPfc.hh:199
XrdSysError * GetLog()
Definition: XrdPfcFile.cc:1563
const std::string & GetLocalPath() const
Definition: XrdPfcFile.hh:269
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 209 of file XrdPfcFile.hh.

◆ DirectResponseHandler

friend class DirectResponseHandler
friend

Definition at line 210 of file XrdPfcFile.hh.


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