XRootD
XrdPfcDirState.hh
Go to the documentation of this file.
1 #ifndef __XRDPFC_DIRSTATE_HH__
2 #define __XRDPFC_DIRSTATE_HH__
3 
4 #include "XrdPfcStats.hh"
5 
6 #include <ctime>
7 #include <map>
8 #include <string>
9 
10 
11 //==============================================================================
12 // Manifest:
13 //------------------------------------------------------------------------------
14 // - Data-holding struct DirUsage -- complementary to Stats.
15 // - Base classes for DirState and DataFsState, shared between in-memory
16 // tree form and snap-shot vector form.
17 // - Forward declatation of structs for DirState export in vector form:
18 // - struct DirStateElement \_ for stats and usages snapshot
19 // - struct DataFsSnapshot /
20 // - struct DirPurgeElement \_ for purge snapshot
21 // - struct DataFsPurgeshot /
22 // Those are in another file so the object file can be included in the
23 // dedicated binary for processing of the binary dumps.
24 // - class DirState -- state of a directory, including current delta-stats.
25 // - class DataFSState -- manager of the DirState tree, starting from root (as in "/").
26 //
27 // Structs for DirState export in vector form (DirStateElement and DataFsSnapshot)
28 // are declared in XrdPfcDirStateSnapshot.hh.
29 
30 //==============================================================================
31 
32 
33 namespace XrdPfc
34 {
35 class PathTokenizer;
36 
37 //==============================================================================
38 // Data-holding struct DirUsage -- complementary to Stats.
39 //==============================================================================
40 
41 struct DirUsage
42 {
43  time_t m_LastOpenTime = 0;
44  time_t m_LastCloseTime = 0;
45  long long m_StBlocks = 0;
46  int m_NFilesOpen = 0;
47  int m_NFiles = 0;
48  int m_NDirectories = 0;
49 
50  DirUsage() = default;
51 
52  DirUsage(const DirUsage& s) = default;
53 
54  DirUsage& operator=(const DirUsage&) = default;
55 
56  DirUsage(const DirUsage &a, const DirUsage &b) :
61  m_NFiles (a.m_NFiles + b.m_NFiles),
63  {}
64 
65  void update_from_stats(const DirStats& s)
66  {
71  }
72 
73  void update_last_times(const DirUsage& u)
74  {
77  }
78 };
79 
80 
81 //==============================================================================
82 // Base classes, shared between in-memory tree form and snap-shot vector form.
83 //==============================================================================
84 
86 {
87  std::string m_dir_name;
88 
90  DirStateBase(const std::string &dname) : m_dir_name(dname) {}
91 };
92 
94 {
95  time_t m_usage_update_time = 0;
96  time_t m_stats_reset_time = 0;
97 
98  long long m_disk_total = 0; // In bytes, from Oss::StatVS() on space data
99  long long m_disk_used = 0; // ""
100  long long m_file_usage = 0; // Calculate usage by data files in the cache
101  long long m_meta_total = 0; // In bytes, from Oss::StatVS() on space meta
102  long long m_meta_used = 0; // ""
103 };
104 
105 
106 //==============================================================================
107 // Structs for DirState export in vector form
108 //==============================================================================
109 
110 struct DirStateElement;
111 struct DataFsSnapshot;
112 
113 struct DirPurgeElement;
114 struct DataFsPurgeshot;
115 
116 
117 //==============================================================================
118 // DirState
119 //==============================================================================
120 
121 struct DirState : public DirStateBase
122 {
123  typedef std::map<std::string, DirState> DsMap_t;
124  typedef DsMap_t::iterator DsMap_i;
125 
128 
131 
132  // This should be optional, only if needed and only up to some max level.
133  // Preferably stored in some extrnal vector (as AccessTokens are) and indexed from here.
134  // DirStats m_purge_stats; // here + subdir, running avg., as per purge params
135  // DirStats m_report_stats; // here + subdir, reset after sshot dump
136 
137  DirState *m_parent = nullptr;
139  int m_depth;
140  bool m_scanned = false; // set to true after files in this directory are scanned.
141 
142  void init();
143 
144  DirState* create_child(const std::string &dir);
145 
146  DirState* find_path_tok(PathTokenizer &pt, int pos, bool create_subdirs,
147  DirState **last_existing_dir = nullptr);
148 
149  // --- public part ---
150 
151  DirState();
152 
154 
155  DirState(DirState *parent, const std::string& dname);
156 
157  DirState* get_parent() { return m_parent; }
158 
159  DirState* find_path(const std::string &path, int max_depth, bool parse_as_lfn, bool create_subdirs,
160  DirState **last_existing_dir = nullptr);
161 
162  DirState* find_dir(const std::string &dir, bool create_subdirs);
163 
164  // initial scan support
166 
167  // stat support
169  void apply_stats_to_usages();
170  void reset_stats();
171 
172  int count_dirs_to_level(int max_depth) const;
173 
174  void dump_recursively(const char *name, int max_depth) const;
175 };
176 
177 
178 //==============================================================================
179 // DataFsState
180 //==============================================================================
181 
183 {
185 
187 
188  DirState* get_root() { return & m_root; }
189 
190  DirState* find_dirstate_for_lfn(const std::string& lfn, DirState **last_existing_dir = nullptr)
191  {
192  return m_root.find_path(lfn, -1, true, true, last_existing_dir);
193  }
194 
196  void apply_stats_to_usages();
197  void reset_stats();
198 
199  void dump_recursively(int max_depth) const;
200 };
201 
202 }
203 
204 #endif
static void parent()
long long m_StBlocksRemoved
Definition: XrdPfcStats.hh:144
long long m_StBlocksAdded
number of 512-byte blocks the file has grown by
Definition: XrdPfcStats.hh:43
Definition: XrdPfc.hh:41
void dump_recursively(int max_depth) const
void upward_propagate_stats_and_times()
DirState * find_dirstate_for_lfn(const std::string &lfn, DirState **last_existing_dir=nullptr)
DirStateBase(const std::string &dname)
DirUsage m_recursive_subdir_usage
DirState * get_parent()
std::map< std::string, DirState > DsMap_t
DsMap_t::iterator DsMap_i
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)
DirState()
Constructor.
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 apply_stats_to_usages()
void dump_recursively(const char *name, int max_depth) const
void upward_propagate_initial_scan_usages()
void upward_propagate_stats_and_times()
DirUsage & operator=(const DirUsage &)=default
DirUsage(const DirUsage &s)=default
void update_from_stats(const DirStats &s)
DirUsage(const DirUsage &a, const DirUsage &b)
long long m_StBlocks
void update_last_times(const DirUsage &u)
DirUsage()=default