MCPcopy Index your code
hub / github.com/arana-db/kiwi

github.com/arana-db/kiwi @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
3,091 symbols 11,710 edges 251 files 919 documented · 30%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Kiwi

English | 简体中文

Introduction

Kiwi is a Redis-compatible key-value database built in Rust, providing high capacity and strong consistency through RocksDB and the Raft protocol.

Features

  • Dual Runtime Architecture: Network and storage runtimes are separated for performance isolation
  • RocksDB Backend: Uses RocksDB as the persistent storage backend
  • Redis Protocol Compatibility: Highly compatible with Redis protocol
  • Raft Consensus: Integrates OpenRaft for strong consistency and high availability
  • Adaptor Pattern: Custom adapter layer bridging storage with OpenRaft
  • High Performance: Optimized request processing with dedicated thread pools
  • Asynchronous Communication: Message channel-based asynchronous communication
  • Fault Isolation: Network and storage operations run in isolated runtimes

Architecture

src/server/    → Entry point (main.rs)
src/net/       → TCP server, connection handling, cluster routing
src/cmd/       → Command definitions: Cmd trait, CmdMeta, command table
src/executor/  → Command executor: tokio async task pool
src/storage/   → Multi-instance RocksDB, column families, TTL
src/engine/    → Engine trait abstraction over RocksDB
src/resp/      → RESP protocol: parser, encoder, RespData types
src/raft/      → Raft consensus: OpenRaft integration, state machine, router
src/conf/      → Configuration: loading, validation, RaftClusterConfig
src/client/    → Client context: connection state, argv, reply buffer
src/common/runtime/ → Runtime management: async channel between net & storage
src/common/macro/   → Proc macros: #[stack_trace_debug]
src/kstd/      → Utilities: LockMgr (sharded key-level locking)

Request Flow

Client → TCP accept [network runtime] → RESP parse → Command lookup
  → CmdExecutor [network runtime] → Cmd.execute() calls StorageClient
    → MessageChannel →
  → StorageServer [storage runtime] → RocksDB
    ← oneshot response ←
  → RESP encode [network runtime] → write back to client

Roadmap

  • ✅ Dual-runtime architecture for performance isolation
  • ✅ Message channel-based async communication
  • ✅ Basic Redis commands (GET, SET, DEL, etc.)
  • ✅ OpenRaft integration via adaptor pattern
  • 🚧 Most Redis commands
  • 🚧 Complete cluster mode
  • 🚧 Extended command support and execution optimization
  • 🚧 Module extension capabilities
  • 🚧 Comprehensive metrics and monitoring

Getting Started

Prerequisites

# Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# protobuf compiler (macOS)
brew install protobuf

# protobuf compiler (Linux)
apt install protobuf-compiler

Get the Code

git clone https://github.com/arana-db/kiwi.git
cd kiwi

Standalone Mode

make standalone                    # builds (release) and starts kiwi on 127.0.0.1:7379

# In another terminal:
redis-cli -p 7379 set foo bar     # OK
redis-cli -p 7379 get foo         # "bar"

Cluster Mode

make cluster                       # start a 3-node Raft cluster (default)
make cluster NODES=5               # start a 5-node cluster

See docs/cluster.md for the manual step-by-step procedure and Raft architecture details.

Documentation

Document Description
docs/development.md Dev environment, build optimization, sccache
docs/cluster.md Raft cluster quickstart and write-path verification
docs/key-encoding.md Key encoding internals (Chinese)
kiwi --sample-config Generate a default config file
kiwi --full-sample-config Generate a config with all available keys

Dependencies

RocksDB (Temporary Fork)

This project uses a customized fork of rust-rocksdb because the official crate does not yet support the TablePropertiesCollector FFI functions required by the Raft module. Once the needed functionality lands in upstream rust-rocksdb, we will switch back.

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

License

Apache License 2.0. See LICENSE.

Extension points exported contracts — how you extend this code

Cmd (Interface)
(no doc) [108 implementers]
src/cmd/src/lib.rs
DbCfAccess (Interface)
Thin wrapper interface: provides ability to get TableProperties by CF Equivalent to C++ Redis's GetDB() + GetColumnFami [3 …
src/storage/src/logindex/db_access.rs
StreamTrait (Interface)
(no doc) [4 implementers]
src/client/src/lib.rs
ServerTrait (Interface)
(no doc) [4 implementers]
src/net/src/lib.rs
LeaderGate (Interface)
Lightweight leadership view used by the network layer to gate writes. Lets `net` decide whether to accept a write local [2 …
src/raft/src/leader_gate.rs
Command (Interface)
(no doc) [1 implementers]
src/resp/src/command.rs
Engine (Interface)
(no doc) [1 implementers]
src/engine/src/engine.rs
Batch (Interface)
Trait for batch write operations. This trait abstracts the batch write mechanism to support both standalone (RocksDB di [2 …
src/storage/src/batch.rs

Core symbols most depended-on inside this repo

set_reply
called by 424
src/client/src/lib.rs
encode
called by 369
src/storage/src/format.rs
len
called by 294
src/net/src/buffer.rs
clone
called by 262
src/cmd/src/lib.rs
push
called by 235
src/resp/src/types.rs
argv
called by 214
src/client/src/lib.rs
lock
called by 150
src/kstd/src/lock_mgr.rs
map
called by 145
src/resp/src/types.rs

Shape

Method 1,540
Function 1,130
Class 362
Enum 46
Interface 13

Languages

Rust97%
Python3%

Modules by API surface

src/common/runtime/metrics.rs110 symbols
src/storage/src/storage_impl.rs101 symbols
src/raft/src/log_store_rocksdb.rs89 symbols
src/common/runtime/message.rs85 symbols
src/common/runtime/storage_server.rs66 symbols
src/storage/tests/redis_zset_test.rs61 symbols
src/resp/src/parse.rs61 symbols
src/common/runtime/tests.rs50 symbols
src/resp/src/encode.rs48 symbols
src/storage/src/format_list_meta_value.rs41 symbols
src/engine/src/rocksdb_engine.rs40 symbols
src/storage/tests/redis_basic_test.rs38 symbols

For agents

$ claude mcp add kiwi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact