Skip to content

Commit

Permalink
rename flashback into truncate
Browse files Browse the repository at this point in the history
Signed-off-by: longfangsong <[email protected]>
  • Loading branch information
longfangsong committed Dec 3, 2021
1 parent 40ac22e commit 9dc2a77
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions text/0081-flashback.md → text/0081-truncate.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@ Though it is impossible to do lossless recovery in this situation, we can recove
Basically, we need a method to return TiKV to a certain version (timestamp), we should add a new RPC to kvproto:

```protobuf
message FlashBackRequest {
message TruncateRequest {
Context context = 1;
uint64 checkpoint_ts = 2;
}
message FlashBackResponse {
message TruncateResponse {
string error = 1;
}
service Tikv {
// …
rpc FlashBack(kvrpcpb.FlashBackRequest) returns (kvrpcpb.FlashBackResponse) {}
rpc Truncate(kvrpcpb.TruncateRequest) returns (kvrpcpb.TruncateResponse) {}
}
```

When a TiKV recieve `FlashBackRequest`, it will create a `FlashBackWorker` instance and start the work.
When a TiKV receive `TruncateRequest`, it will create a `TruncateWorker` instance and start the work.

There are several steps to follow when doing the flash back:
There are several steps to follow when doing truncate:

### 1. Wait all committed raft log are applied

We can just polling each region's `RegionInfo` in a method similar with [`Debugger::region_info`](https://github.com/tikv/tikv/blob/789c99666f2f9faaa6c6e5b021ac0cf7a76ae24e/src/server/debug.rs#L188) does, and wait for `commit_index` to be equal to `apply_index`.

### 2. Clean WriteCF and DefaultCF
W
Then we can remove all data created by transactions which commited after `checkpoint_ts`, this can be done by remove all `Write` records which `commit_ts > checkpoint_ts` and corresponding data in `DEFAULT_CF` from KVEngine, ie.

Then we can remove all data created by transactions which committed after `checkpoint_ts`, this can be done by remove all `Write` records which `commit_ts > checkpoint_ts` and corresponding data in `DEFAULT_CF` from KVEngine, ie.

```rust
fn scan_next_batch(&mut self, batch_size: usize) -> Option<Vec<(Vec<u8>, Write)>> {
Expand Down

0 comments on commit 9dc2a77

Please sign in to comment.