41 IO(io, cache), m_localStat(0), m_info(cache.GetTrace(), false), m_info_file(0)
44 GetBlockSizeFromPath();
69 for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
72 if (it->second) it->second->ioUpdated(
this);
88 for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
91 if (it->second && it->second->ioActive(
this))
111 for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
115 it->second->RequestSyncOfDetachStats();
125 void IOFileBlock::CloseInfoFile()
138 m_info_file->
Fsync();
139 m_info_file->
Close();
147 void IOFileBlock::GetBlockSizeFromPath()
149 const static std::string tag =
"hdfsbsize=";
152 size_t pos1 = path.find(tag);
153 size_t t = tag.length();
155 if (pos1 != path.npos)
158 size_t pos2 = path.find(
"&", pos1);
159 if (pos2 != path.npos )
161 std::string bs = path.substr(pos1, pos2 - pos1);
162 m_blocksize = atoi(bs.c_str());
166 m_blocksize = atoi(path.substr(pos1).c_str());
169 TRACEIO(
Debug,
"GetBlockSizeFromPath(), blocksize = " << m_blocksize );
174 File* IOFileBlock::newBlockFile(
long long off,
int blocksize)
180 std::stringstream ss;
184 sprintf(&offExt[0],
"___%lld_%lld", m_blocksize, off);
200 if ( ! m_localStat)
return -ENOENT;
202 memcpy(&sbuff, m_localStat,
sizeof(
struct stat));
209 if ( ! m_localStat)
return -ENOENT;
211 return m_localStat->st_size;
215 int IOFileBlock::initLocalStat()
227 if (m_info_file->
Open(path.c_str(), O_RDWR, 0600, myEnv) ==
XrdOssOK)
229 if (m_info.
Read(m_info_file, path.c_str()))
232 TRACEIO(
Info,
"initCachedStat successfully read size from existing info file = " << tmpStat.st_size);
238 TRACEIO(
Debug,
"initCachedStat info file is not complete");
246 if (m_info_file) {
delete m_info_file; m_info_file = 0; }
249 TRACEIO(
Debug,
"initCachedStat get stat from client res= " << res <<
"size = " << tmpStat.st_size);
255 if (m_info_file->
Open(path.c_str(), O_RDWR, 0600, myEnv) ==
XrdOssOK)
262 m_info.
Write(m_info_file, path.c_str());
263 m_info_file->
Fsync();
267 TRACEIO(
Error,
"initCachedStat can't open info file path");
272 TRACEIO(
Error,
"initCachedStat can't create info file path");
279 m_localStat =
new struct stat;
280 memcpy(m_localStat, &tmpStat,
sizeof(
struct stat));
291 long long fileSize =
FSize();
299 if (off + size > fileSize)
300 size = fileSize - off;
302 long long off0 = off;
303 int idx_first = off0 / m_blocksize;
304 int idx_last = (off0 + size - 1) / m_blocksize;
306 TRACEIO(Dump,
"Read() "<< off <<
"@" << size <<
" block range ["<< idx_first <<
", " << idx_last <<
"]");
308 for (
int blockIdx = idx_first; blockIdx <= idx_last; ++blockIdx)
313 std::map<int, File*>::iterator it = m_blocks.find(blockIdx);
314 if (it != m_blocks.end())
320 size_t pbs = m_blocksize;
322 int lastIOFileBlock = (fileSize-1)/m_blocksize;
323 if (blockIdx == lastIOFileBlock )
325 pbs = fileSize - blockIdx*m_blocksize;
330 fb = newBlockFile(blockIdx*m_blocksize, pbs);
331 m_blocks.insert(std::make_pair(blockIdx, fb));
336 int readBlockSize = size;
337 if (idx_first != idx_last)
339 if (blockIdx == idx_first)
341 readBlockSize = (blockIdx + 1) * m_blocksize - off0;
342 TRACEIO(Dump,
"Read partially till the end of the block");
344 else if (blockIdx == idx_last)
346 readBlockSize = (off0 + size) - blockIdx * m_blocksize;
347 TRACEIO(Dump,
"Read partially till the end of the block");
351 readBlockSize = m_blocksize;
355 TRACEIO(Dump,
"Read() block[ " << blockIdx <<
"] read-block-size[" << readBlockSize <<
"], offset[" << readBlockSize <<
"] off = " << off );
365 void Done(
int result)
override
366 { m_cond.
Lock(); m_retval = result; m_cond.Signal(); m_cond.UnLock(); }
372 retvalBlock = fb->
Read(
this, buff, off, readBlockSize, &rh);
373 if (retvalBlock == -EWOULDBLOCK)
382 retvalBlock =
GetInput()->
Read(buff, off, readBlockSize);
385 TRACEIO(Dump,
"Read() Block read returned " << retvalBlock);
386 if (retvalBlock == readBlockSize)
388 bytes_read += retvalBlock;
392 else if (retvalBlock >= 0)
394 TRACEIO(
Warning,
"Read() incomplete read, missing bytes " << readBlockSize-retvalBlock);
399 TRACEIO(
Error,
"Read() read error, retval" << retvalBlock);
int stat(const char *path, struct stat *buf)
virtual int Close(long long *retsz=0)=0
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
virtual int Create(const char *tid, const char *path, mode_t mode, XrdOucEnv &env, int opts=0)=0
virtual XrdOssDF * newFile(const char *tident)=0
virtual int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *envP=0)=0
virtual const char * Path()=0
virtual int Read(char *buff, long long offs, int rlen)=0
virtual int Fstat(struct stat &sbuff)
Attaches/creates and detaches/deletes cache-io objects for disk based cache.
File * GetFile(const std::string &, IO *, long long off=0, long long filesize=0)
const Configuration & RefConfiguration() const
Reference XrdPfc configuration.
static Cache & GetInstance()
Singleton access.
void ReleaseFile(File *, IO *)
int Read(IO *io, char *buff, long long offset, int size, ReadReqRH *rh)
Normal read.
void Update(XrdOucCacheIO &iocp) override
long long FSize() override
virtual int Read(char *buff, long long offs, int rlen)=0
Pass Read request to the corresponding File object.
int Fstat(struct stat &sbuff) override
IOFileBlock(XrdOucCacheIO *io, Cache &cache)
bool ioActive() override
Abstract virtual method of XrdPfc::IO Called to check if destruction needs to be done in a separate t...
void DetachFinalize() override
Abstract virtual method of XrdPfc::IO Called to destruct the IO object after it is no longer used.
Base cache-io class that implements some XrdOucCacheIO abstract methods.
XrdOucCacheIO * GetInput()
Cache & m_cache
reference to Cache object
const char * RefreshLocation()
void Update(XrdOucCacheIO &iocp) override
unsigned short ObtainReadSid()
std::string GetFilename()
Status of cached file. Can be read from and written into a binary file.
static const char * s_infoExtension
bool Write(XrdOssDF *fp, const char *dname, const char *fname=0)
long long GetFileSize() const
Get file size.
bool Read(XrdOssDF *fp, const char *dname, const char *fname=0)
Read content of cinfo file into this object.
void SetBufferSizeFileSizeAndCreationTime(long long bs, long long fs)
void WriteIOStatDetach(Stats &s)
Write close time together with bytes missed, hits, and disk.
Statistics of cache utilisation by a File object.
long long m_hdfsbsize
used with m_hdfsmode, default 128MB
long long m_bufferSize
prefetch buffer size, default 1MB
std::string m_username
username passed to oss plugin
ReadReqRH(unsigned short sid, XrdOucCacheIOCB *iocb)