Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
autumn-plugin-rocksdb
An Autumn plugin for RocksDB. Handlers read and write keys in an embedded store. The same database can hold the app cache and the sessions.
- Key-value API:
get,put,delete, JSON values, column families and atomic batches. - Scans: prefix and range scans in pages, with a cursor for the next page.
- Cache:
RocksCacheis the Autumn app cache. Each entry expires. Entries survive a restart. - Sessions:
RocksSessionStoreis the Autumn session store. Sessions survive a restart. - Limits: a timeout, a call limit, and size limits for keys, values, batches and scan pages.
- Operations: a readiness check, Prometheus metrics, checkpoints, and a flush and close at shutdown.
- Tests: use an in-memory database. The tests need no server.
Install
[]
= "0.1"
use ;
use *;
async
async
Add profiles to column_families in autumn.toml. See Configuration.
The first build compiles RocksDB from C++ source. It takes 10 to 15 minutes on 4 CPU cores. It needs a C++ compiler and clang.
The lz4, zstd and snappy features are on by default. They build these compression libraries into RocksDB. RocksDB writes Snappy blocks by default, so snappy lets the plugin read databases from other tools. The zlib feature adds zlib.
An app can have one RocksDB plugin only. Use column families to keep data sets apart.
The plugin re-exports the rocksdb crate and uses its types in with_db and setup hooks. A rocksdb update is a breaking release of this crate.
Configuration
The plugin reads [rocksdb] in autumn.toml. Profile sections and profile files override it. AUTUMN_ROCKSDB__<KEY> variables override all files. A list variable has comma-separated items.
[]
= "data/rocksdb" # ":memory:" gives an in-memory database
= "read_write" # or "read_only"
= true
= ["profiles", "orders"]
= 5000 # includes the wait for a call slot
= 64
= 16384
= 16777216
= 67108864
= 1000
= 16777216
= false # true waits for the write-ahead log on disk
= false # true installs RocksCache as the app cache
= 86400 # the longest cache TTL
= false # true installs RocksSessionStore
# session_ttl_secs = 86400 # default: session.max_age_secs of Autumn
= true
= true
= "lz4" # "none", "lz4", "zstd" or "snappy"
= 10 # 0 turns the bloom filter off
# block_cache_bytes = 67108864
# write_buffer_bytes = 67108864
# max_open_files = -1
# max_background_jobs = 4
The default path is :memory:. Set path to keep data after a restart.
On Unix, the plugin makes a new database directory with mode 0700. Only the owner can read it.
Use RocksDbPlugin::config to give a configuration in code. Use RocksDbPlugin::configure to change the configuration after the plugin reads it.
Reads and writes
The methods of RocksDb use the default column family. db.cf("name") gives a Keyspace for another column family. Add each column family to column_families.
db.put.await?;
let name = db.get.await?; // Option<Vec<u8>>
db.cf.put_json.await?;
db.delete.await?;
A batch writes all entries or none:
db.batch
.put
.put_in
.delete
.commit
.await?;
A write that times out after it starts can still complete. Its outcome is unknown. A write that times out before it starts never runs.
Scans
A scan reads one page in key order. Page::next is the cursor of the next page. It is None when no entry is left.
let mut cursor = None;
loop
A page also ends at max_scan_bytes. One entry above that limit gives EntryTooLarge with the key of the entry. Read it with get, or give the key to after to skip it.
Cache and sessions
Set cache = true. The plugin installs RocksCache as the app cache. Autumn keeps one app cache for each process. #[cached] functions then store their values in RocksDB.
- Each cache entry expires.
cache_ttl_secsis the longest TTL. An entry without a TTL gets it. - A cache call does not wait. If all call slots are busy, a read is a miss and a write does nothing.
- A cache write does not wait for a RocksDB write stall. A stalled write does nothing.
- The cache has no size limit. Expired entries leave the disk at compaction.
Set sessions = true. The plugin installs RocksSessionStore. Each session expires session_ttl_secs after its last save. The key on disk is the SHA-256 hash of the session ID, not the ID.
A compaction filter removes expired cache entries and sessions from disk. A read after the expiry is a miss before the filter runs.
The cache and the sessions use the reserved column families autumn_cache and autumn_sessions. The user API refuses names with the autumn_ prefix.
Setup hooks and the full API
A setup hook runs at startup, before the first request. A failed hook stops the boot.
new.setup
with_db gives the full rocksdb API on a blocking thread, for example for a snapshot. The timeout and the call limit apply. sync_writes does not apply to writes in with_db or in setup hooks.
let value = db.with_db.await?;
checkpoint makes a consistent copy of a file database, for example for a backup. The directory must not exist. On Unix, the copy has mode 0700. The copy holds all data, so keep it safe.
Errors
RocksDbError::status gives the HTTP status. or_http() converts a result for a handler.
| Error | Status |
|---|---|
Timeout |
504 |
ShuttingDown, and the kinds Busy, TryAgain, TimedOut and ShutdownInProgress |
503 |
KeyTooLarge, ValueTooLarge, BatchTooLarge |
413 |
ScanLimit |
400 |
| All others | 500 |
The error text and the Debug output never show a RocksDB message, because it can hold a file path. detail() gives the full message. Do not show it to users. kind() gives the ErrorKind.
Operations
- Readiness:
/actuator/healthhas arocksdbcomponent. It is down before startup and after the close. It is also down when writes stop, or when the background error count grew in the last 60 seconds. - Metrics:
rocksdb_calls_started_total,rocksdb_calls_total,rocksdb_calls_open,rocksdb_read_bytes_total,rocksdb_written_bytes_total,rocksdb_cache_requests_totalandrocksdb_background_errors. Gauges for each column family give keys, file sizes, memtables and pending compaction. - Shutdown: Autumn marks the shutdown before it drains the requests. At the mark, the plugin flushes the write-ahead log and the memtables. The database stays open for the drain.
- Close: after the drain, the plugin refuses new calls. It waits up to 5 seconds for open calls. Then it flushes a writable file database, if
flush_on_shutdownistrue. Then it closes the database. - One process can open a database for writes. Other processes can open it with
access_mode = "read_only". A read-only open is a view of the database at the time of the open. It does not see later writes.
License
Apache-2.0.