You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+143Lines changed: 143 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,149 @@ Uses [`bytes`](https://github.com/tokio-rs/bytes) as the underlying `Slice` type
62
62
63
63
*Disabled by default.*
64
64
65
+
### tool
66
+
67
+
Enables the `lsm` CLI binary for interacting with LSM trees from the command line.
68
+
69
+
*Disabled by default.*
70
+
71
+
## CLI Tool
72
+
73
+
The crate includes an optional CLI tool (`lsm`) for inspecting and manipulating LSM trees.
74
+
75
+
### Installation
76
+
77
+
```bash
78
+
cargo install lsm-tree --features tool
79
+
```
80
+
81
+
Or build from source:
82
+
83
+
```bash
84
+
cargo build --release --features tool
85
+
```
86
+
87
+
### Usage
88
+
89
+
The tool can be used either with direct commands or in interactive shell mode.
90
+
91
+
#### Direct Commands
92
+
93
+
```bash
94
+
# Set a key-value pair
95
+
lsm /path/to/db set mykey "my value"
96
+
97
+
# Get a value
98
+
lsm /path/to/db get mykey
99
+
100
+
# Delete a key
101
+
lsm /path/to/db del mykey
102
+
103
+
# List all keys (aliases: list, ls)
104
+
lsm /path/to/db scan
105
+
106
+
# List keys with a prefix
107
+
lsm /path/to/db scan "user:"
108
+
109
+
# List keys in a range [start, end)
110
+
lsm /path/to/db range a z
111
+
112
+
# Count items
113
+
lsm /path/to/db count
114
+
115
+
# Show database info
116
+
lsm /path/to/db info
117
+
118
+
# Flush memtable to disk
119
+
lsm /path/to/db flush
120
+
121
+
# Run compaction
122
+
lsm /path/to/db compact
123
+
```
124
+
125
+
#### Interactive Shell
126
+
127
+
Start an interactive shell by running without a command:
128
+
129
+
```bash
130
+
lsm /path/to/db
131
+
```
132
+
133
+
The shell supports all the above commands plus:
134
+
135
+
-`begin` - Start a batch/transaction
136
+
-`commit` - Commit the current batch
137
+
-`rollback` - Discard the current batch
138
+
-`exit` / `quit` - Exit (flushes data first)
139
+
-`abort` - Exit without flushing
140
+
-`help` - Show available commands
141
+
142
+
#### Batch Operations
143
+
144
+
The shell supports batching multiple operations into an atomic unit:
145
+
146
+
```
147
+
lsm> begin
148
+
OK (batch started)
149
+
lsm> set key1 value1
150
+
OK (batched, ready to commit)
151
+
lsm> set key2 value2
152
+
OK (batched, ready to commit)
153
+
lsm> del key3
154
+
OK (batched, ready to commit)
155
+
lsm> commit
156
+
OK (batch committed, ready to flush)
157
+
```
158
+
159
+
While a batch is active:
160
+
-`get` reads from the batch first, then falls back to the tree
161
+
-`scan` and `range` warn that they ignore uncommitted batch operations
162
+
-`info` shows the pending batch operations
163
+
-`rollback` discards all batched operations
164
+
165
+
#### Long Scan
166
+
167
+
Use `-l` / `--long` to show internal entry details including sequence numbers, value types, and tombstones:
168
+
169
+
```
170
+
lsm> scan -l
171
+
=== Active Memtable ===
172
+
key1 = value1 [seqno=0, type=Value]
173
+
key2 [seqno=1, type=Tombstone]
174
+
175
+
=== Persisted (on disk) ===
176
+
key3 = value3 [seqno=2, type=Value]
177
+
178
+
(3 total items, 2 in memtable, 1 persisted, 1 tombstones)
179
+
```
180
+
181
+
#### Blob Trees with Indirect Items
182
+
183
+
A blob tree uses key-value separation, storing large values in separate blob files and keeping indirect references (indirections) in the main LSM-tree. This improves performance for large values by reducing write amplification and improving compaction efficiency.
184
+
185
+
To create a blob tree, use the `--blob-tree` flag along with `--separation-threshold` (or `-t`) to specify the size threshold in bytes. Values larger than this threshold will be stored as indirect items:
186
+
187
+
```bash
188
+
# Create a blob tree with 1 KiB separation threshold
189
+
lsm --blob-tree --separation-threshold 1024 /path/to/db set largekey "very large value..."
190
+
191
+
# Or using the short form
192
+
lsm -b -t 1KiB /path/to/db set largekey "very large value..."
193
+
194
+
# In interactive mode
195
+
lsm --blob-tree -t 1024 /path/to/db
196
+
lsm>set largekey "very large value..."
197
+
OK (set)
198
+
lsm> flush
199
+
OK (flushed)
200
+
lsm> scan -l
201
+
=== Active Memtable ===
202
+
=== Persisted (on disk) ===
203
+
largekey = very large value... [seqno=0, type=Indirection]
204
+
```
205
+
206
+
After flushing, values that exceed the separation threshold will appear as `type=Indirection` in verbose scan output, indicating they are stored in separate blob files rather than inline in the table.
0 commit comments