RocksDB Integration#
Overview#
HugeGraph uses RocksDB as a local, embedded storage backend in two distinct contexts:
hugegraph-server(hugegraph-rocksdbmodule): the primary OLTP/OLAP backend for standalone or non-distributed deployments, exposing RocksDB directly to graph queries.hugegraph-store(hg-store-rocksdbmodule): the underlying storage for each Raft partition in the distributedhg-storetier.
Entry points:
- Server store:
RocksDBStore.java,RocksDBStdSessions.java - Store-tier options:
hugegraph-store/.../RocksDBOptions.java - Server options:
hugegraph-server/.../RocksDBOptions.java
Configuration#
Both modules share the same option key namespace (rocksdb.*) but have different defaults tuned for their workloads.
Data & WAL Paths (server)#
| Option | Default | Notes |
|---|---|---|
rocksdb.data_path | rocksdb-data/data | Primary data directory |
rocksdb.wal_path | rocksdb-data/wal | WAL directory; separate path enables different durability settings |
rocksdb.data_disks | (empty) | Per-table disk overrides, e.g. g/vertex: /fast-disk |
rocksdb.sst_path | (empty) | Bulk-ingest SST file directory |
Durability#
rocksdb.use_fsync(defaultfalse): when true, every store to stable storage issues anfsync.rocksdb.bytes_per_sync/rocksdb.wal_bytes_per_sync(default0): incremental OS sync of SST/WAL files;0disables.rocksdb.atomic_flush(defaultfalse): atomically flush multiple column families to MANIFEST. Not needed when WAL is always enabled.- Raft mode: when
RAFT_MODE=true, each session disables WAL (setDisableWAL(true)) and sync (setSync(false)) because Raft log + snapshot handles recovery.
Performance Tuning#
| Option | Server default | Store default | Purpose |
|---|---|---|---|
rocksdb.optimize_mode | true | true | optimizeLevelStyleCompaction, increase parallelism, enable adaptive write threads |
rocksdb.max_background_jobs | 8 | 8 | Total flush + compaction threads |
rocksdb.max_subcompactions | 4 | 4 | Threads per compaction job |
rocksdb.write_buffer_size | 128 MB | 32 MB | Per-CF memtable size |
rocksdb.max_write_buffer_number | 6 | 32 | Max in-memory write buffers |
rocksdb.delayed_write_rate | 16 MB/s | 64 MB/s | Throttle when compaction lags |
rocksdb.compaction_style | LEVEL | LEVEL | LEVEL/UNIVERSAL/FIFO |
rocksdb.total_memory_size | N/A | 48 GB | Store-tier global memtable limit |
Bulk-load mode (rocksdb.bulkload_mode=true): disables auto-compaction and removes all level-0/pending-compaction limits for maximum write throughput.
Block cache / Bloom filter: block cache defaults to 8 MB (rocksdb.block_cache_capacity). Bloom filter is off by default (bloom_filter_bits_per_key=-1); set to 10 for ~1% FPR.
initOptions() applies all of the above at open time.
Snapshot-Based Recovery (hugegraph-server)#
RocksDBStore exposes createSnapshot and resumeSnapshot at the store level; RocksDBStdSessions executes them:
createSnapshot(snapshotPath): callsrocksdb.createCheckpoint(snapshotPath)on every open RocksDB instance in the store.resumeSnapshot(snapshotPath, deleteSnapshot): closes RocksDB, deletes the origin data directory, moves (or hard-links whendeleteSnapshot=false) the snapshot directory to the original path, then callsreloadRocksDB().hardLinkSnapshot: opens the snapshot read-only, creates a checkpoint into a_tempdirectory, and returns that path. Used to preserve the original snapshot while restoring.
Note:
resumeSnapshotcloses RocksDB before deleting the origin directory. Closing after copying would risk dirty data.
Snapshot-Based Recovery (hugegraph-store / Raft tier)#
In the distributed store, snapshots tie into the Raft state machine. The flow is:
PartitionStateMachine.onSnapshotSave()βSnapshotHandler.onSnapshotSave()βRocksDBSession.saveSnapshot()creates a RocksDBCheckpointat_temp, then atomically renames to the final path.- Files are registered with the JRaft
SnapshotWriter; CRC64 checksums are computed (full checksum for files β€ 8 KB; head+tail 4 KB blocks for larger files). - A
should_not_loadmarker prevents the local node from redundantly loading its own snapshot. RocksDBSession.loadSnapshot(): under a write lock, hard-links snapshot files to_temp, callsverifySnapshot()(opens read-only, validates all column family handles), and only on success atomically moves the verified directory to the live database path. A corrupt snapshot therefore never replaces a healthy database.
Exception Handling#
In RocksDBStore.open(), specific RocksDBException messages are caught and handled gracefully :
| Exception message | Handling |
|---|---|
"No locks available" | Another instance already has the lock; copy the existing RocksDBSessions reference (shared optimized-disk path). |
"Column family not found" | Schema store logs a warning and retries opening with an empty CF list or no CF list depending on whether another keyspace's data exists. |
| Any other | Wrapped in ConnectionException and rethrown. |
General corruption (e.g., a RocksDBException that is none of the above) causes startup failure. Built-in repair (RocksDB.repairDB()) is not implemented in HugeGraph's integration; recovery is expected via snapshot restore.
Key Source Files#
| File | Purpose |
|---|---|
hugegraph-server/.../RocksDBOptions.java | All server-side configuration options with defaults |
hugegraph-store/.../RocksDBOptions.java | Store-tier configuration options (larger defaults tuned for distributed use) |
RocksDBStore.java | Store lifecycle, open/close, snapshot orchestration, disk mapping |
RocksDBStdSessions.java | Low-level RocksDB open, session management, snapshot create/resume, initOptions() |
SnapshotHandler.java | JRaft β RocksDB snapshot bridge (store tier) |
RocksDBSession.java | Checkpoint, verification, and load logic (store tier) |