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

Downloads original file into a single file on local disk. Handles read requests as they come along. More...

#include <XrdPfcIOFile.hh>

Inheritance diagram for XrdPfc::IOFile:
Collaboration diagram for XrdPfc::IOFile:

Public Member Functions

 IOFile (XrdOucCacheIO *io, Cache &cache)
 ~IOFile ()
void DetachFinalize () override
 Abstract virtual method of XrdPfc::IO Called to destruct the IO object after it is no longer used.
long long FSize () override
int Fstat (struct stat &sbuff) override
bool HasFile () const
 Check if File was opened successfully.
bool ioActive () override
 Abstract virtual method of XrdPfc::IO Called to check if destruction needs to be done in a separate task.
virtual int pgRead (char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
void pgRead (XrdOucCacheIOCB &iocb, char *buff, long long off, int size, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
int Read (char *buff, long long off, int size) override
 Pass Read request to the corresponding File object.
void Read (XrdOucCacheIOCB &iocb, char *buff, long long off, int size) override
int ReadV (const XrdOucIOVec *readV, int n) override
 Pass ReadV request to the corresponding File object.
void ReadV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int n) override
void Update (XrdOucCacheIO &iocp) override
Public Member Functions inherited from XrdPfc::IO
 IO (XrdOucCacheIO *io, Cache &cache)
virtual XrdOucCacheIO * Base ()
 Original data source.
bool Detach (XrdOucCacheIOCD &iocdP) final
XrdOucCacheIO * GetInput ()
const char * GetLocation ()
XrdSysTrace * GetTrace ()
const char * Path () override
 Original data source URL.
int Sync () override
virtual void Sync (XrdOucCacheIOCB &iocb)
int Trunc (long long Offset) override
virtual void Trunc (XrdOucCacheIOCB &iocb, long long offs)
int Write (char *Buffer, long long Offset, int Length) override
virtual void Write (XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
Public Member Functions inherited from XrdOucCacheIO
 XrdOucCacheIO ()
 Construct and Destructor.
virtual const char * Location (bool refresh=false)
virtual int pgWrite (char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual void pgWrite (XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual void Preread (aprParms &Parms)
virtual void Preread (long long offs, int rlen, int opts=0)
virtual int WriteV (const XrdOucIOVec *writV, int wnum)
virtual void WriteV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)

Additional Inherited Members

Static Public Attributes inherited from XrdOucCacheIO
static const uint64_t forceCS = 0x0000000000000001ULL
static const int SingleUse = 0x0001
 Mark pages for single use.
Protected Member Functions inherited from XrdPfc::IO
std::string GetFilename ()
const char * GetPath ()
unsigned short ObtainReadSid ()
const char * RefreshLocation ()
bool register_block_error (int res)
bool register_incomplete_read ()
Protected Member Functions inherited from XrdOucCacheIO
virtual ~XrdOucCacheIO ()
Protected Attributes inherited from XrdPfc::IO
RAtomic_int m_active_read_reqs
 number of active read requests
Cache & m_cache
 reference to Cache object
std::map< int, int > m_error_counts
int m_incomplete_count {0}
const char * m_traceID

Detailed Description

Downloads original file into a single file on local disk. Handles read requests as they come along.

Definition at line 38 of file XrdPfcIOFile.hh.

Constructor & Destructor Documentation

◆ IOFile()

IOFile::IOFile ( XrdOucCacheIO * io,
Cache & cache )

Definition at line 36 of file XrdPfcIOFile.cc.

36 :
37 IO(io, cache),
38 m_file(0)
39{
40 m_file = Cache::GetInstance().GetFile(GetFilename(), this);
41}
File * GetFile(const std::string &, IO *, long long off=0, long long filesize=0)
Definition XrdPfc.cc:389
static Cache & GetInstance()
Singleton access.
Definition XrdPfc.cc:132
IO(XrdOucCacheIO *io, Cache &cache)
Definition XrdPfcIO.cc:7
std::string GetFilename()
Definition XrdPfcIO.cc:36

References XrdPfc::IO::IO(), XrdOucCacheIO::XrdOucCacheIO(), XrdPfc::Cache::GetFile(), XrdPfc::IO::GetFilename(), and XrdPfc::Cache::GetInstance().

Referenced by pgRead(), Read(), and ReadV().

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

◆ ~IOFile()

IOFile::~IOFile ( )

Definition at line 44 of file XrdPfcIOFile.cc.

45{
46 // called from Detach() if no sync is needed or
47 // from Cache's sync thread
48 TRACEIO(Debug, "~IOFile() " << this);
49}
#define TRACEIO(act, x)
bool Debug

References Debug, and TRACEIO.

Member Function Documentation

◆ DetachFinalize()

void IOFile::DetachFinalize ( )
overridevirtual

Abstract virtual method of XrdPfc::IO Called to destruct the IO object after it is no longer used.

Implements XrdPfc::IO.

Definition at line 116 of file XrdPfcIOFile.cc.

117{
118 // Effectively a destructor.
119
120 TRACE(Debug, "DetachFinalize() " << this);
121
122 m_file->RequestSyncOfDetachStats();
123 Cache::GetInstance().ReleaseFile(m_file, this);
124
125 if (( ! m_error_counts.empty() || m_incomplete_count > 0) && XRD_TRACE What >= TRACE_Error) {
126 char info[1024];
127 int pos = 0, cap = 1024;
128 bool truncated = false;
129 for (auto [err, cnt] : m_error_counts) {
130 int len = snprintf(&info[pos], cap, " ( %d : %d)", err, cnt);
131 if (len >= cap) {
132 truncated = true;
133 break;
134 }
135 pos += len;
136 cap -= len;
137 }
138 TRACE(Error, "DetachFinalize() " << this << " n_incomplete_reads=" << m_incomplete_count
139 << ", block (error : count) report:" << info << (truncated ? " - truncated" : ""));
140 }
141
142 delete this;
143}
#define TRACE_Error
Definition XrdPfcTrace.hh:7
#define XRD_TRACE
#define TRACE(act, x)
Definition XrdTrace.hh:63
void ReleaseFile(File *, IO *)
Definition XrdPfc.cc:473
int m_incomplete_count
Definition XrdPfcIO.hh:88
std::map< int, int > m_error_counts
Definition XrdPfcIO.hh:89

References Debug, Error, XrdPfc::Cache::GetInstance(), XrdPfc::IO::m_error_counts, XrdPfc::IO::m_incomplete_count, XrdPfc::Cache::ReleaseFile(), TRACE, TRACE_Error, and XRD_TRACE.

Here is the call graph for this function:

◆ FSize()

long long IOFile::FSize ( )
overridevirtual

Obtain size of the file.

Returns
Size of the file in bytes.

Implements XrdOucCacheIO.

Definition at line 66 of file XrdPfcIOFile.cc.

67{
68 return m_file->GetFileSize();
69}

◆ Fstat()

int IOFile::Fstat ( struct stat & sbuff)
overridevirtual

Perform an fstat() operation (defaults to passthrough).

Parameters
sbuffreference to the stat buffer to be filled in. Only fields st_size, st_blocks, st_mtime (st_atime and st_ctime may be set to st_mtime), st_ino, and st_mode need to be set. All other fields are preset and should not be changed.
Returns
<0 - fstat failed, value is -errno. =0 - fstat succeeded, sbuff holds stat information. >0 - fstat could not be done, forward operation to next level.

Reimplemented from XrdOucCacheIO.

Definition at line 52 of file XrdPfcIOFile.cc.

53{
54 // This is only called during Cache::Attach / Cache::GetFile() for file creation.
55 // Should really be separate name but one needs to change virtual interface
56 // so initialStat() becomes virtual in the base-class.
57 // Also, IOFileBlock should be ditched.
58 if ( ! m_file) {
59 return initialStat(sbuff);
60 }
61
62 return m_file->Fstat(sbuff);
63}

References stat.

◆ HasFile()

bool XrdPfc::IOFile::HasFile ( ) const
inline

Check if File was opened successfully.

Definition at line 48 of file XrdPfcIOFile.hh.

48{ return m_file != 0; }

Referenced by XrdPfc::Cache::Attach().

Here is the caller graph for this function:

◆ ioActive()

bool IOFile::ioActive ( )
overridevirtual

Abstract virtual method of XrdPfc::IO Called to check if destruction needs to be done in a separate task.

Implements XrdPfc::IO.

Definition at line 109 of file XrdPfcIOFile.cc.

110{
112 return m_file->ioActive(this);
113}
const char * RefreshLocation()
Definition XrdPfcIO.hh:55

References XrdPfc::IO::RefreshLocation().

Here is the call graph for this function:

◆ pgRead() [1/2]

int XrdOucCacheIO::pgRead ( char * buff,
long long offs,
int rdlen,
std::vector< uint32_t > & csvec,
uint64_t opts = 0,
int * csfix = 0 )
virtual

Reimplemented from XrdOucCacheIO.

Definition at line 190 of file XrdOucCache.cc.

45{
46 (void)csfix;
47 int bytes;
48
49// Read the data into the buffer
50//
51 bytes = Read(buff, offs, rdlen);
52
53// Calculate checksums if so wanted
54//
55 if (bytes > 0 && (opts & forceCS))
56 XrdOucPgrwUtils::csCalc((const char *)buff, (ssize_t)offs,
57 (size_t)bytes, csvec);
58
59// All done
60//
61 return bytes;
62}
struct myOpts opts
static const uint64_t forceCS
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
int Read(char *buff, long long off, int size) override
Pass Read request to the corresponding File object.

◆ pgRead() [2/2]

void IOFile::pgRead ( XrdOucCacheIOCB & iocb,
char * buff,
long long offs,
int rdlen,
std::vector< uint32_t > & csvec,
uint64_t opts = 0,
int * csfix = 0 )
overridevirtual

Read file pages and checksums using asynchronous I/O (default sync).

Parameters
iocbreference to the callback object that receives the result. All results are returned via this object's Done() method. If the caller holds any locks they must be recursive locks as the callback may occur on the calling thread.
buffpointer to buffer where the bytes are to be placed.
offsThe offset where the read is to start.
rdlenThe number of bytes to read.
csvecA vector which will be filled with the corresponding CRC32C checksum for each page or page segment.
optsProcessing options: forceCS - always return checksums even when not available.
csfixWhen not nil, returns the number of corrected checksum errs.

Reimplemented from XrdOucCacheIO.

Definition at line 198 of file XrdPfcIOFile.cc.

200{
201 struct ZHandler : ReadReqRH
202 { using ReadReqRH::ReadReqRH;
203 IOFile *m_io = nullptr;
204 std::function<void (int)> m_lambda {0};
205
206 void Done(int result) override {
207 if (m_lambda) m_lambda(result);
208 m_io->ReadEnd(result, this);
209 }
210 };
211
213
214 auto *rh = new ZHandler(ObtainReadSid(), &iocb);
215 rh->m_io = this;
216
217 TRACEIO(Dump, "pgRead() async " << this << " sid: " << Xrd::hex1 << rh->m_seq_id << " off: " << off << " size: " << size);
218
220 rh->m_lambda = [=, &csvec](int result) {
221 if (result > 0)
222 XrdOucPgrwUtils::csCalc((const char *)buff, (ssize_t)off, (size_t)result, csvec);
223 };
224
225 int retval = ReadBegin(buff, off, size, rh);
226 if (retval != kReadPending)
227 {
228 rh->Done(retval);
229 }
230}
virtual void Done(int result)=0
RAtomic_int m_active_read_reqs
number of active read requests
Definition XrdPfcIO.hh:70
unsigned short ObtainReadSid()
Definition XrdPfcIO.hh:57
constexpr int kReadPending
Definition XrdPfcFile.hh:54
ReadReqRH(unsigned short sid, XrdOucCacheIOCB *iocb)
Definition XrdPfcFile.hh:63

References IOFile(), XrdPfc::ReadReqRH::ReadReqRH(), XrdOucPgrwUtils::csCalc(), XrdOucCacheIO::forceCS, Xrd::hex1, XrdPfc::kReadPending, XrdPfc::IO::m_active_read_reqs, XrdPfc::IO::ObtainReadSid(), opts, and TRACEIO.

Here is the call graph for this function:

◆ Read() [1/2]

int IOFile::Read ( char * buff,
long long off,
int size )
overridevirtual

Pass Read request to the corresponding File object.

Implements XrdOucCacheIO.

Definition at line 151 of file XrdPfcIOFile.cc.

152{
154
155 auto *rh = new ReadReqRHCond(ObtainReadSid(), nullptr);
156
157 TRACEIO(Dump, "Read() sync " << this << " sid: " << Xrd::hex1 << rh->m_seq_id << " off: " << off << " size: " << size);
158
159 rh->m_cond.Lock();
160 int retval = ReadBegin(buff, off, size, rh);
161 if (retval == kReadPending)
162 {
163 rh->m_cond.Wait();
164 retval = rh->m_retval;
165 }
166 rh->m_cond.UnLock();
167
168 return ReadEnd(retval, rh);
169}

References Xrd::hex1, XrdPfc::kReadPending, XrdPfc::IO::m_active_read_reqs, XrdPfc::IO::ObtainReadSid(), and TRACEIO.

Here is the call graph for this function:

◆ Read() [2/2]

void IOFile::Read ( XrdOucCacheIOCB & iocb,
char * buff,
long long offs,
int rlen )
overridevirtual

Perform an asynchronous read (defaults to synchronous).

Parameters
iocbreference to the callback object that receives the result. All results are returned via this object's Done() method. If the caller holds any locks they must be recursive locks as the callback may occur on the calling thread.
buffpointer to the buffer to receive the results. The buffer must remain valid until the callback is invoked.
offsthe offset into the file.
rlenthe number of bytes to read.

Reimplemented from XrdOucCacheIO.

Definition at line 172 of file XrdPfcIOFile.cc.

173{
174 struct ZHandler : ReadReqRH
175 { using ReadReqRH::ReadReqRH;
176 IOFile *m_io = nullptr;
177
178 void Done(int result) override {
179 m_io->ReadEnd(result, this);
180 }
181 };
182
184
185 auto *rh = new ZHandler(ObtainReadSid(), &iocb);
186 rh->m_io = this;
187
188 TRACEIO(Dump, "Read() async " << this << " sid: " << Xrd::hex1 << rh->m_seq_id << " off: " << off << " size: " << size);
189
190 int retval = ReadBegin(buff, off, size, rh);
191 if (retval != kReadPending)
192 {
193 rh->Done(retval);
194 }
195}

References IOFile(), XrdPfc::ReadReqRH::ReadReqRH(), Xrd::hex1, XrdPfc::kReadPending, XrdPfc::IO::m_active_read_reqs, XrdPfc::IO::ObtainReadSid(), and TRACEIO.

Here is the call graph for this function:

◆ ReadV() [1/2]

int IOFile::ReadV ( const XrdOucIOVec * readV,
int n )
overridevirtual

Pass ReadV request to the corresponding File object.

Reimplemented from XrdOucCacheIO.

Definition at line 277 of file XrdPfcIOFile.cc.

278{
280
281 auto *rh = new ReadReqRHCond(ObtainReadSid(), nullptr);
282
283 TRACEIO(Dump, "ReadV() sync " << this << " sid: " << Xrd::hex1 << rh->m_seq_id << " n_chunks: " << n);
284
285 rh->m_cond.Lock();
286 int retval = ReadVBegin(readV, n, rh);
287 if (retval == kReadPending)
288 {
289 rh->m_cond.Wait();
290 retval = rh->m_retval;
291 }
292 rh->m_cond.UnLock();
293 return ReadVEnd(retval, rh);
294}

References Xrd::hex1, XrdPfc::kReadPending, XrdPfc::IO::m_active_read_reqs, XrdPfc::ReadReqRH::m_seq_id, XrdPfc::IO::ObtainReadSid(), and TRACEIO.

Here is the call graph for this function:

◆ ReadV() [2/2]

void IOFile::ReadV ( XrdOucCacheIOCB & iocb,
const XrdOucIOVec * readV,
int rnum )
overridevirtual

Perform an asynchronous vector read (defaults to synchronous).

Parameters
iocbreference to the callback object that receives the result. All results are returned via this object's Done() method. If the caller holds any locks they must be recursive locks as the callback may occur on the calling thread.
readVpointer to a vector of read requests.
rnumthe number of elements in the vector.

Reimplemented from XrdOucCacheIO.

Definition at line 297 of file XrdPfcIOFile.cc.

298{
299 struct ZHandler : ReadReqRH
300 { using ReadReqRH::ReadReqRH;
301 IOFile *m_io = nullptr;
302
303 void Done(int result) override { m_io-> ReadVEnd(result, this); }
304 };
305
307
308 auto *rh = new ZHandler(ObtainReadSid(), &iocb);
309 rh->m_io = this;
310
311 TRACEIO(Dump, "ReadV() async " << this << " sid: " << Xrd::hex1 << rh->m_seq_id << " n_chunks: " << n);
312
313 int retval = ReadVBegin(readV, n, rh);
314 if (retval != kReadPending)
315 {
316 rh->Done(retval);
317 }
318}

References IOFile(), XrdPfc::ReadReqRH::ReadReqRH(), XrdOucCacheIOCB::Done(), Xrd::hex1, XrdPfc::kReadPending, XrdPfc::IO::m_active_read_reqs, XrdPfc::ReadReqRH::m_seq_id, XrdPfc::IO::ObtainReadSid(), and TRACEIO.

Here is the call graph for this function:

◆ Update()

void IOFile::Update ( XrdOucCacheIO & iocp)
overridevirtual

Update the originally passed XrdOucCacheIO object with the object passed. All future uses underlying XrdOucCacheIO object must now use this object. Update() is called when Prepare() indicated that the file should not be physically opened and a file method was invoked in the XrdOucCacheIO passed to Attach(). When this occurs, the file is actually opened and Update() called to replace the original XrdOucCacheIO object with one that uses the newly opened file.

Parameters
iocpreference to the new XrdOucCacheIO object.

Reimplemented from XrdPfc::IO.

Definition at line 102 of file XrdPfcIOFile.cc.

103{
104 IO::Update(iocp);
105 m_file->ioUpdated(this);
106}
void Update(XrdOucCacheIO &iocp) override
Definition XrdPfcIO.cc:17

References XrdOucCacheIO::XrdOucCacheIO(), and XrdPfc::IO::Update().

Here is the call graph for this function:

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