Skip to content
Radu Popescu edited this page Jan 31, 2018 · 2 revisions

A CernVM FS cache plugin based on Redis

In this tutorial we will learn how to build a CernVM FS cache plugin. The plugin we will develop uses Redis as a backing store.

Requirements

For the tutorial, CernVM FS is needed. On Linux, we can use the latest public release of the client and development tool packages (cvmfs and cvmfs-dev). On macOS, please download this version of the package.

The cache plugin requires the Redis server and the hiredis C client library, as well as libev. These dependencies can be installed on Debian, Ubuntu:

$ sudo apt-get install g++ cmake make redis-{server,tools} libhiredis-dev libev-dev

or on macOS:

$ brew install cmake redis hiredis libev

Overview of the cache plugin API

Cache plugins are separate processes which communicate with the main CernVM FS client process through a socket, using a well defined protocol. Creating a cache plugin involves implementing a set of callback functions which are registered with the cache plugin helper library's event loop during the plugin's initialization phase.

The callback functions are grouped into different capability levels: reading, writing, listing, getting the total space information for the cache etc. A plugin can declare its own capability level but, at minimum, must implement the reading capability.

At the beginning of the plugin's main function, the plugin should be initialized: this involves parsing the configuration parameters, creating a plugin context and registering the plugin callbacks, initializing the connection with the CVMFS client process. Finally the plugin enters its own event loop.

For the purpose of the tutorial, the plugin will only implement reading and writing capabilities.

The full documentation for the cache plugin API is available on the documentation page. It can also be useful to inspect the header of the cache plugin utility library, at /usr/local/include/libcvmfs_cache.h.

We can use the example dummy plugin - included with the tutorial code - as a starting point for the redis plugin. This dummy plugin stores objects in memory using std::map containers.

Compiling the example code

To build the redis cache plugin, first initialize the Git submodules:

$ git submodule init && git submodule update

The only submodule is the redox library, which provides a convenient C++ interface to Redis. With the submodule initialized, we can configure and build the plugin:

$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install

Running the plugin

During development, the plugin can be run independently of CVMFS (we assume this command is run in the root of the Git repo):

$ /usr/local/bin/cache-redis config/cache-redis.conf

With the plugin started, we can mount a CVMFS repository configured to use it as a cache manager. The tutorial repository includes the example configuration file for the CMS repository. When the CVMFS_CACHE_redis_CMDLINE configuration parameter is set, the plugin will run in supervised mode - the main CVMFS process is responsible to spawn the cache plugin process and connect to it.