Skip to content

Commit

Permalink
XrdApps::JCache: major extension to allow disconnected file serving -…
Browse files Browse the repository at this point in the history
… enable via config async=1|true or XRD_JCACHE_ASYNC=1|true or via CGI ?xrd.jcache.async=1

- with async operation there is no source check done about the filesize and the assumption is, that the filesize and mtime is correct
XrdApps::JCache: add new counter showing the time 'lost' in waiting for Open
  • Loading branch information
apeters1971 committed Jun 14, 2024
1 parent a1f7f5f commit f8fcd50
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 39 deletions.
4 changes: 4 additions & 0 deletions src/XrdApps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ add_library(
XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc
XrdApps/XrdClJCachePlugin/vector/XrdClVectorCache.cc
XrdApps/XrdClJCachePlugin/vector/XrdClVectorCache.hh
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheOpenHandler.cc
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheOpenHandler.hh
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadHandler.hh
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadVHandler.hh
XrdApps/XrdClJCachePlugin/cache/Journal.cc
XrdApps/XrdClJCachePlugin/cache/Journal.hh
XrdApps/XrdClJCachePlugin/cache/IntervalTree.hh
Expand Down
38 changes: 28 additions & 10 deletions src/XrdApps/XrdClJCachePlugin/cache/Journal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,22 @@ void Journal::read_jheader() {
return;
}
// TODO: understand why the mtime is +-1s
if ((abs(fheader.mtime - jheader.mtime) > 1) ||
(fheader.mtime_nsec != jheader.mtime_nsec) ||
(fheader.filesize != jheader.filesize)) {
if (fheader.mtime) {
if (jheader.mtime) {
if ((abs(fheader.mtime - jheader.mtime) > 1) ||
(fheader.mtime_nsec != jheader.mtime_nsec) ||
(jheader.filesize && (fheader.filesize != jheader.filesize))) {
std::cerr << "warning: remote file change detected - purging path:"
<< path << std::endl;
std::cerr << fheader.mtime << ":" << jheader.mtime << " "
<< fheader.mtime_nsec << ":" << jheader.mtime_nsec << " "
<< fheader.filesize << ":" << jheader.filesize << std::endl;
reset();
return;
}
reset();
return;
} else {
// we assume the contents referenced in the header is ok to allow disconnected ops
jheader.mtime = fheader.mtime;
jheader.filesize = fheader.filesize;
}
}

Expand Down Expand Up @@ -155,13 +159,27 @@ int Journal::read_journal() {
//! Journal attach
//------------------------------------------------------------------------------
int Journal::attach(const std::string &lpath, uint64_t mtime,
uint64_t mtime_nsec, uint64_t size) {
uint64_t mtime_nsec, uint64_t size, bool ifexists) {
std::lock_guard<std::mutex> guard(mtx);
path = lpath;
jheader.mtime = mtime;
jheader.mtime_nsec = mtime_nsec;
jheader.filesize = size;

if (!ifexists) {
jheader.mtime = mtime;
jheader.mtime_nsec = mtime_nsec;
jheader.filesize = size;
}

if (ifexists) {
struct stat buf;
// check if there is already a journal for this file known
if (::stat(path.c_str(), &buf)) {
return -ENOENT;
} else {
if ((size_t)buf.st_size < sizeof(jheader_t)) {
return -EINVAL;
}
}
}
if ((fd == -1)) {
// need to open the file
size_t tries = 0;
Expand Down
12 changes: 11 additions & 1 deletion src/XrdApps/XrdClJCachePlugin/cache/Journal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public:

// base class interface
int attach(const std::string &path, uint64_t mtime, uint64_t mtime_nsec,
uint64_t size);
uint64_t size, bool ifexists=false);
int detach();
int unlink();

Expand All @@ -100,6 +100,16 @@ public:

std::string dump();

off_t getHeaderFileSize() {
std::lock_guard<std::mutex> guard(mtx);
return jheader.filesize;
}

off_t getHeaderMtime() {
std::lock_guard<std::mutex> guard(mtx);
return jheader.mtime;
}

private:
void process_intersection(interval_tree<uint64_t, const void *> &write,
interval_tree<uint64_t, uint64_t>::iterator acr,
Expand Down
7 changes: 6 additions & 1 deletion src/XrdApps/XrdClJCachePlugin/file/CacheStats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace JCache {
struct CacheStats {
CacheStats(bool doe = false)
: bytesRead(0), bytesReadV(0), bytesCached(0), bytesCachedV(0),
readOps(0), readVOps(0), readVreadOps(0), nreadfiles(0),
readOps(0), readVOps(0), readVreadOps(0), nreadfiles(0), totaldatasize(0),
dumponexit(doe), peakrate(0) {
// Get the current real time
struct timeval now;
Expand Down Expand Up @@ -219,6 +219,7 @@ struct CacheStats {
outFile << " \"readVreadOps\": " << readVreadOps.load() << ",\n";
outFile << " \"nreadfiles\": " << nreadfiles.load() << ",\n";
outFile << " \"totaldatasize\": " << totaldatasize.load() << ",\n";
outFile << " \"opentime_ms\": " << opentime.load() << ",\n";

std::lock_guard<std::mutex> lock(urlMutex);
outFile << " \"urls\": [";
Expand Down Expand Up @@ -315,6 +316,8 @@ struct CacheStats {
<< std::endl;
oss << "# JCache : open unique f. read : " << sStats.UniqueUrls()
<< std::endl;
oss << "# JCache : time to open files (s) : " << std::setprecision(3) << sStats.opentime.load()
<< std::endl;
oss << "# "
"-------------------------------------------------------------------"
"---- #"
Expand Down Expand Up @@ -361,6 +364,8 @@ struct CacheStats {
std::atomic<uint64_t> readVreadOps;
std::atomic<uint64_t> nreadfiles;
std::atomic<uint64_t> totaldatasize;
std::atomic<double> opentime;

std::atomic<bool> dumponexit;
std::set<std::string> urls;
std::mutex urlMutex;
Expand Down
Loading

0 comments on commit f8fcd50

Please sign in to comment.