Joel Rosdahl [Sun, 8 Aug 2021 08:40:58 +0000 (10:40 +0200)]
refactor: Improve handling of statistics updates and expected events
Ccache uses exceptions for both truly exceptional events (such as I/O
error) and non-exceptional events (such as unsupported compiler
arguments). Regardless of the nature of the event, at most one
statistics counter can be incremented.
Improve this by:
- Using nonstd::expected instead of exceptions internally in the main
code flow. This makes the code easier to reason about.
- Adding support for communicating several statistics counter updates
both for success and failure code paths. This is in preparation for
future improvements of statistics related to secondary storage.
Joel Rosdahl [Sat, 7 Aug 2021 11:12:56 +0000 (13:12 +0200)]
fix: Don’t read let Context read user configuration in unit tests
accd21e4 inadvertently made unit tests populate Context::config from the
environment and the user configuration. Fix this by moving code for
reading config, setting of logging, etc. into a separate method only to
be called by non-test code.
Joel Rosdahl [Sat, 7 Aug 2021 07:00:17 +0000 (09:00 +0200)]
feat(storage): Add support for cache sharding on secondary storage (#912)
This adds support for a shards attribute with a comma-separated list of
names for sharding (partitioning) the cache entries using Rendezvous
hashing, typically to spread the cache over a server cluster. When set,
the storage URL must contain an asterisk (*), which will be replaced by
one of the shard names to form a real URL. A shard name can optionally
have an appended weight within parentheses to indicate how much of the
key space should be associated with that shard. A shard with weight w
will contain w/S of the cache, where S is the sum of all shard weights.
A weight could for instance be set to represent the available memory for
a memory cache on a specific server. The default weight is 1.
will put 55% (3/5.5) of the cache on redis://cache-a.example.com, 18%
(1/5.5) on redis://cache-b.example.com and 27% (1.5/5.5) on
redis://cache-c.example.com.
Joel Rosdahl [Fri, 30 Jul 2021 18:10:50 +0000 (20:10 +0200)]
build: Only probe for faster linker in dev build mode and on x86_64
Using Gold or LLD on less common platforms such as MIPS may not be a
good idea (see e.g.
<https://www.sourceware.org/bugzilla/show_bug.cgi?id=22838>), so be
conservative and only probe for a faster linker on platforms that likely
don’t have toolchain bugs. Also, using a faster linker is in practice
only relevant for dev builds.
Arne Hasselbring [Fri, 30 Jul 2021 18:29:45 +0000 (20:29 +0200)]
fix: Disable preprocessor hits for PCHs with Clang again (#909)
I added this in 3ec58dbcaa1e7903d59dce4c77baff7bc3783269 as I thought
clang only saves the timestamps of included files, so as long as they
are turned off by -Xclang -fno-pch-timestamp, preprocessed hits should be
possible. However, clang also saves the size and possibly a hash of the
un-preprocessed source file, so preprocessed hits don't make much sense.
As long as only the timestamp of a PCH source file changed, e.g. through
git operations, there should still be direct hits.
Joel Rosdahl [Fri, 30 Jul 2021 08:19:35 +0000 (10:19 +0200)]
build: Improve message when pkg-config can’t find libhiredis
pkg_check_modules stops immediately when given the REQUIRED argument so
the nicer error message won’t be reached. Fix this by simply removing
REQUIRED since that will make the configuration step fail in a better
way.
Joel Rosdahl [Wed, 28 Jul 2021 18:15:10 +0000 (20:15 +0200)]
build: Remove “_lib” suffix from ccache_lib and third_party_lib
This means that libthird_party_lib.a will become libthird_party.a which
removes repetition of “lib”. ccache_lib can’t be renamed to just ccache
since that’s the name of the main binary, so that’s renamed to
ccache_framework.
Joel Rosdahl [Thu, 22 Jul 2021 11:06:40 +0000 (13:06 +0200)]
Move/split statistics functionality into core and storage::primary
- The Counters class has been moved to core::StatisticsCounters.
- Functionality in the Statistics namespace has been split into:
- core::StatsLog: Knows about “stats log” format.
- core::Statistics: Knows about properties of statistics fields and
how to present them.
- storage::primary::PrimaryStorage: Knows how to store and update
statistics in the primary storage backend.
- storage::primary::StatsFile: Knows about the “stats file” format.
Joel Rosdahl [Mon, 19 Jul 2021 10:50:20 +0000 (12:50 +0200)]
HTTP storage: Fix crash when not specifying port
Url::port(const std::string&) apparently doesn’t accept an empty string
as the port (even though Url::port() can return an empty string), so
work around that.
Joel Rosdahl [Fri, 16 Jul 2021 20:12:17 +0000 (22:12 +0200)]
Improve secondary storage framework
- Let the secondary storage framework create backend instances on demand and
track their failure state - the framework will stop calling a backend after a
connection error/timeout. This makes it possible for a backend to create a
connection in the constructor if wanted.
- Added API and implementation for redacting secrets in secondary storage URLs
and attributes. Passwords in URLs are now redacted in debug logs but not for
"ccache -p" and "ccache -k secondary_storage".
- Adapted existing storage backends to the new APIs. In particular, the Redis
backend could be simplified.
- Moved the SecondaryStorage class to src/storage/secondary, analogous to
PrimaryStorage which is in src/storage/primary.
Joel Rosdahl [Sun, 11 Jul 2021 19:57:40 +0000 (21:57 +0200)]
Remove read-only tests of HTTP and Redis storage backends
The “read-only” tests in secondary_http and secondary_redis were
inspired by the “read-only” test in secondary_file. However, that test
actually verifies the secondary storage *framework*, not the storage
backend itself, so it’s enough to just do it in secondary_file.
Joel Rosdahl [Sun, 11 Jul 2021 19:51:49 +0000 (21:51 +0200)]
Make secondary_http and secondary_redis tests independent
Instead of starting an HTTP or Redis server that lives for the duration
of the test suite, start a new one for each test case. This makes tests
more independent and also opens up for future testing of e.g. different
ports and authentication modes by allowing different server
configurations for each test case.