New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
txn_types: Add GC fence feild to Write records #9207
Conversation
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@hicqu, Thanks for your review. The bot only counts LGTMs from Reviewers and higher roles, but you're still welcome to leave your comments. See the corresponding SIG page for more information. Related SIG: transaction(slack). |
@@ -68,6 +70,47 @@ pub struct Write { | |||
/// Also note that `has_overlapped_rollback` field is only necessary when the Rollback record | |||
/// should be protected. | |||
pub has_overlapped_rollback: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems it can be replaced by gc_fence
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's produced because commit_ts == rollback_ts in the lock, it doesn't need a gc fence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's produced because commit_ts == rollback_ts in the lock, it doesn't need a gc fence.
components/txn_types/src/write.rs
Outdated
@@ -21,6 +21,7 @@ const FLAG_LOCK: u8 = b'L'; | |||
const FLAG_ROLLBACK: u8 = b'R'; | |||
|
|||
const FLAG_OVERLAPPED_ROLLBACK: u8 = b'R'; | |||
const FLAG_GC_FENCE: u8 = b'F'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to call it a prefix instead of a flag because it has a timestamp payload?
/// doesn't have an newer version. | ||
/// * `Some(ts)`: A commit record that has been rewritten due to overlapping rollback, | ||
/// and it's next version's `commit_ts` is `ts` | ||
pub gc_fence: Option<TimeStamp>, | ||
} | ||
|
||
impl std::fmt::Debug for Write { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug
needs updating
@@ -217,6 +277,10 @@ impl WriteRef<'_> { | |||
if self.has_overlapped_rollback { | |||
b.push(FLAG_OVERLAPPED_ROLLBACK); | |||
} | |||
if let Some(ts) = self.gc_fence { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can calculate a better capacity estimation like https://github.com/tikv/tikv/blob/6b4466ba8a/components/txn_types/src/lock.rs#L161
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, one query about the comment
/// * `Some(0)`: A commit record that has been rewritten due to overlapping rollback, but it | ||
/// doesn't have an newer version. | ||
/// * `Some(ts)`: A commit record that has been rewritten due to overlapping rollback, | ||
/// and it's next version's `commit_ts` is `ts` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great comment! 👍👍👍
components/txn_types/src/write.rs
Outdated
/// record, add a special field `gc_fence` on it. If there is a newer version after the record | ||
/// being rewritten, the next version's `commit_ts` will be recorded. When MVCC reading finds | ||
/// a commit record with a GC fence timestamp but the corresponding version that matches that ts | ||
/// doesn't exest, the current version will be believed to be already GC-ed and ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you say when and what the gc fence would be set to in the example?
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest lgtm.
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
/merge |
@hicqu Oops! auto merge is restricted to Committers of the SIG.See the corresponding SIG page for more information. Related SIG: transaction(slack). |
/merge |
/run-all-tests |
@@ -217,9 +291,25 @@ impl WriteRef<'_> { | |||
if self.has_overlapped_rollback { | |||
b.push(FLAG_OVERLAPPED_ROLLBACK); | |||
} | |||
if let Some(ts) = self.gc_fence { | |||
b.push(GC_FENCE_PREFIX); | |||
b.encode_u64(ts.into_inner()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not encode_var_u64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VarInt saves space when ts is 0. But VarInt occupies more space (9 bytes vs 8 bytes) and is slower when ts is a real timestamp.
It has little difference to me because overlapping happens rarely...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it doesn't matter much which encoding to use here, but encode_u64 looks faster than var_u64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's strange to encode start_ts in var int and this ts in u64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see in Lock's encoding, everything new is using encode_u64...
@MyonKeminta merge failed. |
/run-all-tests |
/merge |
/run-all-tests |
- tikv/tikv#8349 and tikv/tikv#9207 has introduced new behavior in txt write. - When meet `GC fence` flag, it is definitely a rewriting record and there must be a complete row has been written, just ignore it in tiflash. Signed-off-by: Tong Zhigao <tongzhigao@pingcap.com>
Signed-off-by: MyonKeminta MyonKeminta@users.noreply.github.com
What problem does this PR solve?
Issue Number:
Adds a
gc_fence
field toWrite
records which will be used to resolve the compatibility issue between async commit and gc compaction filter/cdc/tiflash.What is changed and how it works?
Added a
gc_fence
field.Related changes
Check List
Tests
Side effects
Release note