66 #define THDFSFile_TRACE 67 #ifndef THDFSFile_TRACE 69 Debug("THDFSFile", "%s", x); 80 const char *ftitle,
Int_t compress):
81 TFile(path,
"WEB", ftitle, compress)
94 if (!create && !recreate && !update && !read) {
101 struct hdfsBuilder *bld = hdfsNewBuilder();
103 SysError(
"THDFSFile",
"Error creating hdfs builder");
111 const char *user = (ugi->
fUser).Data();
112 hdfsBuilderSetUserName(bld, user);
116 fFS = hdfsBuilderConnect(bld);
119 SysError(
"THDFSFile",
"HDFS client for %s cannot open the filesystem",
124 if (create || update || recreate) {
125 Int_t mode = O_RDWR | O_CREAT;
126 if (recreate) mode |= O_TRUNC;
134 SysError(
"THDFSFile",
"file %s can not be opened", path);
145 SysError(
"THDFSFile",
"file %s can not be opened for reading", path);
151 Init(create || recreate);
182 tSize num_read_total = 0;
185 tSize num_read = hdfsRead((hdfsFS)
fFS, (hdfsFile)
fHdfsFH, (
char *)buf + num_read_total, len - num_read_total);
186 num_read_total += num_read;
190 }
else if (num_read == 0) {
193 }
while (num_read_total < len);
196 return num_read_total;
206 if (whence == SEEK_SET)
208 else if (whence == SEEK_CUR)
210 else if (whence == SEEK_END) {
212 SysError(
"THDFSFile",
"Unable to seek past end of file");
216 hdfsFileInfo *info = hdfsGetPathInfo((hdfsFS)
fFS,
fPath);
221 SysError(
"THDFSFile",
"Unable to seek to end of file");
227 SysError(
"THDFSFile",
"Unknown whence!");
232 SysError(
"THDFSFile",
"Unable to seek to the given position");
253 if ((
fHdfsFH = hdfsOpenFile((hdfsFS)
fFS,
fPath, flags, 0, 0, 0)) == 0) {
254 SysError(
"THDFSFile",
"Unable to open file %s in HDFS", pathname);
265 int result = hdfsCloseFile((hdfsFS)
fFS, (hdfsFile)
fHdfsFH);
287 hdfsFileInfo *info = hdfsGetPathInfo((hdfsFS)
fFS,
fPath);
291 if (info->mKind == kObjectKindFile)
293 else if (info->mKind == kObjectKindDirectory)
295 *modtime = info->mLastMod;
340 struct hdfsBuilder *bld = hdfsNewBuilder();
342 SysError(
"THDFSSystem",
"Error creating hdfs builder");
350 const char *user = (ugi->
fUser).Data();
351 hdfsBuilderSetUserName(bld, user);
355 fFH = hdfsBuilderConnect(bld);
358 SysError(
"THDFSSystem",
"HDFS client cannot open the filesystem");
379 Error(
"MakeDirectory",
"No filesystem handle (should never happen)");
399 Error(
"OpenDirectory",
"No filesystem handle (should never happen)");
411 hdfsFileInfo * dir = 0;
415 if (dir->mKind != kObjectKindDirectory) {
432 Error(
"FreeDirectory",
"No filesystem handle (should never happen)");
436 Error(
"FreeDirectory",
"invalid directory pointer (should never happen)");
452 Error(
"GetDirEntry",
"No filesystem handle (should never happen)");
456 Error(
"GetDirEntry",
"invalid directory pointer (should never happen)");
460 Error(
"GetDirEntry",
"Passed an invalid directory pointer.");
468 hdfsFileInfo *fileInfo = ((hdfsFileInfo *)dirp) +
fDirCtr;
472 tempUrl.
SetUrl(
"hdfs:///");
490 Error(
"GetPathInfo",
"No filesystem handle (should never happen)");
503 buf.
fMode = fileInfo->mPermissions;
506 buf.
fSize = fileInfo->mSize;
507 buf.
fMtime = fileInfo->mLastAccess;
524 Error(
"AccessPathName",
"No filesystem handle (should never happen)");
543 Error(
"Unlink",
"No filesystem handle (should never happen)");
548 return hdfsDelete((hdfsFS)
fFH, path, 1);
void SetFile(const char *file)
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
void * fDirp
Pointer to the array of file information.
Int_t SysClose(Int_t fd)
Close the file in HDFS.
Int_t SysSync(Int_t fd)
Sync remaining data to disk; Not supported by HDFS.
THDFSFile(const char *path, Option_t *option="", const char *ftitle="", Int_t compress=1)
Usual Constructor. See the TFile constructor for details.
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
void * OpenDirectory(const char *name)
Open a directory via hdfs.
This class represents a WWW compatible URL.
static const Bool_t R__HDFS_ALLOW_CHANGES
virtual void SetName(const char *name)
Set the name of the TNamed.
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
void * fFS
HDFS user handle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
void ToUpper()
Change string to upper case.
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
virtual ~THDFSFile()
Close and clean-up HDFS file.
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Perform a stat on the HDFS file; see TFile::SysStat().
Int_t Unlink(const char *path)
Unlink, i.e.
void FreeDirectory(void *dirp)
Free a directory.
TString & Insert(Ssiz_t pos, const char *s)
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
const char * GetFile() const
Long64_t fSysOffset
Seek offset in file.
void ResetErrno() const
ResetErrno; simply calls TSystem::ResetErrno().
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Reads and writes its data via the HDFS protocols.
R__EXTERN TSystem * gSystem
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Directory handler for HDFS (THDFSFile).
Int_t fDirCtr
The current position in the fDirp array.
void * fHdfsFH
HDFS file handle.
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Open a file in HDFS.
virtual void Init(Bool_t create)
Initialize a TFile object.
Bool_t fWritable
True if directory is writable.
virtual ULong_t Hash() const
Return hash value for this object.
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence)
Seek to a specified position in the file.
static const char hdfs_default_host[]
virtual Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
TString fOption
File options.
virtual Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
Int_t MakeDirectory(const char *name)
Make a directory.
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
TUrl * fUrlp
Pointer to the array of directory content URLs.
const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Int_t SysRead(Int_t fd, void *buf, Int_t len)
Read specified number of bytes from current offset into the buffer.
void * fFH
HDFS filesystem handle.
static void ResetErrno()
Static function resetting system error number.
Int_t fDirEntries
The number of entries in the fDirp array.
void SetErrorStr(const char *errstr)
Set the system error string.
static const int hdfs_default_port
Abstract base class defining a generic interface to the underlying Operating System.
Int_t SysWrite(Int_t fd, const void *buf, Int_t len)
Write a buffer into the file; this is not supported currently.