Skip to content

Commit

Permalink
Update FasterKV.md
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc authored Oct 26, 2020
1 parent b7bd249 commit a08b95b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/cs/FasterKV.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ This call shifts the begin address of the log, deleting any log segment files ne
FASTER also support true "log compaction", where the log is scanned and live records are copied to the tail so that the store does not expire any data. You can perform log compaction over a FasterKv client session (`ClientSession`) as follows:

```cs
session.Compact(compactUntil, shiftBeginAddress: true);
compactUntil = session.Compact(compactUntil, shiftBeginAddress: true);
```

This call perform synchronous compaction on the provided session until the specific `compactUntil` address, scanning and copying the live records to the tail. Typically, you may compact 10-20% of the log, e.g., you set `compactUntil` address to `store.Log.BeginAddress + (store.Log.TailAddress - store.Log.BeginAddress) / 5`. The parameter `shiftBeginAddress`, when true, causes the compation to also shift the begin address when the compaction is complete. However, since live records are written to the tail, this operation may result in data loss if the store fails immediately. If you do not want to lose data, you need to trigger compaction with `shiftBeginAddress` set to false, then complete a checkpoint (either fold-over or snaphot is fine), and then shift the begin address, as shown below:
This call perform synchronous compaction on the provided session until the specific `compactUntil` address, scanning and copying the live records to the tail. It returns the actual log address that the call compacted until (next nearest record boundary). Typically, you may compact 10-20% of the log, e.g., you set `compactUntil` address to `store.Log.BeginAddress + (store.Log.TailAddress - store.Log.BeginAddress) / 5`. The parameter `shiftBeginAddress`, when true, causes the compation to also shift the begin address when the compaction is complete. However, since live records are written to the tail, this operation may result in data loss if the store fails immediately. If you do not want to lose data, you need to trigger compaction with `shiftBeginAddress` set to false, then complete a checkpoint (either fold-over or snaphot is fine), and then shift the begin address, as shown below:

```cs
long compactUntil = store.Log.BeginAddress + (store.Log.TailAddress - store.Log.BeginAddress) / 5;
session.Compact(compactUntil, shiftBeginAddress: false);
compactUntil = session.Compact(compactUntil, shiftBeginAddress: false);
await store.TakeHybridLogCheckpointAsync(CheckpointType.FoldOver);
store.Log.ShiftBeginAddress(compactUntil);
```
Expand Down

0 comments on commit a08b95b

Please sign in to comment.