xrootd
XrdCmsKey.hh
Go to the documentation of this file.
1 #ifndef __XRDCMSKEY_HH__
2 #define __XRDCMSKEY_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C m s K e y . h h */
6 /* */
7 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 #include <string.h>
16 
17 #include "XrdCms/XrdCmsTypes.hh"
18 
19 /******************************************************************************/
20 /* C l a s s X r d C m s K e y */
21 /******************************************************************************/
22 
23 // The XrdCmsKey object describes a key (in our case a path). It is used to
24 // locate cached keys and is updated with relevant information as it is
25 // processed in order to speed up the search when multiple lookups occur.
26 //
27 class XrdCmsKeyItem;
28 
29 class XrdCmsKey
30 {
31 public:
32 
34 char *Val;
35 unsigned int Hash;
36 short Len;
37 unsigned char TOD;
38 unsigned char Ref;
39 
40 void setHash();
41 
42 inline int Equiv(XrdCmsKey &oth)
43  {return Hash == oth.Hash && Ref == oth.Ref;}
44 
45 inline XrdCmsKey& operator=(const XrdCmsKey &rhs)
46  {Val = strdup(rhs.Val); Hash = rhs.Hash;
47  Len = rhs.Len;
48  return *this;
49  }
50 
51 inline int operator==(const XrdCmsKey &oth)
52  {return Hash == oth.Hash && !strcmp(Val, oth.Val);}
53 
54 inline int operator!=(const XrdCmsKey &oth)
55  {return Hash != oth.Hash || strcmp(Val, oth.Val);}
56 
57  XrdCmsKey(char *key=0, int klen=0)
58  : TODRef(0), Val(key), Hash(0), Len(klen), Ref('\0') {}
59  ~XrdCmsKey() {};
60 };
61 
62 /******************************************************************************/
63 /* C l a s s X r d C m s K e y L o c */
64 /******************************************************************************/
65 
66 // The XrdCmsKeyLoc object describes the location of the key (servers as well
67 // our local cache). The semantics differ depending on whether it is in the
68 // cache or the information has been reported out of the cache.
69 //
71 {
72 public:
73 
74 SMask_t hfvec; // Servers that are staging or have the file
75 SMask_t pfvec; // Servers that are staging the file
76 SMask_t qfvec; // Servers that are not yet queried
77 unsigned int TOD_B; // Server currency clock
78 unsigned int Reserved;
79 union {
80 unsigned int HashSave; // Where hash goes upon item unload
82  };
83 short roPend; // Redirectors waiting for R/O response
84 short rwPend; // Redirectors waiting for R/W response
85 
86 inline
88  {hfvec=rhs.hfvec; pfvec=rhs.pfvec; TOD_B=rhs.TOD_B;
89  deadline = rhs.deadline;
90  roPend = rhs.roPend; rwPend = rhs.rwPend;
91  return *this;
92  }
93 
94  XrdCmsKeyLoc() : roPend(0), rwPend(0) {}
96 };
97 
98 /******************************************************************************/
99 /* C l a s s X r d C m s K e y I t e m */
100 /******************************************************************************/
101 
102 // The XrdCmsKeyItem object marries the XrdCmsKey and XrdCmsKeyLoc objects in
103 // the key cache. It is only used by logical manipulator, XrdCmsCache, which
104 // always front-ends the physical manipulator, XrdCmsNash.
105 //
107 {
108 public:
109 
113 
114 static XrdCmsKeyItem *Alloc(unsigned int theTock);
115 
116  void Recycle();
117 
118  void Reload();
119 
120 static int Replenish();
121 
122 static void Stats(int &isAlloc, int &isFree, int &wasEmpty);
123 
124 static XrdCmsKeyItem *Unload(unsigned int theTock);
125 
126 static XrdCmsKeyItem *Unload(XrdCmsKeyItem *theItem);
127 
128  XrdCmsKeyItem() {} // Warning see the constructor!
129  ~XrdCmsKeyItem() {} // These are usually never deleted
130 
131 static const unsigned int TickRate = 64;
132 static const unsigned int TickMask = 63;
133 static const int minAlloc = 4096;
134 static const int minFree = 1024;
135 
136 private:
137 
140 static int numFree;
141 static int numHave;
142 static int numNull;
143 };
144 #endif