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
deadlock: more solid role change observer #6415
deadlock: more solid role change observer #6415
Conversation
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…-role-change-observer
let mut leader_region_id = self.leader_region_id.lock().unwrap(); | ||
if *leader_region_id == region.get_id() { | ||
*leader_region_id = INVALID_ID; | ||
self.scheduler.change_role(Role::Follower); |
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 possible that when a merge happens, a Destroy
happens first and an Update
follows? May there be no leader between the two message?
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.
Yes. The Update
will be coming soon since the Destroy
happens.
if is_leader_region(ctx.region()) { | ||
self.change_role(role.into()); | ||
let region = ctx.region(); | ||
// A region is created first, so the leader region id must be valid. |
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 is_leader_region
is false, please return as early as possible.
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.
It is.
let region = ctx.region(); | ||
// A region is created first, so the leader region id must be valid. | ||
if Self::is_leader_region(region) | ||
&& *self.leader_region_id.lock().unwrap() == region.get_id() |
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 possible it is the leader region while the region id is not leader_region_id ? what shall we do if it happens?
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 happens, it must be a stale region and need to do nothing since region id is updated when receiving Create or Update event.
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
I suggest to implement deadlock manager on the TiDB side for following reasons:
|
@BusyJay But TiKVs need to access the deadlock manager. I think it's not a good idea to let TiKV to access TiDB. In my opinion, we can implement it in TiKV, but adopt a similar election mechanism like TiDB's ddl/gc leader rather than relying on a special region. |
TiDB can poll changes from TiKV just like what green GC has done. The difference is that Green GC can abort the call at the end of a round of GC, but deadlock manager will keep listening until new leader is elected. |
I think an election mechanism is needed since we should make sure the leader of the deadlock detector won't change unless it is down. But it's a long-term work. |
Each method has advantages and disadvantages, and move the deadlock manager to tidb is a long job, maybe we can consider it in the future. For now, we need to consider if current PR can improve the efficiency to detect the leader of the deadlock_manager, and determine if it is worth to merge into v3.0.9 @youjiali1995 @BusyJay @MyonKeminta |
That's exactly how TiDB leader behaves. |
@AndreMouche Agree. It's just an advice after seeing the effort we have been made to tweak deadlock manager. |
…-role-change-observer Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…youjiali1995/tikv into more-solid-role-change-observer
/run-all-tests |
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
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
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
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
* [3.1] external_storage: add S3 support (tikv#6209) (tikv#6536) * external_storage: add S3 support (tikv#6209) Signed-off-by: Yi Wu <yiwu@pingcap.com> Signed-off-by: kennytm <kennytm@gmail.com> * lock_manager: more metrics (tikv#6392) (tikv#6422) (tikv#6444) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> * lock_manager: update default config (tikv#6426) (tikv#6429) (tikv#6446) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> * Update rocksdb and titan. Update rust-rocksdb url (tikv#6554) Signed-off-by: Yi Wu <yiwu@pingcap.com> * raft_client: connect to other stores using peer_address (tikv#5569) (tikv#6491) * *: pick threads statistics for regions (tikv#6605) Co-authored-by: jiyingtk <1039793452@qq.com> Co-authored-by: disksing <i@disksing.com> * fix test_replica_read::test_read_after_cleanup_range_for_snap (tikv#6493) Signed-off-by: 5kbpers <tangminghua@pingcap.com> * deadlock: more solid role change observer (tikv#6415) (tikv#6431) (tikv#6445) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> * raftstore: read index message count metric (tikv#6579) (tikv#6610) Signed-off-by: 5kbpers <tangminghua@pingcap.com> * raftstore: speed up conf change (tikv#6421) (tikv#6432) Signed-off-by: Jay Lee <busyjaylee@gmail.com> * raftstore: fix a panic in read index queue (tikv#6609) (tikv#6613) Signed-off-by: qupeng <qupeng@pingcap.com> * pick tikv#6414, tikv#6487, tikv#6477 and tikv#6539 to release-3.1 (tikv#6564) * raftstore: extract batch system (tikv#6414) * apply: support yield (tikv#6487) * batch-system: add benchmark (tikv#6477) * Introduce pre transfer leader (tikv#6539) Signed-off-by: Jay Lee <BusyJayLee@gmail.com> * raftstore: set wait_merge_state to none after resuming pending state (tikv#6621) Signed-off-by: Liqi Geng <gengliqiii@gmail.com> * raftstore: learner load merge target & fix a merge network recovery bug (tikv#6623) Signed-off-by: Liqi Geng <gengliqiii@gmail.com> * change merge flow path (tikv#6617) Signed-off-by: Liqi Geng <gengliqiii@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> Co-authored-by: Lei Zhao <zlwgx1023@gmail.com> Co-authored-by: yiwu-arbug <yiwu@pingcap.com> Co-authored-by: disksing <i@disksing.com> Co-authored-by: ShuNing <nolouch@gmail.com> Co-authored-by: jiyingtk <1039793452@qq.com> Co-authored-by: pingcap-github-bot <sre-bot@pingcap.com> Co-authored-by: 5kbpers <20279863+5kbpers@users.noreply.github.com> Co-authored-by: Jay <BusyJay@users.noreply.github.com> Co-authored-by: gengliqi <gengliqiii@gmail.com>
* [3.1] external_storage: add S3 support (tikv#6209) (tikv#6536) * external_storage: add S3 support (tikv#6209) Signed-off-by: Yi Wu <yiwu@pingcap.com> Signed-off-by: kennytm <kennytm@gmail.com> * lock_manager: more metrics (tikv#6392) (tikv#6422) (tikv#6444) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> * lock_manager: update default config (tikv#6426) (tikv#6429) (tikv#6446) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> * Update rocksdb and titan. Update rust-rocksdb url (tikv#6554) Signed-off-by: Yi Wu <yiwu@pingcap.com> * raft_client: connect to other stores using peer_address (tikv#5569) (tikv#6491) * *: pick threads statistics for regions (tikv#6605) Co-authored-by: jiyingtk <1039793452@qq.com> Co-authored-by: disksing <i@disksing.com> * fix test_replica_read::test_read_after_cleanup_range_for_snap (tikv#6493) Signed-off-by: 5kbpers <tangminghua@pingcap.com> * deadlock: more solid role change observer (tikv#6415) (tikv#6431) (tikv#6445) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> * raftstore: read index message count metric (tikv#6579) (tikv#6610) Signed-off-by: 5kbpers <tangminghua@pingcap.com> * raftstore: speed up conf change (tikv#6421) (tikv#6432) Signed-off-by: Jay Lee <busyjaylee@gmail.com> * raftstore: fix a panic in read index queue (tikv#6609) (tikv#6613) Signed-off-by: qupeng <qupeng@pingcap.com> * pick tikv#6414, tikv#6487, tikv#6477 and tikv#6539 to release-3.1 (tikv#6564) * raftstore: extract batch system (tikv#6414) * apply: support yield (tikv#6487) * batch-system: add benchmark (tikv#6477) * Introduce pre transfer leader (tikv#6539) Signed-off-by: Jay Lee <BusyJayLee@gmail.com> * raftstore: set wait_merge_state to none after resuming pending state (tikv#6621) Signed-off-by: Liqi Geng <gengliqiii@gmail.com> * raftstore: learner load merge target & fix a merge network recovery bug (tikv#6623) Signed-off-by: Liqi Geng <gengliqiii@gmail.com> * change merge flow path (tikv#6617) Signed-off-by: Liqi Geng <gengliqiii@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> Co-authored-by: Lei Zhao <zlwgx1023@gmail.com> Co-authored-by: yiwu-arbug <yiwu@pingcap.com> Co-authored-by: disksing <i@disksing.com> Co-authored-by: ShuNing <nolouch@gmail.com> Co-authored-by: jiyingtk <1039793452@qq.com> Co-authored-by: pingcap-github-bot <sre-bot@pingcap.com> Co-authored-by: 5kbpers <20279863+5kbpers@users.noreply.github.com> Co-authored-by: Jay <BusyJay@users.noreply.github.com> Co-authored-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
What have you changed?
To prevent potential bugs, observe more events of raftstore to change the role of the deadlock detector.
What is the type of the changes?
How is the PR tested?
Have tested it with Schrodinger for several days.
Does this PR affect documentation (docs) or should it be mentioned in the release notes?
No
Does this PR affect
tidb-ansible
?No