Skip to content

Add optional Redis secondary storage backend - #875

Merged
jrosdahl merged 51 commits into
ccache:masterfrom
afbjorklund:redis-storage-backend
Jul 10, 2021
Merged

jrosdahl merged 51 commits into
ccache:masterfrom
afbjorklund:redis-storage-backend

Conversation

@afbjorklund

@afbjorklund afbjorklund commented Jun 28, 2021 •

Copy link
Copy Markdown
Contributor

Requires the "hiredis" library.

https://github.com/redis/hiredis

Tests also requires redis-server and redis-cli.

Closes #859.

@afbjorklund
afbjorklund force-pushed the redis-storage-backend branch 2 times, most recently from 677e26e to 7394b0c Compare June 28, 2021 21:49
Requires the "hiredis" library.

Tests also requires redis-server and redis-cli.

The attributes have not yet been implemented.

Closes ccache#859.
@afbjorklund
afbjorklund force-pushed the redis-storage-backend branch from 7394b0c to e93e8b4 Compare June 28, 2021 21:57
That is: pkgconfig/hiredis.pc instead of
         cmake/Hiredis/HiredisConfig.cmake

Needed for Homebrew, not needed for Ubuntu
@afbjorklund
afbjorklund force-pushed the redis-storage-backend branch from 7f812e9 to 1631f99 Compare June 29, 2021 06:28
The include directory is supposed to be added to the
search path (and it is, both for cmake and pkg-config)

Unfortunately this exposes a "pedantic" warning about
some C code not being valid C++ code, so suppress that.
@afbjorklund

afbjorklund commented Jun 30, 2021 •

Copy link
Copy Markdown
Contributor Author

Unfortunately there are some issues with the headers. The included "HiredisConfig.cmake" is broken, returning wrong include dir:

find_path(HIREDIS_INCLUDE_DIRS hiredis/hiredis.h HINTS "/usr/include")
find_library(HIREDIS_LIB_HIREDIS NAMES hiredis HINTS "/usr/lib")

Since you are supposed to include <hiredis.h> (as per the example code), the include directory needs to be "/usr/include/hiredis"

However, when you do - you get an error from the pedantic C++ treating warnings as errors. (When parsing system header)

/usr/include/hiredis/sds.h:48:10: error: ISO C++ forbids flexible array member ‘buf’ [-Werror=pedantic]

Final straw is that the different clang-format versions seem to argue about include order:

 
-#include <hiredis/hiredis.h>
 #include <storage/SecondaryStorage.hpp>
 #include <storage/types.hpp>
 
+#include <hiredis/hiredis.h>
+

When it comes to system headers, as compared to local headers (such as storage)

Comment thread test/suites/secondary_redis.bash Resolved
Comment thread CMakeLists.txt Resolved
@gjasny

gjasny commented Jun 30, 2021 •

Copy link
Copy Markdown
Contributor

Since you are supposed to include <hiredis.h> (as per the example code), the include directory needs to be "/usr/include/hiredis"

However, when you do - you get an error from the pedantic C++ treating warnings as errors. (When parsing system header)

/usr/include/hiredis/sds.h:48:10: error: ISO C++ forbids flexible array member ‘buf’ [-Werror=pedantic]

You could try making that include dir as a SYSTEM include. That usually shuts up the compiler warnings.

Another option is surrounding the include in your code with:

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
#endif

#include <hiredis.h>

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

But with multiple compilers that gets ugly pretty fast.

@afbjorklund

This comment has been minimized.

@afbjorklund

afbjorklund commented Jun 30, 2021 •

Copy link
Copy Markdown
Contributor Author

No idea why Redis won't shut down on Mac, would be thankful if someone could check it ?

ctest -V -R 'secondary.*'

Here (on Ubuntu) it runs faster than the file test, and shuts down happily once test is done.

34: PASSED
1/2 Test #34: test.secondary_file ..............   Passed    0.64 sec

35: PASSED
35: 3766025:signal-handler (1625083885) Received SIGTERM scheduling shutdown...
35: 3766025:signal-handler (1625083885) Received SIGTERM scheduling shutdown...
35: 3766025:M 30 Jun 2021 22:11:25.129 # User requested shutdown...
35: 3766025:M 30 Jun 2021 22:11:25.129 # Redis is now ready to exit, bye bye...
2/2 Test #35: test.secondary_redis .............   Passed    0.63 sec

Added a 10 second timeout, that should kill the redis-server.

Possibly we should mock the file access and redis access ?

@jrosdahl jrosdahl added the issue: feature New feature label Jul 1, 2021
@jrosdahl

jrosdahl commented Jul 1, 2021

Copy link
Copy Markdown
Member

Thanks for working on this!

The title says "WIP" but the PR is not marked as a draft. Do you want me to start reviewing or is it still WIP?

Unfortunately there are some issues with the headers. The included "HiredisConfig.cmake" is broken, returning wrong include dir:

find_path(HIREDIS_INCLUDE_DIRS hiredis/hiredis.h HINTS "/usr/include")
find_library(HIREDIS_LIB_HIREDIS NAMES hiredis HINTS "/usr/lib")

Since you are supposed to include <hiredis.h> (as per the example code), the include directory needs to be "/usr/include/hiredis"

I would spontaneously say that setting up the include path so that you #include <hiredis/hiredis.h> sounds better (a library shouldn't require a special -I IMO). What downside do you see what that variant?

Final straw is that the different clang-format versions seem to argue about include order:

I think that's not different clang-format versions but different configuration since I changed how include grouping works on master very recently.

No idea why Redis won't shut down on Mac, would be thankful if someone could check it ?

I have no idea either, but if it blocks you I'd say just disable the test on macOS for now.

@afbjorklund

afbjorklund commented Jul 1, 2021 •

Copy link
Copy Markdown
Contributor Author

Thanks for working on this!

The title says "WIP" but the PR is not marked as a draft. Do you want me to start reviewing or is it still WIP?

Sorry, some other github projects use "WIP" with a bot that sets a "work-in-progress-do-not-merge" label...

It is ready for review now, but could possibly need some squashing and rebasing before eventually merging ?

Since you are supposed to include <hiredis.h> (as per the example code), the include directory needs to be "/usr/include/hiredis"

I would spontaneously say that setting up the include path so that you #include <hiredis/hiredis.h> sounds better (a library shouldn't require a special -I IMO). What downside do you see what that variant?

There are no immediate downsides, it should work on "both" platforms (Ubuntu and Homebrew)

It is just that it is documented (examples and pkg-config) as <hiredis.h>, I suppose ?

https://docs.redislabs.com/latest/rs/references/client_references/client_c/

And we would need to add the homebrew prefix, if not relying on pkg-config for the include dir.

I seem to recall similar issues earlier when using glib, with <glib/glib.h> versus <glib.h> ?

No idea why Redis won't shut down on Mac, would be thankful if someone could check it ?

I have no idea either, but if it blocks you I'd say just disable the test on macOS for now.

The tests do pass, the only downside is that the test takedown takes an extra ~9 (10 - 1) seconds...

Instead of shutting down immediately when test is done (1s), it waits for the timeout (10s) to happen

@afbjorklund

afbjorklund commented Jul 1, 2021 •

Copy link
Copy Markdown
Contributor Author

It seems that there is a <module>_PREFIX variable set up in cmake when using pkg_check_modules

So if we don't want to use $HIREDIS_INCLUDEDIR, we could use $HIREDIS_PREFIX/include ?

https://cmake.org/cmake/help/latest/module/FindPkgConfig.html

I have no idea why CMake adds two similar variables, and they don't seem to match the documentation:

deb (from CMakeCache.txt, some variables not shown)

HIREDIS_INCLUDEDIR:INTERNAL=/usr/include/hiredis
HIREDIS_INCLUDE_DIRS:INTERNAL=/usr/include/hiredis
HIREDIS_LIBDIR:INTERNAL=/usr/lib
HIREDIS_LIBRARY_DIRS:INTERNAL=
HIREDIS_PREFIX:INTERNAL=/usr
HIREDIS_VERSION:INTERNAL=0.14.0

brew (from CMakeCache.txt, some variables not shown)

HIREDIS_INCLUDEDIR:INTERNAL=/home/anders/.linuxbrew/Cellar/hiredis/1.0.0/include/hiredis
HIREDIS_INCLUDE_DIRS:INTERNAL=/home/anders/.linuxbrew/Cellar/hiredis/1.0.0/include/hiredis
HIREDIS_LIBDIR:INTERNAL=/home/anders/.linuxbrew/Cellar/hiredis/1.0.0/lib
HIREDIS_LIBRARY_DIRS:INTERNAL=/home/anders/.linuxbrew/Cellar/hiredis/1.0.0/lib
HIREDIS_PREFIX:INTERNAL=/home/anders/.linuxbrew/Cellar/hiredis/1.0.0
HIREDIS_VERSION:INTERNAL=1.0.0

include_directories(${HIREDIS_INCLUDEDIR})
target_link_directories(ccache_lib PUBLIC ${HIREDIS_LIBDIR})


EDIT:
Apparently there is some removal of redundant directories, that deletes /usr/lib from LIBRARY_DIRS.
So the LIBDIR is the raw directory from pkg-config, and LIBRARY_DIRS is after cmake has processed it...

Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
Comment thread src/storage/secondary/RedisStorage.hpp Resolved
Comment thread test/suites/secondary_redis.bash Resolved
Comment thread test/suites/secondary_redis.bash Resolved
Comment thread test/suites/secondary_redis.bash Resolved
@afbjorklund

afbjorklund commented Jul 2, 2021 •

Copy link
Copy Markdown
Contributor Author

Final straw is that the different clang-format versions seem to argue about include order:

I think that's not different clang-format versions but different configuration since I changed how include grouping works on master very recently.

Changed it, and it fell apart. So there is definitely some difference between format target and "Code formatting" ?

https://github.com/ccache/ccache/pull/875/checks?check_run_id=2974781282

Locally:

$ VERBOSE=1  misc/format-files --all --check
clang-format version 10.0.1 (https://github.com/muttleyxd/clang-format-static-binaries 22538c65f5523303768249afb8b52742bd0b7f32)
$

GitHub CI:

clang-format version 10.0.1 (https://github.com/muttleyxd/clang-format-static-binaries 22538c65f5523303768249afb8b52742bd0b7f32)
Error: src/storage/secondary/RedisStorage.hpp not formatted with Clang-Format

Would it help, if it the local files didn't use system includes ?

#pragma once

#include "storage/SecondaryStorage.hpp"
#include "storage/types.hpp"

#include <hiredis/hiredis.h>

Unfortunately this exposes a "pedantic" warning about
some C code not being valid C++ code, so suppress that.
@afbjorklund

afbjorklund commented Jul 9, 2021 •

Copy link
Copy Markdown
Contributor Author

Looks like it doesn't build on Windows after all.

return type ‘struct storage::secondary::timeval’ is incomplete

Inclined to going back to just disabling Redis there.

EDIT: Seems that I had just missed to include a hiredis <win32.h> header.

Except that the whole thing is guarded by #ifdef _MSC_VER (Microsoft C++)

#include <winsock2.h> /* for struct timeval */

@afbjorklund
afbjorklund force-pushed the redis-storage-backend branch from 8368cbb to 5e6afb2 Compare July 9, 2021 19:53
@afbjorklund

afbjorklund commented Jul 10, 2021 •

Copy link
Copy Markdown
Contributor Author

There are still test flakes on Mac, the server starts up in 3 us but it still cannot contact Redis ?

Could not connect to Redis at 127.0.0.1:7777: Connection refused

Most likely the "sleep" command doesn't support fractions, so that sleep 0.1 means sleep 0 ?

And the new kill setup doesn't seem to be working either...

41/42 Test #36: test.secondary_redis .............***Failed 10.40 sec

After 10 seconds the timeout kicks in, and stops the server.

@jrosdahl

Copy link
Copy Markdown
Member

Looks like it doesn't build on Windows after all.

EDIT: Seems that I had just missed to include a hiredis <win32.h> header.

Except that the whole thing is guarded by #ifdef _MSC_VER (Microsoft C++)

#include <winsock2.h> /* for struct timeval */

I think you should add

#ifdef HAVE_SYS_TIME_H
#  include <sys/time.h>
#endif

to RedisStorage.hpp instead (and remove the forward declaration of struct timeval). That should fix the "invalid application of ‘sizeof’ to incomplete type ‘storage::secondary::timeval’" errors you see as well.

@afbjorklund

afbjorklund commented Jul 10, 2021 •

Copy link
Copy Markdown
Contributor Author

Right, I included the local headers before the system headers.. <DOH>

But since we're not using CLI defines, I guess I also need config.h in there ?

Should try to get a MinGW build environment setup again, failing for some reason...

CMake Error at /usr/share/cmake-3.16/Modules/CheckTypeSize.cmake:120 (try_compile):


Looks like that cmake output is "normal", but still ended up with a compile error.

In file included from ../../src/core/wincompat.hpp:80,
                 from ../../src/Config.cpp:30:
/usr/share/mingw-w64/include/winsock2.h:15:2: error: #warning Please include winsock2.h before windows.h [-Werror=cpp]
   15 | #warning Please include winsock2.h before windows.h
      |  ^~~~~~~
cc1plus: all warnings being treated as errors

Seems like this compiler is too old for ccache.

../../src/Stat.cpp:67:38: error: ‘FILE_ATTRIBUTE_TAG_INFO’ does not name a type; did you mean ‘FILE_ATTRIBUTE_OFFLINE’?

../../src/Stat.cpp:144:12: error: ‘GetFileInformationByHandleEx’ was not declared in this scope; did you mean ‘GetFileInformationByHandle’?

Also do it in the header, before timeval
@jrosdahl

Copy link
Copy Markdown
Member

we can't really build a static library (without patching hiredis)

Right, we need a static library with -DHIREDIS_FROM_INTERNET since I don't think it's reasonable to have to install a custom shared library alongside ccache. (In fact, I'm inclined to default to static linking for dependencies, including libzstd and libhiredis in all use cases.)

Since there is no static target in the CMakeLists.txt

It seems like there is a static library target on hiredis master but it's not included in a release yet.

Maybe we should just give up and bundle dependencies instead... 🤔

@afbjorklund

afbjorklund commented Jul 10, 2021 •

Copy link
Copy Markdown
Contributor Author

Maybe we should just give up and bundle dependencies instead... thinking

For this library we could go back to making it optional, and disable it on Windows.

I would be fine with making it compile on Windows of course, like this timeval

You could (as a user) use something like MSYS2, to handle the system dependencies.

https://packages.msys2.org/base/mingw-w64-hiredis

@jrosdahl

jrosdahl commented Jul 10, 2021 •

Copy link
Copy Markdown
Member

I guess I also need config.h in there ?

config.h is always included implicitly nowadays:

target_compile_options(
standard_settings
INTERFACE -include ${CMAKE_BINARY_DIR}/config.h
)

@jrosdahl

jrosdahl commented Jul 10, 2021 •

Copy link
Copy Markdown
Member

For this library we could go back to making it optional, and disable it on Windows.

I'm OK with it being optional (as in "opt out"), but it should be easy enough to create a static library of our own for the Windows build.

But I think you can leave the Redis backend disabled for the Windows builds for now so that it doesn't block your PR progress. Then I can have a look at improving this later. Sounds OK?

@afbjorklund

Copy link
Copy Markdown
Contributor Author

Sounds good, then I can remove some of the other hacks as well. Maybe leave find_package, but clean it up.

Maybe this was apparent, but the aim was to do a squash and rebase before merging this work-in-progress :-D

@jrosdahl

Copy link
Copy Markdown
Member

Maybe this was apparent, but the aim was to do a squash and rebase before merging this work-in-progress :-D

Sure. And you don't have to squash unless you want to – I always do that as part of merging anyway (unless it's obvious that the PR author has separated stuff in clean commits).

@afbjorklund

Copy link
Copy Markdown
Contributor Author

I mostly meant the merges and the reverts, but there were some other minor fixes that could be squashed together.

@afbjorklund
afbjorklund force-pushed the redis-storage-backend branch from 62d91c0 to e0f6b2c Compare July 10, 2021 14:54
@jrosdahl jrosdahl added this to the 4.4 milestone Jul 10, 2021
@jrosdahl
jrosdahl merged commit 1ef6348 into ccache:master Jul 10, 2021
@jrosdahl

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue: feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage backends: Redis

3 participants