xrootd
XrdCmsCluster.hh
Go to the documentation of this file.
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_All = 0x0001, LS_IPO  = 0x0002};
00117 
00118 XrdCmsSelected *List(SMask_t mask, CmsLSOpts opts);
00119 
00120 // Returns the location of a file
00121 //
00122 int             Locate(XrdCmsSelect &Sel);
00123 
00124 // Always run as a separate thread to monitor subscribed node performance
00125 //
00126 void           *MonPerf();
00127 
00128 // Alwats run as a separate thread to maintain the node reference count
00129 //
00130 void           *MonRefs();
00131 
00132 // Return total number of redirect references (sloppy as we don't lock it)
00133 //
00134 long long       Refs() {return SelWcnt+SelWtot+SelRcnt+SelRtot;}
00135 
00136 // Called to remove a node from the cluster
00137 //
00138 void            Remove(const char *reason, XrdCmsNode *theNode, int immed=0);
00139 
00140 // Called to reset the node reference counts for nodes matching smask
00141 //
00142 void            ResetRef(SMask_t smask);
00143 
00144 // Called to select the best possible node to serve a file (two forms)
00145 //
00146 int             Select(XrdCmsSelect &Sel);
00147 
00148 int             Select(int isrw, int isMulti, SMask_t pmask, int &port,
00149                        char *hbuff, int &hlen);
00150 
00151 // Called to get cluster space (for managers and supervisors only)
00152 //
00153 void            Space(XrdCms::SpaceData &sData, SMask_t smask);
00154 
00155 // Called to return statistics
00156 //
00157 int             Stats(char *bfr, int bln); // Server
00158 int             Statt(char *bfr, int bln); // Manager
00159 
00160                 XrdCmsCluster();
00161                ~XrdCmsCluster() {} // This object should never be deleted
00162 
00163 private:
00164 int         Assign(const char *Cid);
00165 XrdCmsNode *calcDelay(int nump, int numd, int numf, int numo,
00166                       int nums, int &delay, const char **reason);
00167 int         Drop(int sent, int sinst, XrdCmsDrop *djp=0);
00168 void        Record(char *path, const char *reason);
00169 int         Multiple(SMask_t mVec);
00170 enum        {eExists, eDups, eROfs, eNoRep, eNoEnt}; // Passed to SelFail
00171 int         SelFail(XrdCmsSelect &Sel, int rc);
00172 int         SelNode(XrdCmsSelect &Sel, SMask_t  pmask, SMask_t  amask);
00173 XrdCmsNode *SelbyCost(SMask_t, int &, int &, const char **, int);
00174 XrdCmsNode *SelbyLoad(SMask_t, int &, int &, const char **, int);
00175 XrdCmsNode *SelbyRef (SMask_t, int &, int &, const char **, int);
00176 int         SelDFS(XrdCmsSelect &Sel, SMask_t amask,
00177                    SMask_t &pmask, SMask_t &smask, int isRW);
00178 void        sendAList(XrdLink *lp);
00179 void        setAltMan(int snum, unsigned int ipaddr, int port);
00180 
00181 static const  int AltSize = 24; // Number of IP:Port characters per entry
00182 
00183 XrdSysMutex   cidMutex;         // Protects to cid list
00184 XrdOucTList  *cidFirst;         // Cluster ID to cluster number map
00185 
00186 XrdSysMutex   XXMutex;          // Protects cluster summary state variables
00187 XrdSysMutex   STMutex;          // Protects all node information  variables
00188 XrdCmsNode   *NodeTab[STMax];   // Current  set of nodes
00189 
00190 int           STHi;             // NodeTab high watermark
00191 int           doReset;          // Must send reset event to Managers[resetMask]
00192 long long     SelWcnt;          // Curr  number of r/w selections (successful)
00193 long long     SelWtot;          // Total number of r/w selections (successful)
00194 long long     SelRcnt;          // Curr  number of r/o selections (successful)
00195 long long     SelRtot;          // Total number of r/o selections (successful)
00196 long long     SelTcnt;          // Total number of all selections
00197 
00198 // The following is a list of IP:Port tokens that identify supervisor nodes.
00199 // The information is sent via the try request to redirect nodes; as needed.
00200 // The list is alays rotated by one entry each time it is sent.
00201 //
00202 char          AltMans[STMax*AltSize]; // ||123.123.123.123:12345|| = 21
00203 char         *AltMend;
00204 int           AltMent;
00205 
00206 // The foloowing three variables are protected by the STMutex
00207 //
00208 SMask_t       resetMask;        // Nodes to receive a reset event
00209 SMask_t       peerHost;         // Nodes that are acting as peers
00210 SMask_t       peerMask;         // Always ~peerHost
00211 };
00212 
00213 namespace XrdCms
00214 {
00215 extern    XrdCmsCluster Cluster;
00216 }
00217 #endif