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 00013 #include <stdlib.h> 00014 #include <string.h> 00015 #include <strings.h> 00016 00017 #include "XrdCms/XrdCmsTypes.hh" 00018 #include "XrdOuc/XrdOucTList.hh" 00019 #include "XrdSys/XrdSysPthread.hh" 00020 00021 class XrdLink; 00022 class XrdCmsDrop; 00023 class XrdCmsNode; 00024 class XrdCmsSelect; 00025 namespace XrdCms 00026 { 00027 struct CmsRRHdr; 00028 } 00029 00030 /******************************************************************************/ 00031 /* O p t i o n F l a g s */ 00032 /******************************************************************************/ 00033 00034 namespace XrdCms 00035 { 00036 00037 // Flags passed to Add() 00038 // 00039 static const int CMS_noStage = 1; 00040 static const int CMS_Suspend = 2; 00041 static const int CMS_Perm = 4; 00042 static const int CMS_isMan = 8; 00043 static const int CMS_Lost = 16; 00044 static const int CMS_isPeer = 32; 00045 static const int CMS_isProxy = 64; 00046 static const int CMS_noSpace =128; 00047 00048 // Class passed to Space() 00049 // 00050 class SpaceData 00051 { 00052 public: 00053 00054 long long Total; // Total space 00055 int wMinF; // Free space minimum to select wFree node 00056 int wFree; // Free space for nodes providing r/w access 00057 int wNum; // Number of nodes providing r/w access 00058 int wUtil; // Average utilization 00059 int sFree; // Free space for nodes providing staging 00060 int sNum; // Number of nodes providing staging 00061 int sUtil; // Average utilization 00062 00063 SpaceData() : Total(0), wMinF(0), 00064 wFree(0), wNum(0), wUtil(0), 00065 sFree(0), sNum(0), sUtil(0) {} 00066 ~SpaceData() {} 00067 }; 00068 } 00069 00070 /******************************************************************************/ 00071 /* C l a s s X r d C m s C l u s t e r */ 00072 /******************************************************************************/ 00073 00074 // This a single-instance global class 00075 // 00076 class XrdCmsBaseFR; 00077 class XrdCmsSelected; 00078 00079 class XrdCmsCluster 00080 { 00081 public: 00082 friend class XrdCmsDrop; 00083 00084 int NodeCnt; // Number of active nodes 00085 00086 // Called to add a new node to the cluster. Status values are defined above. 00087 // 00088 XrdCmsNode *Add(XrdLink *lp, int dport, int Status, 00089 int sport, const char *theNID); 00090 00091 // Sends a message to all nodes matching smask (three forms for convenience) 00092 // 00093 SMask_t Broadcast(SMask_t, const struct iovec *, int, int tot=0); 00094 00095 SMask_t Broadcast(SMask_t smask, XrdCms::CmsRRHdr &Hdr, 00096 char *Data, int Dlen=0); 00097 00098 SMask_t Broadcast(SMask_t smask, XrdCms::CmsRRHdr &Hdr, 00099 void *Data, int Dlen); 00100 00101 // Sends a message to a single node in a round-robbin fashion. 00102 // 00103 int Broadsend(SMask_t smask, XrdCms::CmsRRHdr &Hdr, 00104 void *Data, int Dlen); 00105 00106 // Returns the node mask matching the given IP address 00107 // 00108 SMask_t getMask(unsigned int IPv4adr); 00109 00110 // Returns the node mask matching the given cluster ID 00111 // 00112 SMask_t getMask(const char *Cid); 00113 00114 // Extracts out node information. Opts are one or more of CmsLSOpts 00115 // 00116 enum CmsLSOpts {LS_Best = 0x0001, LS_All = 0x0002, 00117 LS_IPO = 0x0004, LS_IPV6 = 0x0008}; 00118 00119 XrdCmsSelected *List(SMask_t mask, CmsLSOpts opts); 00120 00121 // Returns the location of a file 00122 // 00123 int Locate(XrdCmsSelect &Sel); 00124 00125 // Always run as a separate thread to monitor subscribed node performance 00126 // 00127 void *MonPerf(); 00128 00129 // Alwats run as a separate thread to maintain the node reference count 00130 // 00131 void *MonRefs(); 00132 00133 // Called to remove a node from the cluster 00134 // 00135 void Remove(const char *reason, XrdCmsNode *theNode, int immed=0); 00136 00137 // Called to reset the node reference counts for nodes matching smask 00138 // 00139 void ResetRef(SMask_t smask); 00140 00141 // Called to select the best possible node to serve a file (two forms) 00142 // 00143 int Select(XrdCmsSelect &Sel); 00144 00145 int Select(int isrw, SMask_t pmask, int &port, 00146 char *hbuff, int &hlen); 00147 00148 // Called to get cluster space (for managers and supervisors only) 00149 // 00150 void Space(XrdCms::SpaceData &sData, SMask_t smask); 00151 00152 // Called to returns statistics (not really implemented) 00153 // 00154 int Stats(char *bfr, int bln); 00155 00156 XrdCmsCluster(); 00157 ~XrdCmsCluster() {} // This object should never be deleted 00158 00159 private: 00160 int Assign(const char *Cid); 00161 XrdCmsNode *calcDelay(int nump, int numd, int numf, int numo, 00162 int nums, int &delay, const char **reason); 00163 int Drop(int sent, int sinst, XrdCmsDrop *djp=0); 00164 void Record(char *path, const char *reason); 00165 int Multiple(SMask_t mVec); 00166 enum {eExists, eDups, eROfs, eNoRep, eNoEnt}; // Passed to SelFail 00167 int SelFail(XrdCmsSelect &Sel, int rc); 00168 int SelNode(XrdCmsSelect &Sel, SMask_t pmask, SMask_t amask); 00169 XrdCmsNode *SelbyCost(SMask_t, int &, int &, const char **, int); 00170 XrdCmsNode *SelbyLoad(SMask_t, int &, int &, const char **, int); 00171 XrdCmsNode *SelbyRef (SMask_t, int &, int &, const char **, int); 00172 int SelDFS(XrdCmsSelect &Sel, SMask_t amask, 00173 SMask_t &pmask, SMask_t &smask, int isRW); 00174 void sendAList(XrdLink *lp); 00175 void setAltMan(int snum, unsigned int ipaddr, int port); 00176 00177 00178 static const int AltSize = 24; // Number of IP:Port characters per entry 00179 00180 XrdSysMutex cidMutex; // Protects to cid list 00181 XrdOucTList *cidFirst; // Cluster ID to cluster number map 00182 00183 XrdSysMutex XXMutex; // Protects cluster summary state variables 00184 XrdSysMutex STMutex; // Protects all node information variables 00185 XrdCmsNode *NodeTab[STMax]; // Current set of nodes 00186 00187 int STHi; // NodeTab high watermark 00188 int SelAcnt; // Total number of r/w selections 00189 int SelRcnt; // Total number of r/o selections 00190 int doReset; // Must send reset event to Managers[resetMask] 00191 00192 // The following is a list of IP:Port tokens that identify supervisor nodes. 00193 // The information is sent via the try request to redirect nodes; as needed. 00194 // The list is alays rotated by one entry each time it is sent. 00195 // 00196 char AltMans[STMax*AltSize]; // ||123.123.123.123:12345|| = 21 00197 char *AltMend; 00198 int AltMent; 00199 00200 // The foloowing three variables are protected by the STMutex 00201 // 00202 SMask_t resetMask; // Nodes to receive a reset event 00203 SMask_t peerHost; // Nodes that are acting as peers 00204 SMask_t peerMask; // Always ~peerHost 00205 }; 00206 00207 namespace XrdCms 00208 { 00209 extern XrdCmsCluster Cluster; 00210 } 00211 #endif