This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a TiKV Client for C++ - a C++ client library for TiKV (distributed transactional key-value database). It is built on top of the TiKV Client in Rust via cxx - a safe FFI bridge between Rust and C++.
Status: Proof-of-concept stage, under heavy development. Currently only supports synchronous API.
# Install Rust environment
curl https://sh.rustup.rs -sSf | sh# Debug build
cmake -S . -B build && cmake --build build
# Release build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build
# Install to /usr/local
sudo cmake --install buildExamples require a running TiKV server:
# Start TiKV (using tiup)
tiup playground nightly
# Build examples
cd example && cmake -S . -B build && cmake --build build
# Run examples
./build/raw # Raw KV API example
./build/txn # Transaction API exampleThis project uses a dual-language architecture with Rust providing the core client functionality and C++ providing the public API:
-
Rust Layer (
src/lib.rs): Implements the FFI bridge usingcxx. It wraps thetikv-clientRust crate and exposes functions to C++ via the#[cxx::bridge]macro. -
C++ Wrapper Layer (
src/tikv_client.cpp,include/tikv_client.h): Provides idiomatic C++ classes (RawKVClient,TransactionClient,Transaction) that wrap the Rust FFI functions. -
Generated Bindings: During build,
cxxgenerates C++ headers and source files from the Rust bridge:build/cxxbridge/client-cpp/src/lib.rs.h(generated header)build/cxxbridge/client-cpp/src/lib.rs.cc(generated source)
- CMake orchestrates the entire build process
- CMake invokes
cargoto build the Rust static library (libtikvrust.a) - The C++ library (
libtikvcpp.a) links against the Rust static library - Both libraries must be linked by consumers (see
example/CMakeLists.txt)
tikv_client::RawKVClient: Simple key-value operations (get,put,scan,remove,batch_put,remove_range)tikv_client::TransactionClient: Transaction management (begin,begin_pessimistic)tikv_client::Transaction: Individual transaction operations (get,put,scan,commit,rollback)tikv_client::KvPair: Key-value pair structure
- Each Rust client struct (
RawKVClient,TransactionClient) contains its owntokio::runtime::Runtimefor executing async Rust code synchronously - The
Transactionstruct holds atokio::runtime::Handlecloned from its parent client - Raw KV operations accept a timeout parameter (milliseconds); transactional operations do not
batch_get_for_updateis currently unimplemented (returns error)
Rust (via Cargo): tikv-client, cxx, tokio, futures, anyhow, log, libc, env_logger
System Libraries: pthread, dl, ssl, crypto
C++ Standard: C++17