Skip to content

Commit

Permalink
Cleanup items from code review
Browse files Browse the repository at this point in the history
- Switch to the cinfo file's creation time to use for the age attribute,
  not the file's ctime.
- Cleanup the initCacheFile signature; input argument is not necessary.
- Tune up some debug messages.
  • Loading branch information
bbockelm authored and osschar committed Feb 23, 2023
1 parent 2c0b531 commit 0d74d6a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/XrdHttp/XrdHttpReq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2288,18 +2288,16 @@ int XrdHttpReq::PostProcessHTTPReq(bool final_) {

// Always try to parse response. In the case of a caching proxy, the open
// will have created the file in cache
filectime = 0;
if (iovP[1].iov_len > 1) {
TRACEI(REQ, "Stat for GET " << resource.c_str()
<< " stat=" << (char *) iovP[1].iov_base);

long dummyl;
sscanf((const char *) iovP[1].iov_base, "%ld %lld %ld %ld %ld",
sscanf((const char *) iovP[1].iov_base, "%ld %lld %ld %ld",
&dummyl,
&filesize,
&fileflags,
&filemodtime,
&filectime);
&filemodtime);

// As above: if the client specified a response size, we use that.
// Otherwise, utilize the filesize
Expand All @@ -2320,7 +2318,7 @@ int XrdHttpReq::PostProcessHTTPReq(bool final_) {
if (!responseHeader.empty()) {
responseHeader += "\r\n";
}
long object_age = time(NULL) - filectime;
long object_age = time(NULL) - filemodtime;
responseHeader += std::string("Age: ") + std::to_string(object_age < 0 ? 0 : object_age);
}

Expand Down
20 changes: 12 additions & 8 deletions src/XrdPfc/XrdPfcIOFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ IOFile::~IOFile()
//______________________________________________________________________________
int IOFile::Fstat(struct stat &sbuff)
{
std::string name = GetFilename() + Info::s_infoExtension;

int res = 0;
if( ! m_localStat)
{
res = initCachedStat(name.c_str());
res = initCachedStat();
if (res) return res;
}

Expand All @@ -74,7 +72,7 @@ long long IOFile::FSize()
}

//______________________________________________________________________________
int IOFile::initCachedStat(const char* path)
int IOFile::initCachedStat()
{
// Called indirectly from the constructor.

Expand All @@ -83,18 +81,24 @@ int IOFile::initCachedStat(const char* path)
int res = -1;
struct stat tmpStat;

if (m_cache.GetOss()->Stat(GetFilename().c_str(), &tmpStat) == XrdOssOK)
std::string fname = GetFilename();
std::string iname = fname + Info::s_infoExtension;
if (m_cache.GetOss()->Stat(fname.c_str(), &tmpStat) == XrdOssOK)
{
XrdOssDF* infoFile = m_cache.GetOss()->newFile(Cache::GetInstance().RefConfiguration().m_username.c_str());
XrdOucEnv myEnv;
int res_open;
if ((res_open = infoFile->Open(path, O_RDONLY, 0600, myEnv)) == XrdOssOK)
if ((res_open = infoFile->Open(iname.c_str(), O_RDONLY, 0600, myEnv)) == XrdOssOK)
{
Info info(m_cache.GetTrace());
if (info.Read(infoFile, path))
if (info.Read(infoFile, iname.c_str()))
{
// The filesize from the file itself may be misleading if its download is incomplete; take it from the cinfo.
tmpStat.st_size = info.GetFileSize();
TRACEIO(Info, trace_pfx << "successfully read size from info file = " << tmpStat.st_size);
// We are arguably abusing the mtime to be the creation time of the file; then ctime becomes the
// last time additional data was cached.
tmpStat.st_mtime = info.GetCreationTime();
TRACEIO(Info, trace_pfx << "successfully read size " << tmpStat.st_size << " and creation time " << tmpStat.st_mtime << " from info file");
res = 0;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/XrdPfc/XrdPfcIOFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private:
int ReadVEnd(int retval, ReadReqRH *rh);

struct stat *m_localStat;
int initCachedStat(const char* path);
int initCachedStat();


};
Expand Down

0 comments on commit 0d74d6a

Please sign in to comment.