Skip to content
This repository was archived by the owner on May 14, 2022. It is now read-only.

Commit 7a01c92

Browse files
authored
Merge pull request #55 from ssb-ngi-pointer/compact
Compaction
2 parents 0e41f9c + eeb7602 commit 7a01c92

File tree

7 files changed

+1354
-37
lines changed

7 files changed

+1354
-37
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,45 @@ log.since((offset) => {
178178
})
179179
```
180180

181+
### Compact the log (remove deleted records)
182+
183+
```js
184+
log.compact((err) => {
185+
// This callback will be called once, when the compaction is done.
186+
})
187+
```
188+
189+
### Track progress of compactions
190+
191+
As an [obz] observable:
192+
193+
```js
194+
log.compactionProgress((progress) => {
195+
console.log(progress)
196+
// {
197+
// startOffset,
198+
// compactedOffset,
199+
// unshiftedOffset,
200+
// percent,
201+
// done,
202+
// sizeDiff,
203+
// }
204+
})
205+
```
206+
207+
Where
208+
209+
- `startOffset`: the starting point for compaction. All offsets smaller than
210+
this have been left untouched by the compaction algorithm.
211+
- `compactedOffset`: all records up until this point have been compacted so far.
212+
- `unshiftedOffset`: offset for the first record that hasn't yet been "moved"
213+
to previous slots. Tracking this allows you to see the algorithm proceeding.
214+
- `percent`: a number between 0 and 1 to indicate the progress of compaction.
215+
- `done`: a boolean indicating whether compaction is ongoing (`false`) or done
216+
(`true`).
217+
- `sizeDiff`: number of bytes freed after compaction is finished. Only available
218+
if `done` is `true`.
219+
181220
### Close the log
182221

183222
```js

0 commit comments

Comments
 (0)