XRootD
Loading...
Searching...
No Matches
XrdCmsClientMan Class Reference

#include <XrdCmsClientMan.hh>

+ Collaboration diagram for XrdCmsClientMan:

Public Member Functions

 XrdCmsClientMan (char *host, int port, int cw, int nr, int rw, int rd)
 
 ~XrdCmsClientMan ()
 
int delayResp (XrdOucErrInfo &Resp)
 
int isActive ()
 
int manPort ()
 
char * Name ()
 
XrdCmsClientMannextManager ()
 
char * NPfx ()
 
int Send (unsigned int &iMan, char *msg, int mlen=0)
 
int Send (unsigned int &iMan, const struct iovec *iov, int iovcnt, int iotot=0)
 
void setNext (XrdCmsClientMan *np)
 
void * Start ()
 
int Suspended ()
 
int waitTime ()
 
int whatsUp (const char *user, const char *path, unsigned int iMan)
 

Static Public Member Functions

static void setConfig (const char *cfn)
 
static void setNetwork (XrdInet *nP)
 

Static Public Attributes

static char doDebug = 0
 

Detailed Description

Definition at line 47 of file XrdCmsClientMan.hh.

Constructor & Destructor Documentation

◆ XrdCmsClientMan()

XrdCmsClientMan::XrdCmsClientMan ( char * host,
int port,
int cw,
int nr,
int rw,
int rd )

Definition at line 66 of file XrdCmsClientMan.cc.

68 : syncResp(0)
69{
70 static XrdSysMutex initMutex;
71 static int Instance = 0;
72 char *dot;
73
74 Host = strdup(host);
75 if ((dot = index(Host, '.')))
76 {*dot = '\0'; HPfx = strdup(Host); *dot = '.';}
77 else HPfx = strdup(Host);
78 Port = port;
79 Link = 0;
80 Active = 0;
81 Silent = 0;
82 Suspend = 1;
83 RecvCnt = 0;
84 nrMax = nr;
85 NetBuff = BuffPool.Alloc(XrdOucEI::Max_Error_Len);
86 repWMax = rw;
87 repWait = 0;
88 minDelay= rd;
89 maxDelay= rd*3;
90 chkCount= chkVal;
91 lastUpdt= lastTOut = time(0);
92 Next = 0;
93 manInst = 1;
94
95// Compute dally value
96//
97 dally = cw / 2 - 1;
98 if (dally < 3) dally = 3;
99 else if (dally > 10) dally = 10;
100
101// Provide a unique mask number for this manager
102//
103 initMutex.Lock();
104 manMask = 1<<Instance++;
105 initMutex.UnLock();
106}
XrdOucBuffer * Alloc(int sz)
static const size_t Max_Error_Len

References XrdOucBuffPool::Alloc(), XrdSysMutex::Lock(), XrdOucEI::Max_Error_Len, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ ~XrdCmsClientMan()

XrdCmsClientMan::~XrdCmsClientMan ( )

Definition at line 112 of file XrdCmsClientMan.cc.

113{
114 if (Link) Link->Close();
115 if (Host) free(Host);
116 if (HPfx) free(HPfx);
117 if (NetBuff) NetBuff->Recycle();
118}
void Recycle()
Recycle the buffer. The buffer may be reused in the future.

References XrdLink::Close(), and XrdOucBuffer::Recycle().

+ Here is the call graph for this function:

Member Function Documentation

◆ delayResp()

int XrdCmsClientMan::delayResp ( XrdOucErrInfo & Resp)

Definition at line 124 of file XrdCmsClientMan.cc.

125{
126 XrdCmsResp *rp;
127 int msgid;
128
129// Obtain the message ID
130//
131 if (!(msgid = Resp.getErrInfo()))
132 {Say.Emsg("Manager", Host, "supplied invalid waitr msgid");
133 Resp.setErrInfo(EILSEQ, "redirector protocol error");
134 syncResp.Post();
135 return SFS_ERROR;
136 }
137
138// Allocate a delayed response object
139//
140 if (!(rp = XrdCmsResp::Alloc(&Resp, msgid)))
141 {Say.Emsg("Manager",ENOMEM,"allocate resp object for",Resp.getErrUser());
142 Resp.setErrInfo(0, "0");
143 syncResp.Post();
144 return SFS_STALL;
145 }
146
147// Add this object to our delayed response queue. If the manager bounced then
148// purge all of the pending repsonses to avoid sending wrong ones.
149//
150 if (msgid < maxMsgID) RespQ.Purge();
151 maxMsgID = msgid;
152 RespQ.Add(rp);
153
154// Tell client to wait for response. The semaphore post allows the manager
155// to get the next message from the cmsd. This prevents us from getting the
156// delayed response before the response object is added to the queue.
157//
158 Resp.setErrInfo(0, "");
159 syncResp.Post();
160 return SFS_STARTED;
161}
#define SFS_ERROR
#define SFS_STALL
#define SFS_STARTED
void Add(XrdCmsResp *rp)
static XrdCmsResp * Alloc(XrdOucErrInfo *erp, int msgid)
Definition XrdCmsResp.cc:64
const char * getErrUser()
int setErrInfo(int code, const char *emsg)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysError Say

References XrdCmsRespQ::Add(), XrdCmsResp::Alloc(), XrdSysError::Emsg(), XrdOucErrInfo::getErrInfo(), XrdOucErrInfo::getErrUser(), XrdSysSemaphore::Post(), XrdCmsRespQ::Purge(), XrdCms::Say, XrdOucErrInfo::setErrInfo(), SFS_ERROR, SFS_STALL, and SFS_STARTED.

+ Here is the call graph for this function:

◆ isActive()

int XrdCmsClientMan::isActive ( )
inline

Definition at line 55 of file XrdCmsClientMan.hh.

55{AtomicRet(myData, Active);}
#define AtomicRet(mtx, x)

References AtomicRet.

◆ manPort()

int XrdCmsClientMan::manPort ( )
inline

Definition at line 62 of file XrdCmsClientMan.hh.

62{return Port;}

◆ Name()

char * XrdCmsClientMan::Name ( )
inline

Definition at line 59 of file XrdCmsClientMan.hh.

59{return Host;}

Referenced by XrdCmsFinderRMT::Prepare().

+ Here is the caller graph for this function:

◆ nextManager()

XrdCmsClientMan * XrdCmsClientMan::nextManager ( )
inline

Definition at line 57 of file XrdCmsClientMan.hh.

57{return Next;}

Referenced by XrdCmsFinderRMT::~XrdCmsFinderRMT().

+ Here is the caller graph for this function:

◆ NPfx()

char * XrdCmsClientMan::NPfx ( )
inline

Definition at line 60 of file XrdCmsClientMan.hh.

60{return HPfx;}

◆ Send() [1/2]

int XrdCmsClientMan::Send ( unsigned int & iMan,
char * msg,
int mlen = 0 )

Definition at line 167 of file XrdCmsClientMan.cc.

168{
169 int allok = 0;
170
171// Determine message length
172//
173 if (!mlen) mlen = strlen(msg);
174
175// Send the request
176//
177 myData.Lock();
178 iMan = manInst;
179 if (Active)
180 {if (Link)
181 {if (!(allok = Link->Send(msg, mlen) > 0))
182 {Active = 0;
183 Link->Close(1);
184 manInst++;
185 } else SendCnt++;
186 }
187 }
188 myData.UnLock();
189
190// All done
191//
192 return allok;
193}

References XrdLink::Close(), XrdSysMutex::Lock(), XrdLink::Send(), and XrdSysMutex::UnLock().

Referenced by XrdCmsFinderRMT::Forward(), and XrdCmsFinderRMT::Prepare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Send() [2/2]

int XrdCmsClientMan::Send ( unsigned int & iMan,
const struct iovec * iov,
int iovcnt,
int iotot = 0 )

Definition at line 197 of file XrdCmsClientMan.cc.

198{
199 int allok = 0;
200
201// Send the request
202//
203 myData.Lock();
204 iMan = manInst;
205 if (Active)
206 {if (Link)
207 {if (!(allok = Link->Send(iov, iovcnt, iotot) > 0))
208 {Active = 0;
209 Link->Close(1);
210 manInst++;
211 } else SendCnt++;
212 }
213 }
214 myData.UnLock();
215
216// All done
217//
218 return allok;
219}

References XrdLink::Close(), XrdSysMutex::Lock(), XrdLink::Send(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ setConfig()

static void XrdCmsClientMan::setConfig ( const char * cfn)
inlinestatic

Definition at line 81 of file XrdCmsClientMan.hh.

81{ConfigFN = cfn;}

Referenced by XrdCmsFinderRMT::Configure().

+ Here is the caller graph for this function:

◆ setNetwork()

static void XrdCmsClientMan::setNetwork ( XrdInet * nP)
inlinestatic

Definition at line 79 of file XrdCmsClientMan.hh.

79{Network = nP;}

Referenced by XrdCmsFinderRMT::Configure().

+ Here is the caller graph for this function:

◆ setNext()

void XrdCmsClientMan::setNext ( XrdCmsClientMan * np)
inline

Definition at line 77 of file XrdCmsClientMan.hh.

77{Next = np;}

◆ Start()

void * XrdCmsClientMan::Start ( )

Definition at line 225 of file XrdCmsClientMan.cc.

226{
227
228// First step is to connect to the manager
229//
230 do {Hookup();
231 // Now simply start receiving messages on the stream. When we get a
232 // respwait reply then we must be assured that the object representing
233 // the request is added to the queue before the actual reply arrives.
234 // We do this by waiting on syncResp which is posted once the request
235 // object is fully processed. The actual response associated with the
236 // respwait is synchronized during the callback phase since the client
237 // must receive the respwait before the subsequent response.
238 //
239 while(Receive())
240 if (Response.modifier & CmsResponse::kYR_async) relayResp();
241 else if (Response.rrCode == kYR_status) setStatus();
242 else if (XrdCmsClientMsg::Reply(HPfx, Response, NetBuff))
243 {if (Response.rrCode == kYR_waitresp) syncResp.Wait();}
244
245 // Tear down the connection
246 //
247 myData.Lock();
248 if (Link) {Link->Close(); Link = 0;}
249 Active = 0; Suspend = 1;
250 myData.UnLock();
251
252 // Indicate the problem
253 //
254 Say.Emsg("ClientMan", "Disconnected from", Host);
255 XrdSysTimer::Snooze(dally);
256 } while(1);
257
258// We should never get here
259//
260 return (void *)0;
261}
static int Reply(const char *Man, XrdCms::CmsRRHdr &hdr, XrdOucBuffer *buff)
static void Snooze(int seconds)
kXR_char modifier
Definition YProtocol.hh:85
@ kYR_waitresp
Definition YProtocol.hh:145
kXR_char rrCode
Definition YProtocol.hh:84
@ kYR_status
Definition YProtocol.hh:112

References XrdLink::Close(), XrdSysError::Emsg(), XrdCms::CmsResponse::kYR_async, XrdCms::kYR_status, XrdCms::kYR_waitresp, XrdSysMutex::Lock(), XrdCms::CmsRRHdr::modifier, XrdCmsClientMsg::Reply(), XrdCms::CmsRRHdr::rrCode, XrdCms::Say, XrdSysTimer::Snooze(), XrdSysMutex::UnLock(), and XrdSysSemaphore::Wait().

Referenced by XrdCmsStartManager().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Suspended()

int XrdCmsClientMan::Suspended ( )
inline

Definition at line 70 of file XrdCmsClientMan.hh.

70 {AtomicBeg(myData);
71 int sVal = AtomicGet(Suspend);
72 AtomicEnd(myData);
73 if (!sVal) return sVal;
74 return chkStatus();
75 }
#define AtomicBeg(Mtx)
#define AtomicGet(x)
#define AtomicEnd(Mtx)

References AtomicBeg, AtomicEnd, and AtomicGet.

◆ waitTime()

int XrdCmsClientMan::waitTime ( )
inline

Definition at line 86 of file XrdCmsClientMan.hh.

86{AtomicRet(myData, repWait);}

References AtomicRet.

◆ whatsUp()

int XrdCmsClientMan::whatsUp ( const char * user,
const char * path,
unsigned int iMan )

Definition at line 267 of file XrdCmsClientMan.cc.

269{
270 EPNAME("whatsUp");
271 unsigned int xMan;
272 int theDelay, inQ;
273 bool lClose = false;
274
275// The cmsd did not respond. Increase silent count and see if restart is needed
276// Otherwise, increase the wait interval just in case things are just slow.
277//
278 myData.Lock();
279 if (Active)
280 {if (Active == RecvCnt)
281 {if ((time(0)-lastTOut) >= repWait)
282 {Silent++;
283 if (Silent > nrMax)
284 {Active = 0; Silent = 0; Suspend = 1;
285 if (Link && iMan == manInst)
286 {Link->Close(1);
287 manInst++; lClose = true;
288 }
289 } else if (Silent & 0x02 && repWait < repWMax) repWait++;
290 }
291 } else {Active = RecvCnt; Silent = 0; lastTOut = time(0);}
292 }
293
294// Calclulate how long to delay the client. This will be based on the number
295// of outstanding requests bounded by the config delay value.
296//
297 inQ = XrdCmsClientMsg::inQ();
298 theDelay = inQ * qTime;
299 xMan = manInst;
300 myData.UnLock();
301 theDelay = theDelay/1000 + (theDelay % 1000 ? 1 : 0);
302 if (theDelay < minDelay) theDelay = minDelay;
303 if (theDelay > maxDelay) theDelay = maxDelay;
304
305// Do Some tracing here
306//
307 TRACE(Redirect, user <<" no resp from inst " <<iMan <<" of "<<HPfx
308 <<" in " <<repWait
309 <<" inst " <<xMan <<(lClose ? " closed" : " steady")
310 <<"; inQ " <<inQ <<" delay " <<theDelay <<" path=" <<path);
311 return theDelay;
312}
#define EPNAME(x)
#define TRACE(act, x)
Definition XrdTrace.hh:63

References XrdLink::Close(), EPNAME, XrdCmsClientMsg::inQ(), XrdSysMutex::Lock(), TRACE, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

Member Data Documentation

◆ doDebug

char XrdCmsClientMan::doDebug = 0
static

The documentation for this class was generated from the following files: