XRootD
XrdSsiSessReal Class Reference

#include <XrdSsiSessReal.hh>

+ Inheritance diagram for XrdSsiSessReal:
+ Collaboration diagram for XrdSsiSessReal:

Public Member Functions

 XrdSsiSessReal (XrdSsiServReal *servP, const char *sName, int uent, bool hold=false)
 
 ~XrdSsiSessReal ()
 
const char * GetKey ()
 
uint32_t GetSID ()
 
void InitSession (XrdSsiServReal *servP, const char *sName, int uent, bool hold, bool newSID=false)
 
void Lock ()
 
XrdSsiMutexMutexP ()
 
bool Provision (XrdSsiRequest *reqP, const char *epURL)
 
bool Run (XrdSsiRequest *reqP)
 
void SetKey (const char *key)
 
void TaskFinished (XrdSsiTaskReal *tP)
 
void UnHold (bool cleanup=true)
 
void UnLock ()
 
bool Unprovision ()
 
int XeqEvent (XrdCl::XRootDStatus *status, XrdCl::AnyObject **respP)
 
void XeqEvFin ()
 
- Public Member Functions inherited from XrdSsiEvent
 XrdSsiEvent ()
 
 ~XrdSsiEvent ()
 
void AddEvent (XrdCl::XRootDStatus *st, XrdCl::AnyObject *resp)
 
void ClrEvent ()
 
virtual void DoIt ()
 
virtual void HandleResponse (XrdCl::XRootDStatus *status, XrdCl::AnyObject *response)
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 
- Public Member Functions inherited from XrdCl::ResponseHandler
virtual ~ResponseHandler ()
 
virtual void HandleResponseWithHosts (XRootDStatus *status, AnyObject *response, HostList *hostList)
 

Public Attributes

XrdCl::File epFile
 
XrdSsiSessRealnextSess
 
- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Additional Inherited Members

- Static Public Member Functions inherited from XrdCl::ResponseHandler
static ResponseHandlerWrap (std::function< void(XRootDStatus &, AnyObject &)> func)
 
static ResponseHandlerWrap (std::function< void(XRootDStatus *, AnyObject *)> func)
 
- Protected Attributes inherited from XrdSsiEvent
char tident [24]
 

Detailed Description

Definition at line 44 of file XrdSsiSessReal.hh.

Constructor & Destructor Documentation

◆ XrdSsiSessReal()

XrdSsiSessReal::XrdSsiSessReal ( XrdSsiServReal servP,
const char *  sName,
int  uent,
bool  hold = false 
)
inline

Definition at line 86 of file XrdSsiSessReal.hh.

90  : sessMutex(XrdSsiMutex::Recursive),
91  resKey(0), sessName(0), sessNode(0)
92  {InitSession(servP, sName, uent, hold, true);}
void InitSession(XrdSsiServReal *servP, const char *sName, int uent, bool hold, bool newSID=false)

References InitSession().

+ Here is the call graph for this function:

◆ ~XrdSsiSessReal()

XrdSsiSessReal::~XrdSsiSessReal ( )

Definition at line 128 of file XrdSsiSessReal.cc.

129 {
130  XrdSsiTaskReal *tP;
131 
132  if (resKey) free(resKey);
133  if (sessName) free(sessName);
134  if (sessNode) free(sessNode);
135 
136  while((tP = freeTask)) {freeTask = tP->attList.next; delete tP;}
137 }
XrdSsiTaskReal * next

References XrdSsiTaskReal::attList, and XrdSsiTaskReal::dlQ::next.

Member Function Documentation

◆ GetKey()

const char* XrdSsiSessReal::GetKey ( )
inline

Definition at line 50 of file XrdSsiSessReal.hh.

50 {return resKey;}

Referenced by XrdSsiServReal::Recycle().

+ Here is the caller graph for this function:

◆ GetSID()

uint32_t XrdSsiSessReal::GetSID ( )
inline

Definition at line 52 of file XrdSsiSessReal.hh.

52 {return sessID;}

Referenced by XrdSsiServReal::Recycle().

+ Here is the caller graph for this function:

◆ InitSession()

void XrdSsiSessReal::InitSession ( XrdSsiServReal servP,
const char *  sName,
int  uent,
bool  hold,
bool  newSID = false 
)

Definition at line 143 of file XrdSsiSessReal.cc.

145 {
146  EPNAME("InitSession");
147  requestP = 0;
148  uEnt = uent;
149  attBase = 0;
150  freeTask = 0;
151  myService = servP;
152  nextTID = 0;
153  alocLeft = XrdSsiRRInfo::idMax;
154  isHeld = hold;
155  inOpen = false;
156  noReuse = false;
157  if (resKey) {free(resKey); resKey = 0;}
158  if (sessName) free(sessName);
159  sessName = (sName ? strdup(sName) : 0);
160  if (sessNode) free(sessNode);
161  sessNode = 0;
162  if (newSID)
163  {if (servP == 0) sessID = 0xffffffff;
164  else {Atomic_BEG(sidMutex);
165  sessID = Atomic_INC(sidVal);
166  Atomic_END(sidMutex);
167  snprintf(tident, sizeof(tident), "S %u#", sessID);
168  DEBUG("new sess for "<<sName<<" uent="<<uent<<" hold="<<hold);
169  }
170  } else {
171  DEBUG("reuse sess for "<<sName<<" uent="<<uent<<" hold="<<hold);
172  }
173 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
#define Atomic_INC(x)
#define Atomic_END(x)
#define Atomic_BEG(x)
char tident[24]
Definition: XrdSsiEvent.hh:62
static const unsigned int idMax
Definition: XrdSsiRRInfo.hh:41

References Atomic_BEG, Atomic_END, Atomic_INC, DEBUG, EPNAME, XrdSsiRRInfo::idMax, and tident.

Referenced by XrdSsiSessReal().

+ Here is the caller graph for this function:

◆ Lock()

void XrdSsiSessReal::Lock ( )
inline

Definition at line 60 of file XrdSsiSessReal.hh.

60 {sessMutex.Lock();}

References XrdSsiMutex::Lock().

+ Here is the call graph for this function:

◆ MutexP()

XrdSsiMutex* XrdSsiSessReal::MutexP ( )
inline

Definition at line 62 of file XrdSsiSessReal.hh.

62 {return &sessMutex;}

◆ Provision()

bool XrdSsiSessReal::Provision ( XrdSsiRequest reqP,
const char *  epURL 
)

Definition at line 225 of file XrdSsiSessReal.cc.

226 {
227  EPNAME("Provision");
228  XrdCl::XRootDStatus epStatus;
229  XrdSsiMutexMon rHelp(&sessMutex);
231 
232 // Set retry flag as appropriate
233 //
234  if (XrdSsiRRAgent::isaRetry(reqP, true)) oFlags |= XrdCl::OpenFlags::Refresh;
235 
236 // Issue the open and if the open was started, return success.
237 //
238  DEBUG("Provisioning " <<epURL);
239  epStatus = epFile.Open((const std::string)epURL, oFlags,
241  (XrdCl::ResponseHandler *)this,
242  reqP->GetTimeOut());
243 
244 // If there was an error, scuttle the request. Note that errors will be returned
245 // on a separate thread to avoid hangs here.
246 //
247  if (!epStatus.IsOK())
248  {std::string eTxt;
249  int eNum = XrdSsiUtils::GetErr(epStatus, eTxt);
250  XrdSsiUtils::RetErr(*reqP, eTxt.c_str(), eNum);
251  XrdSsi::sidScale.retEnt(uEnt);
252  return false;
253  }
254 
255 // Queue a new task and indicate our state
256 //
257  NewTask(reqP);
258  inOpen = true;
259  return true;
260 }
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:99
Handle an async response.
static bool isaRetry(XrdSsiRequest *rP, bool reset=false)
uint16_t GetTimeOut()
void retEnt(int xEnt)
Definition: XrdSsiScale.cc:95
XrdCl::File epFile
static int GetErr(XrdCl::XRootDStatus &Status, std::string &eText)
Definition: XrdSsiUtils.cc:191
static void RetErr(XrdSsiRequest &reqP, const char *eTxt, int eNum)
Definition: XrdSsiUtils.cc:220
XrdSsiScale sidScale
Mode
Access mode.
Flags
Open flags, may be or'd when appropriate.
@ Read
Open only for reading.
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124

References DEBUG, EPNAME, XrdSsiUtils::GetErr(), XrdSsiRequest::GetTimeOut(), XrdSsiRRAgent::isaRetry(), XrdCl::Status::IsOK(), XrdCl::OpenFlags::Read, XrdCl::OpenFlags::Refresh, XrdSsiScale::retEnt(), XrdSsiUtils::RetErr(), and XrdSsi::sidScale.

Referenced by XrdSsiServReal::ProcessRequest().

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

◆ Run()

bool XrdSsiSessReal::Run ( XrdSsiRequest reqP)

Definition at line 287 of file XrdSsiSessReal.cc.

288 {
289  XrdSsiMutexMon sessMon(sessMutex);
290  XrdSsiTaskReal *tP;
291 
292 // If we are not allowed to be reused, return to indicated try someone else
293 //
294  if (noReuse) return false;
295 
296 // Reserve a stream ID. If we cannot then indicate we cannot be reused
297 //
298  if (!XrdSsi::sidScale.rsvEnt(uEnt)) return false;
299 
300 // Queue a new task
301 //
302  tP = NewTask(reqP);
303 
304 // If we are already open and we have a task, send off the request
305 //
306  if (!inOpen && tP && !tP->SendRequest(sessNode)) noReuse = true;
307  return true;
308 }
bool SendRequest(const char *node)

References XrdSsiTaskReal::SendRequest(), and XrdSsi::sidScale.

+ Here is the call graph for this function:

◆ SetKey()

void XrdSsiSessReal::SetKey ( const char *  key)
inline

Definition at line 68 of file XrdSsiSessReal.hh.

69  {if (resKey) free(resKey);
70  resKey = (key ? strdup(key) : 0);
71  }

Referenced by XrdSsiServReal::ProcessRequest().

+ Here is the caller graph for this function:

◆ TaskFinished()

void XrdSsiSessReal::TaskFinished ( XrdSsiTaskReal tP)

Definition at line 348 of file XrdSsiSessReal.cc.

349 {
350  EPNAME("TaskFin");
351 // Lock our mutex
352 //
353  sessMutex.Lock();
354 
355 // Remove task from the task list if it's in it and release the task object.
356 //
357  if (tP == attBase || tP->attList.next != tP)
358  {REMOVE(attBase, attList, tP);}
359  RelTask(tP);
360 
361 // Return the request entry number
362 //
363  XrdSsi::sidScale.retEnt(uEnt);
364 
365 // If we are waiting for a provision to finish, simply exit as the event
366 // handler will notice that there is no task and will unprovision. Otherwise
367 //
368 
369 
370 // If we can shutdown, then unprovision which will drive a shutdown. Note
371 // that Unprovision() returns without the sessMutex, otherwise we must
372 // unlock it before we return. A shutdown invalidates this object!
373 //
374  if (!inOpen)
375  {if (!isHeld && !attBase) Unprovision();
376  else sessMutex.UnLock();
377  } else {
378  DEBUG("Unprovision deferred for " <<sessName);
379  sessMutex.UnLock();
380  }
381 }
#define REMOVE(dlbase, dlvar, curitem)

References XrdSsiTaskReal::attList, DEBUG, EPNAME, XrdSsiTaskReal::dlQ::next, REMOVE, XrdSsiScale::retEnt(), and XrdSsi::sidScale.

+ Here is the call graph for this function:

◆ UnHold()

void XrdSsiSessReal::UnHold ( bool  cleanup = true)

Definition at line 387 of file XrdSsiSessReal.cc.

388 {
389  XrdSsiMutexMon sessMon(sessMutex);
390 
391 // Immediately stopo reuse of this object
392 //
393  if (isHeld && resKey && myService) myService->StopReuse(resKey);
394 
395 // Turn off the hold flag and if we have no attached tasks, schedule shutdown
396 //
397  isHeld = false;
398  if (cleanup && !attBase) XrdSsi::schedP->Schedule(new CleanUp(this));
399 }
void Schedule(XrdJob *jp)
void StopReuse(const char *resKey)
XrdScheduler * schedP
Definition: XrdSsiClient.cc:74

References XrdSsi::schedP, and XrdScheduler::Schedule().

+ Here is the call graph for this function:

◆ UnLock()

void XrdSsiSessReal::UnLock ( )
inline

Definition at line 77 of file XrdSsiSessReal.hh.

77 {sessMutex.UnLock();}

References XrdSsiMutex::UnLock().

Referenced by XrdSsiServReal::Recycle().

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

◆ Unprovision()

bool XrdSsiSessReal::Unprovision ( )

Definition at line 408 of file XrdSsiSessReal.cc.

409 {
410  EPNAME("Unprovision");
411  XrdCl::XRootDStatus uStat;
412 
413 // Clear any pending events
414 //
415  DEBUG("Closing " <<sessName);
416 
417 // If the file is not open (it might be due to an open error) then do a
418 // shutdown right away. Otherwise, try to close if successful the event
419 // handler will do the shutdown, Otherwise, we do a Futterwacken dance.
420 //
421  if (!epFile.IsOpen()) {Shutdown(uStat, false); return false;}
422  else {uStat = epFile.Close((XrdCl::ResponseHandler *)this);
423  if (!uStat.IsOK()) {Shutdown(uStat, true); return false;}
424  else sessMutex.UnLock();
425  }
426  return true;
427 }
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:151
bool IsOpen() const
Check if the file is open.
Definition: XrdClFile.cc:846

References DEBUG, EPNAME, and XrdCl::Status::IsOK().

+ Here is the call graph for this function:

◆ XeqEvent()

int XrdSsiSessReal::XeqEvent ( XrdCl::XRootDStatus status,
XrdCl::AnyObject **  respP 
)
virtual

Implements XrdSsiEvent.

Definition at line 433 of file XrdSsiSessReal.cc.

435 {
436 // Lock out mutex. Note that events like shutdown unlock the mutex. The only
437 // events handled here are open() and close().
438 //
439  sessMutex.Lock();
440  XrdSsiTaskReal *ztP, *ntP, *tP = attBase;
441 
442 // If we are not in the open phase then this is due to a close event. Simply
443 // do a shutdown and return to stop event processing.
444 //
445  if (!inOpen)
446  {Shutdown(*status, true); // sessMutex gets unlocked!
447  return -1; // This object no longer valid!
448  }
449 
450 // We are no longer in open. However, if open encounetered an error then this
451 // session cannot be reused because the file object is in a bad state.
452 //
453  inOpen = false;
454  noReuse = !status->IsOK();
455 
456 // If we have no requests then we may want to simply shoutdown.
457 // Note that shutdown and unprovision unlock the sessMutex.
458 //
459  if (!tP)
460  {if (isHeld)
461  {sessMutex.UnLock();
462  return 1;
463  }
464  if (!status->IsOK()) Shutdown(*status, false);
465  else {if (!isHeld) return (Unprovision() ? 1 : -1);
466  else sessMutex.UnLock();
467  }
468  return 1; // Flush events and continue
469  }
470 
471 // We are here because the open finally completed. If the open failed, then
472 // schedule an error for all pending tasks. The Finish() call on each will
473 // drive the cleanup of this session.
474 //
475  if (!status->IsOK())
476  {XrdSsiErrInfo eInfo;
477  XrdSsiUtils::SetErr(*status, eInfo);
478  do {tP->SchedError(&eInfo); tP = tP->attList.next;}
479  while(tP != attBase);
480  sessMutex.UnLock();
481  return 1;
482  }
483 
484 // Obtain the endpoint name
485 //
486  std::string currNode;
487  if (epFile.GetProperty(dsProperty, currNode))
488  {if (sessNode) free(sessNode);
489  sessNode = strdup(currNode.c_str());
490  } else sessNode = strdup("Unknown!");
491 
492 // Execute each pending request. Make sure not to reference the task object
493 // chain pointer after invoking SendRequest() as it may become invalid.
494 //
495  ztP = attBase;
496  do {ntP = tP->attList.next;
497  if (!tP->SendRequest(sessNode)) noReuse = true;
498  tP = ntP;
499  } while(tP != ztP);
500 
501 // We are done, field the next event
502 //
503  sessMutex.UnLock();
504  return 0;
505 }
bool GetProperty(const std::string &name, std::string &value) const
Definition: XrdClFile.cc:878
void SchedError(XrdSsiErrInfo *eInfo=0)
static void SetErr(XrdCl::XRootDStatus &Status, XrdSsiErrInfo &eInfo)
Definition: XrdSsiUtils.cc:232

References XrdSsiTaskReal::attList, XrdCl::Status::IsOK(), XrdSsiTaskReal::dlQ::next, XrdSsiTaskReal::SchedError(), XrdSsiTaskReal::SendRequest(), and XrdSsiUtils::SetErr().

+ Here is the call graph for this function:

◆ XeqEvFin()

void XrdSsiSessReal::XeqEvFin ( )
inlinevirtual

Implements XrdSsiEvent.

Definition at line 84 of file XrdSsiSessReal.hh.

84 {}

Member Data Documentation

◆ epFile

XrdCl::File XrdSsiSessReal::epFile

Definition at line 96 of file XrdSsiSessReal.hh.

◆ nextSess

XrdSsiSessReal* XrdSsiSessReal::nextSess

Definition at line 48 of file XrdSsiSessReal.hh.

Referenced by XrdSsiServReal::~XrdSsiServReal(), and XrdSsiServReal::Recycle().


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