XRootD
XrdCmsState Class Reference

#include <XrdCmsState.hh>

+ Collaboration diagram for XrdCmsState:

Public Types

enum  StateType {
  Active = 0 ,
  Counts ,
  FrontEnd ,
  Space ,
  Stage
}
 

Public Member Functions

 XrdCmsState ()
 
 ~XrdCmsState ()
 
void Enable ()
 
void * Monitor ()
 
int Port ()
 
void sendState (XrdLink *Link)
 
void Set (int ncount)
 
void Set (int ncount, int isman, const char *AdminPath)
 
void Update (StateType StateT, int ActivVal, int StageVal=0)
 

Public Attributes

int NoStaging
 
int Suspended
 

Static Public Attributes

static const char All_NoStage = 4
 
static const char All_Suspend = 3
 
static const char FES_Suspend = 2
 
static const char SRV_Suspend = 1
 

Detailed Description

Definition at line 38 of file XrdCmsState.hh.

Member Enumeration Documentation

◆ StateType

Enumerator
Active 
Counts 
FrontEnd 
Space 
Stage 

Definition at line 56 of file XrdCmsState.hh.

Constructor & Destructor Documentation

◆ XrdCmsState()

XrdCmsState::XrdCmsState ( )

Definition at line 61 of file XrdCmsState.cc.

61  : mySemaphore(0)
62 {
63  minNodeCnt = 1;
64  numActive = 0;
65  numStaging = 0;
66  currState = All_NoStage | All_Suspend;
67  prevState = 0;
70  feOK = 0;
71  noSpace = 0;
72  adminNoStage = 0;
73  adminSuspend = 0;
74  NoStageFile = "";
75  SuspendFile = "";
76  isMan = 0;
77  dataPort = 0;
78  Enabled = 0;
79 }
static const char All_NoStage
Definition: XrdCmsState.hh:66
static const char All_Suspend
Definition: XrdCmsState.hh:65

References All_NoStage, All_Suspend, NoStaging, and Suspended.

◆ ~XrdCmsState()

XrdCmsState::~XrdCmsState ( )
inline

Definition at line 61 of file XrdCmsState.hh.

61 {}

Member Function Documentation

◆ Enable()

void XrdCmsState::Enable ( )

Definition at line 85 of file XrdCmsState.cc.

86 {
87  struct stat buff;
88 
89 // Set correct admin staging state
90 //
91  Update(Stage, stat(NoStageFile, &buff));
92 
93 // Set correct admin suspend state
94 //
95  Update(Active, stat(SuspendFile, &buff));
96 
97 // We will force the information to be sent to interested parties by making
98 // the previous state different from the current state and enabling ourselves.
99 //
100  myMutex.Lock();
101  Enabled = 1;
102  prevState = ~currState;
103  mySemaphore.Post();
104  myMutex.UnLock();
105 }
int stat(const char *path, struct stat *buf)
void Update(StateType StateT, int ActivVal, int StageVal=0)
Definition: XrdCmsState.cc:258

References Active, XrdSysMutex::Lock(), XrdSysSemaphore::Post(), Stage, stat(), XrdSysMutex::UnLock(), and Update().

Referenced by XrdCmsConfig::DoIt().

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

◆ Monitor()

void * XrdCmsState::Monitor ( )

Definition at line 111 of file XrdCmsState.cc.

112 {
113  CmsStatusRequest myStatus = {{0, kYR_status, 0, 0}};
114  int RTsend, theState, Changes, myPort;
115 
116 // Do this forever (we are only posted when finally enabled)
117 //
118  do {mySemaphore.Wait();
119  myMutex.Lock();
120  Changes = currState ^ prevState;
121  theState = currState;
122  prevState = currState;
123  myPort = dataPort;
124  myMutex.UnLock();
125 
126  if (Changes && (myStatus.Hdr.modifier = Status(Changes, theState)))
127  {if (myStatus.Hdr.modifier & CmsStatusRequest::kYR_Resume)
128  {myStatus.Hdr.streamid = htonl(myPort); RTsend = 1;}
129  else {myStatus.Hdr.streamid = 0;
130  RTsend = (isMan > 0 ? (theState & SRV_Suspend) : 0);
131  }
132  if (isMan && RTsend)
133  RTable.Send("status", (char *)&myStatus, sizeof(myStatus));
134  XrdCmsManager::Inform(myStatus.Hdr);
135  }
136  } while(1);
137 
138 // All done
139 //
140  return (void *)0;
141 }
static void Inform(const char *What, const char *Data, int Dlen)
void Send(const char *What, const char *data, int dlen)
static const char SRV_Suspend
Definition: XrdCmsState.hh:63
kXR_char modifier
Definition: YProtocol.hh:85
XrdCmsRTable RTable
Definition: XrdCmsRTable.cc:40
kXR_unt32 streamid
Definition: YProtocol.hh:83
@ kYR_status
Definition: YProtocol.hh:112

References XrdCms::CmsStatusRequest::Hdr, XrdCmsManager::Inform(), XrdCms::kYR_status, XrdSysMutex::Lock(), XrdCms::CmsRRHdr::modifier, XrdCms::RTable, XrdCmsRTable::Send(), SRV_Suspend, XrdCms::CmsRRHdr::streamid, XrdSysMutex::UnLock(), and XrdSysSemaphore::Wait().

Referenced by XrdCmsStartMonStat().

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

◆ Port()

int XrdCmsState::Port ( )

Definition at line 147 of file XrdCmsState.cc.

148 {
149  int xPort;
150 
151  myMutex.Lock();
152  xPort = dataPort;
153  myMutex.UnLock();
154  return xPort;
155 }

References XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ sendState()

void XrdCmsState::sendState ( XrdLink Link)

Definition at line 161 of file XrdCmsState.cc.

162 {
163  CmsStatusRequest myStatus = {{0, kYR_status, 0, 0}};
164 
165  myMutex.Lock();
166  myStatus.Hdr.modifier = Suspended
167  ? CmsStatusRequest::kYR_Suspend
168  : CmsStatusRequest::kYR_Resume;
169 
170  myStatus.Hdr.modifier |= NoStaging
171  ? CmsStatusRequest::kYR_noStage
172  : CmsStatusRequest::kYR_Stage;
173 
174  lp->Send((char *)&myStatus.Hdr, sizeof(myStatus.Hdr));
175  myMutex.UnLock();
176 }

References XrdCms::CmsStatusRequest::Hdr, XrdCms::kYR_status, XrdSysMutex::Lock(), XrdCms::CmsRRHdr::modifier, NoStaging, XrdLink::Send(), Suspended, and XrdSysMutex::UnLock().

Referenced by XrdCmsNode::do_Update().

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

◆ Set() [1/2]

void XrdCmsState::Set ( int  ncount)

Definition at line 182 of file XrdCmsState.cc.

183 {
184 
185 // Set the node count (this requires a lock)
186 //
187  myMutex.Lock();
188  minNodeCnt = ncount;
189  myMutex.UnLock();
190 }

References XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdCmsCluster::Add(), and XrdCmsConfig::Configure2().

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

◆ Set() [2/2]

void XrdCmsState::Set ( int  ncount,
int  isman,
const char *  AdminPath 
)

Definition at line 194 of file XrdCmsState.cc.

195 {
196  char fnbuff[1048];
197  int i;
198 
199 // This is a configuration call no locks are required.
200 //
201  minNodeCnt = ncount;
202  isMan = isman;
203  i = strlen(AdminPath);
204  strcpy(fnbuff, AdminPath);
205  if (AdminPath[i-1] != '/') fnbuff[i++] = '/';
206  strcpy(fnbuff+i, "NOSTAGE");
207  NoStageFile = strdup(fnbuff);
208  strcpy(fnbuff+i, "SUSPEND");
209  SuspendFile = strdup(fnbuff);
210 }

◆ Update()

void XrdCmsState::Update ( StateType  StateT,
int  ActivVal,
int  StageVal = 0 
)

Definition at line 258 of file XrdCmsState.cc.

259 {
260  EPNAME("Update");
261  const char *What;
262  char newVal;
263 
264 // Create new state
265 //
266  myMutex.Lock();
267  switch(StateT)
268  {case Active: if ((newVal = ActivCnt ? 0 : 1) != adminSuspend)
269  { if ( newVal && !StageCnt) unlink(SuspendFile);
270  else if (!newVal || !StageCnt) unlink(SuspendFile);
271  else close(open(SuspendFile, O_WRONLY|O_CREAT,
272  S_IRUSR|S_IWUSR));
273  adminSuspend = newVal;
274  }
275  What = "Active";
276  break;
277  case Counts: numStaging += StageCnt;
278  numActive += ActivCnt;
279  What = "Counts";
280  break;
281  case FrontEnd: if ((feOK = (ActivCnt ? 1 : 0)) && StageCnt >= 0)
282  dataPort = StageCnt;
283  What = "FrontEnd";
284  break;
285  case Space: noSpace = (ActivCnt ? 0 : 1);
286  What = "Space";
287  break;
288  case Stage: if ((newVal = ActivCnt ? 0 : 1) != adminNoStage)
289  {if (newVal) unlink(NoStageFile);
290  else close(open(NoStageFile, O_WRONLY|O_CREAT,
291  S_IRUSR|S_IWUSR));
292  adminNoStage = newVal;
293  }
294  What = "Stage";
295  break;
296  default: Say.Emsg("State", "Invalid state update");
297  What = "Unknown";
298  break;
299  }
300 
301  DEBUG(What <<" Parm1=" <<ActivCnt <<" Parm2=" <<StageCnt);
302  currState=(numActive < minNodeCnt || adminSuspend ? SRV_Suspend:0)
303  |(numStaging < 1 || noSpace || adminNoStage ? All_NoStage:0)
304  | ( !feOK ? FES_Suspend:0);
305 
306  Suspended = currState & All_Suspend;
307  NoStaging = currState & All_NoStage;
308 
309 // If any changes are noted then we must send out notifications
310 //
311  if (currState != prevState && Enabled) mySemaphore.Post();
312 
313 // All done
314 //
315  myMutex.UnLock();
316 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
int open(const char *path, int oflag,...)
int unlink(const char *path)
#define close(a)
Definition: XrdPosix.hh:43
static const char FES_Suspend
Definition: XrdCmsState.hh:64
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
XrdSysError Say

References Active, All_NoStage, All_Suspend, close, Counts, DEBUG, XrdSysError::Emsg(), EPNAME, FES_Suspend, FrontEnd, XrdSysMutex::Lock(), NoStaging, open(), XrdSysSemaphore::Post(), XrdCms::Say, Space, SRV_Suspend, Stage, Suspended, unlink(), and XrdSysMutex::UnLock().

Referenced by XrdCmsCluster::Add(), XrdCmsConfig::Configure2(), XrdCmsNode::do_Status(), XrdCmsConfig::DoIt(), Enable(), XrdCmsMeter::Init(), XrdCmsAdmin::Login(), XrdCmsAdmin::MonAds(), XrdCmsAdmin::Notes(), XrdCmsCluster::Remove(), and XrdCmsMeter::RunFS().

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

Member Data Documentation

◆ All_NoStage

const char XrdCmsState::All_NoStage = 4
static

Definition at line 66 of file XrdCmsState.hh.

Referenced by XrdCmsState(), and Update().

◆ All_Suspend

const char XrdCmsState::All_Suspend = 3
static

Definition at line 65 of file XrdCmsState.hh.

Referenced by XrdCmsState(), and Update().

◆ FES_Suspend

const char XrdCmsState::FES_Suspend = 2
static

Definition at line 64 of file XrdCmsState.hh.

Referenced by Update().

◆ NoStaging

int XrdCmsState::NoStaging

Definition at line 43 of file XrdCmsState.hh.

Referenced by XrdCmsState(), sendState(), and Update().

◆ SRV_Suspend

const char XrdCmsState::SRV_Suspend = 1
static

Definition at line 63 of file XrdCmsState.hh.

Referenced by Monitor(), and Update().

◆ Suspended

int XrdCmsState::Suspended

Definition at line 42 of file XrdCmsState.hh.

Referenced by XrdCmsState(), XrdCmsProtocol::Execute(), sendState(), and Update().


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