15 const char *m_traceID =
"ResourceMonitor";
26 static const char *trc_pfx =
"UnlinkPurgeStateFilesInMap ";
29 int protected_cnt = 0;
30 int deleted_file_count = 0;
31 long long deleted_st_blocks = 0;
32 long long protected_st_blocks = 0;
33 long long st_blocks_to_remove = (bytes_to_remove >> 9) + 1ll;
38 auto &oss = *cache.GetOss();
40 TRACE(
Info, trc_pfx <<
"Started, root_path = " << root_path <<
", bytes_to_remove = " << bytes_to_remove);
47 if (st_blocks_to_remove <= 0 && it->first != 0)
52 std::string &infoPath = it->second.path;
55 if (cache.IsFileActiveOrPurgeProtected(dataPath))
58 protected_st_blocks += it->second.nStBlocks;
59 TRACE(
Debug, trc_pfx <<
"File is active or purge-protected: " << dataPath <<
" size: " << 512ll * it->second.nStBlocks);
66 oss.Unlink(infoPath.c_str());
67 TRACE(Dump, trc_pfx <<
"Removed file: '" << infoPath <<
"' size: " << 512ll *
fstat.st_size);
71 TRACE(
Error, trc_pfx <<
"Can't locate file " << dataPath);
77 st_blocks_to_remove -= it->second.nStBlocks;
78 deleted_st_blocks += it->second.nStBlocks;
81 oss.Unlink(dataPath.c_str());
82 TRACE(Dump, trc_pfx <<
"Removed file: '" << dataPath <<
"' size: " << 512ll * it->second.nStBlocks <<
", time: " << it->first);
84 resmon.register_file_purge(dataPath, it->second.nStBlocks);
87 if (protected_cnt > 0)
89 TRACE(
Info, trc_pfx <<
"Encountered " << protected_cnt <<
" protected files, sum of their size: " << 512ll * protected_st_blocks);
92 TRACE(
Info, trc_pfx <<
"Finished, removed " << deleted_file_count <<
" data files, removed total size " << 512ll * deleted_st_blocks)
94 return deleted_st_blocks;
101 static const char *trc_pfx =
"OldStylePurgeDriver ";
104 auto &oss = *cache.GetOss();
106 time_t purge_start = time(0);
111 PurgePin *purge_pin = cache.GetPurgePin();
112 long long std_blocks_removed_by_pin = 0;
120 TRACE(
Debug,
"PurgePin remove total " << clearVal <<
" bytes");
125 TRACE(
Debug, trc_pfx <<
"PurgePin scanning dir " << ppit->path.c_str() <<
" to remove " << ppit->nBytesToRecover <<
" bytes");
130 TRACE(
Warning, trc_pfx <<
"purge-pin scan of directory failed for " << ppit->path);
145 long long pin_removed_bytes = std_blocks_removed_by_pin * 512ll;
146 long long default_purge_blocks_removed = 0;
155 purgeState.
setMinTime(time(0) - conf.m_purgeColdFilesAge);
157 if (conf.is_uvkeep_purge_in_effect())
166 TRACE(
Error, trc_pfx <<
"default purge namespace traversal failed at top-directory, this should not happen.");
170 TRACE(
Debug, trc_pfx <<
"default purge usage measured from cinfo files " << purgeState.
getNBytesTotal() <<
" bytes.");
178 int purge_duration = time(0) - purge_start;
179 long long total_bytes_removed = (default_purge_blocks_removed + std_blocks_removed_by_pin) * 512ll;
180 TRACE(
Info, trc_pfx <<
"Finished, removed total size " << total_bytes_removed <<
", purge duration " << purge_duration);
int stat(const char *path, struct stat *buf)
int fstat(int fildes, struct stat *buf)
static const Configuration & Conf()
static ResourceMonitor & ResMon()
static Cache & GetInstance()
Singleton access.
static const Cache & TheOne()
void setUVKeepMinTime(time_t min_time)
void setMinTime(time_t min_time)
bool TraverseNamespace(const char *root_path)
long long getNBytesTotal() const
void MoveListEntriesToMap()
Status of cached file. Can be read from and written into a binary file.
static const size_t s_infoExtensionLen
Base class for reguesting directory space to obtain.
virtual long long GetBytesToRecover(const DataFsPurgeshot &)=0
std::vector< DirInfo > list_t
void OldStylePurgeDriver(DataFsPurgeshot &ps)
long long UnlinkPurgeStateFilesInMap(FPurgeState &purgeState, long long bytes_to_remove, const std::string &root_path)
long long m_bytes_to_remove