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 int lifeline; // TOD when nil entry should expire 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 lifeline = rhs.lifeline; 00109 roPend = rhs.roPend; rwPend = rhs.rwPend; 00110 return *this; 00111 } 00112 00113 XrdCmsKeyLoc() : lifeline(0), roPend(0), rwPend(0) {} 00114 ~XrdCmsKeyLoc() {} 00115 }; 00116 00117 /******************************************************************************/ 00118 /* C l a s s X r d C m s K e y I t e m */ 00119 /******************************************************************************/ 00120 00121 // The XrdCmsKeyItem object marries the XrdCmsKey and XrdCmsKeyLoc objects in 00122 // the key cache. It is only used by logical manipulator, XrdCmsCache, which 00123 // always front-ends the physical manipulator, XrdCmsNash. 00124 // 00125 class XrdCmsKeyItem 00126 { 00127 public: 00128 00129 XrdCmsKeyLoc Loc; 00130 XrdCmsKey Key; 00131 XrdCmsKeyItem *Next; 00132 00133 static XrdCmsKeyItem *Alloc(unsigned int theTock); 00134 00135 void Recycle(); 00136 00137 void Reload(); 00138 00139 static int Replenish(); 00140 00141 static void Stats(int &isAlloc, int &isFree, int &wasEmpty); 00142 00143 static XrdCmsKeyItem *Unload(unsigned int theTock); 00144 00145 static XrdCmsKeyItem *Unload(XrdCmsKeyItem *theItem); 00146 00147 XrdCmsKeyItem() {} // Warning see the constructor! 00148 ~XrdCmsKeyItem() {} // These are usually never deleted 00149 00150 static const unsigned int TickRate = 64; 00151 static const unsigned int TickMask = 63; 00152 static const int minAlloc = 4096; 00153 static const int minFree = 1024; 00154 00155 private: 00156 00157 static XrdCmsKeyItem *TockTable[TickRate]; 00158 static XrdCmsKeyItem *Free; 00159 static int numFree; 00160 static int numHave; 00161 static int numNull; 00162 }; 00163 #endif