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 #include "XrdPfcDirStateBase.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 
34 namespace XrdPfc
35 {
36 class PathTokenizer;
37 
38 using unlink_func = std::function<int(const std::string&)>;
39 
40 //==============================================================================
41 // Structs for DirState export in vector form
42 //==============================================================================
43 
44 struct DirStateElement;
45 struct DataFsSnapshot;
46 
47 struct DirPurgeElement;
48 struct DataFsPurgeshot;
49 
50 
51 //==============================================================================
52 // DirState
53 //==============================================================================
54 
55 struct 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;
73  int m_depth;
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 
91  DirState* get_parent() { return m_parent; }
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 {
121  time_t m_stats_reset_time = 0;
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()
Definition: XrdPfc.hh:41
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)
void update_stats_and_usages(time_t last_update, bool purge_empty_dirs, unlink_func unlink_foo)
DirState * find_dirstate_for_lfn(const std::string &lfn, DirState **last_existing_dir=nullptr)
void reset_sshot_stats(time_t last_update)
DirState * m_parent
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)
int generate_dir_path(std::string &result)
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 dump_recursively(const char *name, int max_depth) const
void upward_propagate_initial_scan_usages()
DirStats m_sshot_stats
void update_stats_and_usages(bool purge_empty_dirs, unlink_func unlink_foo)