Skip to content

Commit a2cc55c

Browse files
committed
Update text/0081-truncate.md
Co-authored-by: Lei Zhao <zlwgx1023@gmail.com> Update text/0081-truncate.md Co-authored-by: Lei Zhao <zlwgx1023@gmail.com> fix indent Signed-off-by: longfangsong <longfangsong@icloud.com>
1 parent 9dc2a77 commit a2cc55c

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

text/0081-truncate.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ message TruncateResponse {
3333
}
3434
3535
service Tikv {
36-
// …
37-
rpc Truncate(kvrpcpb.TruncateRequest) returns (kvrpcpb.TruncateResponse) {}
36+
// …
37+
rpc Truncate(kvrpcpb.TruncateRequest) returns (kvrpcpb.TruncateResponse) {}
3838
}
3939
```
4040

@@ -44,45 +44,45 @@ There are several steps to follow when doing truncate:
4444

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

47-
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`.
47+
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 `apply_index` to be equal to `commit_index`.
4848

4949
### 2. Clean WriteCF and DefaultCF
5050

5151
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.
5252

5353
```rust
5454
fn scan_next_batch(&mut self, batch_size: usize) -> Option<Vec<(Vec<u8>, Write)>> {
55-
let mut writes = None;
56-
for _ in 0..batch_size {
57-
if let Some((key, write)) = self.next_write()? {
58-
let commit_ts = Key::decode_ts_from(keys::origin_key(&key));
59-
let mut writes = writes.get_or_insert(Vec::new());
60-
if commit_ts > self.ts {
61-
writes.push((key, write));
62-
}
63-
} else {
64-
return writes;
55+
let mut writes = None;
56+
for _ in 0..batch_size {
57+
if let Some((key, write)) = self.next_write()? {
58+
let commit_ts = Key::decode_ts_from(keys::origin_key(&key));
59+
let mut writes = writes.get_or_insert(Vec::new());
60+
if commit_ts > self.ts {
61+
writes.push((key, write));
6562
}
63+
} else {
64+
return writes;
6665
}
67-
writes
66+
}
67+
writes
6868
}
6969

7070
pub fn process_next_batch(
71-
&mut self,
72-
batch_size: usize,
73-
wb: &mut RocksWriteBatch,
71+
&mut self,
72+
batch_size: usize,
73+
wb: &mut RocksWriteBatch,
7474
) -> bool {
75-
let writes = if let Some(writes) = self.scan_next_batch(batch_size) {
76-
writes
77-
} else {
78-
return false;
79-
}
80-
for (key, write) in writes {
81-
let default_key = Key::append_ts(Key::from_raw(&key), write.start_ts).to_raw().unwrap();
82-
box_try!(wb.delete_cf(CF_WRITE, &key));
83-
box_try!(wb.delete_cf(CF_DEFAULT, &default_key));
84-
}
85-
true
75+
let writes = if let Some(writes) = self.scan_next_batch(batch_size) {
76+
writes
77+
} else {
78+
return false;
79+
}
80+
for (key, write) in writes {
81+
let default_key = Key::append_ts(Key::from_raw(&key), write.start_ts).to_raw().unwrap();
82+
box_try!(wb.delete_cf(CF_WRITE, &key));
83+
box_try!(wb.delete_cf(CF_DEFAULT, &default_key));
84+
}
85+
true
8686
}
8787
```
8888

0 commit comments

Comments
 (0)