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