1 #ifndef __XRDPFC_FILE_HH__
2 #define __XRDPFC_FILE_HH__
40 class BlockResponseHandler;
41 class DirectResponseHandler;
44 struct ReadVBlockListRAM;
45 struct ReadVChunkListRAM;
46 struct ReadVBlockListDisk;
47 struct ReadVChunkListDisk;
127 Block(
File *f,
IO *io,
void *rid,
char *buf,
long long off,
int size,
int rsize,
178 void Done(
int result)
override;
197 void Done(
int result)
override;
220 int Read(
IO *io,
char* buff,
long long offset,
int size,
ReadReqRH *rh);
260 const char*
lPath()
const;
295 File(
const std::string &path,
long long offset,
long long fileSize);
305 void parse_pfc_url_args(
XrdOucCacheIO* inputIO,
long long &pfc_blocksize,
int &pfc_prefetch)
const;
307 static const char *m_traceID;
315 const std::string m_filename;
316 const long long m_offset;
317 const long long m_file_size;
321 typedef std::set<IO*> IoSet_t;
322 typedef IoSet_t::iterator IoSet_i;
325 IoSet_i m_current_io;
330 std::vector<int> m_writes_during_sync;
331 int m_non_flushed_cnt;
333 bool m_detach_time_logged;
338 typedef std::list<int> IntList_t;
339 typedef IntList_t::iterator IntList_i;
341 typedef std::map<int, Block*> BlockMap_t;
342 typedef BlockMap_t::iterator BlockMap_i;
344 BlockMap_t m_block_map;
346 long long m_block_size;
353 long long m_st_blocks;
354 long long m_resmon_report_threshold;
357 void check_delta_stats();
358 void report_and_merge_delta_stats();
360 std::set<std::string> m_remote_locations;
361 void insert_remote_location(
const std::string &loc);
365 enum PrefetchState_e { kOff=-1, kOn, kHold, kStopped, kComplete };
367 PrefetchState_e m_prefetch_state;
368 int m_prefetch_max_blocks_in_flight;
370 long long m_prefetch_bytes;
371 int m_prefetch_read_cnt;
372 int m_prefetch_hit_cnt;
373 float m_prefetch_score;
375 void inc_prefetch_read_cnt(
int prc) {
if (prc) { m_prefetch_read_cnt += prc; calc_prefetch_score(); } }
376 void inc_prefetch_hit_cnt (
int phc) {
if (phc) { m_prefetch_hit_cnt += phc; calc_prefetch_score(); } }
377 void calc_prefetch_score() { m_prefetch_score = float(m_prefetch_hit_cnt) / m_prefetch_read_cnt; }
381 bool overlap(
int blk,
392 Block* PrepareBlockRequest(
int i, IO *io,
void *req_id,
bool prefetch);
394 void ProcessBlockRequest (Block *b);
397 void RequestBlocksDirect(IO *io, ReadRequest *read_req, std::vector<XrdOucIOVec>& ioVec,
int expected_size);
399 int ReadBlocksFromDisk(std::vector<XrdOucIOVec>& ioVec,
int expected_size);
401 int ReadOpusCoalescere(IO *io,
const XrdOucIOVec *readV,
int readVnum,
402 ReadReqRH *rh,
const char *tpfx);
404 void ProcessDirectReadFinished(ReadRequest *rreq,
int bytes_read,
int error_cond);
405 void ProcessBlockError(Block *b, ReadRequest *rreq);
406 void ProcessBlockSuccess(Block *b, ChunkRequest &creq);
407 void FinalizeReadRequest(ReadRequest *rreq);
409 void ProcessBlockResponse(Block *b,
int res);
413 void inc_ref_count(Block* b);
414 void dec_ref_count(Block* b,
int count = 1);
415 void free_block(Block*);
417 bool select_current_io_or_disable_prefetching(
bool skip_current);
419 int offsetIdx(
int idx)
const;
424 inline void File::inc_ref_count(Block* b)
432 inline void File::dec_ref_count(Block* b,
int count)
435 assert(b->is_finished());
436 b->m_refcnt -= count;
437 assert(b->m_refcnt >= 0);
439 if (b->m_refcnt == 0)
void Done(int result) override
BlockResponseHandler(Block *b)
int * ptr_n_cksum_errors()
Block(File *f, IO *io, void *rid, char *buf, long long off, int size, int rsize, bool m_prefetch, bool cks_net)
void * get_req_id() const
long long get_offset() const
vChunkRequest_t m_chunk_reqs
vCkSum_t & ref_cksum_vec()
bool req_cksum_net() const
void reset_error_and_set_io(IO *io, void *rid)
Attaches/creates and detaches/deletes cache-io objects for disk based cache.
void Done(int result) override
DirectResponseHandler(File *file, ReadRequest *rreq, int to_wait)
bool FinalizeSyncBeforeExit()
Returns true if any of blocks need sync. Called from Cache::dec_ref_cnt on zero ref cnt.
const char * lPath() const
Log path.
int ReadV(IO *io, const XrdOucIOVec *readV, int readVnum, ReadReqRH *rh)
Vector read.
void WriteBlockToDisk(Block *b)
float GetPrefetchScore() const
void StopPrefetchingOnIO(IO *io)
std::string GetRemoteLocations() const
const Info::AStat * GetLastAccessStats() const
size_t GetAccessCnt() const
int Fstat(struct stat &sbuff)
static File * FileOpen(const std::string &path, long long offset, long long fileSize, XrdOucCacheIO *inputIO)
Static constructor that also does Open. Returns null ptr if Open fails.
void RequestSyncOfDetachStats()
Flags that detach stats should be written out in final sync. Called from CacheIO upon Detach.
long long GetPrefetchedBytes() const
int GetNDownloadedBlocks() const
void BlocksRemovedFromWriteQ(std::list< Block * > &)
Handle removal of a set of blocks from Cache's write queue.
int GetPrefetchCountOnIO(IO *io)
void Sync()
Sync file cache inf o and output data with disk.
XrdSysTrace * GetTrace() const
int Read(IO *io, char *buff, long long offset, int size, ReadReqRH *rh)
Normal read.
void ioUpdated(IO *io)
Notification from IO that it has been updated (remote open).
long long initiate_emergency_shutdown()
long long GetFileSize() const
const Stats & RefStats() const
void BlockRemovedFromWriteQ(Block *)
Handle removal of a block from Cache's write queue.
const std::string & GetLocalPath() const
bool is_in_emergency_shutdown()
XrdSysError * GetLog() const
bool ioActive(IO *io)
Initiate close. Return true if still IO active. Used in XrdPosixXrootd::Close()
Base cache-io class that implements some XrdOucCacheIO abstract methods.
Status of cached file. Can be read from and written into a binary file.
const AStat * GetLastAccessStats() const
Get latest access stats.
long long GetBufferSize() const
Get prefetch buffer size.
int GetNDownloadedBlocks() const
Get number of downloaded blocks.
size_t GetAccessCnt() const
Get number of accesses.
int GetNBlocks() const
Get number of blocks represented in download-state bit-vector.
Statistics of cache utilisation by a File object.
OpenImpl< false > Open(Ctx< File > file, Arg< std::string > url, Arg< OpenFlags::Flags > flags, Arg< Access::Mode > mode=Access::None, uint16_t timeout=0)
Factory for creating ReadImpl objects.
CloseImpl< false > Close(Ctx< File > file, uint16_t timeout=0)
Factory for creating CloseImpl objects.
std::vector< ChunkRequest > vChunkRequest_t
std::vector< ChunkRequest >::iterator vChunkRequest_i
std::list< Block * > BlockList_t
std::vector< uint32_t > vCkSum_t
std::list< Block * >::iterator BlockList_i
ChunkRequest(ReadRequest *rreq, char *buf, long long off, int size)
ReadReqRH(unsigned short sid, XrdOucCacheIOCB *iocb)
void update_error_cond(int ec)
ReadRequest(IO *io, ReadReqRH *rh)