XRootD
XrdPfc::ResourceMonitor Class Reference

#include <XrdPfcResourceMonitor.hh>

+ Collaboration diagram for XrdPfc::ResourceMonitor:

Public Member Functions

 ResourceMonitor (XrdOss &oss)
 
 ~ResourceMonitor ()
 
void CrossCheckIfScanIsInProgress (const std::string &lfn, XrdSysCondVar &cond)
 
void fill_pshot_vec_children (const DirState &parent_ds, int parent_idx, std::vector< DirPurgeElement > &vec, int max_depth)
 
void fill_sshot_vec_children (const DirState &parent_ds, int parent_idx, std::vector< DirStateElement > &vec, int max_depth)
 
void heart_beat ()
 
void init_before_main ()
 
void main_thread_function ()
 
bool perform_initial_scan ()
 
void perform_purge_check (bool purge_cold_files, int tl)
 
void perform_purge_task (DataFsPurgeshot &ps)
 
void perform_purge_task_cleanup ()
 
int process_queues ()
 
void register_file_close (int token_id, time_t close_timestamp, const Stats &full_stats)
 
int register_file_open (const std::string &filename, time_t open_timestamp, bool existing_file)
 
void register_file_purge (const std::string &filename, long long size_in_st_blocks)
 
void register_file_purge (DirState *target, long long size_in_st_blocks)
 
void register_file_update_stats (int token_id, const Stats &stats)
 
void register_multi_file_purge (const std::string &target, long long size_in_st_blocks, int n_files)
 
void register_multi_file_purge (DirState *target, long long size_in_st_blocks, int n_files)
 
void scan_dir_and_recurse (FsTraversal &fst)
 
AccessToken & token (int i)
 
void update_vs_and_file_usage_info ()
 

Public Attributes

bool m_purge_task_active {false}
 
bool m_purge_task_complete {false}
 
XrdSysCondVar m_purge_task_cond {0}
 
time_t m_purge_task_end {0}
 
time_t m_purge_task_start {0}
 

Detailed Description

Definition at line 37 of file XrdPfcResourceMonitor.hh.

Constructor & Destructor Documentation

◆ ResourceMonitor()

ResourceMonitor::ResourceMonitor ( XrdOss oss)

Definition at line 31 of file XrdPfcResourceMonitor.cc.

31  :
32  m_fs_state(* new DataFsState),
33  m_oss(oss)
34 {}

◆ ~ResourceMonitor()

ResourceMonitor::~ResourceMonitor ( )

Definition at line 36 of file XrdPfcResourceMonitor.cc.

37 {
38  delete &m_fs_state;
39 }

Member Function Documentation

◆ CrossCheckIfScanIsInProgress()

void ResourceMonitor::CrossCheckIfScanIsInProgress ( const std::string &  lfn,
XrdSysCondVar cond 
)

Definition at line 45 of file XrdPfcResourceMonitor.cc.

46 {
47  m_dir_scan_mutex.Lock();
48  if (m_dir_scan_in_progress) {
49  m_dir_scan_open_requests.push_back({lfn, cond});
50  LfnCondRecord &lcr = m_dir_scan_open_requests.back();
51  cond.Lock();
52  m_dir_scan_mutex.UnLock();
53  while ( ! lcr.f_checked)
54  cond.Wait();
55  cond.UnLock();
56  } else {
57  m_dir_scan_mutex.UnLock();
58  }
59 }

References XrdSysCondVar::Lock(), XrdSysMutex::Lock(), XrdSysCondVar::UnLock(), XrdSysMutex::UnLock(), and XrdSysCondVar::Wait().

+ Here is the call graph for this function:

◆ fill_pshot_vec_children()

void ResourceMonitor::fill_pshot_vec_children ( const DirState parent_ds,
int  parent_idx,
std::vector< DirPurgeElement > &  vec,
int  max_depth 
)

Definition at line 496 of file XrdPfcResourceMonitor.cc.

500 {
501  int pos = vec.size();
502  int n_children = parent_ds.m_subdirs.size();
503 
504  for (auto const & [name, child] : parent_ds.m_subdirs)
505  {
506  vec.emplace_back( DirPurgeElement(child, parent_idx) );
507  }
508 
509  if (parent_ds.m_depth < max_depth)
510  {
511  DirPurgeElement &parent_dpe = vec[parent_idx];
512  parent_dpe.m_daughters_begin = pos;
513  parent_dpe.m_daughters_end = pos + n_children;
514 
515  for (auto const & [name, child] : parent_ds.m_subdirs)
516  {
517  if (n_children > 0)
518  fill_pshot_vec_children(child, pos, vec, max_depth);
519  ++pos;
520  }
521  }
522 }
static void child()
void fill_pshot_vec_children(const DirState &parent_ds, int parent_idx, std::vector< DirPurgeElement > &vec, int max_depth)

References child(), XrdPfc::DirPurgeElement::m_daughters_begin, XrdPfc::DirPurgeElement::m_daughters_end, XrdPfc::DirState::m_depth, and XrdPfc::DirState::m_subdirs.

Referenced by perform_purge_check().

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

◆ fill_sshot_vec_children()

void ResourceMonitor::fill_sshot_vec_children ( const DirState parent_ds,
int  parent_idx,
std::vector< DirStateElement > &  vec,
int  max_depth 
)

Definition at line 468 of file XrdPfcResourceMonitor.cc.

472 {
473  int pos = vec.size();
474  int n_children = parent_ds.m_subdirs.size();
475 
476  for (auto const & [name, child] : parent_ds.m_subdirs)
477  {
478  vec.emplace_back( DirStateElement(child, parent_idx) );
479  }
480 
481  if (parent_ds.m_depth < max_depth)
482  {
483  DirStateElement &parent_dse = vec[parent_idx];
484  parent_dse.m_daughters_begin = pos;
485  parent_dse.m_daughters_end = pos + n_children;
486 
487  for (auto const & [name, child] : parent_ds.m_subdirs)
488  {
489  if (n_children > 0)
490  fill_sshot_vec_children(child, pos, vec, max_depth);
491  ++pos;
492  }
493  }
494 }
void fill_sshot_vec_children(const DirState &parent_ds, int parent_idx, std::vector< DirStateElement > &vec, int max_depth)

References child(), XrdPfc::DirStateElement::m_daughters_begin, XrdPfc::DirStateElement::m_daughters_end, XrdPfc::DirState::m_depth, and XrdPfc::DirState::m_subdirs.

+ Here is the call graph for this function:

◆ heart_beat()

void ResourceMonitor::heart_beat ( )

Definition at line 349 of file XrdPfcResourceMonitor.cc.

350 {
351  static const char *tpfx = "heart_beat() ";
352 
353  const Configuration &conf = Cache::Conf();
354 
355  const int s_queue_proc_interval = 10;
356  // const s_stats_up_prop_interval = 60; -- for when we have dedicated purge / stat report structs
357  const int s_sshot_report_interval = 60; // to be bumped (300s?) or made configurable.
358  const int s_purge_check_interval = 60;
359  const int s_purge_report_interval = conf.m_purgeInterval;
360  const int s_purge_cold_files_interval = conf.m_purgeInterval * conf.m_purgeAgeBasedPeriod;
361 
362  // initial scan performed as part of config
363 
364  time_t now = time(0);
365  time_t next_queue_proc_time = now + s_queue_proc_interval;
366  time_t next_sshot_report_time = now + s_sshot_report_interval;
367  time_t next_purge_check_time = now + s_purge_check_interval;
368  time_t next_purge_report_time = now + s_purge_report_interval;
369  time_t next_purge_cold_files_time = now + s_purge_cold_files_interval;
370 
371  // XXXXX On initial entry should reclaim space from queues as they might have grown
372  // very large during the initial scan.
373 
374  while (true)
375  {
376  time_t start = time(0);
377  time_t next_event = std::min({ next_queue_proc_time, next_sshot_report_time,
378  next_purge_check_time, next_purge_report_time, next_purge_cold_files_time });
379 
380  if (next_event > start)
381  {
382  unsigned int t_sleep = next_event - start;
383  TRACE(Debug, tpfx << "sleeping for " << t_sleep << " seconds until the next beat.");
384  sleep(t_sleep);
385  }
386 
387  // Check if purge has been running and has completed yet.
388  // For now this is only used to prevent removal of empty leaf directories
389  // during stat propagation so we do not need to wait for the condition in
390  // the above sleep.
391  if (m_purge_task_active) {
393  if (m_purge_task_complete) {
395  }
396  }
397 
398  // Always process the queues.
399  int n_processed = process_queues();
400  next_queue_proc_time += s_queue_proc_interval;
401  TRACE(Debug, tpfx << "process_queues -- n_records=" << n_processed);
402 
403  // Always update basic info on m_fs_state (space, usage, file_usage).
405 
406  now = time(0);
407  if (next_sshot_report_time <= now)
408  {
409  next_sshot_report_time += s_sshot_report_interval;
410 
411  // XXXX pass in m_purge_task_active as control over "should empty dirs be purged";
412  // Or should this be separate pass or variant in purge?
414 
415  m_fs_state.apply_stats_to_usages();
416 
417  // Dump statistics before actual purging so maximum usage values get recorded.
418  // This should dump out binary snapshot into /pfc-stats/, if so configured.
419  // Also, optionally, json.
420  // Could also go to gstream but this easily gets too large.
421  if (conf.is_dir_stat_reporting_on())
422  {
423  const int store_depth = conf.m_dirStatsStoreDepth;
424  #ifdef RM_DEBUG
425  const DirState &root_ds = *m_fs_state.get_root();
426  dprintf("Snapshot n_dirs=%d, total n_dirs=%d\n", root_ds.count_dirs_to_level(store_depth),
428  #endif
429  m_fs_state.dump_recursively(store_depth);
430 
431  /*
432  // json dump to std::out for debug purpose
433  DataFsSnapshot ss(m_fs_state);
434  ss.m_dir_states.reserve(n_sshot_dirs);
435 
436  ss.m_dir_states.emplace_back( DirStateElement(root_ds, -1) );
437  fill_sshot_vec_children(root_ds, 0, ss.m_dir_states, store_depth);
438 
439  // This should really be export to a file (preferably binary, but then bin->json command is needed, too).
440  ss.dump();
441  */
442  }
443 
444  m_fs_state.reset_stats();
445 
446  now = time(0);
447  }
448 
449  bool do_purge_check = next_purge_check_time <= now;
450  bool do_purge_report = next_purge_report_time <= now;
451  bool do_purge_cold_files = next_purge_cold_files_time <= now;
452  if (do_purge_check || do_purge_report || do_purge_cold_files)
453  {
454  perform_purge_check(do_purge_cold_files, do_purge_report ? TRACE_Info : TRACE_Debug);
455 
456  next_purge_check_time = now + s_purge_check_interval;
457  if (do_purge_report) next_purge_report_time = now + s_purge_report_interval;
458  if (do_purge_cold_files) next_purge_cold_files_time = now + s_purge_cold_files_interval;
459  }
460 
461  } // end while forever
462 }
#define TRACE_Debug
Definition: XrdCmsTrace.hh:37
#define TRACE_Info
#define dprintf(...)
#define TRACE(act, x)
Definition: XrdTrace.hh:63
static const Configuration & Conf()
Definition: XrdPfc.cc:132
void perform_purge_check(bool purge_cold_files, int tl)
Contains parameters configurable from the xrootd config file.
Definition: XrdPfc.hh:64
int m_dirStatsStoreDepth
depth to which statistics should be collected
Definition: XrdPfc.hh:105
int m_purgeAgeBasedPeriod
peform cold file / uvkeep purge every this many purge cycles
Definition: XrdPfc.hh:99
int m_purgeInterval
sleep interval between cache purges
Definition: XrdPfc.hh:97
bool is_dir_stat_reporting_on() const
Definition: XrdPfc.hh:70
void dump_recursively(int max_depth) const
void upward_propagate_stats_and_times()
DirUsage m_recursive_subdir_usage
int count_dirs_to_level(int max_depth) const

References XrdPfc::DataFsState::apply_stats_to_usages(), XrdPfc::Cache::Conf(), XrdPfc::DirState::count_dirs_to_level(), Macaroons::Debug, dprintf, XrdPfc::DataFsState::dump_recursively(), XrdPfc::DataFsState::get_root(), XrdPfc::Configuration::is_dir_stat_reporting_on(), XrdPfc::Configuration::m_dirStatsStoreDepth, XrdPfc::DirState::m_here_usage, XrdPfc::DirUsage::m_NDirectories, m_purge_task_active, m_purge_task_complete, m_purge_task_cond, XrdPfc::Configuration::m_purgeAgeBasedPeriod, XrdPfc::Configuration::m_purgeInterval, XrdPfc::DirState::m_recursive_subdir_usage, perform_purge_check(), process_queues(), XrdPfc::DataFsState::reset_stats(), TRACE, TRACE_Debug, TRACE_Info, update_vs_and_file_usage_info(), and XrdPfc::DataFsState::upward_propagate_stats_and_times().

Referenced by main_thread_function().

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

◆ init_before_main()

void ResourceMonitor::init_before_main ( )

Definition at line 804 of file XrdPfcResourceMonitor.cc.

805 {
806  // setup for in-scan -- this is called from initial setup.
807  MutexHolder _lck(m_dir_scan_mutex);
808  m_dir_scan_in_progress = true;
809 }

Referenced by XrdPfc::Cache::Config().

+ Here is the caller graph for this function:

◆ main_thread_function()

void ResourceMonitor::main_thread_function ( )

Definition at line 811 of file XrdPfcResourceMonitor.cc.

812 {
813  const char *tpfx = "main_thread_function ";
814  {
815  time_t is_start = time(0);
816  TRACE(Info, tpfx << "Stating initial directory scan.");
817 
818  if ( ! perform_initial_scan()) {
819  TRACE(Error, tpfx << "Initial directory scan has failed. This is a terminal error, aborting.")
820  _exit(1);
821  }
822  // Reset of m_dir_scan_in_progress is done in perform_initial_scan()
823 
824  time_t is_duration = time(0) - is_start;
825  TRACE(Info, tpfx << "Initial directory scan complete, duration=" << is_duration <<"s");
826 
827  // run first process queues
828  int n_proc_is = process_queues();
829  TRACE(Info, tpfx << "First process_queues finished, n_records=" << n_proc_is);
830 
831  // shrink queues if scan time was longer than 30s.
832  if (is_duration > 30 || n_proc_is > 3000)
833  {
834  m_file_open_q.shrink_read_queue();
835  m_file_update_stats_q.shrink_read_queue();
836  m_file_close_q.shrink_read_queue();
837  m_file_purge_q1.shrink_read_queue();
838  m_file_purge_q2.shrink_read_queue();
839  m_file_purge_q3.shrink_read_queue();
840  }
841  }
842  heart_beat();
843 }
if(Avsz)
Status of cached file. Can be read from and written into a binary file.
Definition: XrdPfcInfo.hh:41

References Macaroons::Error, heart_beat(), perform_initial_scan(), process_queues(), and TRACE.

Referenced by ResourceMonitorThread().

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

◆ perform_initial_scan()

bool ResourceMonitor::perform_initial_scan ( )

Definition at line 167 of file XrdPfcResourceMonitor.cc.

168 {
169  // Called after PFC configuration is complete, but before full startup of the daemon.
170  // Base line usages are accumulated as part of the file-system, traversal.
171 
173 
174  DirState *root_ds = m_fs_state.get_root();
175  FsTraversal fst(m_oss);
176  fst.m_protected_top_dirs.insert("pfc-stats"); // XXXX This should come from config. Also: N2N?
177 
178  if ( ! fst.begin_traversal(root_ds, "/"))
179  return false;
180 
181  {
182  XrdSysMutexHelper _lock(m_dir_scan_mutex);
183  m_dir_scan_in_progress = true;
184  m_dir_scan_check_counter = 0; // recheck oob file-open requests periodically.
185  }
186 
188 
189  fst.end_traversal();
190 
191  // We have all directories scanned, available in DirState tree, let all remaining files go
192  // and then we shall do the upward propagation of usages.
193  {
194  XrdSysMutexHelper _lock(m_dir_scan_mutex);
195  m_dir_scan_in_progress = false;
196  m_dir_scan_check_counter = 0;
197 
198  while ( ! m_dir_scan_open_requests.empty())
199  {
200  LfnCondRecord &lcr = m_dir_scan_open_requests.front();
201  lcr.f_cond.Lock();
202  lcr.f_checked = true;
203  lcr.f_cond.Signal();
204  lcr.f_cond.UnLock();
205 
206  m_dir_scan_open_requests.pop_front();
207  }
208  }
209 
210  // Do upward propagation of usages.
212  m_current_usage_in_st_blocks = root_ds->m_here_usage.m_StBlocks +
215 
216  return true;
217 }
void scan_dir_and_recurse(FsTraversal &fst)
void upward_propagate_initial_scan_usages()
long long m_StBlocks

References XrdPfc::FsTraversal::begin_traversal(), XrdPfc::FsTraversal::end_traversal(), XrdPfc::DataFsState::get_root(), XrdPfc::DirState::m_here_usage, XrdPfc::FsTraversal::m_protected_top_dirs, XrdPfc::DirState::m_recursive_subdir_usage, XrdPfc::DirUsage::m_StBlocks, scan_dir_and_recurse(), update_vs_and_file_usage_info(), and XrdPfc::DirState::upward_propagate_initial_scan_usages().

Referenced by main_thread_function().

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

◆ perform_purge_check()

void ResourceMonitor::perform_purge_check ( bool  purge_cold_files,
int  tl 
)

Definition at line 660 of file XrdPfcResourceMonitor.cc.

661 {
662  static const char *trc_pfx = "perform_purge_check() ";
663  const Configuration &conf = Cache::Conf();
664 
665  std::unique_ptr<DataFsPurgeshot> psp( new DataFsPurgeshot(m_fs_state) );
666  DataFsPurgeshot &ps = *psp;
667 
668  ps.m_file_usage = 512ll * m_current_usage_in_st_blocks;
669  // These are potentially wrong as cache might be writing over preallocated byte ranges.
671  // Can have another estimate based on eiter writes or st-blocks from purge-stats, once we have them.
672 
673  TRACE_INT(tl, trc_pfx << "Purge check:");
674 
675  ps.m_bytes_to_remove = 0;
676  if (conf.are_file_usage_limits_set())
677  {
678  ps.m_bytes_to_remove = get_file_usage_bytes_to_remove(ps, ps.m_estimated_writes_from_writeq, tl);
679  }
680  else
681  {
682  if (ps.m_disk_used > conf.m_diskUsageHWM)
683  {
684  TRACE_INT(tl, "Disk usage: " << ps.m_disk_used << " exceed highWatermark.");
686  }
687  }
688 
689  ps.m_space_based_purge = ps.m_bytes_to_remove ? 1 : 0;
690 
691  // Purge precheck -- check if age-based purge is required
692  // We ignore uvkeep time, it requires reading of cinfo files and it is enforced in File::Open() anyway.
693 
694  if (purge_cold_files && conf.is_age_based_purge_in_effect()) // || conf.is_uvkeep_purge_in_effect())
695  {
696  ps.m_age_based_purge = true;
697  }
698 
699  TRACE_INT(tl, "\tbytes_to_remove = " << ps.m_bytes_to_remove << " B");
700  TRACE_INT(tl, "\tspace_based_purge = " << ps.m_space_based_purge);
701  TRACE_INT(tl, "\tage_based_purge = " << ps.m_age_based_purge);
702 
703  bool periodic = Cache::GetInstance().GetPurgePin() ?
705 
706  if ( ! ps.m_space_based_purge && ! ps.m_age_based_purge && !periodic ) {
707  TRACE(Info, trc_pfx << "purge not required.");
709  return;
710  }
711  if (m_purge_task_active) {
712  TRACE(Warning, trc_pfx << "purge required but previous purge task is still active!");
713  return;
714  }
715 
716  TRACE(Info, trc_pfx << "scheduling purge task.");
717 
718  // At this point we have all the information: report, decide on action.
719  // There is still some missing infrastructure, especially as regards to purge-plugin:
720  // - at what point do we start bugging the pu-pin to start coughing up purge lists?
721  // - have a new parameter or just do it "one cycle before full"?
722  // - what if it doesn't -- when do we do the old-stlye scan & purge?
723  // - how do we do age-based purge and uvkeep purge?
724  // - they are really quite different -- and could run separately, registering
725  // files into a purge-candidate list. This has to be rechecked before the actual
726  // deletion -- eg, by comparing stat time of cinfo + doing the is-active / is-purge-protected.
727 
728  const DirState &root_ds = *m_fs_state.get_root();
729  const int n_calc_dirs = 1 + root_ds.m_here_usage.m_NDirectories + root_ds.m_recursive_subdir_usage.m_NDirectories;
730 #ifdef RM_DEBUG
731  const int n_pshot_dirs = root_ds.count_dirs_to_level(9999);
732  dprintf("purge dir count recursive=%d vs from_usage=%d\n", n_pshot_dirs, n_calc_dirs);
733 #endif
734  ps.m_dir_vec.reserve(n_calc_dirs);
735  ps.m_dir_vec.emplace_back( DirPurgeElement(root_ds, -1) );
736  fill_pshot_vec_children(root_ds, 0, ps.m_dir_vec, 9999);
737 
738  m_purge_task_active = true;
739 
740  struct PurgeDriverJob : public XrdJob
741  {
742  DataFsPurgeshot *m_purge_shot_ptr;
743 
744  PurgeDriverJob(DataFsPurgeshot *psp) :
745  XrdJob("XrdPfc::ResourceMonitor::PurgeDriver"),
746  m_purge_shot_ptr(psp)
747  {}
748 
749  void DoIt() override
750  {
751  Cache::ResMon().perform_purge_task(*m_purge_shot_ptr);
753 
754  delete m_purge_shot_ptr;
755  delete this;
756  }
757  };
758 
759  Cache::schedP->Schedule( new PurgeDriverJob(psp.release()) );
760 }
int DoIt(int argpnt, int argc, char **argv, bool singleshot)
Definition: XrdAccTest.cc:262
#define TRACE_INT(act, x)
Definition: XrdPfcTrace.hh:47
@ Warning
Definition: XrdJob.hh:43
PurgePin * GetPurgePin() const
Definition: XrdPfc.hh:267
static ResourceMonitor & ResMon()
Definition: XrdPfc.cc:133
void ClearPurgeProtectedSet()
Definition: XrdPfc.cc:664
static Cache & GetInstance()
Singleton access.
Definition: XrdPfc.cc:130
static XrdScheduler * schedP
Definition: XrdPfc.hh:285
long long WritesSinceLastCall()
Definition: XrdPfc.cc:318
virtual bool CallPeriodically()
void perform_purge_task(DataFsPurgeshot &ps)
void Schedule(XrdJob *jp)
long long m_diskUsageHWM
cache purge - disk usage high water mark
Definition: XrdPfc.hh:93
bool are_file_usage_limits_set() const
Definition: XrdPfc.hh:67
long long m_diskUsageLWM
cache purge - disk usage low water mark
Definition: XrdPfc.hh:92
bool is_age_based_purge_in_effect() const
Definition: XrdPfc.hh:68
std::vector< DirPurgeElement > m_dir_vec

References XrdPfc::Configuration::are_file_usage_limits_set(), XrdPfc::PurgePin::CallPeriodically(), XrdPfc::Cache::ClearPurgeProtectedSet(), XrdPfc::Cache::Conf(), XrdPfc::DirState::count_dirs_to_level(), DoIt(), dprintf, fill_pshot_vec_children(), XrdPfc::DataFsState::get_root(), XrdPfc::Cache::GetInstance(), XrdPfc::Cache::GetPurgePin(), XrdPfc::Configuration::is_age_based_purge_in_effect(), XrdPfc::DataFsPurgeshot::m_age_based_purge, XrdPfc::DataFsPurgeshot::m_bytes_to_remove, XrdPfc::DataFsPurgeshot::m_dir_vec, XrdPfc::DataFsStateBase::m_disk_used, XrdPfc::Configuration::m_diskUsageHWM, XrdPfc::Configuration::m_diskUsageLWM, XrdPfc::DataFsPurgeshot::m_estimated_writes_from_writeq, XrdPfc::DataFsStateBase::m_file_usage, XrdPfc::DirState::m_here_usage, XrdPfc::DirUsage::m_NDirectories, m_purge_task_active, XrdPfc::DirState::m_recursive_subdir_usage, XrdPfc::DataFsPurgeshot::m_space_based_purge, perform_purge_task(), perform_purge_task_cleanup(), XrdPfc::Cache::ResMon(), XrdPfc::Cache::schedP, XrdScheduler::Schedule(), TRACE, TRACE_INT, Warning, and XrdPfc::Cache::WritesSinceLastCall().

Referenced by heart_beat().

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

◆ perform_purge_task()

void ResourceMonitor::perform_purge_task ( DataFsPurgeshot ps)

Definition at line 767 of file XrdPfcResourceMonitor.cc.

768 {
769  // BEWARE: Runs in a dedicated thread - is only to communicate back to the
770  // hear_beat() / data structs via the purge queues and condition variable.
771 
772  // const char *tpfx = "perform_purge_task ";
773 
774  {
776  m_purge_task_start = time(0);
777  }
778 
779  // For now, fall back to the old purge ... to be improved with:
780  // - new scan, following the DataFsPurgeshot;
781  // - usage of cinfo stat mtime for time of last access (touch already done at output);
782  // - use DirState* to report back purged files.
783  // Already changed to report back purged files --- but using the string / path variant.
784  OldStylePurgeDriver(ps); // In XrdPfcPurge.cc
785 }
void OldStylePurgeDriver(DataFsPurgeshot &ps)
Definition: XrdPfcPurge.cc:99

References m_purge_task_cond, m_purge_task_start, and XrdPfc::OldStylePurgeDriver().

Referenced by perform_purge_check().

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

◆ perform_purge_task_cleanup()

void ResourceMonitor::perform_purge_task_cleanup ( )

Definition at line 787 of file XrdPfcResourceMonitor.cc.

788 {
789  // Separated out so the purge_task can exit without post-checks.
790 
791  {
793  m_purge_task_end = time(0);
794  m_purge_task_complete = true;
796  }
798 }

References XrdPfc::Cache::ClearPurgeProtectedSet(), XrdPfc::Cache::GetInstance(), m_purge_task_complete, m_purge_task_cond, m_purge_task_end, and XrdSysCondVar::Signal().

Referenced by perform_purge_check().

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

◆ process_queues()

int ResourceMonitor::process_queues ( )

Definition at line 223 of file XrdPfcResourceMonitor.cc.

224 {
225  static const char *trc_pfx = "process_queues() ";
226 
227  // Assure that we pick up only entries that are present now.
228  // We really want all open records to be processed before file-stats updates
229  // and all those before the close records.
230  // Purges are sort of tangential as they really just modify bytes / number
231  // of files in a directory and do not deal with any persistent file id tokens.
232 
233  int n_records = 0;
234  {
235  XrdSysMutexHelper _lock(&m_queue_mutex);
236  n_records += m_file_open_q.swap_queues();
237  n_records += m_file_update_stats_q.swap_queues();
238  n_records += m_file_close_q.swap_queues();
239  n_records += m_file_purge_q1.swap_queues();
240  n_records += m_file_purge_q2.swap_queues();
241  n_records += m_file_purge_q3.swap_queues();
242  ++m_queue_swap_u1;
243  }
244 
245  for (auto &i : m_file_open_q.read_queue())
246  {
247  // i.id: LFN, i.record: OpenRecord
248  AccessToken &at = token(i.id);
249  dprintf("process file open for token %d, time %ld -- %s\n",
250  i.id, i.record.m_open_time, at.m_filename.c_str());
251 
252  // Resolve fname into DirState.
253  // We could clear the filename after this ... or keep it, should we need it later on.
254  // For now it is just used for debug printouts.
255  DirState *last_existing_ds = nullptr;
256  DirState *ds = m_fs_state.find_dirstate_for_lfn(at.m_filename, &last_existing_ds);
257  at.m_dir_state = ds;
258  ds->m_here_stats.m_NFilesOpened += 1;
259 
260  // If this is a new file figure out how many new parent dirs got created along the way.
261  if ( ! i.record.m_existing_file) {
262  ds->m_here_stats.m_NFilesCreated += 1;
263  DirState *pp = ds;
264  while (pp != last_existing_ds) {
265  pp = pp->get_parent();
267  }
268  }
269 
270  ds->m_here_usage.m_LastOpenTime = i.record.m_open_time;
271  }
272 
273  for (auto &i : m_file_update_stats_q.read_queue())
274  {
275  // i.id: token, i.record: Stats
276  AccessToken &at = token(i.id);
277  // Stats
278  DirState *ds = at.m_dir_state;
279  dprintf("process file update for token %d, %p -- %s\n",
280  i.id, ds, at.m_filename.c_str());
281 
282  ds->m_here_stats.AddUp(i.record);
283  m_current_usage_in_st_blocks += i.record.m_StBlocksAdded;
284  }
285 
286  for (auto &i : m_file_close_q.read_queue())
287  {
288  // i.id: token, i.record: CloseRecord
289  AccessToken &at = token(i.id);
290  dprintf("process file close for token %d, time %ld -- %s\n",
291  i.id, i.record.m_close_time, at.m_filename.c_str());
292 
293  DirState *ds = at.m_dir_state;
294  ds->m_here_stats.m_NFilesClosed += 1;
295  ds->m_here_usage.m_LastCloseTime = i.record.m_close_time;
296 
297  at.clear();
298  }
299  { // Release the AccessToken slots under lock.
300  XrdSysMutexHelper _lock(&m_queue_mutex);
301  for (auto &i : m_file_close_q.read_queue())
302  m_access_tokens_free_slots.push_back(i.id);
303  }
304 
305  for (auto &i : m_file_purge_q1.read_queue())
306  {
307  // i.id: DirState*, i.record: PurgeRecord
308  DirState *ds = i.id;
309  ds->m_here_stats.m_StBlocksRemoved += i.record.m_size_in_st_blocks;
310  ds->m_here_stats.m_NFilesRemoved += i.record.m_n_files;
311  m_current_usage_in_st_blocks -= i.record.m_size_in_st_blocks;
312  }
313  for (auto &i : m_file_purge_q2.read_queue())
314  {
315  // i.id: directory-path, i.record: PurgeRecord
316  DirState *ds = m_fs_state.get_root()->find_path(i.id, -1, false, false);
317  if ( ! ds) {
318  TRACE(Error, trc_pfx << "DirState not found for directory path '" << i.id << "'.");
319  // find_path can return the last dir found ... but this clearly isn't a valid purge record.
320  continue;
321  }
322  ds->m_here_stats.m_StBlocksRemoved += i.record.m_size_in_st_blocks;
323  ds->m_here_stats.m_NFilesRemoved += i.record.m_n_files;
324  m_current_usage_in_st_blocks -= i.record.m_size_in_st_blocks;
325  }
326  for (auto &i : m_file_purge_q3.read_queue())
327  {
328  // i.id: LFN, i.record: size of file in st_blocks
329  DirState *ds = m_fs_state.get_root()->find_path(i.id, -1, true, false);
330  if ( ! ds) {
331  TRACE(Error, trc_pfx << "DirState not found for LFN path '" << i.id << "'.");
332  continue;
333  }
334  ds->m_here_stats.m_StBlocksRemoved += i.record;
335  ds->m_here_stats.m_NFilesRemoved += 1;
336  m_current_usage_in_st_blocks -= i.record;
337  }
338 
339  // Read queues / vectors are cleared at swap time.
340  // We might consider reducing their capacity by half if, say, their usage is below 25%.
341 
342  return n_records;
343 }
void AddUp(const DirStats &s)
Definition: XrdPfcStats.hh:187
long long m_StBlocksRemoved
Definition: XrdPfcStats.hh:144
DirState * find_dirstate_for_lfn(const std::string &lfn, DirState **last_existing_dir=nullptr)
DirState * get_parent()
DirState * find_path(const std::string &path, int max_depth, bool parse_as_lfn, bool create_subdirs, DirState **last_existing_dir=nullptr)

References XrdPfc::DirStats::AddUp(), dprintf, Macaroons::Error, XrdPfc::DataFsState::find_dirstate_for_lfn(), XrdPfc::DirState::find_path(), XrdPfc::DirState::get_parent(), XrdPfc::DataFsState::get_root(), XrdPfc::DirState::m_here_stats, XrdPfc::DirState::m_here_usage, XrdPfc::DirUsage::m_LastCloseTime, XrdPfc::DirUsage::m_LastOpenTime, XrdPfc::DirStats::m_NDirectoriesCreated, XrdPfc::DirStats::m_NFilesClosed, XrdPfc::DirStats::m_NFilesCreated, XrdPfc::DirStats::m_NFilesOpened, XrdPfc::DirStats::m_NFilesRemoved, XrdPfc::DirStats::m_StBlocksRemoved, token(), and TRACE.

Referenced by heart_beat(), and main_thread_function().

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

◆ register_file_close()

void XrdPfc::ResourceMonitor::register_file_close ( int  token_id,
time_t  close_timestamp,
const Stats full_stats 
)
inline

Definition at line 185 of file XrdPfcResourceMonitor.hh.

185  {
186  XrdSysMutexHelper _lock(&m_queue_mutex);
187  m_file_close_q.push(token_id, {close_timestamp, full_stats});
188  }

Referenced by XrdPfc::File::~File(), and XrdPfc::Cache::ExecuteCommandUrl().

+ Here is the caller graph for this function:

◆ register_file_open()

int XrdPfc::ResourceMonitor::register_file_open ( const std::string &  filename,
time_t  open_timestamp,
bool  existing_file 
)
inline

Definition at line 149 of file XrdPfcResourceMonitor.hh.

149  {
150  // Simply return a token, we will resolve it in the actual processing of the queue.
151  XrdSysMutexHelper _lock(&m_queue_mutex);
152  int token_id;
153  if ( ! m_access_tokens_free_slots.empty()) {
154  token_id = m_access_tokens_free_slots.back();
155  m_access_tokens_free_slots.pop_back();
156  m_access_tokens[token_id].m_filename = filename;
157  m_access_tokens[token_id].m_last_queue_swap_u1 = m_queue_swap_u1 - 1;
158  } else {
159  token_id = (int) m_access_tokens.size();
160  m_access_tokens.push_back({filename, m_queue_swap_u1 - 1});
161  }
162 
163  m_file_open_q.push(token_id, {open_timestamp, existing_file});
164  return token_id;
165  }

Referenced by XrdPfc::Cache::ExecuteCommandUrl().

+ Here is the caller graph for this function:

◆ register_file_purge() [1/2]

void XrdPfc::ResourceMonitor::register_file_purge ( const std::string &  filename,
long long  size_in_st_blocks 
)
inline

Definition at line 204 of file XrdPfcResourceMonitor.hh.

204  {
205  XrdSysMutexHelper _lock(&m_queue_mutex);
206  m_file_purge_q3.push(filename, size_in_st_blocks);
207  }

◆ register_file_purge() [2/2]

void XrdPfc::ResourceMonitor::register_file_purge ( DirState target,
long long  size_in_st_blocks 
)
inline

Definition at line 192 of file XrdPfcResourceMonitor.hh.

192  {
193  XrdSysMutexHelper _lock(&m_queue_mutex);
194  m_file_purge_q1.push(target, {size_in_st_blocks, 1});
195  }

Referenced by XrdPfc::Cache::UnlinkFile().

+ Here is the caller graph for this function:

◆ register_file_update_stats()

void XrdPfc::ResourceMonitor::register_file_update_stats ( int  token_id,
const Stats stats 
)
inline

Definition at line 167 of file XrdPfcResourceMonitor.hh.

167  {
168  XrdSysMutexHelper _lock(&m_queue_mutex);
169  AccessToken &at = token(token_id);
170  // Check if this is the first update within this queue swap cycle.
171  if (at.m_last_queue_swap_u1 != m_queue_swap_u1) {
172  m_file_update_stats_q.push(token_id, stats);
173  at.m_last_queue_swap_u1 = m_queue_swap_u1;
174  at.m_last_write_queue_pos = m_file_update_stats_q.write_queue_size() - 1;
175  } else {
176  Stats &existing_stats = m_file_update_stats_q.write_record(at.m_last_write_queue_pos);
177  existing_stats.AddUp(stats);
178  }
179  // Optionally, one could return "scaler" to moodify stat-reporting
180  // frequency in the file ... if it comes too often or too rarely.
181  // See also the logic for determining reporting interval (in N_bytes_read)
182  // in File::Open().
183  }
XrdPosixStats Stats
Definition: XrdPosixFile.cc:63

References XrdPfc::Stats::AddUp(), and token().

Referenced by XrdPfc::Cache::ExecuteCommandUrl().

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

◆ register_multi_file_purge() [1/2]

void XrdPfc::ResourceMonitor::register_multi_file_purge ( const std::string &  target,
long long  size_in_st_blocks,
int  n_files 
)
inline

Definition at line 200 of file XrdPfcResourceMonitor.hh.

200  {
201  XrdSysMutexHelper _lock(&m_queue_mutex);
202  m_file_purge_q2.push(target, {size_in_st_blocks, n_files});
203  }

◆ register_multi_file_purge() [2/2]

void XrdPfc::ResourceMonitor::register_multi_file_purge ( DirState target,
long long  size_in_st_blocks,
int  n_files 
)
inline

Definition at line 196 of file XrdPfcResourceMonitor.hh.

196  {
197  XrdSysMutexHelper _lock(&m_queue_mutex);
198  m_file_purge_q1.push(target, {size_in_st_blocks, n_files});
199  }

◆ scan_dir_and_recurse()

void ResourceMonitor::scan_dir_and_recurse ( FsTraversal fst)

Definition at line 114 of file XrdPfcResourceMonitor.cc.

115 {
116  dprintf("In scan_dir_and_recurse for '%s', size of dir_vec = %d, file_stat_map = %d\n",
117  fst.m_current_path.c_str(),
118  (int)fst.m_current_dirs.size(), (int)fst.m_current_files.size());
119 
120  // Breadth first, accumulate into "here", unless it was already scanned via an
121  // OOB open file request.
122  if ( ! fst.m_dir_state->m_scanned)
123  {
124  DirUsage &here = fst.m_dir_state->m_here_usage;
125  for (auto it = fst.m_current_files.begin(); it != fst.m_current_files.end(); ++it)
126  {
127  dprintf("would be doing something with %s ... has_data=%d, has_cinfo=%d\n",
128  it->first.c_str(), it->second.has_data, it->second.has_cinfo);
129 
130  // XXX Make some of these optional?
131  // Remove files that do not have both cinfo and data?
132  // Remove empty directories before even descending?
133  // Leave this for some consistency pass?
134  // Note that FsTraversal supports ignored paths ... some details (config, N2N) to be clarified.
135 
136  if (it->second.has_data && it->second.has_cinfo) {
137  here.m_StBlocks += it->second.stat_data.st_blocks;
138  here.m_NFiles += 1;
139  }
140  }
141  fst.m_dir_state->m_scanned = true;
142  }
143 
144  // Swap-out directories as inter_dir_scan can use the FsTraversal.
145  std::vector<std::string> dirs;
146  dirs.swap(fst.m_current_dirs);
147 
148  if (++m_dir_scan_check_counter >= 100)
149  {
150  process_inter_dir_scan_open_requests(fst);
151  m_dir_scan_check_counter = 0;
152  }
153 
154  // Descend into sub-dirs, do not accumulate into recursive_subdir_usage yet. This is done
155  // in a separate pass to allow for proper accounting of files being opened during the initial scan.
156  for (auto &dname : dirs)
157  {
158  if (fst.cd_down(dname))
159  {
161  fst.cd_up();
162  }
163  // XXX else try to remove it?
164  }
165 }
std::vector< std::string > m_current_dirs
bool cd_down(const std::string &dir_name)
std::map< std::string, FilePairStat > m_current_files

References XrdPfc::FsTraversal::cd_down(), XrdPfc::FsTraversal::cd_up(), dprintf, XrdPfc::FsTraversal::m_current_dirs, XrdPfc::FsTraversal::m_current_files, XrdPfc::FsTraversal::m_current_path, XrdPfc::FsTraversal::m_dir_state, XrdPfc::DirState::m_here_usage, XrdPfc::DirUsage::m_NFiles, XrdPfc::DirState::m_scanned, and XrdPfc::DirUsage::m_StBlocks.

Referenced by perform_initial_scan().

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

◆ token()

AccessToken& XrdPfc::ResourceMonitor::token ( int  i)
inline

Definition at line 217 of file XrdPfcResourceMonitor.hh.

217 { return m_access_tokens[i]; }

Referenced by process_queues(), and register_file_update_stats().

+ Here is the caller graph for this function:

◆ update_vs_and_file_usage_info()

void ResourceMonitor::update_vs_and_file_usage_info ( )

Definition at line 528 of file XrdPfcResourceMonitor.cc.

529 {
530  static const char *trc_pfx = "update_vs_and_file_usage_info() ";
531 
532  const auto &conf = Cache::Conf();
533  XrdOssVSInfo vsi;
534 
535  // StatVS error (after it succeeded in config) implies a memory corruption (according to Mr. H).
536  if (m_oss.StatVS(&vsi, conf.m_data_space.c_str(), 1) < 0) {
537  TRACE(Error, trc_pfx << "can't get StatVS for oss space '" << conf.m_data_space << "'. This is a fatal error.");
538  _exit(1);
539  }
540  m_fs_state.m_disk_total = vsi.Total;
541  m_fs_state.m_disk_used = vsi.Total - vsi.Free;
542  m_fs_state.m_file_usage = 512ll * m_current_usage_in_st_blocks;
543  if (m_oss.StatVS(&vsi, conf.m_meta_space.c_str(), 1) < 0) {
544  TRACE(Error, trc_pfx << "can't get StatVS for oss space '" << conf.m_meta_space << "'. This is a fatal error.");
545  _exit(1);
546  }
547  m_fs_state.m_meta_total = vsi.Total;
548  m_fs_state.m_meta_used = vsi.Total - vsi.Free;
549 }
long long Total
Definition: XrdOssVS.hh:90
long long Free
Definition: XrdOssVS.hh:91
virtual int StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0)
Definition: XrdOss.cc:117

References XrdPfc::Cache::Conf(), Macaroons::Error, XrdOssVSInfo::Free, XrdPfc::DataFsStateBase::m_disk_total, XrdPfc::DataFsStateBase::m_disk_used, XrdPfc::DataFsStateBase::m_file_usage, XrdPfc::DataFsStateBase::m_meta_total, XrdPfc::DataFsStateBase::m_meta_used, XrdOss::StatVS(), XrdOssVSInfo::Total, and TRACE.

Referenced by heart_beat(), and perform_initial_scan().

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

Member Data Documentation

◆ m_purge_task_active

bool XrdPfc::ResourceMonitor::m_purge_task_active {false}

Definition at line 248 of file XrdPfcResourceMonitor.hh.

Referenced by heart_beat(), and perform_purge_check().

◆ m_purge_task_complete

bool XrdPfc::ResourceMonitor::m_purge_task_complete {false}

Definition at line 249 of file XrdPfcResourceMonitor.hh.

Referenced by heart_beat(), and perform_purge_task_cleanup().

◆ m_purge_task_cond

XrdSysCondVar XrdPfc::ResourceMonitor::m_purge_task_cond {0}

◆ m_purge_task_end

time_t XrdPfc::ResourceMonitor::m_purge_task_end {0}

Definition at line 247 of file XrdPfcResourceMonitor.hh.

Referenced by perform_purge_task_cleanup().

◆ m_purge_task_start

time_t XrdPfc::ResourceMonitor::m_purge_task_start {0}

Definition at line 246 of file XrdPfcResourceMonitor.hh.

Referenced by perform_purge_task().


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