Skip to content
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

Merged
merged 5 commits into from Dec 10, 2020

Conversation

MyonKeminta
Copy link
Contributor

Signed-off-by: MyonKeminta MyonKeminta@users.noreply.github.com

What problem does this PR solve?

Issue Number:

Adds a gc_fence field to Write 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

  • Unit test

Side effects

Release note

  • No release note.

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@ti-srebot
Copy link
Contributor

@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).

@MyonKeminta MyonKeminta requested a review from nrc December 9, 2020 09:10
@@ -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,
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

@sticnarf sticnarf left a 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.

@@ -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';
Copy link
Contributor

@sticnarf sticnarf Dec 10, 2020

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor

@nrc nrc left a 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`
Copy link
Contributor

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! 👍👍👍

/// 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.
Copy link
Contributor

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?

@ti-srebot ti-srebot added the status/LGT1 Status: PR - There is already 1 approval label Dec 10, 2020
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Copy link
Contributor

@sticnarf sticnarf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest lgtm.

@ti-srebot ti-srebot removed the status/LGT1 Status: PR - There is already 1 approval label Dec 10, 2020
@ti-srebot ti-srebot added the status/LGT2 Status: PR - There are already 2 approvals label Dec 10, 2020
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@hicqu
Copy link
Contributor

hicqu commented Dec 10, 2020

/merge

@ti-srebot
Copy link
Contributor

@hicqu Oops! auto merge is restricted to Committers of the SIG.See the corresponding SIG page for more information. Related SIG: transaction(slack).

@sticnarf
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Status: Can merge to base branch label Dec 10, 2020
@ti-srebot
Copy link
Contributor

/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();
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

@ti-srebot
Copy link
Contributor

@MyonKeminta merge failed.

@hicqu
Copy link
Contributor

hicqu commented Dec 10, 2020

/run-all-tests

@MyonKeminta
Copy link
Contributor Author

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 18b7b7a into tikv:master Dec 10, 2020
@MyonKeminta MyonKeminta deleted the m/add-gc-fence-field branch December 10, 2020 07:28
solotzg added a commit to pingcap/tiflash that referenced this pull request Dec 11, 2020
- 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>
@sticnarf sticnarf added this to In progress in Async Commit via automation Dec 29, 2020
@sticnarf sticnarf moved this from In progress to Done in Async Commit Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/transaction SIG: Transaction status/can-merge Status: Can merge to base branch status/LGT2 Status: PR - There are already 2 approvals
Projects
Async Commit
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants