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

Constructor & Destructor Documentation

◆ ~File()

File::~File ( )

Destructor.

Definition at line 76 of file XrdPfcFile.cc.

77 {
78  if (m_info_file)
79  {
80  TRACEF(Debug, "~File() close info ");
81  m_info_file->Close();
82  delete m_info_file;
83  m_info_file = NULL;
84  }
85 
86  if (m_data_file)
87  {
88  TRACEF(Debug, "~File() close output ");
89  m_data_file->Close();
90  delete m_data_file;
91  m_data_file = NULL;
92  }
93 
94  TRACEF(Debug, "~File() ended, prefetch score = " << m_prefetch_score);
95 }
#define TRACEF(act, x)
Definition: XrdPfcTrace.hh:62
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 295 of file XrdPfcFile.cc.

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

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

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

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

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

299 { return --m_ref_cnt; }

◆ DeltaStatsFromLastCall()

Stats File::DeltaStatsFromLastCall ( )

Definition at line 142 of file XrdPfcFile.cc.

143 {
144  // Not locked, only used from Cache / Purge thread.
145 
146  Stats delta = m_last_stats;
147 
148  m_last_stats = m_stats.Clone();
149 
150  delta.DeltaToReference(m_last_stats);
151 
152  return delta;
153 }
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 99 of file XrdPfcFile.cc.

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

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

272 {
273  // Returns true if sync is required.
274  // This method is called after corresponding IO is detached from PosixCache.
275 
276  XrdSysCondVarHelper _lck(m_state_cond);
277  if ( ! m_in_shutdown)
278  {
279  if ( ! m_writes_during_sync.empty() || m_non_flushed_cnt > 0 || ! m_detach_time_logged)
280  {
281  Stats loc_stats = m_stats.Clone();
282  m_cfi.WriteIOStatDetach(loc_stats);
283  m_detach_time_logged = true;
284  m_in_sync = true;
285  TRACEF(Debug, "FinalizeSyncBeforeExit requesting sync to write detach stats");
286  return true;
287  }
288  }
289  TRACEF(Debug, "FinalizeSyncBeforeExit sync not required");
290  return false;
291 }
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:

◆ get_ref_cnt()

int XrdPfc::File::get_ref_cnt ( )
inline

Definition at line 297 of file XrdPfcFile.hh.

297 { return m_ref_cnt; }

◆ GetAccessCnt()

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

Definition at line 290 of file XrdPfcFile.hh.

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

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

279 { 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 289 of file XrdPfcFile.hh.

289 { 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 274 of file XrdPfcFile.hh.

274 { 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 1485 of file XrdPfcFile.cc.

1486 {
1487  return Cache::GetInstance().GetLog();
1488 }
XrdSysError * GetLog()
Definition: XrdPfc.hh:397
static Cache & GetInstance()
Singleton access.
Definition: XrdPfc.cc:159

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

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

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

◆ GetPrefetchScore()

float File::GetPrefetchScore ( ) const

Definition at line 1480 of file XrdPfcFile.cc.

1481 {
1482  return m_prefetch_score;
1483 }

◆ GetRemoteLocations()

std::string File::GetRemoteLocations ( ) const

Definition at line 1504 of file XrdPfcFile.cc.

1505 {
1506  std::string s;
1507  if ( ! m_remote_locations.empty())
1508  {
1509  size_t sl = 0;
1510  int nl = 0;
1511  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++nl)
1512  {
1513  sl += i->size();
1514  }
1515  s.reserve(2 + sl + 2*nl + nl - 1 + 1);
1516  s = '[';
1517  int j = 1;
1518  for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++j)
1519  {
1520  s += '"'; s += *i; s += '"';
1521  if (j < nl) s += ',';
1522  }
1523  s += ']';
1524  }
1525  else
1526  {
1527  s = "[]";
1528  }
1529  return s;
1530 }

◆ GetTrace()

XrdSysTrace * File::GetTrace ( )

Definition at line 1490 of file XrdPfcFile.cc.

1491 {
1492  return Cache::GetInstance().GetTrace();
1493 }
XrdSysTrace * GetTrace()
Definition: XrdPfc.hh:398

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

298 { return ++m_ref_cnt; }

◆ initiate_emergency_shutdown()

void File::initiate_emergency_shutdown ( )

Definition at line 112 of file XrdPfcFile.cc.

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

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

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

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

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

302 { return m_in_shutdown; }

◆ lPath()

const char * File::lPath ( ) const

Log path.

Definition at line 1392 of file XrdPfcFile.cc.

1393 {
1394  return m_filename.c_str();
1395 }

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

+ Here is the caller graph for this function:

◆ Prefetch()

void File::Prefetch ( )

Definition at line 1407 of file XrdPfcFile.cc.

1408 {
1409  // Check that block is not on disk and not in RAM.
1410  // TODO: Could prefetch several blocks at once!
1411  // blks_max could be an argument
1412 
1413  BlockList_t blks;
1414 
1415  TRACEF(DumpXL, "Prefetch() entering.");
1416  {
1417  XrdSysCondVarHelper _lck(m_state_cond);
1418 
1419  if (m_prefetch_state != kOn)
1420  {
1421  return;
1422  }
1423 
1424  if ( ! select_current_io_or_disable_prefetching(true) )
1425  {
1426  TRACEF(Error, "Prefetch no available IO object found, prefetching stopped. This should not happen, i.e., prefetching should be stopped before.");
1427  return;
1428  }
1429 
1430  // Select block(s) to fetch.
1431  for (int f = 0; f < m_num_blocks; ++f)
1432  {
1433  if ( ! m_cfi.TestBitWritten(f))
1434  {
1435  int f_act = f + m_offset / m_block_size;
1436 
1437  BlockMap_i bi = m_block_map.find(f_act);
1438  if (bi == m_block_map.end())
1439  {
1440  Block *b = PrepareBlockRequest(f_act, *m_current_io, nullptr, true);
1441  if (b)
1442  {
1443  TRACEF(Dump, "Prefetch take block " << f_act);
1444  blks.push_back(b);
1445  // Note: block ref_cnt not increased, it will be when placed into write queue.
1446 
1447  inc_prefetch_read_cnt(1);
1448  }
1449  else
1450  {
1451  // This shouldn't happen as prefetching stops when RAM is 70% full.
1452  TRACEF(Warning, "Prefetch allocation failed for block " << f_act);
1453  }
1454  break;
1455  }
1456  }
1457  }
1458 
1459  if (blks.empty())
1460  {
1461  TRACEF(Debug, "Prefetch file is complete, stopping prefetch.");
1462  m_prefetch_state = kComplete;
1463  cache()->DeRegisterPrefetchFile(this);
1464  }
1465  else
1466  {
1467  (*m_current_io)->m_active_prefetches += (int) blks.size();
1468  }
1469  }
1470 
1471  if ( ! blks.empty())
1472  {
1473  ProcessBlockRequests(blks);
1474  }
1475 }
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:176

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

642 {
643  // rrc_func is ONLY called from async processing.
644  // If this function returns anything other than -EWOULDBLOCK, rrc_func needs to be called by the caller.
645  // This streamlines implementation of synchronous IO::Read().
646 
647  TRACEF(Dump, "Read() sid: " << Xrd::hex1 << rh->m_seq_id << " size: " << iUserSize);
648 
649  m_state_cond.Lock();
650 
651  if (m_in_shutdown || io->m_in_detach)
652  {
653  m_state_cond.UnLock();
654  return m_in_shutdown ? -ENOENT : -EBADF;
655  }
656 
657  // Shortcut -- file is fully downloaded.
658 
659  if (m_cfi.IsComplete())
660  {
661  m_state_cond.UnLock();
662  int ret = m_data_file->Read(iUserBuff, iUserOff, iUserSize);
663  if (ret > 0) m_stats.AddBytesHit(ret);
664  return ret;
665  }
666 
667  XrdOucIOVec readV( { iUserOff, iUserSize, 0, iUserBuff } );
668 
669  return ReadOpusCoalescere(io, &readV, 1, rh, "Read() ");
670 }
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 674 of file XrdPfcFile.cc.

675 {
676  TRACEF(Dump, "ReadV() for " << readVnum << " chunks.");
677 
678  m_state_cond.Lock();
679 
680  if (m_in_shutdown || io->m_in_detach)
681  {
682  m_state_cond.UnLock();
683  return m_in_shutdown ? -ENOENT : -EBADF;
684  }
685 
686  // Shortcut -- file is fully downloaded.
687 
688  if (m_cfi.IsComplete())
689  {
690  m_state_cond.UnLock();
691  int ret = m_data_file->ReadV(const_cast<XrdOucIOVec*>(readV), readVnum);
692  if (ret > 0) m_stats.AddBytesHit(ret);
693  return ret;
694  }
695 
696  return ReadOpusCoalescere(io, readV, readVnum, rh, "ReadV() ");
697 }
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 294 of file XrdPfcFile.hh.

294 { return m_stats; }

◆ RemoveIO()

void File::RemoveIO ( IO io)

Definition at line 332 of file XrdPfcFile.cc.

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

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

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

1023 {
1024  TRACEF(Dump, "Sync()");
1025 
1026  int ret = m_data_file->Fsync();
1027  bool errorp = false;
1028  if (ret == XrdOssOK)
1029  {
1030  Stats loc_stats = m_stats.Clone();
1031  m_cfi.WriteIOStat(loc_stats);
1032  m_cfi.Write(m_info_file, m_filename.c_str());
1033  int cret = m_info_file->Fsync();
1034  if (cret != XrdOssOK)
1035  {
1036  TRACEF(Error, "Sync cinfo file sync error " << cret);
1037  errorp = true;
1038  }
1039  }
1040  else
1041  {
1042  TRACEF(Error, "Sync data file sync error " << ret << ", cinfo file has not been updated");
1043  errorp = true;
1044  }
1045 
1046  if (errorp)
1047  {
1048  TRACEF(Error, "Sync failed, unlinking local files and initiating shutdown of File object");
1049 
1050  // Unlink will also call this->initiate_emergency_shutdown()
1051  Cache::GetInstance().UnlinkFile(m_filename, false);
1052 
1053  XrdSysCondVarHelper _lck(&m_state_cond);
1054 
1055  m_writes_during_sync.clear();
1056  m_in_sync = false;
1057 
1058  return;
1059  }
1060 
1061  int written_while_in_sync;
1062  bool resync = false;
1063  {
1064  XrdSysCondVarHelper _lck(&m_state_cond);
1065  for (std::vector<int>::iterator i = m_writes_during_sync.begin(); i != m_writes_during_sync.end(); ++i)
1066  {
1067  m_cfi.SetBitSynced(*i);
1068  }
1069  written_while_in_sync = m_non_flushed_cnt = (int) m_writes_during_sync.size();
1070  m_writes_during_sync.clear();
1071 
1072  // If there were writes during sync and the file is now complete,
1073  // let us call Sync again without resetting the m_in_sync flag.
1074  if (written_while_in_sync > 0 && m_cfi.IsComplete() && ! m_in_shutdown)
1075  resync = true;
1076  else
1077  m_in_sync = false;
1078  }
1079  TRACEF(Dump, "Sync "<< written_while_in_sync << " blocks written during sync." << (resync ? " File is now complete - resyncing." : ""));
1080 
1081  if (resync)
1082  Sync();
1083 }
#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:1132
void Sync()
Sync file cache inf o and output data with disk.
Definition: XrdPfcFile.cc:1022
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 939 of file XrdPfcFile.cc.

940 {
941  // write block buffer into disk file
942  long long offset = b->m_offset - m_offset;
943  long long size = b->get_size();
944  ssize_t retval;
945 
946  if (m_cfi.IsCkSumCache())
947  if (b->has_cksums())
948  retval = m_data_file->pgWrite(b->get_buff(), offset, size, b->ref_cksum_vec().data(), 0);
949  else
950  retval = m_data_file->pgWrite(b->get_buff(), offset, size, 0, 0);
951  else
952  retval = m_data_file->Write(b->get_buff(), offset, size);
953 
954  if (retval < size)
955  {
956  if (retval < 0)
957  {
958  GetLog()->Emsg("WriteToDisk()", -retval, "write block to disk", GetLocalPath().c_str());
959  }
960  else
961  {
962  TRACEF(Error, "WriteToDisk() incomplete block write ret=" << retval << " (should be " << size << ")");
963  }
964 
965  XrdSysCondVarHelper _lck(m_state_cond);
966 
967  dec_ref_count(b);
968 
969  return;
970  }
971 
972  const int blk_idx = (b->m_offset - m_offset) / m_block_size;
973 
974  // Set written bit.
975  TRACEF(Dump, "WriteToDisk() success set bit for block " << b->m_offset << " size=" << size);
976 
977  bool schedule_sync = false;
978  {
979  XrdSysCondVarHelper _lck(m_state_cond);
980 
981  m_cfi.SetBitWritten(blk_idx);
982 
983  if (b->m_prefetch)
984  {
985  m_cfi.SetBitPrefetch(blk_idx);
986  }
987  if (b->req_cksum_net() && ! b->has_cksums() && m_cfi.IsCkSumNet())
988  {
989  m_cfi.ResetCkSumNet();
990  }
991 
992  dec_ref_count(b);
993 
994  // Set synced bit or stash block index if in actual sync.
995  // Synced state is only written out to cinfo file when data file is synced.
996  if (m_in_sync)
997  {
998  m_writes_during_sync.push_back(blk_idx);
999  }
1000  else
1001  {
1002  m_cfi.SetBitSynced(blk_idx);
1003  ++m_non_flushed_cnt;
1004  if ((m_cfi.IsComplete() || m_non_flushed_cnt >= Cache::GetInstance().RefConfiguration().m_flushCnt) &&
1005  ! m_in_shutdown)
1006  {
1007  schedule_sync = true;
1008  m_in_sync = true;
1009  m_non_flushed_cnt = 0;
1010  }
1011  }
1012  }
1013 
1014  if (schedule_sync)
1015  {
1016  cache()->ScheduleFileSync(this);
1017  }
1018 }
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:146
vCkSum_t & ref_cksum_vec()
Definition: XrdPfcFile.hh:171
char * get_buff() const
Definition: XrdPfcFile.hh:145
bool req_cksum_net() const
Definition: XrdPfcFile.hh:169
bool has_cksums() const
Definition: XrdPfcFile.hh:170
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
Definition: XrdPfc.hh:315
XrdSysError * GetLog()
Definition: XrdPfcFile.cc:1485
std::string & GetLocalPath()
Definition: XrdPfcFile.hh:274
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 214 of file XrdPfcFile.hh.

◆ DirectResponseHandler

friend class DirectResponseHandler
friend

Definition at line 215 of file XrdPfcFile.hh.


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