40 IO(io, cache), m_localStat(0), m_info(cache.
GetTrace(), false), m_info_file(0)
43 GetBlockSizeFromPath();
68 for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
71 if (it->second) it->second->ioUpdated(
this);
87 for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
90 if (it->second && it->second->ioActive(
this))
110 for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
114 it->second->RequestSyncOfDetachStats();
115 m_cache.ReleaseFile(it->second,
this);
124void IOFileBlock::CloseInfoFile()
137 m_info_file->
Fsync();
138 m_info_file->
Close();
146void IOFileBlock::GetBlockSizeFromPath()
148 const static std::string tag =
"hdfsbsize=";
151 size_t pos1 = path.find(tag);
152 size_t t = tag.length();
154 if (pos1 != path.npos)
157 size_t pos2 = path.find(
"&", pos1);
158 if (pos2 != path.npos )
160 std::string bs = path.substr(pos1, pos2 - pos1);
161 m_blocksize = atoi(bs.c_str());
165 m_blocksize = atoi(path.substr(pos1).c_str());
168 TRACEIO(
Debug,
"GetBlockSizeFromPath(), blocksize = " << m_blocksize );
173File* IOFileBlock::newBlockFile(
long long off,
int blocksize)
179 std::stringstream ss;
183 sprintf(&offExt[0],
"___%lld_%lld", m_blocksize, off);
199 if ( ! m_localStat)
return -ENOENT;
201 memcpy(&sbuff, m_localStat,
sizeof(
struct stat));
208 if ( ! m_localStat)
return -ENOENT;
210 return m_localStat->st_size;
214int IOFileBlock::initLocalStat()
226 if (m_info_file->
Open(path.c_str(), O_RDWR, 0600, myEnv) ==
XrdOssOK)
228 if (m_info.
Read(m_info_file, path.c_str()))
231 TRACEIO(
Info,
"initCachedStat successfully read size from existing info file = " << tmpStat.st_size);
237 TRACEIO(
Debug,
"initCachedStat info file is not complete");
245 if (m_info_file) {
delete m_info_file; m_info_file = 0; }
248 TRACEIO(
Debug,
"initCachedStat get stat from client res= " << res <<
"size = " << tmpStat.st_size);
253 m_info_file =
m_cache.GetOss()->newFile(
m_cache.RefConfiguration().m_username.c_str());
254 if (m_info_file->Open(path.c_str(), O_RDWR, 0600, myEnv) ==
XrdOssOK)
259 m_info.SetBufferSizeFileSizeAndCreationTime(
m_cache.RefConfiguration().m_bufferSize, tmpStat.st_size);
261 m_info.Write(m_info_file, path.c_str());
262 m_info_file->Fsync();
266 TRACEIO(
Error,
"initCachedStat can't open info file path");
271 TRACEIO(
Error,
"initCachedStat can't create info file path");
278 m_localStat =
new struct stat;
279 memcpy(m_localStat, &tmpStat,
sizeof(
struct stat));
290 long long fileSize =
FSize();
298 if (off + size > fileSize)
299 size = fileSize - off;
301 long long off0 = off;
302 int idx_first = off0 / m_blocksize;
303 int idx_last = (off0 + size - 1) / m_blocksize;
305 TRACEIO(Dump,
"Read() "<< off <<
"@" << size <<
" block range ["<< idx_first <<
", " << idx_last <<
"]");
307 for (
int blockIdx = idx_first; blockIdx <= idx_last; ++blockIdx)
312 std::map<int, File*>::iterator it = m_blocks.find(blockIdx);
313 if (it != m_blocks.end())
319 size_t pbs = m_blocksize;
321 int lastIOFileBlock = (fileSize-1)/m_blocksize;
322 if (blockIdx == lastIOFileBlock )
324 pbs = fileSize - blockIdx*m_blocksize;
329 fb = newBlockFile(blockIdx*m_blocksize, pbs);
330 m_blocks.insert(std::make_pair(blockIdx, fb));
335 int readBlockSize = size;
336 if (idx_first != idx_last)
338 if (blockIdx == idx_first)
340 readBlockSize = (blockIdx + 1) * m_blocksize - off0;
341 TRACEIO(Dump,
"Read partially till the end of the block");
343 else if (blockIdx == idx_last)
345 readBlockSize = (off0 + size) - blockIdx * m_blocksize;
346 TRACEIO(Dump,
"Read partially till the end of the block");
350 readBlockSize = m_blocksize;
354 TRACEIO(Dump,
"Read() block[ " << blockIdx <<
"] read-block-size[" << readBlockSize <<
"], offset[" << readBlockSize <<
"] off = " << off );
364 void Done(
int result)
override
371 retvalBlock = fb->
Read(
this, buff, off, readBlockSize, &rh);
372 if (retvalBlock == -EWOULDBLOCK)
381 retvalBlock =
GetInput()->
Read(buff, off, readBlockSize);
384 TRACEIO(Dump,
"Read() Block read returned " << retvalBlock);
385 if (retvalBlock == readBlockSize)
387 bytes_read += retvalBlock;
391 else if (retvalBlock >= 0)
393 TRACEIO(Warning,
"Read() incomplete read, missing bytes " << readBlockSize-retvalBlock);
398 TRACEIO(
Error,
"Read() read error, retval" << retvalBlock);
virtual int Close(long long *retsz=0)=0
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
virtual XrdOssDF * newFile(const char *tident)=0
virtual int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *envP=0)=0
virtual int Read(char *buff, long long offs, int rlen)=0
virtual int Fstat(struct stat &sbuff)
virtual const char * Path()=0
XrdOucCacheIO()
Construct and Destructor.
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.
int Read(IO *io, char *buff, long long offset, int size, ReadReqRH *rh)
Normal read.
void Update(XrdOucCacheIO &iocp) override
long long FSize() override
int Fstat(struct stat &sbuff) override
int Read(char *Buffer, long long Offset, int Length) 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.
std::string GetFilename()
IO(XrdOucCacheIO *io, Cache &cache)
XrdOucCacheIO * GetInput()
Cache & m_cache
reference to Cache object
const char * RefreshLocation()
void Update(XrdOucCacheIO &iocp) override
unsigned short ObtainReadSid()
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 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
std::string m_username
username passed to oss plugin
ReadReqRH(unsigned short sid, XrdOucCacheIOCB *iocb)