Operations
Checkpoints of a live database, verifying every block, removing a database safely, the statistics it counts, and the errors it returns with what to do about each.
Checkpoints
Db::checkpoint(dir) writes a consistent copy of a live database into another
directory. The copy holds every batch committed before the call. It opens as a
database of its own, with the same options and the same key provider when
encrypted.
use tessarikv::Db;
async fn backup(db: &Db) -> tessarikv::Result<()> {
db.checkpoint("backups/2026-10-17").await
}
The batches still in memory are flushed first. Then the table files of that
moment are linked into the copy where the storage can (a hard link on the
operating-system storage) and copied otherwise, with a manifest naming them, so the copy needs no log. Reads
and writes go on meanwhile. dir must be empty or absent. A database in memory
cannot be checkpointed.
Verifying a database
Db::verify_checksums() re-reads every table file from storage and verifies
each block's checksum. It fails with a Corruption error naming the file and
offset. Data that fails it needs restoring, not retrying.
Removing a database
Db::destroy(path) removes every file the engine wrote in a database's
directory, in an order a crash cannot turn into a partial database. It refuses a
database that is open.
Statistics
Turn them on with DbOptions::builder().statistics(true); read them with
Db::statistics(), which returns None when they are off.
use tessarikv::{Db, Histogram, Ticker};
fn report(db: &Db) {
if let Some(stats) = db.statistics() {
let hits = stats.ticker(Ticker::BlockCacheHit);
let misses = stats.ticker(Ticker::BlockCacheMiss);
let p99 = stats.histogram(Histogram::GetMicros).quantile(99, 100);
println!("block cache {hits} hits, {misses} misses; get p99 {p99} µs");
}
}
Tickers count since open: GetCalls, MemtableHit, MemtableMiss,
BlockCacheHit, BlockCacheMiss, BlockBytesRead, BloomUseful,
BloomMaybe, KeysWritten, BytesWritten, WalBytes, WalSyncs,
StallMicros, FlushBytes, CompactionBytesRead, CompactionBytesWritten,
CompactionKeysDropped, CompactionFailures.
Histograms cover the latest interval: GetMicros and WriteMicros.
Each count is one wait-free add on a per-thread stripe, so counting does not make threads contend.
Watching for trouble
Db::background_error()—Someonce a log write, a flush or a manifest edit failed. Writes are refused until the database is reopened; reads still work. A failed compaction is retried instead and counted byCompactionFailures.Db::oldest_snapshot()— a sequence far behindSnapshot::sequence()of a new snapshot means something holds an old snapshot, and old versions are piling up on disk.StallMicrosgrowing — compaction is behind. See Compaction and backpressure.
Upgrading and the file format
Every file carries its own format version and a checksum, and on top of that
each database records one store format at the start of its manifest
(tessarikv_constants::STORE_FORMAT, 1 in 0.1.0). From 0.1.0 a release reads
its own store format and every earlier one, so a database written by 0.1.0
opens in every later release.
- A database written in a later store format is refused at open with
Error::UnsupportedFormat(codeunsupported_format, categoryValidation) before any of its tables or logs is read. It names the format it found and the newest one the build reads. Open it with the release that wrote it, or a later one. - Opening a database stamps the store format of the release that opened it, so moving to a newer release is one-way. Take a checkpoint first and keep it until the new release has run.
- A database written by 0.0.x recorded no store format; it is format 0 and opens in 0.1.0. Once 0.1.0 has opened it, 0.0.x no longer does.
- 0.2.0 writes store format 4 (expiring puts, blob files, merge operands and ribbon filters). A format 1 database opens in 0.2.0 and is stamped 4; 0.1.x then refuses it.
- A manifest with no readable edit is refused as
Corruption, never opened as an empty database.
Errors
Every error has a category, Error::category(), that says what to do.
Error::is_retryable() is true for Locked, WriteStalled, Conflict and an
interrupted I/O call.
ErrorCategory | Means | Do |
|---|---|---|
Validation | caller input or options out of range | fix the call |
NotFound | a file the operation needs is missing | check the path |
Conflict | a concurrent write won | re-read and retry |
Unavailable | another holder owns the resource, or writes are stalled | retry later |
Timeout | a bounded wait expired | retry later |
Corruption | stored bytes do not decode or verify | restore the data |
Io | the operating system refused an operation | check the disk |
ReadOnly | writes stopped after a durability failure; reads work | reopen |
ShutDown | the handle is closed | open again |
Internal | the engine broke one of its own invariants | report it |
A Corruption message names where, never the stored bytes, so a log line cannot
leak data.