Skip to content

About

C++17 hotrod client for Infinispan cluster

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Infinispan Hot Rod Client — C++17

A cross-platform C++17 client for Infinispan using the Hot Rod binary protocol (version 4.0/4.1). It is a smart client: it routes keys to their primary owner (hash-aware), fails over automatically, and exposes every operation as a std::future.

Features

  • Full CRUD — PING, GET, PUT, REMOVE.
  • Metadata and version-based (CAS) operations — getWithMetadata, putIfAbsent, replace, containsKey, removeWithVersion, replaceWithVersion.
  • Async API — every operation returns a std::future; operations on a server share one multiplexed connection.
  • Hash-aware routing and failover — consistent hashing (MurmurHash3 x64_32), topology awareness, automatic failover, connection pooling.
  • Multi-server seed list — all hosts in a URI become seeds with startup and runtime failover.
  • Hot Rod URI — build a configured client from a connection string (RemoteCache::fromUri).
  • Security — SASL authentication (SCRAM-SHA-1/256/512, PLAIN, EXTERNAL, OAUTHBEARER) and TLS including mutual TLS (PEM material).
  • Typed error handling — HotRodClientException with user-decided retry for keyed and keyless operations.

For live status and the backlog, see docs/STATUS.md.

Installation

Build requirements

  • A C++17 compiler (GCC 7+, Clang 6+, MSVC 19.20+)
  • CMake 3.15+
  • OpenSSL 1.1.1+ or 3.x
  • Google Test (for the test suite)

Runtime requirements

  • Infinispan Server 16.0+ (integration suites run against :latest)
  • Docker (for integration tests and the quickstart example)

Build the static library (build/libhotrod-client.a):

cmake -S . -B build
cmake --build build

Link against it by adding include/ to your include path and linking libhotrod-client.a (and pthread). See examples/quickstart/CMakeLists.txt for a complete consumer.

Quick Start

#include "hotrod/RemoteCache.h"

using namespace hotrod;

int main() {
    RemoteCache cache("localhost", 11222, "my-cache");
    cache.setClientIntelligence(ClientIntelligence::HASH_DISTRIBUTION_AWARE);
    cache.connect();

    ByteArray key{'k'};
    ByteArray value{'v'};

    cache.put(key, value).get();            // store
    if (auto result = cache.get(key).get()) // std::optional<ByteArray>
        /* use *result */;

    cache.disconnect();
}

A complete, runnable example (with a server launcher) lives in examples/quickstart/:

cd examples/quickstart
./start-server.sh                 # start Infinispan in a container
cmake -S . -B build && cmake --build build
./build/quickstart

Keys and values are ByteArray (std::vector<uint8_t>); the caller marshals its own types. A second example, retry.cpp, demonstrates the user-decided retry loop.

Connection URI

RemoteCache::fromUri builds a configured (not yet connected) client from a connection string. Because RemoteCache is non-movable, it returns a std::unique_ptr:

// hotrod[s]://[user:password@]host1[:port1][,host2[:port2]...][?key=value&...]
auto cache = RemoteCache::fromUri(
    "hotrod://user:password@node1:11222,node2:11222"
    "?sasl_mechanism=SCRAM-SHA-256&client_intelligence=hash_distribution_aware",
    "my-cache");
cache->connect();

All comma-separated hosts become seed servers. The hotrods:// scheme enables TLS; credentials in the userinfo enable SASL. Userinfo and query values are percent-decoded (RFC 3986), so a reserved character in a password is written encoded (for example p@ss → admin:p%40ss@host).

Query key Meaning
client_intelligence basic, topology_aware, or hash_distribution_aware
protocol_version 4.0 or 4.1
sasl_mechanism SASL mechanism name
token bearer token for OAUTHBEARER
ca_file, sni_host_name, ssl_hostname_validation TLS server trust
client_cert_file, client_key_file, client_key_password mutual-TLS client identity

An unknown parameter, a bad value, or a Java keystore key is rejected. Connection timeouts, protocol_version=AUTO, and GSSAPI are not supported yet (issue #10).

Options

Configure these on the RemoteCache before connect():

Setter Purpose
setClientIntelligence(...) cluster-awareness level (default from constructor)
setProtocolVersion(...) Protocol::VERSION_40 / VERSION_41 (default 4.1)
setAuthentication(...) SASL credentials or mechanism
setTls(...) TLS transport encryption (PEM material)
setProxyToNonOwner(bool) owner-to-non-owner routing fallback (default true)

Cache Operations

Every operation is asynchronous; call .get() to wait.

cache.put(key, value).get();                 // store; optional lifespan/maxIdle (seconds)
auto v = cache.get(key).get();               // std::optional<ByteArray>
auto prev = cache.remove(key).get();         // std::optional<EntryWithMetadata>
bool present = cache.containsKey(key).get();

// Metadata + version-based CAS:
if (auto entry = cache.getWithMetadata(key).get()) {
    int64_t version = entry->metadata.version;
    bool replaced = cache.replaceWithVersion(key, newValue, version).get();
}

Pass previousValue = true to put/putIfAbsent/replace/remove to receive the prior entry. See the Cache Operations guide.

Security

// SASL (defaults to SCRAM-SHA-256):
cache.setAuthentication("username", "password");

// TLS (empty ca_file = system trust store):
cache.setTls("/etc/pki/ca.pem");

All certificate material is PEM (not Java JKS/PKCS12). Mutual TLS and the EXTERNAL/OAUTHBEARER mechanisms are configured through TlsConfig and Authentication. See the Security guide for the full details.

Error Handling and Retry

Failures surface as HotRodClientException (a std::runtime_error) from future.get(). Retry is user-decided: catch the exception, classify it, and feed it back as the exclusion set for the next attempt.

try {
    cache.put(key, value).get();
} catch (const HotRodClientException& e) {
    if (isTransient(e)) cache.excluding(e).put(key, value).get();
    else throw;
}

See the Error Handling guide and examples/quickstart/retry.cpp.

Building

Linux (Fedora/RHEL)

sudo dnf install cmake gcc-c++ openssl-devel gtest-devel
cmake -S . -B build && cmake --build build -j$(nproc)
ctest --test-dir build --output-on-failure

Linux (Ubuntu/Debian)

sudo apt install cmake g++ libssl-dev libgtest-dev
cmake -S . -B build && cmake --build build -j$(nproc)
ctest --test-dir build --output-on-failure

Windows (PowerShell)

vcpkg install openssl gtest
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=[path-to-vcpkg]/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --test-dir build -C Release --output-on-failure

Testing

# Unit tests (fast, no server):
./build/unit_tests

# Integration tests (require Docker; start Infinispan automatically):
ctest --test-dir build --output-on-failure

Integration tests use Docker Compose to manage multi-node Infinispan clusters and verify failover, rebalancing, and hash-aware routing. See docs/STATUS.md for the current coverage breakdown.

Code coverage (opt-in)

Configure with -DENABLE_COVERAGE=ON (GCC/Clang; forces a Debug build) and run the tests, then aggregate. Requires gcovr; the patch target also needs diff-cover.

cmake -S . -B build-cov -DENABLE_COVERAGE=ON
cmake --build build-cov
ctest --test-dir build-cov                         # run the suites you want measured
cmake --build build-cov --target coverage          # full report -> build-cov/coverage/index.html
cmake --build build-cov --target coverage-diff     # patch coverage vs origin/main

coverage-diff reports coverage of only the lines changed versus a base ref (-DCOVERAGE_DIFF_BASE=<ref>, default origin/main); set -DCOVERAGE_DIFF_THRESHOLD=<pct> to fail below a patch percentage. coverage-reset clears stale counters between runs.

Documentation

The user guide lives in documentation/ (AsciiDoc). Render it to self-contained HTML with:

./scripts/build-docs.sh            # → documentation/_build/index.html
./scripts/build-docs.sh --serve    # render + serve at http://localhost:8000
./scripts/build-docs.sh --watch    # rebuild on save (needs entr)
# or, via CMake:
cmake --build build --target docs

On push to main the guide is published to GitHub Pages by .github/workflows/docs.yml.

Project Structure

cpp17-client/
├── CMakeLists.txt          # Build configuration (library, tests, docs target)
├── include/hotrod/         # Public API headers (RemoteCache.h, HotRodURI.h, ...)
├── src/                    # Implementation (codec, transport, topology, hash, operations, auth)
├── tests/                  # unit/ (gtest) and integration/ (Docker, multi-node clusters)
├── documentation/          # AsciiDoc user guide (index.adoc + topics/)
├── examples/quickstart/    # GET/PUT/REMOVE + retry + auth examples
├── scripts/                # build-docs.sh + test cluster infrastructure
├── test-configs/           # Server configurations (compose + XML)
└── docs/                   # STATUS.md, DECISIONS.md, WORKFLOW.md

Status and Contributing

Live status is in docs/STATUS.md; design rationale and dated history are in docs/DECISIONS.md. If you are picking this up after a break, start with docs/WORKFLOW.md — the per-session workflow built for intermittent, solo work. When you change project source, update docs/STATUS.md in the same commit (a pre-commit hook enforces it).

References

License

Apache 2.0 (matching the Infinispan project).

About

C++17 hotrod client for Infinispan cluster

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages