xrootd
XrdCmsRRQ.hh
Go to the documentation of this file.
00001 #ifndef __XRDCMSRRQ_HH__
00002 #define __XRDCMSRRQ_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d C m s R R Q . 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 <sys/uio.h>
00034 
00035 #include "XProtocol/XPtypes.hh"
00036 #include "XProtocol/YProtocol.hh"
00037 
00038 #include "XrdCms/XrdCmsTypes.hh"
00039 #include "XrdOuc/XrdOucDLlist.hh"
00040 #include "XrdSys/XrdSysPthread.hh"
00041   
00042 /******************************************************************************/
00043 /*                         X r d C m s R R Q I n f o                          */
00044 /******************************************************************************/
00045   
00046 class XrdCmsRRQInfo
00047 {
00048 public:
00049 void     *Key;     // Key link, which is the cache line address
00050 kXR_unt32 ID;      // Response link, which is the request ID
00051 int       Rinst;   // Redirector instance
00052 short     Rnum;    // Redirector number (RTable slot number)
00053 char      isRW;    // True if r/w access wanted
00054 char      isLU;    // True if locate response wanted
00055 char      minR;    // Minimum number of responses for fast redispatch
00056 char      actR;    // Actual  number of responses
00057 short     Rsvd;
00058 SMask_t   rwVec;   // R/W servers for corresponding path (if isLU is true)
00059 
00060         XrdCmsRRQInfo() : isLU(0) {}
00061         XrdCmsRRQInfo(int rinst, short rnum, kXR_unt32 id, int minQ=0)
00062                         : Key(0), ID(id), Rinst(rinst), Rnum(rnum),
00063                           isRW(0), isLU(0), minR(minQ), actR(0), Rsvd(0),
00064                           rwVec(0) {}
00065        ~XrdCmsRRQInfo() {}
00066 };
00067 
00068 /******************************************************************************/
00069 /*                         X r d C m s R R Q S l o t                          */
00070 /******************************************************************************/
00071   
00072 class XrdCmsRRQSlot
00073 {
00074 friend class XrdCmsRRQ;
00075 
00076 static XrdCmsRRQSlot *Alloc(XrdCmsRRQInfo *Info);
00077 
00078        void           Recycle();
00079 
00080        XrdCmsRRQSlot();
00081       ~XrdCmsRRQSlot() {}
00082 
00083 private:
00084 
00085 static   XrdSysMutex                 myMutex;
00086 static   XrdCmsRRQSlot              *freeSlot;
00087 static   short                       initSlot;
00088 
00089          XrdOucDLlist<XrdCmsRRQSlot> Link;
00090          XrdCmsRRQSlot              *Cont;
00091          XrdCmsRRQSlot              *LkUp;
00092          XrdCmsRRQInfo               Info;
00093          SMask_t                     Arg1;
00094          SMask_t                     Arg2;
00095 unsigned int                         Expire;
00096          int                         slotNum;
00097 };
00098 
00099 /******************************************************************************/
00100 /*                             X r d C m s R R Q                              */
00101 /******************************************************************************/
00102   
00103 class XrdCmsRRQ
00104 {
00105 public:
00106 
00107 short Add(short Snum, XrdCmsRRQInfo *ip);
00108 
00109 void  Del(short Snum, const void *Key);
00110 
00111 int   Init(int Tint=0, int Tdly=0);
00112 
00113 int   Ready(int Snum, const void *Key, SMask_t mask1, SMask_t mask2);
00114 
00115 void *Respond();
00116 
00117 struct Info
00118       {long long Add2Q;    // Number added to queue
00119        long long PBack;    // Number that we could piggy-back
00120        long long Resp;     // Number of reponses for a waiting request
00121        long long Multi;    // Number of multiple response fielded
00122        long long luFast;   // Fast lookups
00123        long long luSlow;   // Slow lookups
00124        long long rdFast;   // Fast redirects
00125        long long rdSlow;   // Slow redirects
00126       };
00127 
00128 void  Statistics(Info &Data) {myMutex.Lock(); Data = Stats; myMutex.UnLock();}
00129 
00130 void *TimeOut();
00131 
00132       XrdCmsRRQ() : isWaiting(0), isReady(0),
00133                     luFast(0),    luSlow(0),  rdFast(0), rdSlow(0),
00134                     Tslice(178),  Tdelay(5),  myClock(0) {}
00135      ~XrdCmsRRQ() {}
00136 
00137 private:
00138 
00139 void sendLocResp(XrdCmsRRQSlot *lP);
00140 void sendLwtResp(XrdCmsRRQSlot *rP);
00141 void sendRedResp(XrdCmsRRQSlot *rP);
00142 static const int numSlots = 1024;
00143 
00144          XrdSysMutex                   myMutex;
00145          XrdSysSemaphore               isWaiting;
00146          XrdSysSemaphore               isReady;
00147          XrdCmsRRQSlot                 Slot[numSlots];
00148          XrdOucDLlist<XrdCmsRRQSlot>   waitQ;
00149          XrdOucDLlist<XrdCmsRRQSlot>   readyQ;  // Redirect/Locate ready queue
00150 static   const int                     iov_cnt = 2;
00151          struct iovec                  data_iov[iov_cnt];
00152          struct iovec                  redr_iov[iov_cnt];
00153          XrdCms::CmsResponse           dataResp;
00154          XrdCms::CmsResponse           redrResp;
00155          XrdCms::CmsResponse           waitResp;
00156 union   {char                          hostbuff[288];
00157          char                          databuff[XrdCms::CmsLocateRequest::RILen
00158                                                *STMax];
00159         };
00160          Info                          Stats;
00161          int                           luFast;
00162          int                           luSlow;
00163          int                           rdFast;
00164          int                           rdSlow;
00165          int                           Tslice;
00166          int                           Tdelay;
00167 unsigned int                           myClock;
00168 };
00169 
00170 namespace XrdCms
00171 {
00172 extern    XrdCmsRRQ RRQ;
00173 }
00174 #endif