This file provides guidance to AI coding agents (e.g., Claude Code, Cursor, ChatGPT Codex, Gemini) when working with code in this repository.
While working on Apache Kvrocks, please remember:
# Configure with Ninja when you want faster incremental builds. # The default generator is Makefiles unless --ninja is specified. ./x.py build --ninja # Build kvrocks and utilities ./x.py build # Build to ./build directory ./x.py build -j N # Build with N parallel jobs ./x.py build --unittest # Build with unit tests ./x.py build -DENABLE_OPENSSL=ON # Build with TLS support ./x.py build --ninja # Use Ninja build system ./x.py build --skip-build # Only run CMake configure ./x.py build -DCMAKE_BUILD_TYPE=Debug # Debug build # Run a local server ./build/kvrocks -c kvrocks.conf # Fetch dependencies ./x.py fetch-deps # Fetch dependency archives
If the build directory was configured with Ninja, prefer incremental rebuilds like cd build && ninja -j16 kvrocks instead of re-running CMake.
# Build and run C++ unit tests ./x.py build --unittest ./x.py test cpp # Run Go integration tests ./x.py test go # Re-run a specific Go test name. # x.py test go currently forwards extra flags to "go test" but still runs "./...". ./x.py test go build -run TestKMetadata
You must run the formatter and linters before submitting code changes. This ensures code quality and consistency across the project. It requires installing clang-format, clang-tidy, and golangci-lint locally. Please refer to the CONTRIBUTING.md for setup instructions.
# Format code (must pass before submitting) ./x.py format # Check code format (fails if not formatted) ./x.py check format # Run clang-tidy ./x.py check tidy # Run golangci-lint for Go tests ./x.py check golangci-lint
Apache Kvrocks is a distributed key-value NoSQL database compatible with the Redis protocol, using RocksDB as its storage engine.
src/server/: Main server orchestration, connection handling, and worker threads. The Server class manages the event loop, worker threads, and coordinates all components.src/storage/: RocksDB integration layer. Key classes:Storage: Manages RocksDB instance, column families, and write batchesContext: Passes snapshot and batch between APIs for transactional consistencysrc/commands/: Redis protocol command implementations. Each command type has a corresponding Commander subclass.src/types/: Redis data structure implementations (String, Hash, List, Set, ZSet, Stream, etc.)src/cluster/: Cluster management, slot migration, and replication.src/search/: Full-text search and vector search (HNSW) implementation.src/config/: Server configuration parsing and management.src/cli/: Command-line interface utilities.src/common/: Shared utilities and helper functions.src/stats/: Statistics and metrics collection.REDIS_REGISTER_COMMANDS macro with flags like kCmdWrite, kCmdReadOnly, kCmdBlocking, etc.__namespace column family.METADATA_ENCODING_VERSION=1 (default): Encodes 64-bit size and expire time in milliseconds.METADATA_ENCODING_VERSION=0: Legacy encoding.Refer to https://kvrocks.apache.org/community/data-structure-on-rocksdb for more details.
.clang-format (Google-based, 2-space indent, 120-column limit, sorted includes)..cc/.h file extensions with snake_case filenames.PascalCase; match existing patterns in nearby code.gofmt-clean and comply with tests/gocase/.golangci.yml.You could provide Go tests for integration-level verification of command behaviors and C++ unit tests for internal logic. Focus on testing new features or bug fixes, and avoid adding tests that don't verify meaningful behavior changes.
tests/gocase/): Use *_test.go files, organized by feature (unit/, integration/, tls/).tests/cppunit/): Use *_test.cc files with GoogleTest framework../x.py test ... entry points for consistent setup.Use conventional commits with a scope indicating the affected component:
feat(rdb): add DUMP support for SortedInt type fix(replication): prevent WAL exhaustion from slow consumers fix(string): add empty string value check for INCR to match Redis behavior perf(hash): use MultiGet to reduce RocksDB calls in HMSET chore(deps): Bump rocksdb to v10.10.1 chore(ci): bump crate-ci/typos action to v1.43.1 chore(tests): replace to slices.Reverse() in go test
Common scopes: server, storage, commands, cluster, search, types, replication, rdb, stream, hash, string, list, set, zset, deps, ci, tests, conf.
src/commands/.Commander subclass with Parse() and Execute() methods.REDIS_REGISTER_COMMANDS macro with appropriate flags.src/types/ if needed.tests/cppunit/.tests/gocase/.src/types/ following existing patterns.src/storage/.src/commands/.REDIS_REGISTER_COMMANDS macro.DEBUG command for runtime inspection.tests/lsan-suppressions and tests/tsan-suppressions for known suppression rules../x.py check format, and you should run ./x.py check tidy, ./x.py check golangci-lint, and the relevant tests when the touched code requires them.Security model: SECURITY.md → THREAT_MODEL.md
Agents that scan this repository should consult SECURITY.md and the linked THREAT_MODEL.md for the project's threat model — in-scope / out-of-scope declarations, the security properties claimed and disclaimed (namespace isolation, admin/namespace token separation, the Lua sandbox), the adversary model, and known non-findings — before reporting issues.