hydradb README

项目的 README,来自 github.com/hydra-db/hydradb。合并为一个 markdown 文件:README.md。

HydraDB

OpenCypher TCK Release License: ELv2 Rust 1.99+ Benchmarks Discord

HydraDB is an object-store-native distributed graph database written in Rust. It pairs durable graph storage on SlateDB with snapshot-consistent OpenCypher queries, GraphBLAS traversal, Neo4j-compatible Bolt, and an HTTPS query API. S3-compatible storage is the source of truth; query nodes and indexers hold only disposable cache in memory and on local SSD, so they scale and restart without moving the graph.

Join the community on Discord. Contributions start with an approved issue; see CONTRIBUTING.md.

Why HydraDB

Architecture

flowchart LR
    C["Applications<br/>Neo4j drivers or HTTPS"]
    SVC["Service or load balancer"]

    subgraph Q["Query tier"]
        Q1["graph-node"]
        Q2["graph-node"]
        QN["graph-node"]
    end

    subgraph I["Indexing tier"]
        IX1["graph-indexer"]
        IXN["graph-indexer"]
    end

    CACHE["Disposable memory and SSD cache"]
    STORE["S3-compatible object storage<br/>WAL, SSTs, leases, CSC generations"]

    C --> SVC
    SVC --> Q1
    SVC --> Q2
    SVC --> QN
    Q1 <--> CACHE
    Q2 <--> CACHE
    QN <--> CACHE
    Q1 <--> STORE
    Q2 <--> STORE
    QN <--> STORE
    IX1 <--> STORE
    IXN <--> STORE

Query nodes serve reads and canonical mutations. Indexer workers build immutable CSC generations asynchronously and publish them through atomic object-store pointers. Readers stay correct when an index is absent or behind because the visible WAL tail is applied to the indexed base. See architecture.md for the full design.

Getting Started

Run with Docker

The published image needs no Rust toolchain or native libraries. Each release pushes ghcr.io/hydra-db/hydradb for linux/amd64 and linux/arm64, tagged latest, the version (0.5.0, 0.5, 0), and sha-<commit>. Its entrypoint is graph-node. A single plaintext development node on a local directory:

mkdir -p .hydradb/store
printf '%s\n' 'local-development-token-32-bytes' > .hydradb/auth-token
chmod 600 .hydradb/auth-token

docker run -d --name hydradb \
  -p 127.0.0.1:7687:7687 -p 127.0.0.1:8443:8443 -p 127.0.0.1:9090:9090 \
  -v "$PWD/.hydradb/store:/data" \
  -v "$PWD/.hydradb/auth-token:/run/secrets/auth-token:ro" \
  -e CLOUD_PROVIDER=local -e LOCAL_PATH=/data \
  -e GRAPH_NAMESPACE=default -e GRAPH_ID=default \
  -e GRAPH_CELL_ID=cell-0 -e GRAPH_CELLS=cell-0 -e GRAPH_NODE_ID=node-0 \
  -e GRAPH_ADVERTISED_BOLT_ADDR=127.0.0.1:7687 \
  -e GRAPH_BOLT_NODE_ADDRESSES=node-0=127.0.0.1:7687 \
  -e GRAPH_AUTH_TOKEN_FILE=/run/secrets/auth-token -e GRAPH_ALLOW_PLAINTEXT=true \
  ghcr.io/hydra-db/hydradb:latest

curl -fsS http://127.0.0.1:9090/readyz && echo READY

Ports, token, and namespace match Run a local node, so its curl examples work unchanged. Bolt clients use any non-empty username and the token as the password. The graph persists in .hydradb/store across docker rm; delete the directory to start over.

The token is readable only by its owner, and the ports are published on loopback only, so nothing outside this machine can reach the node. This recipe is for local development. For production, treat the token as a real secret: generate a unique random value, keep it out of docs and shell history, deliver it through a secret manager (the Helm chart mounts it from a Kubernetes Secret), and turn TLS back on by dropping GRAPH_ALLOW_PLAINTEXT.

The container runs as uid 10001. Docker Desktop maps bind-mount ownership for you. On Linux, hand both mounts to that uid first, or the node exits with Permission denied on the store or the 0600 token:

sudo chown -R 10001:10001 .hydradb/store .hydradb/auth-token

Don't use --user instead: the image's cache directory is owned by 10001, and the node exits with Permission denied. Change GRAPH_ADVERTISED_BOLT_ADDR and GRAPH_BOLT_NODE_ADDRESSES if clients reach the node by another address.

The image also ships graph-indexer and falkor-dump-import (use --entrypoint), and is built with the DataFusion engine and OTLP export. For production, use the Helm chart, which defaults to this image.

Prerequisites

Building from source needs Rust 1.99+, a C/C++ toolchain, libcypher-parser, and SuiteSparse GraphBLAS. just runs the recipes. On Ubuntu or WSL:

sudo apt-get install -y build-essential clang libclang-dev cmake pkg-config \
  libcypher-parser-dev libgraphblas-dev curl git python3 python3-venv

On macOS: brew install just cmake pkg-config llvm suite-sparse and brew install cleishm/neo4j/libcypher-parser. Install Rust from rustup.rs, not Homebrew. AGENTS.md has the full native-dependency setup and the common build and startup failure modes.

Build and verify

git clone https://github.com/hydra-db/hydradb.git
cd hydradb

just native-check   # confirms cypher-parser and GraphBLAS are discoverable
just check          # compiles every default-feature target

bash scripts/runtime_smoke.sh then builds graph-node, starts it, and exercises Bolt and HTTP against a throwaway store, printing runtime-smoke-ok.

Run a local node

A single plaintext development node on a local directory. TLS is required in deployed environments and disabled explicitly here.

mkdir -p .hydradb/store .hydradb/cache
printf '%s\n' 'local-development-token-32-bytes' > .hydradb/auth-token

export CLOUD_PROVIDER=local LOCAL_PATH="$PWD/.hydradb/store"
export GRAPH_NAMESPACE=default GRAPH_ID=default GRAPH_CELL_ID=cell-0 GRAPH_CELLS=cell-0
export GRAPH_NODE_ID=node-0 GRAPH_BOLT_NODE_ADDRESSES=node-0=127.0.0.1:7687
export GRAPH_ADVERTISED_BOLT_ADDR=127.0.0.1:7687
export GRAPH_DATA_CACHE_DIR="$PWD/.hydradb/cache"
export GRAPH_AUTH_TOKEN_FILE="$PWD/.hydradb/auth-token" GRAPH_ALLOW_PLAINTEXT=true
export RUST_MIN_STACK=33554432

cargo run --locked --features server-runtime --bin graph-node

It listens on Bolt 127.0.0.1:7687, HTTP 127.0.0.1:8443, and admin 127.0.0.1:9090. The node holds the foreground; from a second shell, write and read a small graph over HTTP:

TOKEN='local-development-token-32-bytes'

curl -sS http://127.0.0.1:8443/v1/graphs/default/query \
  -H "Authorization: Bearer $TOKEN" -H 'X-Graph-Namespace: default' \
  -H 'Content-Type: application/json' \
  --data '{"cell_id":"cell-0","query":"CREATE (a {id: 1})-[:FOLLOWS]->(b {id: 2})"}'

curl -sS http://127.0.0.1:8443/v1/graphs/default/query \
  -H "Authorization: Bearer $TOKEN" -H 'X-Graph-Namespace: default' \
  -H 'Content-Type: application/json' \
  --data '{"cell_id":"cell-0","query":"MATCH (a {id: 1})-[:FOLLOWS]->(b) RETURN b.id AS id"}'

The second call returns one row with {"type":"vertex_id","value":2}.

Querying

HydraDB speaks a practical OpenCypher subset for reads and mutations: typed relationships, bounded variable-length paths, property and label predicates, ordering, pagination, aggregation, OPTIONAL MATCH, UNION, and batched UNWIND writes. Connect with a Neo4j driver over a routed URI (neo4j://127.0.0.1:7687; neo4j+s:// with a trusted certificate).

Snapshot-scoped native path and degree procedures (algo.SPpaths, algo.SSpaths, algo.MSpaths, algo.degree) run over compiled GraphBLAS topology. The query surface, worked examples, and read-consistency modes are in USING-HYDRADB.md and the OpenCypher subset.

Kubernetes

The Helm chart deploys query nodes, indexer workers, services, cache volumes, network policies, disruption budgets, TLS, authentication, and optional Prometheus integration.

helm upgrade --install hydradb charts/hydradb \
  --namespace hydradb --create-namespace \
  --values charts/hydradb/examples/values-eks.yaml \
  --atomic --timeout 15m

Copy and edit the example values first; credentials, buckets, image references, TLS, and advertised Bolt addresses are environment-specific. See the Helm chart guide.

Observability

The public HTTP server exposes GET /healthz; graph-node and indexer admin servers expose GET /readyz and GET /metrics. Build with otlp added to the feature set to export OpenTelemetry data. Duration histograms state their unit in the metric name (_seconds vs _microseconds); do not compare across the two. The optional failed-query telemetry sink is described in crates/query-telemetry/README.md.

Development

Run just for the full command surface; recipes run from the repository root. just ci runs the local CI-equivalent sequence. The openCypher TCK runner lives under query-language/ behind the just tck-* recipes. Benchmark, stress, chaos, and deployment harnesses are maintained separately in hydra-db/benchmark.

src/core/           configuration, graph model, cache policy, errors
src/shard/          storage lifecycle, reads, writes, queries, path procedures
src/engine/         routing, placement, immutable indexes, index GC
src/query/          OpenCypher parsing, algebra, planning, transport types
src/client/         Bolt, HTTP, authentication, quotas, cursors
src/sparse_kernel/  Rust sparse and SuiteSparse GraphBLAS execution
crates/             placement and telemetry workspace crates
charts/hydradb/     Kubernetes Helm chart
query-language/     openCypher and GQL grammar, harness, and the TCK suite

Documentation

Document Contents
Architecture Design, snapshots, writer ownership, query execution, indexing
Using HydraDB Connecting, the OpenCypher dialect, path queries, query engines, consistency, operating
OpenCypher subset What the engine accepts and rejects at parse time
Helm chart guide Kubernetes configuration, TLS, auth, upgrades

Benchmarks

Published results are on the HydraDB benchmark site; the harness lives in hydra-db/benchmark.

Contributing

Issues and pull requests are welcome. Keep changes focused, add regression coverage for behavioral changes, and run just ci before opening a PR. Changes to storage, fencing, snapshots, routing, or index publication should state the invariant they preserve and include a failure-oriented test.

License

HydraDB is licensed under the Elastic License 2.0 (ELv2).

hydradb (hydra-db/hydradb)

正在搜索数据库…

这是什么?HydraDB 是一个用 Rust 编写的、原生支持对象存储的分布式图数据库:图数据存放在兼容 S3 的存储中,可以通过 OpenCypher 查询,提供与 Neo4j 兼容的 Bolt 连接,以及 HTTPS 的 JSON/NDJSON API。
这和 Neo4j 这样的常规图数据库有什么不同?持久化的图数据存放在对象存储里,而不是服务器的磁盘上:查询节点和索引器在本地 SSD 或 NVMe 上只保留可以随时丢弃的状态,因此可以直接替换或扩缩容,不需要搬动图数据本身。
我怎么在本地把它跑起来?从源码构建:需要 Rust 1.91+、C/C++ 工具链、libcypher-parser 和 SuiteSparse GraphBLAS,整个流程由 just 命令行工具驱动。先用 just smoke 冒烟测试,然后启动一个开发节点,Bolt 服务跑在 7687 端口,HTTP API 在 8443,管理/指标接口在 9090。
查询它需要专门的客户端库吗?不需要:现有的 Neo4j 驱动可以通过 Bolt 5.x 协议连接,使用 routed 模式的 neo4j+s:// 或 neo4j+ssc:// 地址;也可以直接调用 HTTPS API,发送普通 JSON 或流式 NDJSON。直连的 bolt:// 地址只用于诊断。
试用之前有什么坑要注意?源码构建有一些容易踩的坑:在 macOS 上安装 libcypher-parser 需要 cleishm/neo4j 这个 tap;直接调用 cargo 会漏掉 BINDGEN_EXTRA_CLANGARGS(建议用 just);不设置 RUST_MIN_STACK=33554432 的话最初几次查询会直接中断;而且在本地开发环境之外 TLS 默认是开启的。
真正的生产环境部署是什么样子的?通过一个 Helm chart 就能在 Kubernetes 上部署查询节点、索引工作进程、缓存卷、网络策略、中断预算、TLS 和可选的 Prometheus,并针对不同环境配置存储桶、凭据和镜像。Docker 本身只用于测试工具。
algo.SPpaths、algo.SSpaths 和 algo.MSpaths 这些过程是干什么用的?它们是原生的、作用于快照的路径查询过程:SPpaths 查找一个源节点和一个目标节点之间的有界路径,SSpaths 从单一源节点出发查找,MSpaths 则一次性解析大量已建立索引的源-目标对并统一求值,避免客户端发起大量查询。
如果两个写入者同时争抢同一个 cell 会怎样?对象存储的 CAS 租约会为每个 cell 选出活跃的写入者,而 SlateDB 的写入纪元(writer epoch)会把过期的写入者隔离掉,所以旧的写入者无法破坏持久化状态。甚至还有一个 just fence 示例可以演示这种接管过程。
没有真实的 S3 存储桶或集群,我也能测试吗?可以:just smoke 会针对一个临时的本地对象存储跑一遍完整的本地流程(写入、删除边、遍历、重新打开并验证数据持久性),而像 just minio-chaos 这样的 MinIO 测试工具则在 Docker 容器里演练同样的流程。
SuiteSparse GraphBLAS 在这里是用作什么的?查询规划器会按需使用属性索引、反向邻接表、稀疏遍历,以及在合适场景下使用 SuiteSparse GraphBLAS 来做图原生的执行;just smoke-graphblas 可以明确指定遍历内核使用它。
有哪些类似的项目?siglake, walgit, seaweedfs, VictoriaMetrics, thanos, neo4j, automq, emqx
作者
hydra-db
大小
3.4 MB
星标
13.1K
时长
5个月
提交 · 90 天