xrootd
Loading...
Searching...
No Matches
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 <cstring>
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//
45class XrdCmsKeyItem;
46
48{
49public:
50
52char *Val;
53unsigned int Hash;
54short Len;
55unsigned char TOD;
56unsigned char Ref;
57
58void setHash();
59
60inline int Equiv(XrdCmsKey &oth)
61 {return Hash == oth.Hash && Ref == oth.Ref;}
62
63inline XrdCmsKey& operator=(const XrdCmsKey &rhs)
64 {Val = strdup(rhs.Val); Hash = rhs.Hash;
65 Len = rhs.Len;
66 return *this;
67 }
68
69inline int operator==(const XrdCmsKey &oth)
70 {return Hash == oth.Hash && !strcmp(Val, oth.Val);}
71
72inline 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') {}
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{
90public:
91
92SMask_t hfvec; // Servers that are staging or have the file
93SMask_t pfvec; // Servers that are staging the file
94SMask_t qfvec; // Servers that are not yet queried
95unsigned int TOD_B; // Server currency clock
96int lifeline; // TOD when nil entry should expire
97union {
98unsigned int HashSave; // Where hash goes upon item unload
100 };
101short roPend; // Redirectors waiting for R/O response
102short rwPend; // Redirectors waiting for R/W response
103
104inline
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
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{
127public:
128
132
133static XrdCmsKeyItem *Alloc(unsigned int theTock);
134
135 void Recycle();
136
137 void Reload();
138
139static int Replenish();
140
141static void Stats(int &isAlloc, int &isFree, int &wasEmpty);
142
143static XrdCmsKeyItem *Unload(unsigned int theTock);
144
146
147 XrdCmsKeyItem() {} // Warning see the constructor!
148 ~XrdCmsKeyItem() {} // These are usually never deleted
149
150static const unsigned int TickRate = 64;
151static const unsigned int TickMask = 63;
152static const int minAlloc = 4096;
153static const int minFree = 1024;
154
155private:
156
159static int numFree;
160static int numHave;
161static int numNull;
162};
163#endif
unsigned long long SMask_t
Definition XrdCmsTypes.hh:33
Definition XrdCmsKey.hh:126
static int numHave
Definition XrdCmsKey.hh:160
static void Stats(int &isAlloc, int &isFree, int &wasEmpty)
static int numFree
Definition XrdCmsKey.hh:159
static const unsigned int TickMask
Definition XrdCmsKey.hh:151
static XrdCmsKeyItem * Free
Definition XrdCmsKey.hh:158
XrdCmsKeyItem()
Definition XrdCmsKey.hh:147
static XrdCmsKeyItem * Unload(unsigned int theTock)
static const int minAlloc
Definition XrdCmsKey.hh:152
static XrdCmsKeyItem * Alloc(unsigned int theTock)
static XrdCmsKeyItem * TockTable[TickRate]
Definition XrdCmsKey.hh:157
XrdCmsKeyLoc Loc
Definition XrdCmsKey.hh:129
static const int minFree
Definition XrdCmsKey.hh:153
static XrdCmsKeyItem * Unload(XrdCmsKeyItem *theItem)
XrdCmsKey Key
Definition XrdCmsKey.hh:130
static const unsigned int TickRate
Definition XrdCmsKey.hh:150
XrdCmsKeyItem * Next
Definition XrdCmsKey.hh:131
static int Replenish()
~XrdCmsKeyItem()
Definition XrdCmsKey.hh:148
static int numNull
Definition XrdCmsKey.hh:161
Definition XrdCmsKey.hh:89
SMask_t hfvec
Definition XrdCmsKey.hh:92
XrdCmsKeyLoc & operator=(const XrdCmsKeyLoc &rhs)
Definition XrdCmsKey.hh:105
int lifeline
Definition XrdCmsKey.hh:96
SMask_t qfvec
Definition XrdCmsKey.hh:94
~XrdCmsKeyLoc()
Definition XrdCmsKey.hh:114
XrdCmsKeyLoc()
Definition XrdCmsKey.hh:113
unsigned int TOD_B
Definition XrdCmsKey.hh:95
short rwPend
Definition XrdCmsKey.hh:102
short roPend
Definition XrdCmsKey.hh:101
unsigned int HashSave
Definition XrdCmsKey.hh:98
int deadline
Definition XrdCmsKey.hh:99
SMask_t pfvec
Definition XrdCmsKey.hh:93
Definition XrdCmsKey.hh:48
int operator!=(const XrdCmsKey &oth)
Definition XrdCmsKey.hh:72
int Equiv(XrdCmsKey &oth)
Definition XrdCmsKey.hh:60
void setHash()
unsigned int Hash
Definition XrdCmsKey.hh:53
XrdCmsKeyItem * TODRef
Definition XrdCmsKey.hh:51
XrdCmsKey & operator=(const XrdCmsKey &rhs)
Definition XrdCmsKey.hh:63
unsigned char TOD
Definition XrdCmsKey.hh:55
char * Val
Definition XrdCmsKey.hh:52
XrdCmsKey(char *key=0, int klen=0)
Definition XrdCmsKey.hh:75
unsigned char Ref
Definition XrdCmsKey.hh:56
~XrdCmsKey()
Definition XrdCmsKey.hh:77
int operator==(const XrdCmsKey &oth)
Definition XrdCmsKey.hh:69
short Len
Definition XrdCmsKey.hh:54