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 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <string.h>
34 
35 #include "XrdCms/XrdCmsTypes.hh"
36 
37 /******************************************************************************/
38 /* C l a s s X r d C m s K e y */
39 /******************************************************************************/
40 
41 // The XrdCmsKey object describes a key (in our case a path). It is used to
42 // locate cached keys and is updated with relevant information as it is
43 // processed in order to speed up the search when multiple lookups occur.
44 //
45 class XrdCmsKeyItem;
46 
47 class XrdCmsKey
48 {
49 public:
50 
52 char *Val;
53 unsigned int Hash;
54 short Len;
55 unsigned char TOD;
56 unsigned char Ref;
57 
58 void setHash();
59 
60 inline int Equiv(XrdCmsKey &oth)
61  {return Hash == oth.Hash && Ref == oth.Ref;}
62 
63 inline XrdCmsKey& operator=(const XrdCmsKey &rhs)
64  {Val = strdup(rhs.Val); Hash = rhs.Hash;
65  Len = rhs.Len;
66  return *this;
67  }
68 
69 inline int operator==(const XrdCmsKey &oth)
70  {return Hash == oth.Hash && !strcmp(Val, oth.Val);}
71 
72 inline int operator!=(const XrdCmsKey &oth)
73  {return Hash != oth.Hash || strcmp(Val, oth.Val);}
74 
75  XrdCmsKey(char *key=0, int klen=0)
76  : TODRef(0), Val(key), Hash(0), Len(klen), Ref('\0') {}
77  ~XrdCmsKey() {};
78 };
79 
80 /******************************************************************************/
81 /* C l a s s X r d C m s K e y L o c */
82 /******************************************************************************/
83 
84 // The XrdCmsKeyLoc object describes the location of the key (servers as well
85 // our local cache). The semantics differ depending on whether it is in the
86 // cache or the information has been reported out of the cache.
87 //
89 {
90 public:
91 
92 SMask_t hfvec; // Servers that are staging or have the file
93 SMask_t pfvec; // Servers that are staging the file
94 SMask_t qfvec; // Servers that are not yet queried
95 unsigned int TOD_B; // Server currency clock
96 unsigned int Reserved;
97 union {
98 unsigned int HashSave; // Where hash goes upon item unload
100  };
101 short roPend; // Redirectors waiting for R/O response
102 short rwPend; // Redirectors waiting for R/W response
103 
104 inline
106  {hfvec=rhs.hfvec; pfvec=rhs.pfvec; TOD_B=rhs.TOD_B;
107  deadline = rhs.deadline;
108  roPend = rhs.roPend; rwPend = rhs.rwPend;
109  return *this;
110  }
111 
112  XrdCmsKeyLoc() : roPend(0), rwPend(0) {}
114 };
115 
116 /******************************************************************************/
117 /* C l a s s X r d C m s K e y I t e m */
118 /******************************************************************************/
119 
120 // The XrdCmsKeyItem object marries the XrdCmsKey and XrdCmsKeyLoc objects in
121 // the key cache. It is only used by logical manipulator, XrdCmsCache, which
122 // always front-ends the physical manipulator, XrdCmsNash.
123 //
125 {
126 public:
127 
131 
132 static XrdCmsKeyItem *Alloc(unsigned int theTock);
133 
134  void Recycle();
135 
136  void Reload();
137 
138 static int Replenish();
139 
140 static void Stats(int &isAlloc, int &isFree, int &wasEmpty);
141 
142 static XrdCmsKeyItem *Unload(unsigned int theTock);
143 
144 static XrdCmsKeyItem *Unload(XrdCmsKeyItem *theItem);
145 
146  XrdCmsKeyItem() {} // Warning see the constructor!
147  ~XrdCmsKeyItem() {} // These are usually never deleted
148 
149 static const unsigned int TickRate = 64;
150 static const unsigned int TickMask = 63;
151 static const int minAlloc = 4096;
152 static const int minFree = 1024;
153 
154 private:
155 
158 static int numFree;
159 static int numHave;
160 static int numNull;
161 };
162 #endif