Skip to content

Commit

Permalink
use the new XrdPosixCache interface to query cache file info
Browse files Browse the repository at this point in the history
  • Loading branch information
wyang007 committed Jun 1, 2019
1 parent a5da760 commit 4a231b7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 25 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ endif

FLAGS=-D_REENTRANT -D_THREAD_SAFE -Wno-deprecated -std=c++0x

HEADERS=rucioGetMetaLink.hh pfn2cache.hh checkPFCcinfo.hh
SOURCES=XrdOucName2NameDCP4RUCIO.cc XrdOssStatInfoDCP.cc rucioGetMetaLink.cc pfn2cache.cc checkPFCcinfo.cc
OBJECTS=XrdOucName2NameDCP4RUCIO.o XrdOssStatInfoDCP.o rucioGetMetaLink.o pfn2cache.o checkPFCcinfo.o
HEADERS=rucioGetMetaLink.hh pfn2cache.hh cacheQuery.hh
SOURCES=XrdOucName2NameDCP4RUCIO.cc XrdOssStatInfoDCP.cc rucioGetMetaLink.cc pfn2cache.cc cacheQuery.cc
OBJECTS=XrdOucName2NameDCP4RUCIO.o XrdOssStatInfoDCP.o rucioGetMetaLink.o pfn2cache.o cacheQuery.o

DEBUG=-g

XrdName2NameDCP4RUCIO.so: $(OBJECTS) Makefile
g++ ${DEBUG} -shared -fPIC -o $@ $(OBJECTS) -L${XRD_LIB} -L${XRD_LIB}/XrdCl -ldl -lssl -lcurl -lXrdCl -lXrdFileCache-4 -lstdc++
g++ ${DEBUG} -shared -fPIC -o $@ $(OBJECTS) -L${XRD_LIB} -L${XRD_LIB}/XrdCl -ldl -lssl -lcurl -lXrdCl -lXrdFileCache-4 -lXrdPosix -lstdc++

XrdOucName2NameDCP4RUCIO.o: XrdOucName2NameDCP4RUCIO.cc ${HEADERS} Makefile
g++ ${DEBUG} ${FLAGS} -fPIC -I ${XRD_INC} -I ${XRD_LIB} -c -o $@ $<
Expand All @@ -34,8 +34,11 @@ rucioGetMetaLink.o: rucioGetMetaLink.cc ${HEADERS} Makefile
pfn2cache.o: pfn2cache.cc ${HEADERS} Makefile
g++ ${DEBUG} ${FLAGS} -fPIC -I ${XRD_INC} -I ${XRD_LIB} -c -o $@ $<

checkPFCcinfo.o: checkPFCcinfo.cc ${HEADERS} Makefile
g++ ${DEBUG} ${FLAGS} -fPIC -I ${XRD_INC} -I /afs/slac/package/xrootd/githead/xrootd/src -c -o $@ $<
cacheQuery.o: cacheQuery.cc ${HEADERS} Makefile
g++ ${DEBUG} ${FLAGS} -fPIC -I ${XRD_INC} -I ${XRD_LIB} -c -o $@ $<

#checkPFCcinfo.o: checkPFCcinfo.cc ${HEADERS} Makefile
# g++ ${DEBUG} ${FLAGS} -fPIC -I ${XRD_INC} -I ${XRD_LIB} -c -o $@ $<

clean:
rm -vf *.{o,so}
Expand Down
3 changes: 1 addition & 2 deletions XrdOucName2NameDCP4RUCIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ XrdVERSIONINFO(XrdOucgetName2Name, "N2N-Xcache4RUCIO");

#include "rucioGetMetaLink.hh"
#include "pfn2cache.hh"
#include "checkPFCcinfo.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucName2Name.hh"
#include "XrdSys/XrdSysPlatform.hh"
Expand Down Expand Up @@ -99,7 +98,7 @@ XrdOucName2NameDiskCacheProxy4Rucio::XrdOucName2NameDiskCacheProxy4Rucio(XrdSysE
message = myName + " Init: RUCIO metalink server = " + rucioServer;
eDest->Say(message.c_str());

rucioGetMetaLinkInit(localMetaLinkRootDir, gLFNprefix, rucioServer, checkPFCcinfoInit(confg));
rucioGetMetaLinkInit(localMetaLinkRootDir, gLFNprefix, rucioServer);
}

int XrdOucName2NameDiskCacheProxy4Rucio::lfn2pfn(const char* lfn, char* buff, int blen)
Expand Down
48 changes: 48 additions & 0 deletions cacheQuery.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Author: Wei Yang (SLAC National Accelerator Laboratory / Stanford University, 2019)
*/

using namespace std;

#include <stdio.h>
#include <string.h>
#include <string>
#include <errno.h>
#include <iostream>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "XrdVersion.hh"
#include "XrdOuc/XrdOucCacheCM.hh"
#include "XrdPosix/XrdPosixCache.hh"

//______________________________________________________________________________


XrdPosixCache *myCache;

extern "C" {
XrdOucCacheCMInit_t XrdOucCacheCMInit(XrdPosixCache &Cache,
XrdSysLogger *Logger,
const char *Config,
const char *Parms,
XrdOucEnv *envP)
{
myCache = &Cache;
}
};
XrdVERSIONINFO(XrdOucCacheCMInit,CacheCM-4-RUCIO);

int cachedFileIsComplete(std::string url, std::string *localfile)
{
int rc;
char pfn[1024];
char *myurl = strdup(url.c_str());
rc = myCache->CacheQuery(myurl, 0);
myCache->CachePath(myurl, pfn, 1024);
free(myurl);
*localfile = pfn;
return rc;
}

5 changes: 5 additions & 0 deletions cacheQuery.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* Author: Wei Yang (SLAC National Accelerator Laboratory / Stanford University, 2019)
*/

int cachedFileIsComplete(std::string url, std::string *localpath);
27 changes: 11 additions & 16 deletions rucioGetMetaLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace std;
#include <openssl/md5.h>
#include <string>
#include <thread>
#include "checkPFCcinfo.hh"
#include "cacheQuery.hh"
#include "pfn2cache.hh"
#include "XrdCl/XrdClURL.hh"
#include "XrdSys/XrdSysError.hh"
Expand All @@ -36,7 +36,6 @@ std::string rucioServerCgi = "/metalink?schemes=root&sort=geoip";
#define MetaLinkLifeTsec MetaLinkLifeTmin*60

static std::string localMetaLinkRootDir;
static std::string ossLocalRoot;
static std::string gLFNprefix;

struct rucioMetaLink
Expand All @@ -60,12 +59,11 @@ void cleaner()

static int Xcache4RUCIO_DBG = 0;

void rucioGetMetaLinkInit(const std::string dir, const std::string glfnprefix, const std::string rucioserver, const std::string osslocalroot)
void rucioGetMetaLinkInit(const std::string dir, const std::string glfnprefix, const std::string rucioserver)
{
localMetaLinkRootDir = dir;
gLFNprefix = glfnprefix;
rucioServerUrl = "https://" + rucioserver + "/redirect/";
ossLocalRoot = osslocalroot;

std::thread cleanning(cleaner);
cleanning.detach();
Expand Down Expand Up @@ -141,7 +139,7 @@ std::string makeMetaLink(XrdSysError* eDest, const std::string myName, const std
metaLinkFile = metaLinkFile.replace(0, metaLinkFile.find("/"), ""); // remove loginid@hostnaem:port/
if (metaLinkFile.substr(0, 1) == "/") metaLinkFile.replace(0, 1, ""); // remove the next leading /

std::string cinfofile = "/" + pfn2cache("", gLFNprefix, metaLinkFile.c_str()) + ".cinfo";
std::string cachefile = pfn2cache("", gLFNprefix, metaLinkFile.c_str());
metaLinkFile = localMetaLinkRootDir + "/" + metaLinkFile + ".metalink";

metaLinkDir = metaLinkFile;
Expand All @@ -157,16 +155,16 @@ std::string makeMetaLink(XrdSysError* eDest, const std::string myName, const std
if (! stat(metaLinkFile.c_str(), &statBuf))
return metaLinkFile;

if (checkPFCcinfoIsComplete(cinfofile))
std::string localfile;
if (cachedFileIsComplete(cachefile, &localfile) == 1)
{
FILE *fd = fopen(metaLinkFile.c_str(), "w");
if (fd != NULL)
{
tmp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
tmp += "<metalink xmlns=\"urn:ietf:params:xml:ns:metalink\">\n";
tmp += " <file name=\"x\">\n";
tmp += " <url location=\"LOCAL\" priority=\"1\">file://localhost/" + ossLocalRoot
+ cinfofile.substr(0, cinfofile.rfind(".cinfo"))+ "</url>\n";
tmp += " <url location=\"LOCAL\" priority=\"1\">file://localhost/" + localfile + "</url>\n";
tmp += " </file>\n";
tmp += "</metalink>\n";

Expand Down Expand Up @@ -231,11 +229,8 @@ std::string getMetaLink(XrdSysError* eDest, const std::string myName, const std:
md5string[2*2+1] = '\0';
tmp = md5string;

std::string cinfofile;

cinfofile = gLFNprefix + "/" + slashScope + "/"
+ tmp.substr(0, 2) + "/" + tmp.substr(2, 2) + "/"
+ file + ".cinfo";
std::string cachefile = gLFNprefix + "/" + slashScope + "/"
+ tmp.substr(0, 2) + "/" + tmp.substr(2, 2) + "/" + file;

metaLinkDir = localMetaLinkRootDir + gLFNprefix + "/" + slashScope + "/"
+ tmp.substr(0, 2) + "/" + tmp.substr(2, 2);
Expand All @@ -249,16 +244,16 @@ std::string getMetaLink(XrdSysError* eDest, const std::string myName, const std:
if (! stat(metaLinkFile.c_str(), &statBuf))
return metaLinkFile;

if (checkPFCcinfoIsComplete(cinfofile))
std::string localfile;
if (cachedFileIsComplete(cachefile, &localfile) == 1)
{
FILE *fd = fopen(metaLinkFile.c_str(), "w");
if (fd != NULL)
{
tmp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
tmp += "<metalink xmlns=\"urn:ietf:params:xml:ns:metalink\">\n";
tmp += " <file name=\"x\">\n";
tmp += " <url location=\"LOCAL\" priority=\"1\">file://localhost/" + ossLocalRoot
+ cinfofile.substr(0, cinfofile.rfind(".cinfo"))+ "</url>\n";
tmp += " <url location=\"LOCAL\" priority=\"1\">file://localhost/" + localfile + "</url>\n";
tmp += " </file>\n";
tmp += "</metalink>\n";

Expand Down
2 changes: 1 addition & 1 deletion rucioGetMetaLink.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#include "XrdSys/XrdSysError.hh"

void rucioGetMetaLinkInit(const std::string, const std::string, const std::string, const std::string);
void rucioGetMetaLinkInit(const std::string, const std::string, const std::string);
string getMetaLink(XrdSysError*, const std::string, const std::string);
string makeMetaLink(XrdSysError*, const std::string, const std::string);

0 comments on commit 4a231b7

Please sign in to comment.