XRootD
Loading...
Searching...
No Matches
XrdPfc::DirState Struct Reference

#include <XrdPfcDirState.hh>

+ Inheritance diagram for XrdPfc::DirState:
+ Collaboration diagram for XrdPfc::DirState:

Public Types

typedef DsMap_t::iterator DsMap_i
 
typedef std::map< std::string, DirStateDsMap_t
 

Public Member Functions

 DirState ()
 Constructor.
 
 DirState (DirState *parent)
 
 DirState (DirState *parent, const std::string &dname)
 
int count_dirs_to_level (int max_depth) const
 
DirStatecreate_child (const std::string &dir)
 
void dump_recursively (const char *name, int max_depth) const
 
DirStatefind_dir (const std::string &dir, bool create_subdirs)
 
DirStatefind_path (const std::string &path, int max_depth, bool parse_as_lfn, bool create_subdirs, DirState **last_existing_dir=nullptr)
 
DirStatefind_path_tok (PathTokenizer &pt, int pos, bool create_subdirs, DirState **last_existing_dir=nullptr)
 
int generate_dir_path (std::string &result)
 
DirStateget_parent ()
 
void init ()
 
void reset_sshot_stats ()
 
void reset_stats ()
 
void update_stats_and_usages (bool purge_empty_dirs, unlink_func unlink_foo)
 
void upward_propagate_initial_scan_usages ()
 
- Public Member Functions inherited from XrdPfc::DirStateBase
 DirStateBase ()
 
 DirStateBase (const std::string &dname)
 

Public Attributes

int m_depth
 
DirStats m_here_stats
 
DirUsage m_here_usage
 
DirStatem_parent = nullptr
 
DirStats m_recursive_subdir_stats
 
DirUsage m_recursive_subdir_usage
 
bool m_scanned = false
 
DirStats m_sshot_stats
 
DsMap_t m_subdirs
 
- Public Attributes inherited from XrdPfc::DirStateBase
std::string m_dir_name
 

Detailed Description

Definition at line 55 of file XrdPfcDirState.hh.

Member Typedef Documentation

◆ DsMap_i

typedef DsMap_t::iterator XrdPfc::DirState::DsMap_i

Definition at line 58 of file XrdPfcDirState.hh.

◆ DsMap_t

typedef std::map<std::string, DirState> XrdPfc::DirState::DsMap_t

Definition at line 57 of file XrdPfcDirState.hh.

Constructor & Destructor Documentation

◆ DirState() [1/3]

DirState::DirState ( )

Constructor.

Definition at line 12 of file XrdPfcDirState.cc.

12 : m_parent(0), m_depth(0)
13{}

References m_depth, and m_parent.

Referenced by DirState(), DirState(), create_child(), find_dir(), find_path(), find_path_tok(), get_parent(), init(), and update_stats_and_usages().

+ Here is the caller graph for this function:

◆ DirState() [2/3]

DirState::DirState ( DirState * parent)

Constructor

Parameters
DirStateparent directory

Definition at line 19 of file XrdPfcDirState.cc.

19 :
21 m_depth(m_parent->m_depth + 1)
22{}
static void parent()

References DirState(), m_depth, m_parent, and parent().

+ Here is the call graph for this function:

◆ DirState() [3/3]

DirState::DirState ( DirState * parent,
const std::string & dname )

Constructor

Parameters
parentparent DirState object
dnamename of this directory only, no slashes, no extras.

Definition at line 29 of file XrdPfcDirState.cc.

29 :
30 DirStateBase(dname),
32 m_depth(m_parent->m_depth + 1)
33{}

References DirState(), XrdPfc::DirStateBase::DirStateBase(), m_depth, m_parent, and parent().

+ Here is the call graph for this function:

Member Function Documentation

◆ count_dirs_to_level()

int DirState::count_dirs_to_level ( int max_depth) const

Definition at line 233 of file XrdPfcDirState.cc.

234{
235 int n_dirs = 1;
236 if (m_depth < max_depth)
237 {
238 for (auto & [name, ds] : m_subdirs)
239 {
240 n_dirs += ds.count_dirs_to_level(max_depth);
241 }
242 }
243 return n_dirs;
244}

References m_depth, and m_subdirs.

Referenced by XrdPfc::ResourceMonitor::heart_beat(), and XrdPfc::ResourceMonitor::perform_purge_check().

+ Here is the caller graph for this function:

◆ create_child()

DirState * DirState::create_child ( const std::string & dir)

Internal function called from find_dir or find_path_tok

Parameters
dirsubdir name

Definition at line 39 of file XrdPfcDirState.cc.

40{
41 std::pair<DsMap_i, bool> ir = m_subdirs.insert(std::make_pair(dir, DirState(this, dir)));
42 return &ir.first->second;
43}
DirState()
Constructor.

References DirState(), and m_subdirs.

Referenced by find_dir(), and find_path_tok().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_recursively()

void DirState::dump_recursively ( const char * name,
int max_depth ) const

Recursive print of statistics. Called if defined in pfc configuration.

Definition at line 250 of file XrdPfcDirState.cc.

251{
252 printf("%*d %s usage_here=%lld usage_sub=%lld usage_total=%lld num_ios=%d duration=%d b_hit=%lld b_miss=%lld b_byps=%lld b_wrtn=%lld\n",
253 2 + 2 * m_depth, m_depth, name,
254 512 * m_here_usage.m_StBlocks, 512 * m_recursive_subdir_usage.m_StBlocks,
255 512 * (m_here_usage.m_StBlocks + m_recursive_subdir_usage.m_StBlocks),
256 // XXXXX here_stats or sum up? or both?
257 m_here_stats.m_NumIos, m_here_stats.m_Duration,
258 m_here_stats.m_BytesHit, m_here_stats.m_BytesMissed, m_here_stats.m_BytesBypassed,
259 m_here_stats.m_BytesWritten);
260
261 if (m_depth < max_depth)
262 {
263 for (auto & [name, ds] : m_subdirs)
264 {
265 ds.dump_recursively(name.c_str(), max_depth);
266 }
267 }
268}
DirUsage m_recursive_subdir_usage

References m_depth, m_here_stats, m_here_usage, m_recursive_subdir_usage, and m_subdirs.

◆ find_dir()

DirState * DirState::find_dir ( const std::string & dir,
bool create_subdirs )

Non recursive function to find an entry in this directory only.

Parameters
dirsubdir name
boolcreate the subdir in this DirsStat
create_subdirsif true and the dir is not found, a new DirState child is created

Definition at line 98 of file XrdPfcDirState.cc.

100{
101 DsMap_i i = m_subdirs.find(dir);
102
103 if (i != m_subdirs.end())
104 return &i->second;
105
106 if (create_subdirs)
107 return create_child(dir);
108
109 return nullptr;
110}
DsMap_t::iterator DsMap_i
DirState * create_child(const std::string &dir)

References DirState(), create_child(), and m_subdirs.

+ Here is the call graph for this function:

◆ find_path()

DirState * DirState::find_path ( const std::string & path,
int max_depth,
bool parse_as_lfn,
bool create_subdirs,
DirState ** last_existing_dir = nullptr )

Recursive function to find DirState with given absolute dir path

Parameters
pathfull path to parse
max_depthdirectory depth to which to descend (value < 0 means full descent)
parse_as_lfn
create_subdirs

Definition at line 82 of file XrdPfcDirState.cc.

84{
85 PathTokenizer pt(path, max_depth, parse_as_lfn);
86
87 if (last_existing_dir)
88 *last_existing_dir = this;
89
90 return find_path_tok(pt, 0, create_subdirs, last_existing_dir);
91}
DirState * find_path_tok(PathTokenizer &pt, int pos, bool create_subdirs, DirState **last_existing_dir=nullptr)

References DirState(), and find_path_tok().

Referenced by XrdPfc::ResourceMonitor::process_queues().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_path_tok()

DirState * DirState::find_path_tok ( PathTokenizer & pt,
int pos,
bool create_subdirs,
DirState ** last_existing_dir = nullptr )

Internal function called from find_path

Parameters
dirsubdir name

Definition at line 49 of file XrdPfcDirState.cc.

51{
52 if (pos == pt.get_n_dirs())
53 return this;
54
55 DirState *ds = nullptr;
56
57 DsMap_i i = m_subdirs.find(pt.m_dirs[pos]);
58
59 if (i != m_subdirs.end())
60 {
61 ds = &i->second;
62 if (last_existing_dir)
63 *last_existing_dir = ds;
64 }
65 else if (create_subdirs)
66 {
67 ds = create_child(pt.m_dirs[pos]);
68 }
69
70 if (ds)
71 return ds->find_path_tok(pt, pos + 1, create_subdirs, last_existing_dir);
72
73 return nullptr;
74}
std::vector< const char * > m_dirs

References DirState(), create_child(), find_path_tok(), XrdPfc::PathTokenizer::get_n_dirs(), XrdPfc::PathTokenizer::m_dirs, and m_subdirs.

Referenced by find_path(), and find_path_tok().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_dir_path()

int DirState::generate_dir_path ( std::string & result)

Parent-recursively height-first append '/' and directory names to the result string. Returns total number of added characters.

Definition at line 116 of file XrdPfcDirState.cc.

117{
118 int n_chars = 0;
119 if (m_parent) {
120 n_chars += m_parent->generate_dir_path(result) + 1 + m_dir_name.length();
121 result += '/';
122 result += m_dir_name;
123 }
124 return n_chars;
125}

References XrdPfc::DirStateBase::m_dir_name, and m_parent.

Referenced by update_stats_and_usages().

+ Here is the caller graph for this function:

◆ get_parent()

DirState * XrdPfc::DirState::get_parent ( )
inline

Definition at line 91 of file XrdPfcDirState.hh.

91{ return m_parent; }

References DirState(), and m_parent.

Referenced by XrdPfc::ResourceMonitor::process_queues().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

void XrdPfc::DirState::init ( )

References DirState(), and parent().

+ Here is the call graph for this function:

◆ reset_sshot_stats()

void DirState::reset_sshot_stats ( )

Definition at line 224 of file XrdPfcDirState.cc.

225{
226 for (DsMap_i i = m_subdirs.begin(); i != m_subdirs.end(); ++i)
227 {
228 i->second.reset_sshot_stats();
229 }
230 m_sshot_stats.Reset();
231}

References m_sshot_stats, and m_subdirs.

◆ reset_stats()

void DirState::reset_stats ( )

Reset current transaction deltas / stats. Called from ResourceMonitor::heart_beat()

Definition at line 214 of file XrdPfcDirState.cc.

215{
216 for (DsMap_i i = m_subdirs.begin(); i != m_subdirs.end(); ++i)
217 {
218 i->second.reset_stats();
219 }
220 m_here_stats.Reset();
222}
DirStats m_recursive_subdir_stats

References m_here_stats, m_recursive_subdir_stats, and m_subdirs.

◆ update_stats_and_usages()

void DirState::update_stats_and_usages ( bool purge_empty_dirs,
unlink_func unlink_foo )

Upward propagate stats to parents, join last open/close timestamps, and apply deltas / stats to usages.

Additionally, manage removal of empty leaf directories and destruction of corresponding leaf DirState objects.

Definition at line 158 of file XrdPfcDirState.cc.

159{
160 // Hmmh.
161 DsMap_i i = m_subdirs.begin();
162 while (i != m_subdirs.end())
163 {
164 DirState &sub_ds = i->second;
165
166 sub_ds.update_stats_and_usages(purge_empty_dirs, unlink_foo);
167
170 // nothing to do for m_here_stats.
171
172 // Join timestamps from daugters and their sub-daugter trees.
173 m_recursive_subdir_usage.update_last_times(sub_ds.m_recursive_subdir_usage);
174 m_recursive_subdir_usage.update_last_times(sub_ds.m_here_usage);
175
176 // Clean empty leaf directories. Only do one level at a time.
177 // Note that root will never get purged.
178 bool increment_iter = true;
179 if (purge_empty_dirs && sub_ds.m_here_stats.m_NDirectoriesRemoved == 0 &&
180 sub_ds.m_here_usage.m_NDirectories == 0 && sub_ds.m_here_usage.m_NFiles == 0)
181 {
182 assert(sub_ds.m_subdirs.empty());
183
184 std::string dir_path;
185 dir_path.reserve(1024);
186 sub_ds.generate_dir_path(dir_path);
187
188 if (unlink_foo(dir_path) == 0) {
189 DsMap_i j = i++;
190 m_subdirs.erase(j);
191 ++m_here_stats.m_NDirectoriesRemoved;
192 increment_iter = false;
193 }
194 }
195 if (increment_iter)
196 ++i;
197 }
198
199 // Apply current deltas to sshot_stats (and, if eventually needed, purge_stats).
202
203 // Apply deltas / stats to usages.
204 m_here_usage.update_from_stats(m_here_stats);
206
207 // Once we have m_report_stats and m_purge_stats, update them here.
208}
int generate_dir_path(std::string &result)
void update_stats_and_usages(bool purge_empty_dirs, unlink_func unlink_foo)

References DirState(), generate_dir_path(), m_here_stats, m_here_usage, XrdPfc::DirUsage::m_NDirectories, XrdPfc::DirStats::m_NDirectoriesRemoved, XrdPfc::DirUsage::m_NFiles, m_recursive_subdir_stats, m_recursive_subdir_usage, m_sshot_stats, m_subdirs, and update_stats_and_usages().

Referenced by update_stats_and_usages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ upward_propagate_initial_scan_usages()

void DirState::upward_propagate_initial_scan_usages ( )

Propagate usages to parents after initial directory scan. Called from ResourceMonitor::perform_initial_scan()

Definition at line 131 of file XrdPfcDirState.cc.

132{
133 DirUsage &here = m_here_usage;
134 DirUsage &subdirs = m_recursive_subdir_usage;
135
136 for (auto & [name, daughter] : m_subdirs)
137 {
138 daughter.upward_propagate_initial_scan_usages();
139
140 DirUsage &dhere = daughter.m_here_usage;
141 DirUsage &dsubdirs = daughter.m_recursive_subdir_usage;
142
143 here.m_NDirectories += 1;
144
145 subdirs.m_StBlocks += dhere.m_StBlocks + dsubdirs.m_StBlocks;
146 subdirs.m_NFiles += dhere.m_NFiles + dsubdirs.m_NFiles;
147 subdirs.m_NDirectories += dhere.m_NDirectories + dsubdirs.m_NDirectories;
148 }
149}

References m_here_usage, XrdPfc::DirUsage::m_NDirectories, XrdPfc::DirUsage::m_NFiles, m_recursive_subdir_usage, XrdPfc::DirUsage::m_StBlocks, and m_subdirs.

Referenced by XrdPfc::ResourceMonitor::perform_initial_scan().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_depth

◆ m_here_stats

DirStats XrdPfc::DirState::m_here_stats

◆ m_here_usage

◆ m_parent

DirState* XrdPfc::DirState::m_parent = nullptr

Definition at line 71 of file XrdPfcDirState.hh.

Referenced by DirState(), DirState(), DirState(), generate_dir_path(), and get_parent().

◆ m_recursive_subdir_stats

DirStats XrdPfc::DirState::m_recursive_subdir_stats

Definition at line 61 of file XrdPfcDirState.hh.

Referenced by reset_stats(), and update_stats_and_usages().

◆ m_recursive_subdir_usage

◆ m_scanned

bool XrdPfc::DirState::m_scanned = false

Definition at line 74 of file XrdPfcDirState.hh.

Referenced by XrdPfc::ResourceMonitor::scan_dir_and_recurse().

◆ m_sshot_stats

DirStats XrdPfc::DirState::m_sshot_stats

Definition at line 68 of file XrdPfcDirState.hh.

Referenced by reset_sshot_stats(), and update_stats_and_usages().

◆ m_subdirs


The documentation for this struct was generated from the following files: