XRootD
XrdPfcDirStatePurgeshot.hh
Go to the documentation of this file.
1 #ifndef __XRDPFC_DIRSTATEPURGESHOT_HH__
2 #define __XRDPFC_DIRSTATEPURGESHOT_HH__
3 
6 
7 namespace XrdPfc
8 {
10 {
12 
13  int m_parent = -1;
15 
17  DirPurgeElement(const DirStateBase &b, const DirUsage &here_usage, const DirUsage &subdir_usage, int parent) :
18  DirStateBase(b),
19  m_usage(here_usage, subdir_usage),
21  {}
22 };
23 
25 {
26  long long m_bytes_to_remove = 0;
28 
29  bool m_space_based_purge = false;
30  bool m_age_based_purge = false;
31 
32  std::vector<DirPurgeElement> m_dir_vec;
33  // could have parallel vector of DirState* ... or store them in the DirPurgeElement.
34  // requires some interlock / ref-counting with the source tree.
35  // or .... just block DirState removal for the duration of the purge :) Yay.
36 
40  {}
41 
42  int find_dir_entry_from_tok(int entry, PathTokenizer &pt, int pos, int *last_existing_entry) const;
43 
44  int find_dir_entry_for_dir_path(const std::string &dir_path) const;
45 
46  const DirUsage* find_dir_usage_for_dir_path(const std::string &dir_path) const;
47 };
48 
49 
50 inline int DataFsPurgeshot::find_dir_entry_from_tok(int entry, PathTokenizer &pt, int pos, int *last_existing_entry) const
51 {
52  if (pos == pt.get_n_dirs())
53  return entry;
54 
55  const DirPurgeElement &dpe = m_dir_vec[entry];
56  for (int i = dpe.m_daughters_begin; i != dpe.m_daughters_end; ++i)
57  {
58  if (m_dir_vec[i].m_dir_name == pt.get_dir(pos)) {
59  return find_dir_entry_from_tok(i, pt, pos + 1, last_existing_entry);
60  }
61  }
62  if (last_existing_entry)
63  *last_existing_entry = entry;
64  return -1;
65 }
66 
67 inline int DataFsPurgeshot::find_dir_entry_for_dir_path(const std::string &dir_path) const
68 {
69  PathTokenizer pt(dir_path, -1, false);
70  return find_dir_entry_from_tok(0, pt, 0, nullptr);
71 }
72 
73 inline const DirUsage* DataFsPurgeshot::find_dir_usage_for_dir_path(const std::string &dir_path) const
74 {
75  int entry = find_dir_entry_for_dir_path(dir_path);
76  return entry >= 0 ? &m_dir_vec[entry].m_usage : nullptr;
77 }
78 
79 }
80 
81 #endif
static void parent()
Definition: XrdPfc.hh:41
const DirUsage * find_dir_usage_for_dir_path(const std::string &dir_path) const
int find_dir_entry_for_dir_path(const std::string &dir_path) const
std::vector< DirPurgeElement > m_dir_vec
DataFsPurgeshot(const DataFsStateBase &b)
int find_dir_entry_from_tok(int entry, PathTokenizer &pt, int pos, int *last_existing_entry) const
DirPurgeElement(const DirStateBase &b, const DirUsage &here_usage, const DirUsage &subdir_usage, int parent)
const char * get_dir(int pos)