|
xrootd
|
00001 #ifndef __CMS_CLUSTER__H 00002 #define __CMS_CLUSTER__H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C m s C l u s t e r . h h */ 00006 /* */ 00007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <stdlib.h> 00034 #include <string.h> 00035 #include <strings.h> 00036 00037 #include "XrdCms/XrdCmsTypes.hh" 00038 #include "XrdOuc/XrdOucTList.hh" 00039 #include "XrdSys/XrdSysPthread.hh" 00040 00041 class XrdLink; 00042 class XrdCmsDrop; 00043 class XrdCmsNode; 00044 class XrdCmsSelect; 00045 namespace XrdCms 00046 { 00047 struct CmsRRHdr; 00048 } 00049 00050 /******************************************************************************/ 00051 /* O p t i o n F l a g s */ 00052 /******************************************************************************/ 00053 00054 namespace XrdCms 00055 { 00056 00057 // Flags passed to Add() 00058 // 00059 static const int CMS_noStage = 1; 00060 static const int CMS_Suspend = 2; 00061 static const int CMS_Perm = 4; 00062 static const int CMS_isMan = 8; 00063 static const int CMS_Lost = 16; 00064 static const int CMS_isPeer = 32; 00065 static const int CMS_isProxy = 64; 00066 static const int CMS_noSpace =128; 00067 00068 // Class passed to Space() 00069 // 00070 class SpaceData 00071 { 00072 public: 00073 00074 long long Total; // Total space 00075 int wMinF; // Free space minimum to select wFree node 00076 int wFree; // Free space for nodes providing r/w access 00077 int wNum; // Number of nodes providing r/w access 00078 int wUtil; // Average utilization 00079 int sFree; // Free space for nodes providing staging 00080 int sNum; // Number of nodes providing staging 00081 int sUtil; // Average utilization 00082 00083 SpaceData() : Total(0), wMinF(0), 00084 wFree(0), wNum(0), wUtil(0), 00085 sFree(0), sNum(0), sUtil(0) {} 00086 ~SpaceData() {} 00087 }; 00088 } 00089 00090 /******************************************************************************/ 00091 /* C l a s s X r d C m s C l u s t e r */ 00092 /******************************************************************************/ 00093 00094 // This a single-instance global class 00095 // 00096 class XrdCmsBaseFR; 00097 class XrdCmsSelected; 00098 00099 class XrdCmsCluster 00100 { 00101 public: 00102 friend class XrdCmsDrop; 00103 00104 int NodeCnt; // Number of active nodes 00105 00106 // Called to add a new node to the cluster. Status values are defined above. 00107 // 00108 XrdCmsNode *Add(XrdLink *lp, int dport, int Status, 00109 int sport, const char *theNID); 00110 00111 // Sends a message to all nodes matching smask (three forms for convenience) 00112 // 00113 SMask_t Broadcast(SMask_t, const struct iovec *, int, int tot=0); 00114 00115 SMask_t Broadcast(SMask_t smask, XrdCms::CmsRRHdr &Hdr, 00116 char *Data, int Dlen=0); 00117 00118 SMask_t Broadcast(SMask_t smask, XrdCms::CmsRRHdr &Hdr, 00119 void *Data, int Dlen); 00120 00121 // Sends a message to a single node in a round-robbin fashion. 00122 // 00123 int Broadsend(SMask_t smask, XrdCms::CmsRRHdr &Hdr, 00124 void *Data, int Dlen); 00125 00126 // Returns the node mask matching the given IP address 00127 // 00128 SMask_t getMask(unsigned int IPv4adr); 00129 00130 // Returns the node mask matching the given cluster ID 00131 // 00132 SMask_t getMask(const char *Cid); 00133 00134 // Extracts out node information. Opts are one or more of CmsLSOpts 00135 // 00136 enum CmsLSOpts {LS_All = 0x0001, LS_IPO = 0x0002}; 00137 00138 XrdCmsSelected *List(SMask_t mask, CmsLSOpts opts); 00139 00140 // Returns the location of a file 00141 // 00142 int Locate(XrdCmsSelect &Sel); 00143 00144 // Always run as a separate thread to monitor subscribed node performance 00145 // 00146 void *MonPerf(); 00147 00148 // Alwats run as a separate thread to maintain the node reference count 00149 // 00150 void *MonRefs(); 00151 00152 // Return total number of redirect references (sloppy as we don't lock it) 00153 // 00154 long long Refs() {return SelWcnt+SelWtot+SelRcnt+SelRtot;} 00155 00156 // Called to remove a node from the cluster 00157 // 00158 void Remove(const char *reason, XrdCmsNode *theNode, int immed=0); 00159 00160 // Called to reset the node reference counts for nodes matching smask 00161 // 00162 void ResetRef(SMask_t smask); 00163 00164 // Called to select the best possible node to serve a file (two forms) 00165 // 00166 int Select(XrdCmsSelect &Sel); 00167 00168 int Select(int isrw, int isMulti, SMask_t pmask, int &port, 00169 char *hbuff, int &hlen); 00170 00171 // Called to get cluster space (for managers and supervisors only) 00172 // 00173 void Space(XrdCms::SpaceData &sData, SMask_t smask); 00174 00175 // Called to return statistics 00176 // 00177 int Stats(char *bfr, int bln); // Server 00178 int Statt(char *bfr, int bln); // Manager 00179 00180 XrdCmsCluster(); 00181 ~XrdCmsCluster() {} // This object should never be deleted 00182 00183 private: 00184 int Assign(const char *Cid); 00185 XrdCmsNode *calcDelay(int nump, int numd, int numf, int numo, 00186 int nums, int &delay, const char **reason); 00187 int Drop(int sent, int sinst, XrdCmsDrop *djp=0); 00188 void Record(char *path, const char *reason); 00189 int Multiple(SMask_t mVec); 00190 enum {eExists, eDups, eROfs, eNoRep, eNoEnt}; // Passed to SelFail 00191 int SelFail(XrdCmsSelect &Sel, int rc); 00192 int SelNode(XrdCmsSelect &Sel, SMask_t pmask, SMask_t amask); 00193 XrdCmsNode *SelbyCost(SMask_t, int &, int &, const char **, int); 00194 XrdCmsNode *SelbyLoad(SMask_t, int &, int &, const char **, int); 00195 XrdCmsNode *SelbyRef (SMask_t, int &, int &, const char **, int); 00196 int SelDFS(XrdCmsSelect &Sel, SMask_t amask, 00197 SMask_t &pmask, SMask_t &smask, int isRW); 00198 void sendAList(XrdLink *lp); 00199 void setAltMan(int snum, unsigned int ipaddr, int port); 00200 00201 static const int AltSize = 24; // Number of IP:Port characters per entry 00202 00203 XrdSysMutex cidMutex; // Protects to cid list 00204 XrdOucTList *cidFirst; // Cluster ID to cluster number map 00205 00206 XrdSysMutex XXMutex; // Protects cluster summary state variables 00207 XrdSysMutex STMutex; // Protects all node information variables 00208 XrdCmsNode *NodeTab[STMax]; // Current set of nodes 00209 00210 int STHi; // NodeTab high watermark 00211 int doReset; // Must send reset event to Managers[resetMask] 00212 long long SelWcnt; // Curr number of r/w selections (successful) 00213 long long SelWtot; // Total number of r/w selections (successful) 00214 long long SelRcnt; // Curr number of r/o selections (successful) 00215 long long SelRtot; // Total number of r/o selections (successful) 00216 long long SelTcnt; // Total number of all selections 00217 00218 // The following is a list of IP:Port tokens that identify supervisor nodes. 00219 // The information is sent via the try request to redirect nodes; as needed. 00220 // The list is alays rotated by one entry each time it is sent. 00221 // 00222 char AltMans[STMax*AltSize]; // ||123.123.123.123:12345|| = 21 00223 char *AltMend; 00224 int AltMent; 00225 00226 // The foloowing three variables are protected by the STMutex 00227 // 00228 SMask_t resetMask; // Nodes to receive a reset event 00229 SMask_t peerHost; // Nodes that are acting as peers 00230 SMask_t peerMask; // Always ~peerHost 00231 }; 00232 00233 namespace XrdCms 00234 { 00235 extern XrdCmsCluster Cluster; 00236 } 00237 #endif
1.7.6.1