xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdClient
XrdClient.hh
Go to the documentation of this file.
1
#ifndef XRD_CLIENT_H
2
#define XRD_CLIENT_H
3
/******************************************************************************/
4
/* */
5
/* X r d C l i e n t . h h */
6
/* */
7
/* Author: Fabrizio Furano (INFN Padova, 2004) */
8
/* Adapted from TXNetFile (root.cern.ch) originally done by */
9
/* Alvise Dorigo, Fabrizio Furano */
10
/* INFN Padova, 2003 */
11
/* */
12
/* This file is part of the XRootD software suite. */
13
/* */
14
/* XRootD is free software: you can redistribute it and/or modify it under */
15
/* the terms of the GNU Lesser General Public License as published by the */
16
/* Free Software Foundation, either version 3 of the License, or (at your */
17
/* option) any later version. */
18
/* */
19
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22
/* License for more details. */
23
/* */
24
/* You should have received a copy of the GNU Lesser General Public License */
25
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27
/* */
28
/* The copyright holder's institutional names and contributor's names may not */
29
/* be used to endorse or promote products derived from this software without */
30
/* specific prior written permission of the institution or contributor. */
31
/******************************************************************************/
32
34
// //
35
// A UNIX reference client for xrootd. //
36
// //
38
40
// //
41
// //
42
// Some features: //
43
// - Automatic server kind recognition (xrootd load balancer, xrootd //
44
// data server, old rootd) //
45
// - Fault tolerance for read/write operations (read/write timeouts //
46
// and retry) //
47
// - Internal connection timeout (tunable indipendently from the OS //
48
// one) //
49
// - Full implementation of the xrootd protocol //
50
// - handling of redirections from server //
51
// - Connection multiplexing //
52
// - Asynchronous operation mode //
53
// - High performance read caching with read-ahead //
54
// - Thread safe //
55
// - Tunable log verbosity level (0 = nothing, 3 = dump read/write //
56
// buffers too!) //
57
// - Many parameters configurable. But the default are OK for nearly //
58
// all the situations. //
59
// //
61
62
#include "
XProtocol/XProtocol.hh
"
63
64
#include "
XrdClient/XrdClientAbs.hh
"
65
#include "
XrdClient/XrdClientConst.hh
"
66
#include "
XrdOuc/XrdOucString.hh
"
67
#include "
XrdSys/XrdSysSemWait.hh
"
68
#include "XrdVersion.hh"
69
#include <vector>
70
#include <string>
71
72
class
XrdClientReadAheadMgr;
73
class
XrdClientThread;
74
75
struct
XrdClientOpenInfo
{
76
bool
inprogress
;
77
bool
opened
;
78
kXR_unt16
mode
;
79
kXR_unt16
options
;
80
};
81
82
struct
XrdClientStatInfo
{
83
int
stated
;
84
long
long
size
;
85
long
id
;
86
long
flags
;
87
long
modtime
;
88
};
89
90
struct
XrdClientCounters
{
91
int
CacheSize
;
92
93
// This does not take into account the 'suggestions'
94
// like async read or async readV
95
// We count only for functions which return data, eventually
96
// taken from the cache
97
long
long
ReadBytes
;
98
long
long
WrittenBytes
;
99
long
long
WriteRequests
;
100
101
long
long
ReadRequests
;
102
long
long
ReadMisses
;
103
long
long
ReadHits
;
104
float
ReadMissRate
;
105
106
long
long
ReadVRequests
;
// How many readVs (sync) were requested
107
long
long
ReadVSubRequests
;
// In how many sub-readVs they were split
108
long
long
ReadVSubChunks
;
// How many subchunks in total
109
long
long
ReadVBytes
;
// How many bytes were requested (sync)
110
111
long
long
ReadVAsyncRequests
;
// How many readVs (async) were requested
112
long
long
ReadVAsyncSubRequests
;
// In how many sub-readVs they were split
113
long
long
ReadVAsyncSubChunks
;
// How many subchunks in total
114
long
long
ReadVAsyncBytes
;
// How many bytes were requested (async)
115
116
long
long
ReadAsyncRequests
;
117
long
long
ReadAsyncBytes
;
118
};
119
120
121
class
XrdClient
:
public
XrdClientAbs
{
122
friend
void
*
FileOpenerThread
(
void
*, XrdClientThread*);
123
124
125
private
:
126
127
struct
XrdClientOpenInfo
fOpenPars
;
// Just a container for the last parameters
128
// passed to a Open method
129
130
// The open request can be in progress. Further requests must be delayed until
131
// finished.
132
XrdSysCondVar
*
fOpenProgCnd
;
133
134
// Used to open a file in parallel
135
XrdClientThread *
fOpenerTh
;
136
137
// Used to limit the maximum number of concurrent opens
138
static
XrdSysSemWait
fConcOpenSem
;
139
140
bool
fOpenWithRefresh
;
141
142
XrdSysCondVar
*
fReadWaitData
;
// Used to wait for outstanding data
143
144
struct
XrdClientStatInfo
fStatInfo
;
145
146
long
fReadTrimBlockSize
;
147
148
bool
fUseCache
;
149
150
XrdOucString
fInitialUrl
;
151
XrdClientUrlInfo
fUrl
;
152
153
bool
TryOpen
(
kXR_unt16
mode,
154
kXR_unt16
options,
155
bool
doitparallel);
156
157
bool
LowOpen
(
const
char
*file,
158
kXR_unt16
mode,
159
kXR_unt16
options,
160
char
*additionalquery = 0);
161
162
void
TerminateOpenAttempt
();
163
164
void
WaitForNewAsyncData
();
165
166
// Real implementation for ReadV
167
// To call it we need to be aware of the restrictions so the public
168
// interface should be ReadV()
169
kXR_int64
ReadVEach
(
char
*buf,
kXR_int64
*offsets,
int
*lens,
int
&nbuf);
170
171
bool
IsOpenedForWrite
() {
172
// This supposes that no options means read only
173
if
(!
fOpenPars
.
options
)
return
false
;
174
175
if
(
fOpenPars
.
options
&
kXR_open_read
)
return
false
;
176
177
return
true
;
178
}
179
180
XrdClientReadAheadMgr *
fReadAheadMgr
;
181
182
void
PrintCounters
();
183
protected
:
184
185
XrdClientCounters
fCounters
;
186
187
virtual
bool
OpenFileWhenRedirected
(
char
*newfhandle,
188
bool
&wasopen);
189
190
virtual
bool
CanRedirOnError
() {
191
// Can redir away on error if no file is opened
192
// or the file is opened in read mode
193
194
if
( !
fOpenPars
.
opened
)
return
true
;
195
196
return
!
IsOpenedForWrite
();
197
198
}
199
200
201
public
:
202
203
XrdClient
(
const
char
*url, XrdClientCallback *XrdCcb = 0,
void
*XrdCcbArg = 0);
204
virtual
~XrdClient
();
205
206
UnsolRespProcResult
ProcessUnsolicitedMsg
(
XrdClientUnsolMsgSender
*sender,
207
XrdClientMessage *unsolmsg);
208
209
bool
Close
();
210
211
// Ask the server to flush its cache
212
bool
Sync
();
213
214
// Copy the whole file to the local filesystem. Not very efficient.
215
bool
Copy
(
const
char
*localpath);
216
217
// Returns low level information about the cache
218
bool
GetCacheInfo
(
219
// The actual cache size
220
int
&
size
,
221
222
// The number of bytes submitted since the beginning
223
long
long
&bytessubmitted,
224
225
// The number of bytes found in the cache (estimate)
226
long
long
&byteshit,
227
228
// The number of reads which did not find their data
229
// (estimate)
230
long
long
&misscount,
231
232
// miss/totalreads ratio (estimate)
233
float
&missrate,
234
235
// number of read requests towards the cache
236
long
long
&readreqcnt,
237
238
// ratio between bytes found / bytes submitted
239
float
&bytesusefulness
240
);
241
242
243
244
// Returns client-level information about the activity performed up to now
245
bool
GetCounters
(
XrdClientCounters
*cnt );
246
247
// Quickly tells if the file is open
248
inline
bool
IsOpen
() {
return
fOpenPars
.
opened
; }
249
250
// Tells if the file opening is in progress
251
bool
IsOpen_inprogress
();
252
253
// Tells if the file is open, waiting for the completion of the parallel open
254
bool
IsOpen_wait
();
255
256
// Open the file. See the xrootd documentation for mode and options
257
// If parallel, then the open is done by a separate thread, and
258
// all the operations are delayed until the open has finished
259
bool
Open
(
kXR_unt16
mode,
kXR_unt16
options,
bool
doitparallel=
true
);
260
261
// Read a block of data. If no error occurs, it returns all the requested bytes.
262
int
Read
(
void
*buf,
long
long
offset,
int
len);
263
264
// Read multiple blocks of data compressed into a sinle one. It's up
265
// to the application to do the logistic (having the offset and len to find
266
// the position of the required buffer given the big one). If no error
267
// occurs, it returns all the requested bytes.
268
// NOTE: if buf == 0 then the req will be carried out asynchronously, i.e.
269
// the result of the request will only populate the internal cache. A subsequent read()
270
// of that chunk will get the data from the cache
271
kXR_int64
ReadV
(
char
*buf,
long
long
*offsets,
int
*lens,
int
nbuf);
272
273
// Submit an asynchronous read request. Its result will only populate the cache
274
// (if any!!)
275
XReqErrorType
Read_Async
(
long
long
offset,
int
len,
bool
updatecounters=
true
);
276
277
// Get stat info about the file. Normally it tries to guess the file size variations
278
// unless force==true
279
bool
Stat
(
struct
XrdClientStatInfo
*stinfo,
bool
force =
false
);
280
281
// On-the-fly enabling/disabling of the cache
282
bool
UseCache
(
bool
u =
true
);
283
284
// To instantly remove all the chunks in the cache
285
void
RemoveAllDataFromCache
();
286
287
// To remove pieces of data from the cache
288
void
RemoveDataFromCache
(
long
long
begin_offs,
289
long
long
end_offs,
290
bool
remove_overlapped =
false
);
291
292
// To set at run time the cache/readahead parameters for this instance only
293
// If a parameter is < 0 then it's left untouched.
294
// To simply enable/disable the caching, just use UseCache(), not this function
295
void
SetCacheParameters
(
int
CacheSize,
int
ReadAheadSize,
int
RmPolicy);
296
297
// To enable/disable different read ahead strategies. Defined in XrdClientReadAhead.hh
298
void
SetReadAheadStrategy
(
int
strategy);
299
300
// To enable the trimming of the blocks to read. Blocksize will be rounded to a multiple of 512.
301
// Each read request will have the offset and length aligned with a multiple of blocksize
302
// This strategy is similar to a read ahead, but not quite. Here we see it as a transformation
303
// of the stream of the read accesses to request
304
void
SetBlockReadTrimming
(
int
blocksize);
305
306
// Truncates the open file at a specified length
307
bool
Truncate
(
long
long
len);
308
309
// Write data to the file
310
bool
Write
(
const
void
*buf,
long
long
offset,
int
len);
311
312
std::vector<std::string>
fExcludedHosts
;
313
314
};
315
#endif
Generated by
1.8.4