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

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