XRootD
XrdPfc::FPurgeState Class Reference

#include <XrdPfcFPurgeState.hh>

+ Collaboration diagram for XrdPfc::FPurgeState:

Classes

struct  PurgeCandidate
 

Public Types

using list_i = list_t::iterator
 
using list_t = std::list< PurgeCandidate >
 
using map_i = map_t::iterator
 
using map_t = std::multimap< time_t, PurgeCandidate >
 

Public Member Functions

 FPurgeState (long long iNBytesReq, XrdOss &oss)
 Constructor. More...
 
void CheckFile (const FsTraversal &fst, const char *fname, Info &info, struct stat &fstat)
 
time_t getMinTime () const
 
long long getNBytesTotal () const
 
long long getNStBlocksTotal () const
 
void MoveListEntriesToMap ()
 
void ProcessDirAndRecurse (FsTraversal &fst)
 
list_trefList ()
 
map_trefMap ()
 
void setMinTime (time_t min_time)
 
void setUVKeepMinTime (time_t min_time)
 
bool TraverseNamespace (const char *root_path)
 

Detailed Description

Definition at line 22 of file XrdPfcFPurgeState.hh.

Member Typedef Documentation

◆ list_i

using XrdPfc::FPurgeState::list_i = list_t::iterator

Definition at line 37 of file XrdPfcFPurgeState.hh.

◆ list_t

Definition at line 36 of file XrdPfcFPurgeState.hh.

◆ map_i

using XrdPfc::FPurgeState::map_i = map_t::iterator

Definition at line 39 of file XrdPfcFPurgeState.hh.

◆ map_t

using XrdPfc::FPurgeState::map_t = std::multimap<time_t, PurgeCandidate>

Definition at line 38 of file XrdPfcFPurgeState.hh.

Constructor & Destructor Documentation

◆ FPurgeState()

FPurgeState::FPurgeState ( long long  iNBytesReq,
XrdOss oss 
)

Constructor.

Definition at line 29 of file XrdPfcFPurgeState.cc.

29  :
30  m_oss(oss),
31  m_nStBlocksReq((iNBytesReq >> 9) + 1ll), m_nStBlocksAccum(0), m_nStBlocksTotal(0),
32  m_tMinTimeStamp(0), m_tMinUVKeepTimeStamp(0)
33 {
34 
35 }

Member Function Documentation

◆ CheckFile()

void FPurgeState::CheckFile ( const FsTraversal fst,
const char *  fname,
Info info,
struct stat fstat 
)

Open info file. Look at the UV stams and last access time. Store the file in sorted map or in a list.s

Parameters
fnamename of cache-info file
Infoobject
statof the given file

Definition at line 58 of file XrdPfcFPurgeState.cc.

59 {
60  static const char *trc_pfx = "FPurgeState::CheckFile ";
61 
62  long long nblocks = fstat.st_blocks;
63  time_t atime;
64  if (!info.GetLatestDetachTime(atime))
65  {
66  // cinfo file does not contain any known accesses, use fstat.mtime instead.
67  TRACE(Debug, trc_pfx << "could not get access time for " << fst.m_current_path << fname << ", using mtime from stat instead.");
68  atime = fstat.st_mtime;
69  }
70  // TRACE(Dump, trc_pfx << "checking " << fname << " accessTime " << atime);
71 
72  m_nStBlocksTotal += nblocks;
73 
74  // Could remove aged-out / uv-keep-failed files here ... or in the calling function that
75  // can aggreagate info for all files in the directory.
76 
77  // For now keep using 0 time as this is used in the purge loop to make sure we continue even if enough
78  // disk-space has been freed.
79 
80  if (m_tMinTimeStamp > 0 && atime < m_tMinTimeStamp)
81  {
82  m_flist.push_back(PurgeCandidate(fst.m_current_path, fname, nblocks, 0));
83  m_nStBlocksAccum += nblocks;
84  }
85  else if (m_tMinUVKeepTimeStamp > 0 &&
86  Cache::Conf().does_cschk_have_missing_bits(info.GetCkSumState()) &&
87  info.GetNoCkSumTimeForUVKeep() < m_tMinUVKeepTimeStamp)
88  {
89  m_flist.push_back(PurgeCandidate(fst.m_current_path, fname, nblocks, 0));
90  m_nStBlocksAccum += nblocks;
91  }
92  else if (m_nStBlocksAccum < m_nStBlocksReq || (!m_fmap.empty() && atime < m_fmap.rbegin()->first))
93  {
94  m_fmap.insert(std::make_pair(atime, PurgeCandidate(fst.m_current_path, fname, nblocks, atime)));
95  m_nStBlocksAccum += nblocks;
96 
97  // remove newest files from map if necessary
98  while (!m_fmap.empty() && m_nStBlocksAccum - m_fmap.rbegin()->second.nStBlocks >= m_nStBlocksReq)
99  {
100  m_nStBlocksAccum -= m_fmap.rbegin()->second.nStBlocks;
101  m_fmap.erase(--(m_fmap.rbegin().base()));
102  }
103  }
104 }
int fstat(int fildes, struct stat *buf)
#define TRACE(act, x)
Definition: XrdTrace.hh:63
static const Configuration & Conf()
Definition: XrdPfc.cc:132
time_t GetNoCkSumTimeForUVKeep() const
Definition: XrdPfcInfo.hh:301
CkSumCheck_e GetCkSumState() const
Definition: XrdPfcInfo.hh:286
bool GetLatestDetachTime(time_t &t) const
Get latest detach time.
Definition: XrdPfcInfo.cc:472

References XrdPfc::Cache::Conf(), Macaroons::Debug, fstat(), XrdPfc::Info::GetCkSumState(), XrdPfc::Info::GetLatestDetachTime(), XrdPfc::Info::GetNoCkSumTimeForUVKeep(), XrdPfc::FsTraversal::m_current_path, and TRACE.

Referenced by ProcessDirAndRecurse().

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

◆ getMinTime()

time_t XrdPfc::FPurgeState::getMinTime ( ) const
inline

Definition at line 62 of file XrdPfcFPurgeState.hh.

62 { return m_tMinTimeStamp; }

◆ getNBytesTotal()

long long XrdPfc::FPurgeState::getNBytesTotal ( ) const
inline

Definition at line 65 of file XrdPfcFPurgeState.hh.

65 { return 512ll * m_nStBlocksTotal; }

Referenced by XrdPfc::OldStylePurgeDriver().

+ Here is the caller graph for this function:

◆ getNStBlocksTotal()

long long XrdPfc::FPurgeState::getNStBlocksTotal ( ) const
inline

Definition at line 64 of file XrdPfcFPurgeState.hh.

64 { return m_nStBlocksTotal; }

◆ MoveListEntriesToMap()

void FPurgeState::MoveListEntriesToMap ( )

Move remaing entires to the member map. This is used for cold files and for files collected from purge plugin (really?).

Definition at line 41 of file XrdPfcFPurgeState.cc.

42 {
43  for (list_i i = m_flist.begin(); i != m_flist.end(); ++i)
44  {
45  m_fmap.insert(std::make_pair(i->time, *i));
46  }
47  m_flist.clear();
48 }
list_t::iterator list_i

Referenced by XrdPfc::OldStylePurgeDriver().

+ Here is the caller graph for this function:

◆ ProcessDirAndRecurse()

void FPurgeState::ProcessDirAndRecurse ( FsTraversal fst)

Definition at line 106 of file XrdPfcFPurgeState.cc.

107 {
108  static const char *trc_pfx = "FPurgeState::ProcessDirAndRecurse ";
109 
110  for (auto it = fst.m_current_files.begin(); it != fst.m_current_files.end(); ++it)
111  {
112  // Check if the file is currently opened / purge-protected is done before unlinking of the file.
113  const std::string &f_name = it->first;
114  const std::string i_name = f_name + Info::s_infoExtension;
115 
116  XrdOssDF *fh = nullptr;
117  Info cinfo(GetTrace());
118 
119  // XXX Note, the initial scan now uses stat information only!
120 
121  if (! it->second.has_both()) {
122  // cinfo or data file is missing. What do we do? Erase?
123  // Should really be checked in some other "consistency" traversal.
124  continue;
125  }
126 
127  if (fst.open_at_ro(i_name.c_str(), fh) == XrdOssOK &&
128  cinfo.Read(fh, fst.m_current_path.c_str(), i_name.c_str()))
129  {
130  CheckFile(fst, i_name.c_str(), cinfo, it->second.stat_data);
131  }
132  else
133  {
134  TRACE(Warning, trc_pfx << "can't open or read " << fst.m_current_path << i_name << ", err " << XrdSysE2T(errno) << "; purging.");
135  fst.unlink_at(i_name.c_str());
136  fst.unlink_at(f_name.c_str());
137  // generate purge event or not? or just flag possible discrepancy?
138  // should this really be done in some other consistency-check traversal?
139  }
140  fst.close_delete(fh);
141 
142  // Protected top-directories are skipped.
143  }
144 
145  std::vector<std::string> dirs;
146  dirs.swap(fst.m_current_dirs);
147  for (auto &dname : dirs)
148  {
149  if (fst.cd_down(dname))
150  {
152  fst.cd_up();
153  }
154  }
155 }
#define XrdOssOK
Definition: XrdOss.hh:50
@ Warning
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:99
void CheckFile(const FsTraversal &fst, const char *fname, Info &info, struct stat &fstat)
void ProcessDirAndRecurse(FsTraversal &fst)
std::vector< std::string > m_current_dirs
int open_at_ro(const char *fname, XrdOssDF *&ossDF)
int close_delete(XrdOssDF *&ossDF)
int unlink_at(const char *fname)
bool cd_down(const std::string &dir_name)
std::map< std::string, FilePairStat > m_current_files
Status of cached file. Can be read from and written into a binary file.
Definition: XrdPfcInfo.hh:41
static const char * s_infoExtension
Definition: XrdPfcInfo.hh:309

References XrdPfc::FsTraversal::cd_down(), XrdPfc::FsTraversal::cd_up(), CheckFile(), XrdPfc::FsTraversal::close_delete(), XrdPfc::FsTraversal::m_current_dirs, XrdPfc::FsTraversal::m_current_files, XrdPfc::FsTraversal::m_current_path, XrdPfc::FsTraversal::open_at_ro(), XrdPfc::Info::Read(), XrdPfc::Info::s_infoExtension, TRACE, XrdPfc::FsTraversal::unlink_at(), Warning, XrdOssOK, and XrdSysE2T().

Referenced by TraverseNamespace().

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

◆ refList()

list_t& XrdPfc::FPurgeState::refList ( )
inline

Definition at line 59 of file XrdPfcFPurgeState.hh.

59 { return m_flist; }

◆ refMap()

map_t& XrdPfc::FPurgeState::refMap ( )
inline

Definition at line 58 of file XrdPfcFPurgeState.hh.

58 { return m_fmap; }

Referenced by XrdPfc::UnlinkPurgeStateFilesInMap().

+ Here is the caller graph for this function:

◆ setMinTime()

void XrdPfc::FPurgeState::setMinTime ( time_t  min_time)
inline

Definition at line 61 of file XrdPfcFPurgeState.hh.

61 { m_tMinTimeStamp = min_time; }

Referenced by XrdPfc::OldStylePurgeDriver().

+ Here is the caller graph for this function:

◆ setUVKeepMinTime()

void XrdPfc::FPurgeState::setUVKeepMinTime ( time_t  min_time)
inline

Definition at line 63 of file XrdPfcFPurgeState.hh.

63 { m_tMinUVKeepTimeStamp = min_time; }

Referenced by XrdPfc::OldStylePurgeDriver().

+ Here is the caller graph for this function:

◆ TraverseNamespace()

bool FPurgeState::TraverseNamespace ( const char *  root_path)

Definition at line 157 of file XrdPfcFPurgeState.cc.

158 {
159  bool success_p = true;
160 
161  FsTraversal fst(m_oss);
162  fst.m_protected_top_dirs.insert("pfc-stats"); // XXXX This should come from config. Also: N2N?
163  // Also ... this onoly applies to /, not any root_path
164  if (fst.begin_traversal(root_path))
165  {
167  }
168  else
169  {
170  // Fail startup, can't open /.
171  success_p = false;
172  }
173  fst.end_traversal();
174 
175  return success_p;
176 }

References XrdPfc::FsTraversal::begin_traversal(), XrdPfc::FsTraversal::end_traversal(), XrdPfc::FsTraversal::m_protected_top_dirs, and ProcessDirAndRecurse().

Referenced by XrdPfc::OldStylePurgeDriver().

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

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