]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Improve fix for local/remote cache misses in depend mode
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 20 Dec 2022 20:57:33 +0000 (21:57 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 20 Dec 2022 20:57:33 +0000 (21:57 +0100)
src/ccache.cpp
src/storage/Storage.cpp
src/storage/local/LocalStorage.cpp
test/suites/remote_file.bash

index 8791f788eddc4c114c45d3e585161eb43b875e57..c8a21ac354d96fc9a8904961c55f329cf6dfecb8 100644 (file)
@@ -2260,8 +2260,24 @@ cache_compilation(int argc, const char* const* argv)
     MTR_END("main", "find_compiler");
 
     const auto result = do_cache_compilation(ctx, argv);
-    const auto& counters = result ? *result : result.error().counters();
-    ctx.storage.local.increment_statistics(counters);
+    ctx.storage.local.increment_statistics(result ? *result
+                                                  : result.error().counters());
+    const auto& counters = ctx.storage.local.get_statistics_updates();
+
+    if (counters.get(Statistic::cache_miss) > 0) {
+      if (!ctx.config.remote_only()) {
+        ctx.storage.local.increment_statistic(Statistic::local_storage_miss);
+      }
+      if (ctx.storage.has_remote_storage()) {
+        ctx.storage.local.increment_statistic(Statistic::remote_storage_miss);
+      }
+    } else if ((counters.get(Statistic::direct_cache_hit) > 0
+                || counters.get(Statistic::preprocessed_cache_hit) > 0)
+               && counters.get(Statistic::remote_storage_hit) > 0
+               && !ctx.config.remote_only()) {
+      ctx.storage.local.increment_statistic(Statistic::local_storage_miss);
+    }
+
     if (!result) {
       if (result.error().exit_code()) {
         return *result.error().exit_code();
index da707ea6e429d890f63ff300ff99bdda06c58aab..775f4be77a48a1f945b6d2a18180609ae5752e61 100644 (file)
@@ -461,14 +461,6 @@ Storage::get_from_remote_storage(const Digest& key,
           backend->url_for_logging,
           ms);
       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 f1984caa8648a43ee63cf4da329becc6c904e774..c774c73875177b1e5f4ad8297aac837561746e66 100644 (file)
@@ -220,14 +220,8 @@ LocalStorage::get(const Digest& key, const core::CacheEntryType type)
 
   increment_statistic(return_value ? core::Statistic::local_storage_read_hit
                                    : core::Statistic::local_storage_read_miss);
-  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);
+  if (return_value && type == core::CacheEntryType::result) {
+    increment_statistic(core::Statistic::local_storage_hit);
   }
 
   return return_value;
index a48ae561c465896d57591093be043433b571a66e..39184884b727e7e10b7fff8ffc96791ec5e71a85 100644 (file)
@@ -11,7 +11,9 @@ SUITE_remote_file_SETUP() {
     unset CCACHE_NODIRECT
     export CCACHE_REMOTE_STORAGE="file:$PWD/remote"
 
-    generate_code 1 test.c
+    touch test.h
+    echo '#include "test.h"' >test.c
+    backdate test.h
 }
 
 SUITE_remote_file() {
@@ -239,7 +241,7 @@ SUITE_remote_file() {
     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_miss 2
     expect_stat local_storage_read_hit 2
     expect_stat local_storage_read_miss 3
     expect_stat local_storage_write 4
@@ -249,6 +251,24 @@ SUITE_remote_file() {
     expect_stat remote_storage_read_miss 1
     expect_stat remote_storage_write 2 # result + manifest
 
+    # Remote cache read hit for the manifest but no manifest entry matches.
+    $CCACHE -C >/dev/null
+    echo 'int x;' >>test.h
+    backdate test.h
+    $CCACHE_COMPILE -MMD -c test.c
+    expect_stat direct_cache_hit 2
+    expect_stat cache_miss 2
+    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 4 # one manifest read miss
+    expect_stat local_storage_write 7 # download+store manifest, update+store manifest, write result
+    expect_stat remote_storage_hit 1
+    expect_stat remote_storage_miss 2
+    expect_stat remote_storage_read_hit 3
+    expect_stat remote_storage_read_miss 1 # original manifest didn't match -> no read
+    expect_stat remote_storage_write 4
+
     # -------------------------------------------------------------------------
     TEST "umask"