1 #ifndef __XRDPFC_RESOURCEMONITOR_HH__
2 #define __XRDPFC_RESOURCEMONITOR_HH__
20 struct DirStateElement;
21 struct DataFsSnapshot;
22 struct DirPurgeElement;
23 struct DataFsPurgeshot;
41 template<
typename ID,
typename RECORD>
48 using queue_type = std::vector<Entry>;
49 using iterator =
typename queue_type::iterator;
53 int write_queue_size()
const {
return m_write_queue.size(); }
54 bool read_queue_empty()
const {
return m_read_queue.empty(); }
55 int read_queue_size()
const {
return m_read_queue.size(); }
58 void push(
ID id, RECORD
stat) { m_write_queue.push_back({ id,
stat }); }
60 RECORD& write_record(
int pos) {
return m_write_queue[pos].record; }
63 int swap_queues() { m_read_queue.clear(); m_write_queue.swap(m_read_queue);
return read_queue_size(); }
64 const queue_type& read_queue()
const {
return m_read_queue; }
65 iterator begin()
const {
return m_read_queue.begin(); }
66 iterator end()
const {
return m_read_queue.end(); }
69 void shrink_read_queue() { m_read_queue.clear(); m_read_queue.shrink_to_fit(); }
72 queue_type m_write_queue, m_read_queue;
76 std::string m_filename;
77 unsigned int m_last_queue_swap_u1 = 0xffffffff;
78 int m_last_write_queue_pos = -1;
79 DirState *m_dir_state =
nullptr;
83 m_last_queue_swap_u1 = 0xffffffff;
84 m_last_write_queue_pos = -1;
85 m_dir_state =
nullptr;
91 StableChunkPool<AccessToken, 12, 1024> m_access_tokens;
104 long long m_size_in_st_blocks;
108 Queue<int, OpenRecord> m_file_open_q;
109 Queue<int, Stats> m_file_update_stats_q;
110 Queue<int, CloseRecord> m_file_close_q;
111 Queue<DirState*, PurgeRecord> m_file_purge_q1;
112 Queue<std::string, PurgeRecord> m_file_purge_q2;
113 Queue<std::string, long long> m_file_purge_q3;
116 long long m_current_usage_in_st_blocks = 0;
117 int m_dir_count_discrepancy = 0;
118 long long m_token_alloc_failures = 0;
121 unsigned int m_queue_swap_u1 = 0u;
123 DataFsState &m_fs_state;
130 const std::string &f_lfn;
136 std::list<LfnCondRecord> m_dir_scan_open_requests;
137 bool m_dir_scan_in_progress =
true;
141 static constexpr std::chrono::milliseconds s_dir_scan_check_interval{100};
142 std::chrono::steady_clock::time_point m_dir_scan_last_check;
144 void check_inter_dir_scan_open_requests();
145 void process_inter_dir_scan_open_requests();
146 void cross_check_or_process_oob_lfn(
const std::string &lfn, FsTraversal &fst);
147 long long get_file_usage_bytes_to_remove(
const DataFsPurgeshot &ps,
long long previous_file_usage,
int logLeve);
163 int token_id = m_access_tokens.acquire();
166 ++m_token_alloc_failures;
169 AccessToken &at = m_access_tokens[token_id];
170 at.m_filename = filename;
171 at.m_last_queue_swap_u1 = m_queue_swap_u1 - 1;
173 m_file_open_q.push(token_id, {open_timestamp, existing_file});
178 if (token_id < 0)
return;
180 AccessToken &at =
token(token_id);
182 if (at.m_last_queue_swap_u1 != m_queue_swap_u1) {
183 m_file_update_stats_q.push(token_id, stats);
184 at.m_last_queue_swap_u1 = m_queue_swap_u1;
185 at.m_last_write_queue_pos = m_file_update_stats_q.write_queue_size() - 1;
187 Stats &existing_stats = m_file_update_stats_q.write_record(at.m_last_write_queue_pos);
188 existing_stats.
AddUp(stats);
197 if (token_id < 0)
return;
199 m_file_close_q.push(token_id, {close_timestamp, full_stats});
206 m_file_purge_q1.push(target, {size_in_st_blocks, 1});
210 m_file_purge_q1.push(target, {size_in_st_blocks, n_files});
214 m_file_purge_q2.push(target, {size_in_st_blocks, n_files});
218 m_file_purge_q3.push(filename, size_in_st_blocks);
229 AccessToken&
token(
int i) {
return m_access_tokens[i]; }
241 std::vector<DirStateElement> &vec,
246 std::vector<DirPurgeElement> &vec,
bool m_purge_task_complete
void CrossCheckIfScanIsInProgress(const std::string &lfn, XrdSysCondVar &cond)
int register_file_open(const std::string &filename, time_t open_timestamp, bool existing_file)
void perform_purge_check(bool purge_cold_files, int tl)
void fill_sshot_vec_children(const DirState &parent_ds, int parent_idx, std::vector< DirStateElement > &vec, int max_depth)
ResourceMonitor(XrdOss &oss)
void perform_purge_task(DataFsPurgeshot &ps)
void register_file_purge(const std::string &filename, long long size_in_st_blocks)
void scan_dir_and_recurse(FsTraversal &fst)
void register_file_purge(DirState *target, long long size_in_st_blocks)
void fill_pshot_vec_children(const DirState &parent_ds, int parent_idx, std::vector< DirPurgeElement > &vec, int max_depth)
XrdSysCondVar m_purge_task_cond
void perform_purge_task_cleanup()
void register_multi_file_purge(DirState *target, long long size_in_st_blocks, int n_files)
void register_file_update_stats(int token_id, const Stats &stats)
void update_vs_and_file_usage_info()
bool perform_initial_scan()
AccessToken & token(int i)
time_t m_purge_task_start
void register_multi_file_purge(const std::string &target, long long size_in_st_blocks, int n_files)
void main_thread_function()
void register_file_close(int token_id, time_t close_timestamp, const Stats &full_stats)
Statistics of cache utilisation by a File object.
void AddUp(const Stats &s)