58 #include <XrdClient/XrdClient.hh>
60 #include <XrdClient/XrdClientConst.hh>
61 #include <XrdClient/XrdClientEnv.hh>
62 #include <XProtocol/XProtocol.hh>
115 const char *logicalurl) :
116 TNetFile((logicalurl ? logicalurl : url), ftitle, compress,
kFALSE)
118 TUrl urlnoanchor(url);
129 Info(
"TXNetFile",
"(eXtended TNetFile) %s",
130 gROOT->GetVersion());
176 if (strlen(uu.
GetUser()) > 0) {
182 if (strlen(uu.
GetHost()) > 0) {
203 static const char *keys[6] = {
"cachesz=",
"readaheadsz=",
"rmpolicy=",
204 "mxredir=",
"readaheadstrategy=",
"readtrimblksz=" };
209 for (i = 0; i < (
sizeof(keys)/
sizeof(keys[0])); i++) {
223 cachesz = val.
Atoi();
225 readaheadsz = val.
Atoi();
227 rmpolicy = val.
Atoi();
229 mxredir = val.
Atoi();
231 rastrategy = val.
Atoi();
233 readtrimblksz = val.
Atoi();
240 Info(
"ParseCacheOptions",
"found: cachesz = %d, readaheadsz = %d, "
241 "rmpolicy = %d, mxredir = %d, rastrategy = %d, readtrimblksz = %d",
242 cachesz, readaheadsz, rmpolicy, mxredir, rastrategy, readtrimblksz);
254 Int_t cachesz = -1, readaheadsz = -1, rmpolicy = -1, mxredir = -1, np = 0;
255 Int_t readaheadstrategy = -1, readtrimblksz = -1;
271 ::Warning(
"TXNetFile",
"<%s> is not staged - StageOnly flag is set!",url);
282 parallelopen =
kTRUE;
292 Error(
"CreateXClient",
"fatal error: new object creation failed -"
293 " out of system resources.");
300 cachesz, readaheadsz, rmpolicy, mxredir,
301 readaheadstrategy, readtrimblksz);
305 if (
fClient->GetClientConn()) {
307 Info(
"CreateXClient",
"setting maxredir = %d", mxredir);
308 fClient->GetClientConn()->SetMaxRedirCnt(mxredir);
315 Info(
"CreateXClient",
"setting cachesz = %d, readaheadsz = %d, "
317 cachesz, readaheadsz, rmpolicy);
318 fClient->SetCacheParameters(cachesz, readaheadsz, rmpolicy);
320 if (readaheadstrategy >= 0) {
322 Info(
"CreateXClient",
"setting readaheadstrategy = %d", readaheadstrategy);
323 fClient->SetReadAheadStrategy(readaheadstrategy);
326 if (readtrimblksz >= 0) {
328 Info(
"CreateXClient",
"setting readtrimblksz = %d", readtrimblksz);
329 fClient->SetBlockReadTrimming(readtrimblksz);
336 if (!
Open(option, parallelopen)) {
339 Info(
"CreateXClient",
"remote file could not be open");
358 Error(
"CreateXClient",
"getting rootd server protocol");
365 ->GetCurrentUrl()).GetUrl().c_str());
370 Info(
"CreateXClient",
" url: %s",uu.Data());
393 Error(
"CreateXClient",
"rootd: underlying socket undefined");
398 Info(
"CreateXClient",
"rootd: fall back not enabled - closing");
426 Int_t len =
sizeof(cproto);
427 memcpy((
char *)&cproto,
431 ::Error(
"TXNetFile::GetRootdProtocol",
432 "sending %d bytes to rootd server [%s:%d]",
442 ::Error(
"TXNetFile::GetRootdProtocol",
443 "reading %d bytes from rootd server [%s:%d]",
453 len =
sizeof(rproto);
456 ::Error(
"TXNetFile::GetRootdProtocol",
457 "reading %d bytes from rootd server [%s:%d]",
465 ::Info(
"TXNetFile::GetRootdProtocol",
466 "remote rootd: buf1: %d, buf2: %d rproto: %d",
480 kXR_unt16 openOpt = 0;
481 memset(&openOpt, 0,
sizeof(openOpt));
489 openOpt |= kXR_force;
496 Bool_t create = (opt ==
"CREATE" || opt ==
"NEW");
499 Bool_t recreate = (opt ==
"RECREATE");
505 if (!create && !recreate && !update && !read) {
512 if (create || update || recreate)
524 Error(
"Open",
"no write permission, could not open file %s",
529 openOpt |= kXR_open_updt;
538 openOpt |= kXR_delete;
545 mkpath = (*(p + strlen(
"mkpath=")) ==
'1') ?
kTRUE :
kFALSE;
547 openOpt |= kXR_mkpath;
550 openOpt |= kXR_open_read;
554 kXR_unt16 openMode = kXR_or | kXR_gr | kXR_ur | kXR_uw;
558 if (!
fClient->Open(openMode, openOpt, doitparallel)) {
560 Info(
"Open",
"remote file could not be open");
594 Error(
"ReadBuffer",
"ReadBuffer is not possible because object"
595 " is in 'zombie' state");
601 Info(
"ReadBuffer",
"Calling TNetFile::ReadBuffer");
606 Error(
"ReadBuffer",
"The remote file is not open");
654 Info(
"ReadBuffer",
"%d bytes of data read from offset"
655 " %lld (%d requested)", nr,
fOffset, bufferLength);
670 gPerfStats->FileReadEvent(
this, bufferLength, start);
696 Error(
"ReadBuffer",
"ReadBuffer is not possible because object"
697 " is in 'zombie' state");
703 Error(
"ReadBufferAsync",
"Not supported for rootd");
708 Error(
"ReadBuffer",
"The remote file is not open");
742 gPerfStats->FileReadEvent(
this, bufferLength, start);
745 Info(
"ReadBufferAsync",
"%d bytes of data read request from offset"
746 " %lld", bufferLength, offs);
763 Error(
"ReadBuffers",
"ReadBuffers is not possible because object"
764 " is in 'zombie' state");
770 Info(
"ReadBuffers",
"Calling TNetFile::ReadBuffers");
775 Error(
"ReadBuffers",
"The remote file is not open");
783 for (
Int_t i = 0; i < nbuf; i++)
800 Info(
"ReadBuffers",
"response from ReadV(%d) nr: %lld", nbuf, nr);
805 Info(
"ReadBuffers",
"%lld bytes of data read from a list of %d buffers",
809 Info(
"ReadBuffers",
"%lld bytes of data read with a smaller (%d) TFileCacheRead buffer size?",
836 Info(
"ReadBuffers",
"XrdClient->ReadV failed, executing TFile::ReadBuffers");
855 Error(
"WriteBuffer",
"WriteBuffer is not possible because object"
856 " is in 'zombie' state");
862 Info(
"WriteBuffer",
"file not writable");
868 Info(
"WriteBuffer",
"Calling TNetFile::WriteBuffer");
873 Error(
"WriteBuffer",
"The remote file is not open");
888 "error writing %d bytes of data wrote to offset %lld",
894 Info(
"WriteBuffer",
" %d bytes of data wrote to offset"
895 " %lld", bufferLength ,
fOffset);
917 Info(
"Init",
"TFile::Init already called once");
923 Info(
"Init",
"rootd: calling directly TFile::Init");
940 bool usecachesave =
fClient->UseCache(0);
946 fClient->UseCache(usecachesave);
954 if (
fClient->GetClientConn() &&
fClient->GetClientConn()->fRedirOpaque.length() <= 0) {
964 Info(
"Init",
"open request failed!");
979 Info(
"IsOpen",
"Calling TNetFile::IsOpen");
996 if (
fClient->IsOpen_inprogress()) {
1018 Info(
"ReOpen",
"Calling TNetFile::ReOpen");
1033 Info(
"Close",
"Calling TNetFile::Close");
1056 Error(
"Flush",
"Flush is not possible because object is"
1057 " in 'zombie' state");
1063 Info(
"Flush",
"file not writable - do nothing");
1069 Info(
"Flush",
"Calling TNetFile::Flush");
1075 Error(
"Flush",
"The remote file is not open");
1085 Info(
"Flush",
"XrdClient::Sync called.");
1095 Error(
"SysStat",
"SysStat is not possible because object is"
1096 " in 'zombie' state");
1103 Info(
"SysStat",
"calling TNetFile::SysStat");
1109 struct XrdClientStatInfo stinfo;
1111 *
id = (
Long_t)(stinfo.id);
1113 *flags = (
Long_t)(stinfo.flags);
1114 *modtime = (
Long_t)(stinfo.modtime);
1116 Info(
"SysStat",
"got stats = %ld %lld %ld %ld",
1117 *
id, *size, *flags, *modtime);
1121 if (!
IsOpen())
Info(
"SysStat",
"could not stat remote file. Not opened.");
1123 Info(
"SysStat",
"could not stat remote file");
1141 Error(
"SysClose",
"SysClose is not possible because object is"
1142 " in 'zombie' state");
1148 Info(
"SysClose",
"Calling TNetFile::SysClose");
1166 Info(
"SysOpen",
"Calling TNetFile::SysOpen");
1197 if (allowRE.
Length() > 0)
1198 EnvPutString(NAME_REDIRDOMAINALLOW_RE, allowRE.
Data());
1203 EnvPutString(NAME_REDIRDOMAINDENY_RE, denyRE.
Data());
1207 if (allowCO.
Length() > 0)
1208 EnvPutString(NAME_CONNECTDOMAINALLOW_RE, allowCO.
Data());
1213 EnvPutString(NAME_CONNECTDOMAINDENY_RE, denyCO.
Data());
1217 DFLT_CONNECTTIMEOUT);
1218 EnvPutInt(NAME_CONNECTTIMEOUT, connTO);
1222 DFLT_RECONNECTWAIT);
1223 if (recoTO == DFLT_RECONNECTWAIT) {
1226 DFLT_RECONNECTWAIT);
1228 EnvPutInt(NAME_RECONNECTWAIT, recoTO);
1232 DFLT_REQUESTTIMEOUT);
1233 EnvPutInt(NAME_REQUESTTIMEOUT, requTO);
1237 DFLT_MAXREDIRECTCOUNT);
1238 EnvPutInt(NAME_MAXREDIRECTCOUNT, maxRedir);
1243 DFLT_READAHEADSIZE);
1244 EnvPutInt(NAME_READAHEADSIZE, rAheadsiz);
1249 DFLT_READCACHESIZE);
1251 EnvPutInt(NAME_READCACHESIZE, rCachesiz);
1255 DFLT_FIRSTCONNECTMAXCNT);
1256 EnvPutInt(NAME_FIRSTCONNECTMAXCNT, maxRetries);
1260 DFLT_MULTISTREAMCNT);
1261 EnvPutInt(NAME_MULTISTREAMCNT, parStreamsCnt);
1265 DFLT_DFLTTCPWINDOWSIZE);
1266 EnvPutInt(NAME_DFLTTCPWINDOWSIZE, tcpWindowSize);
1270 DFLT_TRANSACTIONTIMEOUT);
1271 EnvPutInt(NAME_TRANSACTIONTIMEOUT, transactionTimeout);
1276 EnvPutInt(NAME_KEEPSOCKOPENIFNOTXRD,
fgRootdBC);
1281 if (socks4Port > 0) {
1284 socks4Host =
"127.0.0.1";
1285 EnvPutString(NAME_SOCKS4HOST, socks4Host.
Data());
1286 EnvPutInt(NAME_SOCKS4PORT, socks4Port);
1289 const char *cenv = 0;
1293 if (autolog.
Length() > 0 &&
1294 (!(cenv =
gSystem->
Getenv(
"XrdSecPWDAUTOLOG")) || strlen(cenv) <= 0))
1303 if (alogfile.
Length() > 0)
1307 if (verisrv.
Length() > 0 &&
1308 (!(cenv =
gSystem->
Getenv(
"XrdSecPWDVERIFYSRV")) || strlen(cenv) <= 0))
1345 if (deplen.
Length() > 0 &&
1346 (!(cenv =
gSystem->
Getenv(
"XrdSecGSIPROXYDEPLEN")) || strlen(cenv) <= 0))
1350 if (pxybits.
Length() > 0)
1354 if (crlcheck.
Length() > 0 &&
1355 (!(cenv =
gSystem->
Getenv(
"XrdSecGSICRLCHECK")) || strlen(cenv) <= 0))
1359 if (delegpxy.
Length() > 0 &&
1360 (!(cenv =
gSystem->
Getenv(
"XrdSecGSIDELEGPROXY")) || strlen(cenv) <= 0))
1364 if (signpxy.
Length() > 0 &&
1365 (!(cenv =
gSystem->
Getenv(
"XrdSecGSISIGNPROXY")) || strlen(cenv) <= 0))
1382 Long64_t bytessubmitted, byteshit, misscount, readreqcnt;
1383 Float_t missrate, bytesusefulness;
1385 if (
fClient->GetCacheInfo(size, bytessubmitted,
1386 byteshit, misscount,
1387 missrate, readreqcnt,
1388 bytesusefulness) ) {
1411 fClient->RemoveAllDataFromCache();
1420 Long64_t bytessubmitted, byteshit, misscount, readreqcnt;
1421 Float_t missrate, bytesusefulness;
1424 byteshit, misscount,
1425 missrate, readreqcnt,
1428 return ((bytes < 0) ? 0 : bytes);
1436 Printf(
"TXNetFile caching information:");
1439 Long64_t bytessubmitted, byteshit, misscount, readreqcnt;
1440 Float_t missrate, bytesusefulness;
1443 byteshit, misscount,
1444 missrate, readreqcnt,
1446 Printf(
" Max size: %d", size);
1447 Printf(
" Bytes submitted: %lld", bytessubmitted);
1448 Printf(
" Bytes hit (estimation): %lld", byteshit);
1449 Printf(
" Miss count: %lld", misscount);
1450 Printf(
" Miss rate: %f", missrate);
1451 Printf(
" Read requests count: %lld", readreqcnt);
1452 Printf(
" Bytes usefulness: %f\n", bytesusefulness);
1454 Printf(
" -- No Xrd client instance allocated --\n");
const char * GetHost() const
virtual Bool_t IsStaged(const char *)
Just check if the file exists locally.
virtual ~TXNetFile()
Destructor.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Int_t ParseOptions(const char *opts, Int_t &cachesz, Int_t &readaheadsz, Int_t &rmpolicy, Int_t &mxredir, Int_t &rastrategy, Int_t &readtrimblksz)
Parse input options for cache parameters.
double read(const std::string &file_name)
reading
void Init(Bool_t create)
Initialize the file.
void SetRemoteProtocol(Int_t rproto)
Int_t SysClose(Int_t fd)
Close currently open file.
Long64_t fBytesWrite
Number of bytes written to this file.
EAsyncOpenStatus
Asynchronous open request status.
static std::atomic< Long64_t > fgBytesRead
Number of bytes read by all TFile objects.
virtual Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode.
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Override TNetFile::SysStat (see parent's method for more details).
A cache when reading files over the network.
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
This class represents a WWW compatible URL.
virtual Bool_t SendFileOpenProgress(TFile *, TList *, const char *, Bool_t=kFALSE)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual TFile::EAsyncOpenStatus GetAsyncOpenStatus()
Return status of asynchronous request.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static void SetFileReadCalls(Int_t readcalls=0)
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
void ToUpper()
Change string to upper case.
void Flush()
Flush file to disk.
Int_t WriteBufferViaCache(const char *buf, Int_t len)
Write buffer via cache.
static Int_t GetRootdProtocol(TSocket *s)
Find out the remote rootd protocol version.
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
virtual Int_t GetBufferSize() const
Return the buffer size to create new TKeys.
const char * GetOptions() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Int_t ReOpen(const Option_t *mode)
Re-open the file (see TNetFile::ReOpen() or TFile::ReOpen() for more details).
void SetServType(Int_t st)
static void SetFileBytesWritten(Long64_t bytes=0)
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Override TNetFile::ReadBuffer to deal with the xrootd server.
const char * Data() const
TFileCacheRead * GetCacheRead(TObject *tree=0) const
Return a pointer to the current read cache.
virtual void Print(Option_t *option="") const
Print the local statistics.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
UShort_t net2host(UShort_t x)
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
R__EXTERN TVirtualMonitoringWriter * gMonitoringWriter
static TFileStager * fgFileStager
virtual const char * Getenv(const char *env)
Get environment variable.
static Long64_t GetFileBytesWritten()
Static function returning the total number of bytes written to all files.
virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len)
Implementation dealing with the xrootd server.
Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE...
Int_t Atoi() const
Return integer value of string.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static void SetEnv()
Set the relevant environment variables.
virtual void ResetCache()
Reset the cache.
virtual Int_t GetBytesToPrefetch() const
Max number of bytes to prefetch.
static UInt_t GetOpenTimeout()
Returns open timeout (in ms).
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Override TNetFile::SysOpen (see parent's method for more details).
virtual void Setenv(const char *name, const char *value)
Set environment variable.
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Return file stat information.
R__EXTERN TSystem * gSystem
static void FormUrl(TUrl uut, TString &uu)
Form url for rootd socket.
#define XrdSysMutexHelper
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
EAsyncOpenStatus fAsyncOpenStatus
!Status of an asynchronous open request
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void Flush()
Flushes un-written data.
char * Form(const char *fmt,...)
static std::atomic< Long64_t > fgBytesWrite
Number of bytes written by all TFile objects.
static std::atomic< Int_t > fgReadCalls
Number of bytes read from all TFile objects.
virtual void Abort(int code=0)
Abort the application.
static Int_t GetFileReadCalls()
Static function returning the total number of read calls from all files.
virtual void Init(Bool_t create)
Initialize a TFile object.
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
Int_t ReadBufferViaCache(char *buf, Int_t len)
Read buffer via cache.
Bool_t fWritable
True if directory is writable.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read a list of buffers given in pos[] and len[] and return it in a single buffer. ...
static Bool_t GetOnlyStaged()
Returns staged only flag.
TString & Remove(Ssiz_t pos)
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Open a remote file. Requires fOption to be set correctly.
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
void SetAnchor(const char *anchor)
virtual Bool_t WriteBuffer(const char *buffer, Int_t BufferLength)
Override TNetFile::WriteBuffer to deal with the xrootd server.
void Close(Option_t *option="")
Close remote file.
Bool_t IsOpen() const
Retruns kTRUE if file is open, kFALSE otherwise.
virtual void Close(const Option_t *opt="")
Close the file (see TNetFile::Close() or TFile::Close() for more details).
virtual void Print(Option_t *option="") const
Print all objects in the file.
The TTimeStamp encapsulates seconds and ns since EPOCH.
TList * fOpenPhases
!Time info about open phases
static TFileStager * Open(const char *stager)
Open a stager, after having loaded the relevant plug-in.
TString fOption
File options.
virtual Bool_t SendFileReadProgress(TFile *)
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Bool_t Open(Option_t *option, Bool_t parallelopen)
The real creation work is done here.
Bool_t FlushWriteCache()
Flush the write cache if active.
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via rootd daemon.
void CreateXClient(const char *url, Option_t *option, Int_t netopt, Bool_t parallelopen)
The real creation work is done here.
Int_t SysClose(Int_t fd)
Override TNetFile::SysClose (see parent's method for more details).
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len.
virtual Bool_t Matches(const char *s)
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Long64_t fArchiveOffset
!Offset at which file starts in archive
void SetUrl(const char *url)
void Init(Bool_t create)
Initialize a TNetFile object.
Long64_t fOffset
!Seek offset cache
void SetService(const char *service)
Bool_t fInitDone
!True if the file has been initialized
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
static void SetFileBytesRead(Long64_t bytes=0)
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
TInetAddress GetInetAddress() const
virtual Bool_t IsOpen() const
Return kTRUE if the file is open, kFALSE otherwise.
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len, where pos[i] is the seek position of block i of...
const char * GetUser() const
Long64_t fBytesRead
Number of bytes read from this file.
void SynchronizeCacheSize()
Synchronize the cache size Alternative purging policy.
virtual void Close(Option_t *option="")
Close a file.
virtual void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.