liveBook · Manning

Actionkv

As explained in Rust in Action: Systems programming concepts and techniques

ActionKV is the book's key-value storage implementation that exposes operations for retrieving, deleting, inserting, and updating stored pairs.

actionkv is a key-value store for pairs of arbitrary-length byte sequences. A key identifies one value: a query for “Fiji” can return “Suva,” but the model does not support a broader query for every capital in a region. section 7.5.1

Its command-line interface takes a data file, an operation, and a key:

  • get retrieves a value; a missing key is reported as not found. section 7.6
  • insert adds a pair, delete removes one, and update replaces a value. section 7.6

The executable dispatches these commands to libactionkv::ActionKV. The library manages the file and encodes and decodes records. To start, open the data file and call load() to build an in-memory index of existing keys’ file offsets. Keys and values use byte slices or byte vectors, so they need not be valid UTF-8 text. section 7.7 section 7.7.1

Figure 7.3 A single record in the Bitcask file format. To parse a record, read the header information, then use that information to read the body. Lastly, verify the body’s contents with the checksum provided in the header.

A Bitcask record has a 12-byte header containing a checksum and the key and value lengths. Those lengths guide reading the body; the checksum verifies it. section 7.7.2

The first executable rebuilds its index each time it starts. The second persists index data in the same file, using a hidden key; retrieval can deserialize that index and use an offset to read a record. The shared library does not need to change. section 7.7.11

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Works through file initialization, record processing, and full library code, then extends the design with a persistent index.
Examples
Uses country-to-capital pairs, four command-line commands, and two executables with different index-loading approaches.
What it assumes
Starts with a Cargo library project and introduces byte-slice aliases while showing how to open a file and load its index.
What you can do after
Build it from scratch as a file-backed key-value store, then add an index that persists between runs.
How it connects
Connects key-value stores to file I/O, in-memory indexes, Bitcask, and log-structured hash tables.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.