]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix reporting of local/remote cache misses in depend mode
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Dec 2022 19:32:15 +0000 (20:32 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Dec 2022 19:38:38 +0000 (20:38 +0100)
src/ccache.cpp
src/storage/Storage.cpp
src/storage/local/LocalStorage.cpp
test/suites/remote_file.bash

index c063a58fe0c6c1d76746340ef21e7984f50e7c41..8791f788eddc4c114c45d3e585161eb43b875e57 100644 (file)
@@ -631,6 +631,11 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
 static std::optional<Digest>
 result_key_from_depfile(Context& ctx, Hash& hash)
 {
+  // Make sure that result hash will always be different from the manifest hash
+  // since there otherwise may a storage key collision (in case the dependency
+  // file is empty).
+  hash.hash_delimiter("result");
+
   const auto file_content =
     util::read_file<std::string>(ctx.args_info.output_dep);
   if (!file_content) {
index 5c843db27baee11b97b19ca55b8de4dc3745ceda..da707ea6e429d890f63ff300ff99bdda06c58aab 100644 (file)
@@ -463,6 +463,11 @@ Storage::get_from_remote_storage(const Digest& key,
       local.increment_statistic(core::Statistic::remote_storage_read_miss);
       if (type == core::CacheEntryType::result) {
         local.increment_statistic(core::Statistic::remote_storage_miss);
+      } else if (m_config.depend_mode()) {
+        // With the depend mode enabled, a missing manifest means that we can't
+        // even try to look up a result, so note the miss already now.
+        ASSERT(type == core::CacheEntryType::manifest);
+        local.increment_statistic(core::Statistic::remote_storage_miss);
       }
     }
   }
index 274a4460381acbc41093e078fa7b7fafa8ddddfb..f1984caa8648a43ee63cf4da329becc6c904e774 100644 (file)
@@ -223,6 +223,11 @@ LocalStorage::get(const Digest& key, const core::CacheEntryType type)
   if (type == core::CacheEntryType::result) {
     increment_statistic(return_value ? core::Statistic::local_storage_hit
                                      : core::Statistic::local_storage_miss);
+  } else if (m_config.depend_mode() && !return_value) {
+    // With the depend mode enabled, a missing manifest means that we can't even
+    // try to look up a result, so note the miss already now.
+    ASSERT(type == core::CacheEntryType::manifest);
+    increment_statistic(core::Statistic::local_storage_miss);
   }
 
   return return_value;
index c4a8c1d293106ad28f72dfeaef31a19626591e7f..a48ae561c465896d57591093be043433b571a66e 100644 (file)
@@ -194,6 +194,61 @@ SUITE_remote_file() {
     expect_stat files_in_cache 4
     expect_file_count 3 '*' remote # CACHEDIR.TAG + result + manifest
 
+    # -------------------------------------------------------------------------
+    TEST "Depend mode"
+
+    export CCACHE_DEPEND=1
+
+    # Compile and send result to local and remote storage.
+    $CCACHE_COMPILE -MMD -c test.c
+    expect_stat direct_cache_hit 0
+    expect_stat cache_miss 1
+    expect_stat files_in_cache 2
+    expect_stat local_storage_hit 0
+    expect_stat local_storage_miss 1
+    expect_stat local_storage_read_hit 0
+    expect_stat local_storage_read_miss 1 # only manifest
+    expect_stat local_storage_write 2 # result + manifest
+    expect_stat remote_storage_hit 0
+    expect_stat remote_storage_miss 1
+    expect_stat remote_storage_read_hit 0
+    expect_stat remote_storage_read_miss 1 # only manifest
+    expect_stat remote_storage_write 2 # result + manifest
+
+    # Get result from local storage.
+    $CCACHE_COMPILE -MMD -c test.c
+    expect_stat direct_cache_hit 1
+    expect_stat cache_miss 1
+    expect_stat local_storage_hit 1
+    expect_stat local_storage_miss 1
+    expect_stat local_storage_read_hit 2 # result + manifest
+    expect_stat local_storage_read_miss 1 # manifest
+    expect_stat local_storage_write 2 # result + manifest
+    expect_stat remote_storage_hit 0
+    expect_stat remote_storage_miss 1
+    expect_stat remote_storage_read_hit 0
+    expect_stat remote_storage_read_miss 1
+    expect_stat remote_storage_write 2
+
+    # Clear local storage.
+    $CCACHE -C >/dev/null
+
+    # Get result from remote storage, copying it to local storage.
+    # TERM=xterm-256color gdb --args $CCACHE_COMPILE -MMD -c test.c
+    $CCACHE_COMPILE -MMD -c test.c
+    expect_stat direct_cache_hit 2
+    expect_stat cache_miss 1
+    expect_stat local_storage_hit 1
+    expect_stat local_storage_miss 3
+    expect_stat local_storage_read_hit 2
+    expect_stat local_storage_read_miss 3
+    expect_stat local_storage_write 4
+    expect_stat remote_storage_hit 1
+    expect_stat remote_storage_miss 1
+    expect_stat remote_storage_read_hit 2 # result + manifest
+    expect_stat remote_storage_read_miss 1
+    expect_stat remote_storage_write 2 # result + manifest
+
     # -------------------------------------------------------------------------
     TEST "umask"