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

Generated on Tue Jul 5 14:46:24 2011 for ROOT_528-00b_version by  doxygen 1.5.1