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

*: check memory locks in replica read #8926

Merged
merged 44 commits into from
Nov 12, 2020

Conversation

sticnarf
Copy link
Contributor

@sticnarf sticnarf commented Nov 2, 2020

What problem does this PR solve?

Issue Number: tikv/sig-transaction#20

Problem Summary: Replica read in TiKV currently conflicts with async commit.

What is changed and how it works?

Depends on pingcap/kvproto#687

This PR changes the read index context from a UUID to something more complex. Now the context may contain the range to check and also may contain the lock returned by the leader. When a leader receives a read index context with key ranges, it will check the in-memory lock table and see if there is any lock blocking this read. If any, it will send the lock back to the follower or learner via the read index context.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • PR to update pingcap/tidb-ansible:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit tests
  • Integration tests

There should be more tests for each reading RPC. We can add them later.

Release note

  • Part of the async commit

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
…ex-2

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
…ad-index

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
…ad-index-2

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
@sticnarf
Copy link
Contributor Author

sticnarf commented Nov 3, 2020

I am not so confident in the raftstore changes. Please be careful in checking whether all paths of replica read are covered.

This PR mixes a lot of transaction related code into raftstore. This makes me feel uncomfortable... Code style and organization suggestions are welcome.

@sticnarf
Copy link
Contributor Author

sticnarf commented Nov 3, 2020

/run-all-tests

@BusyJay
Copy link
Member

BusyJay commented Nov 3, 2020

This PR mixes a lot of transaction related code into raftstore.

Can you put them into coprocessor?

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Copy link
Contributor

@youjiali1995 youjiali1995 left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-srebot ti-srebot added status/LGT2 Status: PR - There are already 2 approvals and removed status/LGT1 Status: PR - There is already 1 approval labels Nov 12, 2020
@@ -3471,6 +3516,127 @@ fn make_transfer_leader_response() -> RaftCmdResponse {
resp
}

const UUID_LEN: usize = 16;
Copy link
Member

Choose a reason for hiding this comment

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

Can it be moved out of peer.rs, like read_queue.rs? It's large enough.

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Copy link
Member

@NingLin-P NingLin-P left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Comment on lines 1033 to 1037
if ctx.coprocessor_host.on_step_read_index(&mut m) {
return Ok(self.raft_group.step(m)?);
}
// Here we hold up MsgReadIndex. If current peer has valid lease, then we could handle the
// request directly, rather than send a heartbeat to check quorum.
Copy link
Member

Choose a reason for hiding this comment

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

Even though there are memory locks encountered, I think we can still utilize the leader lease to avoid broadcasting a heartbeat to check quorum. /cc @5kbpers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@5kbpers explains that to me. Could you please also take a look at my new commit c150ef3?

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@5kbpers
Copy link
Member

5kbpers commented Nov 12, 2020

LGTM

@sticnarf
Copy link
Contributor Author

/merge

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

/run-all-tests

@ti-srebot
Copy link
Contributor

@sticnarf merge failed.

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
@sticnarf
Copy link
Contributor Author

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/raft Component: Raft, RaftStore, etc. 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