xrootd
XrdCmsCluster.hh
Go to the documentation of this file.
1 #ifndef __CMS_CLUSTER__H
2 #define __CMS_CLUSTER__H
3 /******************************************************************************/
4 /* */
5 /* X r d C m s C l u s t e r . h h */
6 /* */
7 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <stdlib.h>
14 #include <string.h>
15 #include <strings.h>
16 
17 #include "XrdCms/XrdCmsTypes.hh"
18 #include "XrdOuc/XrdOucTList.hh"
19 #include "XrdSys/XrdSysPthread.hh"
20 
21 class XrdLink;
22 class XrdCmsDrop;
23 class XrdCmsNode;
24 class XrdCmsSelect;
25 namespace XrdCms
26 {
27 struct CmsRRHdr;
28 }
29 
30 /******************************************************************************/
31 /* O p t i o n F l a g s */
32 /******************************************************************************/
33 
34 namespace XrdCms
35 {
36 
37 // Flags passed to Add()
38 //
39 static const int CMS_noStage = 1;
40 static const int CMS_Suspend = 2;
41 static const int CMS_Perm = 4;
42 static const int CMS_isMan = 8;
43 static const int CMS_Lost = 16;
44 static const int CMS_isPeer = 32;
45 static const int CMS_isProxy = 64;
46 static const int CMS_noSpace =128;
47 
48 // Class passed to Space()
49 //
50 class SpaceData
51 {
52 public:
53 
54 long long Total; // Total space
55 int wMinF; // Free space minimum to select wFree node
56 int wFree; // Free space for nodes providing r/w access
57 int wNum; // Number of nodes providing r/w access
58 int wUtil; // Average utilization
59 int sFree; // Free space for nodes providing staging
60 int sNum; // Number of nodes providing staging
61 int sUtil; // Average utilization
62 
63  SpaceData() : Total(0), wMinF(0),
64  wFree(0), wNum(0), wUtil(0),
65  sFree(0), sNum(0), sUtil(0) {}
67 };
68 }
69 
70 /******************************************************************************/
71 /* C l a s s X r d C m s C l u s t e r */
72 /******************************************************************************/
73 
74 // This a single-instance global class
75 //
76 class XrdCmsBaseFR;
77 class XrdCmsSelected;
78 
80 {
81 public:
82 friend class XrdCmsDrop;
83 
84 int NodeCnt; // Number of active nodes
85 
86 // Called to add a new node to the cluster. Status values are defined above.
87 //
88 XrdCmsNode *Add(XrdLink *lp, int dport, int Status,
89  int sport, const char *theNID);
90 
91 // Sends a message to all nodes matching smask (three forms for convenience)
92 //
93 SMask_t Broadcast(SMask_t, const struct iovec *, int, int tot=0);
94 
96  char *Data, int Dlen=0);
97 
99  void *Data, int Dlen);
100 
101 // Sends a message to a single node in a round-robbin fashion.
102 //
103 int Broadsend(SMask_t smask, XrdCms::CmsRRHdr &Hdr,
104  void *Data, int Dlen);
105 
106 // Returns the node mask matching the given IP address
107 //
108 SMask_t getMask(unsigned int IPv4adr);
109 
110 // Returns the node mask matching the given cluster ID
111 //
112 SMask_t getMask(const char *Cid);
113 
114 // Extracts out node information. Opts are one or more of CmsLSOpts
115 //
116 enum CmsLSOpts {LS_All = 0x0001, LS_IPO = 0x0002};
117 
119 
120 // Returns the location of a file
121 //
122 int Locate(XrdCmsSelect &Sel);
123 
124 // Always run as a separate thread to monitor subscribed node performance
125 //
126 void *MonPerf();
127 
128 // Alwats run as a separate thread to maintain the node reference count
129 //
130 void *MonRefs();
131 
132 // Return total number of redirect references (sloppy as we don't lock it)
133 //
134 long long Refs() {return SelWcnt+SelWtot+SelRcnt+SelRtot;}
135 
136 // Called to remove a node from the cluster
137 //
138 void Remove(const char *reason, XrdCmsNode *theNode, int immed=0);
139 
140 // Called to reset the node reference counts for nodes matching smask
141 //
142 void ResetRef(SMask_t smask);
143 
144 // Called to select the best possible node to serve a file (two forms)
145 //
146 int Select(XrdCmsSelect &Sel);
147 
148 int Select(int isrw, int isMulti, SMask_t pmask, int &port,
149  char *hbuff, int &hlen);
150 
151 // Called to get cluster space (for managers and supervisors only)
152 //
153 void Space(XrdCms::SpaceData &sData, SMask_t smask);
154 
155 // Called to return statistics
156 //
157 int Stats(char *bfr, int bln); // Server
158 int Statt(char *bfr, int bln); // Manager
159 
160  XrdCmsCluster();
161  ~XrdCmsCluster() {} // This object should never be deleted
162 
163 private:
164 int Assign(const char *Cid);
165 XrdCmsNode *calcDelay(int nump, int numd, int numf, int numo,
166  int nums, int &delay, const char **reason);
167 int Drop(int sent, int sinst, XrdCmsDrop *djp=0);
168 void Record(char *path, const char *reason);
169 int Multiple(SMask_t mVec);
170 enum {eExists, eDups, eROfs, eNoRep, eNoEnt}; // Passed to SelFail
171 int SelFail(XrdCmsSelect &Sel, int rc);
172 int SelNode(XrdCmsSelect &Sel, SMask_t pmask, SMask_t amask);
173 XrdCmsNode *SelbyCost(SMask_t, int &, int &, const char **, int);
174 XrdCmsNode *SelbyLoad(SMask_t, int &, int &, const char **, int);
175 XrdCmsNode *SelbyRef (SMask_t, int &, int &, const char **, int);
176 int SelDFS(XrdCmsSelect &Sel, SMask_t amask,
177  SMask_t &pmask, SMask_t &smask, int isRW);
178 void sendAList(XrdLink *lp);
179 void setAltMan(int snum, unsigned int ipaddr, int port);
180 
181 static const int AltSize = 24; // Number of IP:Port characters per entry
182 
183 XrdSysMutex cidMutex; // Protects to cid list
184 XrdOucTList *cidFirst; // Cluster ID to cluster number map
185 
186 XrdSysMutex XXMutex; // Protects cluster summary state variables
187 XrdSysMutex STMutex; // Protects all node information variables
188 XrdCmsNode *NodeTab[STMax]; // Current set of nodes
189 
190 int STHi; // NodeTab high watermark
191 int doReset; // Must send reset event to Managers[resetMask]
192 long long SelWcnt; // Curr number of r/w selections (successful)
193 long long SelWtot; // Total number of r/w selections (successful)
194 long long SelRcnt; // Curr number of r/o selections (successful)
195 long long SelRtot; // Total number of r/o selections (successful)
196 long long SelTcnt; // Total number of all selections
197 
198 // The following is a list of IP:Port tokens that identify supervisor nodes.
199 // The information is sent via the try request to redirect nodes; as needed.
200 // The list is alays rotated by one entry each time it is sent.
201 //
202 char AltMans[STMax*AltSize]; // ||123.123.123.123:12345|| = 21
203 char *AltMend;
205 
206 // The foloowing three variables are protected by the STMutex
207 //
208 SMask_t resetMask; // Nodes to receive a reset event
209 SMask_t peerHost; // Nodes that are acting as peers
210 SMask_t peerMask; // Always ~peerHost
211 };
212 
213 namespace XrdCms
214 {
215 extern XrdCmsCluster Cluster;
216 }
217 #endif