# Command-line tools reference Mini-LSM ships two command-line tools: `mini-lsm-cli` (an interactive key-value REPL) and `compaction-simulator` (a compaction strategy simulator). Both are built with `clap` and therefore support the standard `--help` and `--version` flags. ## `mini-lsm-cli` An interactive REPL that opens (or creates) an LSM database on disk and executes key-value commands read from stdin. Run from the repo root: ```bash cargo run --bin mini-lsm-cli ``` ### Flags All flags use the `--flag value` form. Boolean flags take no value. | Flag | Value | Default | Description | | --------------- | ------------------------------ | ----------- | -------------------------------------------------------- | | `--path` | filesystem path | `lsm.db` | Directory where the LSM database is stored/created. | | `--compaction` | `simple` \| `leveled` \| `tiered` \| `none` | `leveled` | Compaction strategy to use. | | `--enable-wal` | (boolean flag) | off | Enable the write-ahead log. | | `--serializable`| (boolean flag) | off | Enable serializable mode. | Example: ```bash cargo run --bin mini-lsm-cli -- --path /tmp/my.db --compaction tiered --enable-wal ``` ### Interactive (REPL) commands Commands are case-insensitive. The REPL prompts with `mini-lsm-cli> `. | Command | Effect | | ----------------------------- | ------------------------------------------------------------ | | `fill ` | Insert integer keys from `begin` to `end` (inclusive). | | `del ` | Delete a key. | | `get ` | Look up a key; prints `key=value` or `key not exist`. | | `scan` | Print all key-value pairs in order, then the count. | | `scan ` | Print key-value pairs in the inclusive range `[begin, end]`. | | `dump` | Print the internal LSM structure. | | `flush` | Force memtable(s) to flush to SST files. | | `full_compaction` | Force a full compaction. | | `quit` / `close` | Close the database and exit the REPL. | #### Semantics and output format - `fill` writes the values `value@` where `` increments after every executed command. After filling it prints: ``` values filled with epoch ``` - `get` prints either `=` or ` not exist`. The key is printed as the raw string; the value is printed in Rust byte-string debug form (for example `1=b"value1@0"`). - `scan` prints each pair as `b""=b""` (Rust byte-string debug form), followed by a blank line and ` keys scanned`. - `del` prints ` deleted`; `flush` prints `flush success`; `full_compaction` prints `full compaction success`; `dump` prints the internal structure followed by `dump success`. ### Reference-solution binaries The same REPL is available against the reference solutions: ```bash cargo run --bin mini-lsm-cli-ref # week 1 + 2 reference cargo run --bin mini-lsm-cli-mvcc-ref # week 3 MVCC reference ``` ## `compaction-simulator` A non-interactive simulator that flushes mock SSTs and applies a compaction strategy, printing per-iteration state and write/space/read amplification statistics. Run from the repo root: ```bash cargo run --bin compaction-simulator -- [flags] ``` ### Subcommands Exactly one subcommand is required: `simple`, `tiered`, or `leveled`. Each subcommand accepts `--help` for its own flags. #### `simple` — simple leveled compaction | Flag | Value | Default | Description | | ---- | ----- | ------- | ----------- | | `--dump-real-id` | (boolean flag) | off | Dump generated SST IDs instead of the IDs of the original data. | | `--size-only` | (boolean flag) | off | Only dump level sizes; prints one row per compaction iteration. | | `--level0-file-num-compaction-trigger` | integer | 2 | Number of L0 files that triggers compaction. | | `--max-levels` | integer | 3 | Maximum number of levels. | | `--size-ratio-percent` | integer | 200 | Size ratio (percent) between adjacent levels. | | `--iterations` | integer | 50 | Number of simulated flush iterations. | #### `tiered` — tiered compaction | Flag | Value | Default | Description | | ---- | ----- | ------- | ----------- | | `--dump-real-id` | (boolean flag) | off | Dump generated SST IDs instead of the IDs of the original data. | | `--size-only` | (boolean flag) | off | Only dump level sizes. | | `--num-tiers` | integer | 8 | Number of tiers. | | `--max-size-amplification-percent` | integer | 200 | Max size amplification (percent). | | `--size-ratio` | integer | 1 | Size ratio between tiers. | | `--min-merge-width` | integer | 2 | Minimum merge width. | | `--max-merge-width` | integer (optional) | none | Maximum merge width. | | `--iterations` | integer | 50 | Number of simulated flush iterations. | #### `leveled` — leveled compaction | Flag | Value | Default | Description | | ---- | ----- | ------- | ----------- | | `--dump-real-id` | (boolean flag) | off | Dump generated SST IDs instead of the IDs of the original data. | | `--size-only` | (boolean flag) | off | Only dump level sizes. | | `--level0-file-num-compaction-trigger` | integer | 2 | Number of L0 files that triggers compaction. | | `--level-size-multiplier` | integer | 2 | Level size multiplier. | | `--max-levels` | integer | 4 | Maximum number of levels. | | `--base-level-size-mb` | integer | 128 | Base level size in MB. | | `--iterations` | integer | 50 | Number of simulated flush iterations. | | `--sst-size-mb` | integer | 32 | Simulated SST size in MB. | #### Output Each iteration prints a block such as: ``` === Iteration === --- After Flush --- L0 (): [] ... --- Compaction Task --- ... --- After Compaction --- ... --- Statistics --- Write Amplification: /=x Maximum Space Usage: /=x Read Amplification: x ``` With `--size-only`, compaction task detail is suppressed and each iteration prints a single `Levels: ...` row of level/tier sizes. ### Reference-solution binaries ```bash cargo run --bin compaction-simulator-ref # week 1 + 2 reference cargo run --bin compaction-simulator-mvcc-ref # week 3 MVCC reference ``` ## Notes - The `wrapper` binaries (`mini-lsm-wrapper-ref`, `mini-lsm-wrapper-mvcc-ref`) are internal no-op helper targets used to re-export the library crate; they are not intended for end users. - When running `cargo run --bin -- `, everything after `--` is passed to the binary, not to Cargo.