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 int lifeline; // TOD when nil entry should expire
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  lifeline = rhs.lifeline;
109  roPend = rhs.roPend; rwPend = rhs.rwPend;
110  return *this;
111  }
112 
113  XrdCmsKeyLoc() : lifeline(0), roPend(0), rwPend(0) {}
115 };
116 
117 /******************************************************************************/
118 /* C l a s s X r d C m s K e y I t e m */
119 /******************************************************************************/
120 
121 // The XrdCmsKeyItem object marries the XrdCmsKey and XrdCmsKeyLoc objects in
122 // the key cache. It is only used by logical manipulator, XrdCmsCache, which
123 // always front-ends the physical manipulator, XrdCmsNash.
124 //
126 {
127 public:
128 
132 
133 static XrdCmsKeyItem *Alloc(unsigned int theTock);
134 
135  void Recycle();
136 
137  void Reload();
138 
139 static int Replenish();
140 
141 static void Stats(int &isAlloc, int &isFree, int &wasEmpty);
142 
143 static XrdCmsKeyItem *Unload(unsigned int theTock);
144 
145 static XrdCmsKeyItem *Unload(XrdCmsKeyItem *theItem);
146 
147  XrdCmsKeyItem() {} // Warning see the constructor!
148  ~XrdCmsKeyItem() {} // These are usually never deleted
149 
150 static const unsigned int TickRate = 64;
151 static const unsigned int TickMask = 63;
152 static const int minAlloc = 4096;
153 static const int minFree = 1024;
154 
155 private:
156 
159 static int numFree;
160 static int numHave;
161 static int numNull;
162 };
163 #endif
unsigned char TOD
Definition: XrdCmsKey.hh:55
static XrdCmsKeyItem * Alloc(unsigned int theTock)
unsigned int Hash
Definition: XrdCmsKey.hh:53
XrdCmsKeyLoc()
Definition: XrdCmsKey.hh:113
static const unsigned int TickRate
Definition: XrdCmsKey.hh:150
static XrdCmsKeyItem * TockTable[TickRate]
Definition: XrdCmsKey.hh:157
int lifeline
Definition: XrdCmsKey.hh:96
static int numHave
Definition: XrdCmsKey.hh:160
XrdCmsKeyLoc Loc
Definition: XrdCmsKey.hh:129
Definition: XrdCmsKey.hh:88
int deadline
Definition: XrdCmsKey.hh:99
static XrdCmsKeyItem * Free
Definition: XrdCmsKey.hh:158
unsigned int HashSave
Definition: XrdCmsKey.hh:98
unsigned int TOD_B
Definition: XrdCmsKey.hh:95
Definition: XrdCmsKey.hh:125
short roPend
Definition: XrdCmsKey.hh:101
int operator!=(const XrdCmsKey &oth)
Definition: XrdCmsKey.hh:72
static int numFree
Definition: XrdCmsKey.hh:159
static int Replenish()
XrdCmsKey Key
Definition: XrdCmsKey.hh:130
static XrdCmsKeyItem * Unload(unsigned int theTock)
~XrdCmsKeyItem()
Definition: XrdCmsKey.hh:148
int operator==(const XrdCmsKey &oth)
Definition: XrdCmsKey.hh:69
unsigned long long SMask_t
Definition: XrdCmsTypes.hh:33
unsigned char Ref
Definition: XrdCmsKey.hh:56
static const int minFree
Definition: XrdCmsKey.hh:153
SMask_t pfvec
Definition: XrdCmsKey.hh:93
~XrdCmsKeyLoc()
Definition: XrdCmsKey.hh:114
SMask_t qfvec
Definition: XrdCmsKey.hh:94
static void Stats(int &isAlloc, int &isFree, int &wasEmpty)
static const unsigned int TickMask
Definition: XrdCmsKey.hh:151
XrdCmsKeyItem * Next
Definition: XrdCmsKey.hh:131
short rwPend
Definition: XrdCmsKey.hh:102
char * Val
Definition: XrdCmsKey.hh:52
XrdCmsKey(char *key=0, int klen=0)
Definition: XrdCmsKey.hh:75
~XrdCmsKey()
Definition: XrdCmsKey.hh:77
XrdCmsKeyLoc & operator=(const XrdCmsKeyLoc &rhs)
Definition: XrdCmsKey.hh:105
Definition: XrdCmsKey.hh:47
XrdCmsKeyItem * TODRef
Definition: XrdCmsKey.hh:51
XrdCmsKeyItem()
Definition: XrdCmsKey.hh:147
XrdCmsKey & operator=(const XrdCmsKey &rhs)
Definition: XrdCmsKey.hh:63
void setHash()
SMask_t hfvec
Definition: XrdCmsKey.hh:92
int Equiv(XrdCmsKey &oth)
Definition: XrdCmsKey.hh:60
static const int minAlloc
Definition: XrdCmsKey.hh:152
short Len
Definition: XrdCmsKey.hh:54
static int numNull
Definition: XrdCmsKey.hh:161