From 7d69d1228192779f70852fa2b2a7f15e733ae5d2 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Thu, 22 Jul 2021 16:20:01 +0200 Subject: [PATCH] Convert primary storage to a public member of storage::Storage --- src/ccache.cpp | 30 +++++++++++++++--------------- src/storage/Storage.cpp | 16 +++++++--------- src/storage/Storage.hpp | 9 +-------- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/ccache.cpp b/src/ccache.cpp index d586842a2..f5e4b19d3 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -906,10 +906,10 @@ write_result(Context& ctx, const auto file_size_and_count_diff = result_writer.finalize(); if (file_size_and_count_diff) { - ctx.storage.primary().increment_statistic( + ctx.storage.primary.increment_statistic( Statistic::cache_size_kibibyte, file_size_and_count_diff->size_kibibyte); - ctx.storage.primary().increment_statistic(Statistic::files_in_cache, - file_size_and_count_diff->count); + ctx.storage.primary.increment_statistic(Statistic::files_in_cache, + file_size_and_count_diff->count); } else { LOG("Error: {}", file_size_and_count_diff.error()); throw Failure(Statistic::internal_error); @@ -1919,7 +1919,7 @@ log_result_to_debug_log(Context& ctx) return; } - core::Statistics statistics(ctx.storage.primary().get_statistics_updates()); + core::Statistics statistics(ctx.storage.primary.get_statistics_updates()); const auto result_message = statistics.get_result_message(); if (result_message) { LOG("Result: {}", *result_message); @@ -1933,7 +1933,7 @@ log_result_to_stats_log(Context& ctx) return; } - core::Statistics statistics(ctx.storage.primary().get_statistics_updates()); + core::Statistics statistics(ctx.storage.primary.get_statistics_updates()); const auto result_id = statistics.get_result_id(); if (!result_id) { return; @@ -1993,10 +1993,10 @@ cache_compilation(int argc, const char* const* argv) try { Statistic statistic = do_cache_compilation(ctx, argv); - ctx.storage.primary().increment_statistic(statistic); + ctx.storage.primary.increment_statistic(statistic); } catch (const Failure& e) { if (e.statistic() != Statistic::none) { - ctx.storage.primary().increment_statistic(e.statistic()); + ctx.storage.primary.increment_statistic(e.statistic()); } if (e.exit_code()) { @@ -2339,7 +2339,7 @@ handle_main_options(int argc, const char* const* argv) case EVICT_OLDER_THAN: { auto seconds = Util::parse_duration(arg); ProgressBar progress_bar("Evicting..."); - ctx.storage.primary().clean_old( + ctx.storage.primary.clean_old( [&](double progress) { progress_bar.update(progress); }, seconds); if (isatty(STDOUT_FILENO)) { PRINT_RAW(stdout, "\n"); @@ -2372,7 +2372,7 @@ handle_main_options(int argc, const char* const* argv) core::StatisticsCounters counters; time_t last_updated; std::tie(counters, last_updated) = - ctx.storage.primary().get_all_statistics(); + ctx.storage.primary.get_all_statistics(); core::Statistics statistics(counters); PRINT_RAW(stdout, statistics.format_machine_readable(last_updated)); break; @@ -2381,7 +2381,7 @@ handle_main_options(int argc, const char* const* argv) case 'c': // --cleanup { ProgressBar progress_bar("Cleaning..."); - ctx.storage.primary().clean_all( + ctx.storage.primary.clean_all( [&](double progress) { progress_bar.update(progress); }); if (isatty(STDOUT_FILENO)) { PRINT_RAW(stdout, "\n"); @@ -2392,7 +2392,7 @@ handle_main_options(int argc, const char* const* argv) case 'C': // --clear { ProgressBar progress_bar("Clearing..."); - ctx.storage.primary().wipe_all( + ctx.storage.primary.wipe_all( [&](double progress) { progress_bar.update(progress); }); if (isatty(STDOUT_FILENO)) { PRINT_RAW(stdout, "\n"); @@ -2475,7 +2475,7 @@ handle_main_options(int argc, const char* const* argv) core::StatisticsCounters counters; time_t last_updated; std::tie(counters, last_updated) = - ctx.storage.primary().get_all_statistics(); + ctx.storage.primary.get_all_statistics(); core::Statistics statistics(counters); PRINT_RAW(stdout, statistics.format_config_header(ctx.config)); PRINT_RAW(stdout, statistics.format_human_readable(last_updated, false)); @@ -2490,7 +2490,7 @@ handle_main_options(int argc, const char* const* argv) case 'x': // --show-compression { ProgressBar progress_bar("Scanning..."); - ctx.storage.primary().print_compression_statistics( + ctx.storage.primary.print_compression_statistics( [&](double progress) { progress_bar.update(progress); }); break; } @@ -2506,13 +2506,13 @@ handle_main_options(int argc, const char* const* argv) } ProgressBar progress_bar("Recompressing..."); - ctx.storage.primary().recompress( + ctx.storage.primary.recompress( wanted_level, [&](double progress) { progress_bar.update(progress); }); break; } case 'z': // --zero-stats - ctx.storage.primary().zero_all_statistics(); + ctx.storage.primary.zero_all_statistics(); PRINT_RAW(stdout, "Statistics zeroed\n"); break; diff --git a/src/storage/Storage.cpp b/src/storage/Storage.cpp index 51b51b7c2..316239023 100644 --- a/src/storage/Storage.cpp +++ b/src/storage/Storage.cpp @@ -155,9 +155,7 @@ get_storage(const Url& url) } } -Storage::Storage(const Config& config) - : m_config(config), - m_primary_storage(config) +Storage::Storage(const Config& config) : primary(config), m_config(config) { } @@ -171,20 +169,20 @@ Storage::~Storage() void Storage::initialize() { - m_primary_storage.initialize(); + primary.initialize(); add_secondary_storages(); } void Storage::finalize() { - m_primary_storage.finalize(); + primary.finalize(); } nonstd::optional Storage::get(const Digest& key, const core::CacheEntryType type) { - const auto path = m_primary_storage.get(key, type); + const auto path = primary.get(key, type); if (path) { return path; } @@ -202,7 +200,7 @@ Storage::get(const Digest& key, const core::CacheEntryType type) throw core::Fatal("Error writing to {}: {}", tmp_file.path, e.what()); } - m_primary_storage.put(key, type, [&](const std::string& path) { + primary.put(key, type, [&](const std::string& path) { try { Util::copy_file(tmp_file.path, path); } catch (const core::Error& e) { @@ -220,7 +218,7 @@ Storage::put(const Digest& key, const core::CacheEntryType type, const storage::EntryWriter& entry_writer) { - const auto path = m_primary_storage.put(key, type, entry_writer); + const auto path = primary.put(key, type, entry_writer); if (!path) { return false; } @@ -250,7 +248,7 @@ Storage::put(const Digest& key, void Storage::remove(const Digest& key, const core::CacheEntryType type) { - m_primary_storage.remove(key, type); + primary.remove(key, type); remove_from_secondary_storage(key); } diff --git a/src/storage/Storage.hpp b/src/storage/Storage.hpp index e3d10c696..fe905fd39 100644 --- a/src/storage/Storage.hpp +++ b/src/storage/Storage.hpp @@ -46,7 +46,7 @@ public: void initialize(); void finalize(); - primary::PrimaryStorage& primary(); + primary::PrimaryStorage primary; // Returns a path to a file containing the value. nonstd::optional get(const Digest& key, @@ -62,7 +62,6 @@ public: private: const Config& m_config; - primary::PrimaryStorage m_primary_storage; std::vector> m_secondary_storages; std::vector m_tmp_files; @@ -72,10 +71,4 @@ private: void remove_from_secondary_storage(const Digest& key); }; -inline primary::PrimaryStorage& -Storage::primary() -{ - return m_primary_storage; -} - } // namespace storage -- 2.47.3