File size: 7,054 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | # 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 <begin> <end>` | Insert integer keys from `begin` to `end` (inclusive). |
| `del <key>` | Delete a key. |
| `get <key>` | Look up a key; prints `key=value` or `key not exist`. |
| `scan` | Print all key-value pairs in order, then the count. |
| `scan <begin> <end>` | 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<key>@<epoch>` where `<epoch>` increments after every
executed command. After filling it prints:
```
<n> values filled with epoch <epoch>
```
- `get` prints either `<key>=<value>` or `<key> 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"<key>"=b"<value>"` (Rust byte-string debug form),
followed by a blank line and `<n> keys scanned`.
- `del` prints `<key> 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 -- <subcommand> [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 <i> ===
--- After Flush ---
L0 (<n>): [<sst-ids>]
...
--- Compaction Task ---
...
--- After Compaction ---
...
--- Statistics ---
Write Amplification: <w>/<f>=<ratio>x
Maximum Space Usage: <s>/<f>=<ratio>x
Read Amplification: <n>x
```
With `--size-only`, compaction task detail is suppressed and each iteration prints a
single `Levels: <l0> <l1> ...` 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 <bin> -- <args>`, everything after `--` is passed to
the binary, not to Cargo.
|