C++ server analysis cache does not work

  • ALM used: GitHub
  • CI system used: GitHub Workflow
  • Scanner command used when applicable:
    mvn -B -s .github/configs/m2/settings.xml verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.10.0.2594:sonar -Pubuntu18 -Dbuild-type=Debug -DskipDocumentation -Dcoverage -Dsonar.cfamily.compile-commands=./compile_commands.json -Dsonar.cfamily.analysisCache.mode=server -Dsonar.coverage.jacoco.xmlReportPaths=$(pwd)/coverage-aggregator/target/site/jacoco-aggregate/jacoco.xml -PnativeVerbose -PwithoutBacktrace

We have the following setup:
A nightly job which runs against main and there I would assume the analysis should be uploaded to Sonar server. Then we have all the PR jobs which run sonar scan as well. For the scans that are done with the PRs, there is always no hit from cache. Why is that?
My understanding is that, when we run Sonar scan for the PRs, it will look for cache for main, which should be there due to the nightly scan. But this is obviously not the case.
Is this setup wrong? What is your suggestion? Thank you.

Is the issue that no cache is found on the server, or that there are no cache hits?

The log says Loading cache from: server, so I assume there should be cache on the server.
Also in the log Cache: 0/621 hits, 7364897 bytes

Even on the nightly build, it seems to me, if we run against a new commit(because a few new PRs are merged to main) on a new day, the cache is not used:

  1. The 1st run for commit bbaa3b2 at 05:45 on Feb 16 warmed up the cache
  2. The 2nd run for the same commit at 11:21 on Feb 16 has a 100% hit
  3. The run on Feb 17 for a new commit b750420 has 0% hit
  4. the runs on Feb 18 and 19(during the weekend) for the same commit has 100% hit

Hi @pkidpkid, and thanks for sharing the problem with us,

To help us track down the issue. Would it be possible for you to share the full scanner logs for a run where the cache hit rate is 0? This can be obtained by adding the -Dsonar.verbose=true to your scanner command-line.

Let me know if you prefer to share them privately so that I can start a private thread with you…

Best regards,
Michael

Thank you Michael and sorry I was in an event for the last week, so I was not able to reply. Yes, please start a private thread with me.