xrootd
XrdCmsKey.hh
Go to the documentation of this file.
00001 #ifndef __XRDCMSKEY_HH__
00002 #define __XRDCMSKEY_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d C m s K e y . 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 <string.h>
00034 
00035 #include "XrdCms/XrdCmsTypes.hh"
00036 
00037 /******************************************************************************/
00038 /*                       C l a s s   X r d C m s K e y                        */
00039 /******************************************************************************/
00040   
00041 // The XrdCmsKey object describes a key (in our case a path). It is used to
00042 // locate cached keys and is updated with relevant information as it is
00043 // processed in order to speed up the search when multiple lookups occur.
00044 //
00045 class XrdCmsKeyItem;
00046 
00047 class XrdCmsKey
00048 {
00049 public:
00050 
00051 XrdCmsKeyItem    *TODRef;
00052 char             *Val;
00053 unsigned int      Hash;
00054 short             Len;
00055 unsigned char     TOD;
00056 unsigned char     Ref;
00057 
00058 void              setHash();
00059 
00060 inline int        Equiv(XrdCmsKey &oth)
00061                        {return Hash == oth.Hash && Ref == oth.Ref;}
00062 
00063 inline XrdCmsKey& operator=(const XrdCmsKey &rhs)
00064                            {Val = strdup(rhs.Val); Hash = rhs.Hash; 
00065                             Len = rhs.Len;
00066                             return *this;
00067                            }
00068 
00069 inline int        operator==(const XrdCmsKey &oth)
00070                           {return Hash == oth.Hash && !strcmp(Val, oth.Val);}
00071 
00072 inline int        operator!=(const XrdCmsKey &oth)
00073                           {return Hash != oth.Hash || strcmp(Val, oth.Val);}
00074 
00075          XrdCmsKey(char *key=0, int klen=0)
00076                       : TODRef(0), Val(key), Hash(0), Len(klen), Ref('\0') {}
00077         ~XrdCmsKey() {};
00078 };
00079 
00080 /******************************************************************************/
00081 /*                    C l a s s   X r d C m s K e y L o c                     */
00082 /******************************************************************************/
00083   
00084 // The XrdCmsKeyLoc object describes the location of the key (servers as well
00085 // our local cache). The semantics differ depending on whether it is in the
00086 // cache or the information has been reported out of the cache.
00087 //
00088 class XrdCmsKeyLoc
00089 {
00090 public:
00091 
00092 SMask_t        hfvec;    // Servers that are staging or have the file
00093 SMask_t        pfvec;    // Servers that are staging         the file
00094 SMask_t        qfvec;    // Servers that are not yet queried
00095 unsigned int   TOD_B;    // Server currency clock
00096 unsigned int   Reserved;
00097 union {
00098 unsigned int   HashSave; // Where hash goes upon item unload
00099 int            deadline;
00100       };
00101 short          roPend;   // Redirectors waiting for R/O response
00102 short          rwPend;   // Redirectors waiting for R/W response
00103 
00104 inline 
00105 XrdCmsKeyLoc&  operator=(const XrdCmsKeyLoc &rhs)
00106                            {hfvec=rhs.hfvec; pfvec=rhs.pfvec; TOD_B=rhs.TOD_B;
00107                             deadline = rhs.deadline;
00108                             roPend = rhs.roPend; rwPend = rhs.rwPend;
00109                             return *this;
00110                            }
00111 
00112                XrdCmsKeyLoc() : roPend(0), rwPend(0) {}
00113               ~XrdCmsKeyLoc() {}
00114 };
00115   
00116 /******************************************************************************/
00117 /*                   C l a s s   X r d C m s K e y I t e m                    */
00118 /******************************************************************************/
00119   
00120 // The XrdCmsKeyItem object marries the XrdCmsKey and XrdCmsKeyLoc objects in
00121 // the key cache. It is only used by logical manipulator, XrdCmsCache, which
00122 // always front-ends the physical manipulator, XrdCmsNash.
00123 //
00124 class XrdCmsKeyItem
00125 {
00126 public:
00127 
00128        XrdCmsKeyLoc   Loc;
00129        XrdCmsKey      Key;
00130        XrdCmsKeyItem *Next;
00131 
00132 static XrdCmsKeyItem *Alloc(unsigned int theTock);
00133 
00134        void           Recycle();
00135 
00136        void           Reload();
00137 
00138 static int            Replenish();
00139 
00140 static void           Stats(int &isAlloc, int &isFree, int &wasEmpty);
00141 
00142 static XrdCmsKeyItem *Unload(unsigned int   theTock);
00143 
00144 static XrdCmsKeyItem *Unload(XrdCmsKeyItem *theItem);
00145 
00146        XrdCmsKeyItem() {}  // Warning see the constructor!
00147       ~XrdCmsKeyItem() {}  // These are usually never deleted
00148 
00149 static const unsigned int TickRate =   64;
00150 static const unsigned int TickMask =   63;
00151 static const          int minAlloc = 4096;
00152 static const          int minFree  = 1024;
00153 
00154 private:
00155 
00156 static XrdCmsKeyItem *TockTable[TickRate];
00157 static XrdCmsKeyItem *Free;
00158 static int            numFree;
00159 static int            numHave;
00160 static int            numNull;
00161 };
00162 #endif