XRootD
Loading...
Searching...
No Matches
XrdPfcDirState.hh
Go to the documentation of this file.
1#ifndef __XRDPFC_DIRSTATE_HH__
2#define __XRDPFC_DIRSTATE_HH__
3
4#include "XrdPfcStats.hh"
6
7#include <ctime>
8#include <functional>
9#include <map>
10#include <string>
11
12
13//==============================================================================
14// Manifest:
15//------------------------------------------------------------------------------
16// - Data-holding struct DirUsage -- complementary to Stats.
17// - Base classes for DirState and DataFsState, shared between in-memory
18// tree form and snap-shot vector form.
19// - Forward declatation of structs for DirState export in vector form:
20// - struct DirStateElement \_ for stats and usages snapshot
21// - struct DataFsSnapshot /
22// - struct DirPurgeElement \_ for purge snapshot
23// - struct DataFsPurgeshot /
24// Those are in another file so the object file can be included in the
25// dedicated binary for processing of the binary dumps.
26// - class DirState -- state of a directory, including current delta-stats.
27// - class DataFSState -- manager of the DirState tree, starting from root (as in "/").
28//
29// Structs for DirState export in vector form (DirStateElement and DataFsSnapshot)
30// are declared in XrdPfcDirStateSnapshot.hh.
31
32//==============================================================================
33
34namespace XrdPfc
35{
36struct PathTokenizer;
37
38using unlink_func = std::function<int(const std::string&)>;
39
40//==============================================================================
41// Structs for DirState export in vector form
42//==============================================================================
43
44struct DirStateElement;
45struct DataFsSnapshot;
46
47struct DirPurgeElement;
48struct DataFsPurgeshot;
49
50
51//==============================================================================
52// DirState
53//==============================================================================
54
55struct DirState : public DirStateBase
56{
57 typedef std::map<std::string, DirState> DsMap_t;
58 typedef DsMap_t::iterator DsMap_i;
59
62
65
66 // This should be optional, only if needed and only up to some max level.
67 // Preferably stored in some extrnal vector (as AccessTokens are) and indexed from here.
68 DirStats m_sshot_stats; // here + subdir, reset after sshot dump
69 // DirStats m_purge_stats; // here + subdir, running avg., as per purge params
70
71 DirState *m_parent = nullptr;
74 bool m_scanned = false; // set to true after files in this directory are scanned.
75
76 void init();
77
78 DirState* create_child(const std::string &dir);
79
80 DirState* find_path_tok(PathTokenizer &pt, int pos, bool create_subdirs,
81 DirState **last_existing_dir = nullptr);
82
83 // --- public part ---
84
85 DirState();
86
88
89 DirState(DirState *parent, const std::string& dname);
90
92
93 DirState* find_path(const std::string &path, int max_depth, bool parse_as_lfn, bool create_subdirs,
94 DirState **last_existing_dir = nullptr);
95
96 DirState* find_dir(const std::string &dir, bool create_subdirs);
97
98 int generate_dir_path(std::string &result);
99
100 // initial scan support
102
103 // stat & usages updates / management
104 void update_stats_and_usages(bool purge_empty_dirs, unlink_func unlink_foo);
105 void reset_stats();
106 void reset_sshot_stats();
107
108 int count_dirs_to_level(int max_depth) const;
109
110 void dump_recursively(const char *name, int max_depth) const;
111};
112
113
114//==============================================================================
115// DataFsState
116//==============================================================================
117
119{
123 // time_t m_purge_stats_reset_time = 0;
124
126
128
129 DirState* get_root() { return & m_root; }
130
131 DirState* find_dirstate_for_lfn(const std::string& lfn, DirState **last_existing_dir = nullptr)
132 {
133 return m_root.find_path(lfn, -1, true, true, last_existing_dir);
134 }
135
136 void update_stats_and_usages(time_t last_update, bool purge_empty_dirs, unlink_func unlink_foo);
137 void reset_stats(time_t last_update);
138 void reset_sshot_stats(time_t last_update);
139 // void reset_purge_stats();
140
141 void dump_recursively(int max_depth) const;
142};
143
144}
145
146#endif
static void parent()
std::function< int(const std::string &)> unlink_func
void reset_stats(time_t last_update)
void dump_recursively(int max_depth) const
void init_stat_reset_times(time_t t)
DirState * find_dirstate_for_lfn(const std::string &lfn, DirState **last_existing_dir=nullptr)
void update_stats_and_usages(time_t last_update, bool purge_empty_dirs, unlink_func unlink_foo)
void reset_sshot_stats(time_t last_update)
DirUsage m_recursive_subdir_usage
int count_dirs_to_level(int max_depth) const
DirState * create_child(const std::string &dir)
DirStats m_recursive_subdir_stats
DirState * find_dir(const std::string &dir, bool create_subdirs)
DsMap_t::iterator DsMap_i
int generate_dir_path(std::string &result)
DirState()
Constructor.
std::map< std::string, DirState > DsMap_t
DirState * find_path_tok(PathTokenizer &pt, int pos, bool create_subdirs, DirState **last_existing_dir=nullptr)
DirState * find_path(const std::string &path, int max_depth, bool parse_as_lfn, bool create_subdirs, DirState **last_existing_dir=nullptr)
void dump_recursively(const char *name, int max_depth) const
void upward_propagate_initial_scan_usages()
DirState * get_parent()
void update_stats_and_usages(bool purge_empty_dirs, unlink_func unlink_foo)