XRootD
Loading...
Searching...
No Matches
XrdPfc::File Class Reference

#include <XrdPfcFile.hh>

+ Collaboration diagram for XrdPfc::File:

Public Member Functions

 ~File ()
 Destructor.
 
void AddIO (IO *io)
 
void BlockRemovedFromWriteQ (Block *)
 Handle removal of a block from Cache's write queue.
 
void BlocksRemovedFromWriteQ (std::list< Block * > &)
 Handle removal of a set of blocks from Cache's write queue.
 
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.
 
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()
 
void ioUpdated (IO *io)
 Notification from IO that it has been updated (remote open).
 
bool is_in_emergency_shutdown ()
 
const char * lPath () const
 Log path.
 
void Prefetch ()
 
int Read (IO *io, char *buff, long long offset, int size, ReadReqRH *rh)
 Normal read.
 
int ReadV (IO *io, const XrdOucIOVec *readV, int readVnum, ReadReqRH *rh)
 Vector read.
 
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.
 
void StopPrefetchingOnIO (IO *io)
 
void Sync ()
 Sync file cache inf o and output data with disk.
 
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.
 

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)
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}
const char * GetLocation()
Definition XrdPfcIO.hh:46

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

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.
void DeltaToReference(const Stats &ref)

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.

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.

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.

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.

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

1510{
1511 return Cache::GetInstance().GetLog();
1512}
static Cache & GetInstance()
Singleton access.
Definition XrdPfc.cc:160
XrdSysError * GetLog()
Definition XrdPfc.hh:397

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.

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.

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

1505{
1506 return m_prefetch_score;
1507}

◆ GetRemoteLocations()

std::string File::GetRemoteLocations ( ) const

Definition at line 1528 of file XrdPfcFile.cc.

1529{
1530 std::string s;
1531 if ( ! m_remote_locations.empty())
1532 {
1533 size_t sl = 0;
1534 int nl = 0;
1535 for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++nl)
1536 {
1537 sl += i->size();
1538 }
1539 s.reserve(2 + sl + 2*nl + nl - 1 + 1);
1540 s = '[';
1541 int j = 1;
1542 for (std::set<std::string>::iterator i = m_remote_locations.begin(); i != m_remote_locations.end(); ++i, ++j)
1543 {
1544 s += '"'; s += *i; s += '"';
1545 if (j < nl) s += ',';
1546 }
1547 s += ']';
1548 }
1549 else
1550 {
1551 s = "[]";
1552 }
1553 return s;
1554}

◆ GetTrace()

XrdSysTrace * File::GetTrace ( )

Definition at line 1514 of file XrdPfcFile.cc.

1515{
1516 return Cache::GetInstance().GetTrace();
1517}
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 1416 of file XrdPfcFile.cc.

1417{
1418 return m_filename.c_str();
1419}

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

+ Here is the caller graph for this function:

◆ Prefetch()

void File::Prefetch ( )

Definition at line 1431 of file XrdPfcFile.cc.

1432{
1433 // Check that block is not on disk and not in RAM.
1434 // TODO: Could prefetch several blocks at once!
1435 // blks_max could be an argument
1436
1437 BlockList_t blks;
1438
1439 TRACEF(DumpXL, "Prefetch() entering.");
1440 {
1441 XrdSysCondVarHelper _lck(m_state_cond);
1442
1443 if (m_prefetch_state != kOn)
1444 {
1445 return;
1446 }
1447
1448 if ( ! select_current_io_or_disable_prefetching(true) )
1449 {
1450 TRACEF(Error, "Prefetch no available IO object found, prefetching stopped. This should not happen, i.e., prefetching should be stopped before.");
1451 return;
1452 }
1453
1454 // Select block(s) to fetch.
1455 for (int f = 0; f < m_num_blocks; ++f)
1456 {
1457 if ( ! m_cfi.TestBitWritten(f))
1458 {
1459 int f_act = f + m_offset / m_block_size;
1460
1461 BlockMap_i bi = m_block_map.find(f_act);
1462 if (bi == m_block_map.end())
1463 {
1464 Block *b = PrepareBlockRequest(f_act, *m_current_io, nullptr, true);
1465 if (b)
1466 {
1467 TRACEF(Dump, "Prefetch take block " << f_act);
1468 blks.push_back(b);
1469 // Note: block ref_cnt not increased, it will be when placed into write queue.
1470
1471 inc_prefetch_read_cnt(1);
1472 }
1473 else
1474 {
1475 // This shouldn't happen as prefetching stops when RAM is 70% full.
1476 TRACEF(Warning, "Prefetch allocation failed for block " << f_act);
1477 }
1478 break;
1479 }
1480 }
1481 }
1482
1483 if (blks.empty())
1484 {
1485 TRACEF(Debug, "Prefetch file is complete, stopping prefetch.");
1486 m_prefetch_state = kComplete;
1487 cache()->DeRegisterPrefetchFile(this);
1488 }
1489 else
1490 {
1491 (*m_current_io)->m_active_prefetches += (int) blks.size();
1492 }
1493 }
1494
1495 if ( ! blks.empty())
1496 {
1497 ProcessBlockRequests(blks);
1498 }
1499}
bool TestBitWritten(int i) const
Test if block at the given index is written to disk.
std::list< Block * > BlockList_t

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

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

654{
655 // rrc_func is ONLY called from async processing.
656 // If this function returns anything other than -EWOULDBLOCK, rrc_func needs to be called by the caller.
657 // This streamlines implementation of synchronous IO::Read().
658
659 TRACEF(Dump, "Read() sid: " << Xrd::hex1 << rh->m_seq_id << " size: " << iUserSize);
660
661 m_state_cond.Lock();
662
663 if (m_in_shutdown || io->m_in_detach)
664 {
665 m_state_cond.UnLock();
666 return m_in_shutdown ? -ENOENT : -EBADF;
667 }
668
669 // Shortcut -- file is fully downloaded.
670
671 if (m_cfi.IsComplete())
672 {
673 m_state_cond.UnLock();
674 int ret = m_data_file->Read(iUserBuff, iUserOff, iUserSize);
675 if (ret > 0) m_stats.AddBytesHit(ret);
676 return ret;
677 }
678
679 XrdOucIOVec readV( { iUserOff, iUserSize, 0, iUserBuff } );
680
681 return ReadOpusCoalescere(io, &readV, 1, rh, "Read() ");
682}
virtual ssize_t Read(off_t offset, size_t size)
Definition XrdOss.hh:281
bool IsComplete() const
Get complete status.
void AddBytesHit(long long bh)
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 686 of file XrdPfcFile.cc.

687{
688 TRACEF(Dump, "ReadV() for " << readVnum << " chunks.");
689
690 m_state_cond.Lock();
691
692 if (m_in_shutdown || io->m_in_detach)
693 {
694 m_state_cond.UnLock();
695 return m_in_shutdown ? -ENOENT : -EBADF;
696 }
697
698 // Shortcut -- file is fully downloaded.
699
700 if (m_cfi.IsComplete())
701 {
702 m_state_cond.UnLock();
703 int ret = m_data_file->ReadV(const_cast<XrdOucIOVec*>(readV), readVnum);
704 if (ret > 0) m_stats.AddBytesHit(ret);
705 return ret;
706 }
707
708 return ReadOpusCoalescere(io, readV, readVnum, rh, "ReadV() ");
709}
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)

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

1047{
1048 TRACEF(Dump, "Sync()");
1049
1050 int ret = m_data_file->Fsync();
1051 bool errorp = false;
1052 if (ret == XrdOssOK)
1053 {
1054 Stats loc_stats = m_stats.Clone();
1055 m_cfi.WriteIOStat(loc_stats);
1056 m_cfi.Write(m_info_file, m_filename.c_str());
1057 int cret = m_info_file->Fsync();
1058 if (cret != XrdOssOK)
1059 {
1060 TRACEF(Error, "Sync cinfo file sync error " << cret);
1061 errorp = true;
1062 }
1063 }
1064 else
1065 {
1066 TRACEF(Error, "Sync data file sync error " << ret << ", cinfo file has not been updated");
1067 errorp = true;
1068 }
1069
1070 if (errorp)
1071 {
1072 TRACEF(Error, "Sync failed, unlinking local files and initiating shutdown of File object");
1073
1074 // Unlink will also call this->initiate_emergency_shutdown()
1075 Cache::GetInstance().UnlinkFile(m_filename, false);
1076
1077 XrdSysCondVarHelper _lck(&m_state_cond);
1078
1079 m_writes_during_sync.clear();
1080 m_in_sync = false;
1081
1082 return;
1083 }
1084
1085 int written_while_in_sync;
1086 bool resync = false;
1087 {
1088 XrdSysCondVarHelper _lck(&m_state_cond);
1089 for (std::vector<int>::iterator i = m_writes_during_sync.begin(); i != m_writes_during_sync.end(); ++i)
1090 {
1091 m_cfi.SetBitSynced(*i);
1092 }
1093 written_while_in_sync = m_non_flushed_cnt = (int) m_writes_during_sync.size();
1094 m_writes_during_sync.clear();
1095
1096 // If there were writes during sync and the file is now complete,
1097 // let us call Sync again without resetting the m_in_sync flag.
1098 if (written_while_in_sync > 0 && m_cfi.IsComplete() && ! m_in_shutdown)
1099 resync = true;
1100 else
1101 m_in_sync = false;
1102 }
1103 TRACEF(Dump, "Sync "<< written_while_in_sync << " blocks written during sync." << (resync ? " File is now complete - resyncing." : ""));
1104
1105 if (resync)
1106 Sync();
1107}
#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:1133
void Sync()
Sync file cache inf o and output data with disk.
void SetBitSynced(int i)
Mark block as synced to disk.
bool Write(XrdOssDF *fp, const char *dname, const char *fname=0)
void WriteIOStat(Stats &s)
Write bytes missed, hits, and disk.

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

Referenced by Sync().

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

◆ WriteBlockToDisk()

void File::WriteBlockToDisk ( Block b)

Definition at line 963 of file XrdPfcFile.cc.

964{
965 // write block buffer into disk file
966 long long offset = b->m_offset - m_offset;
967 long long size = b->get_size();
968 ssize_t retval;
969
970 if (m_cfi.IsCkSumCache())
971 if (b->has_cksums())
972 retval = m_data_file->pgWrite(b->get_buff(), offset, size, b->ref_cksum_vec().data(), 0);
973 else
974 retval = m_data_file->pgWrite(b->get_buff(), offset, size, 0, 0);
975 else
976 retval = m_data_file->Write(b->get_buff(), offset, size);
977
978 if (retval < size)
979 {
980 if (retval < 0)
981 {
982 GetLog()->Emsg("WriteToDisk()", -retval, "write block to disk", GetLocalPath().c_str());
983 }
984 else
985 {
986 TRACEF(Error, "WriteToDisk() incomplete block write ret=" << retval << " (should be " << size << ")");
987 }
988
989 XrdSysCondVarHelper _lck(m_state_cond);
990
991 dec_ref_count(b);
992
993 return;
994 }
995
996 const int blk_idx = (b->m_offset - m_offset) / m_block_size;
997
998 // Set written bit.
999 TRACEF(Dump, "WriteToDisk() success set bit for block " << b->m_offset << " size=" << size);
1000
1001 bool schedule_sync = false;
1002 {
1003 XrdSysCondVarHelper _lck(m_state_cond);
1004
1005 m_cfi.SetBitWritten(blk_idx);
1006
1007 if (b->m_prefetch)
1008 {
1009 m_cfi.SetBitPrefetch(blk_idx);
1010 }
1011 if (b->req_cksum_net() && ! b->has_cksums() && m_cfi.IsCkSumNet())
1012 {
1013 m_cfi.ResetCkSumNet();
1014 }
1015
1016 dec_ref_count(b);
1017
1018 // Set synced bit or stash block index if in actual sync.
1019 // Synced state is only written out to cinfo file when data file is synced.
1020 if (m_in_sync)
1021 {
1022 m_writes_during_sync.push_back(blk_idx);
1023 }
1024 else
1025 {
1026 m_cfi.SetBitSynced(blk_idx);
1027 ++m_non_flushed_cnt;
1028 if ((m_cfi.IsComplete() || m_non_flushed_cnt >= Cache::GetInstance().RefConfiguration().m_flushCnt) &&
1029 ! m_in_shutdown)
1030 {
1031 schedule_sync = true;
1032 m_in_sync = true;
1033 m_non_flushed_cnt = 0;
1034 }
1035 }
1036 }
1037
1038 if (schedule_sync)
1039 {
1040 cache()->ScheduleFileSync(this);
1041 }
1042}
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
vCkSum_t & ref_cksum_vec()
bool req_cksum_net() const
char * get_buff() const
bool has_cksums() const
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
Definition XrdPfc.hh:315
std::string & GetLocalPath()
XrdSysError * GetLog()
void SetBitPrefetch(int i)
Mark block as obtained through prefetch.
void ResetCkSumNet()
bool IsCkSumNet() const
bool IsCkSumCache() const
void SetBitWritten(int i)
Mark block as written to disk.
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
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 Symbol 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: