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

deadlock: more solid role change observer #6415

Merged

Conversation

youjiali1995
Copy link
Contributor

@youjiali1995 youjiali1995 commented Jan 6, 2020

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?

  • Improvement (a change which is an improvement to an existing feature)

How is the PR tested?

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    Have tested it with Schrodinger for several days.
    image

Does this PR affect documentation (docs) or should it be mentioned in the release notes?

No

Does this PR affect tidb-ansible?

No

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@youjiali1995 youjiali1995 added the component/server Component: Server label Jan 6, 2020
@youjiali1995 youjiali1995 added this to the v3.0.9 milestone Jan 6, 2020
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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Member

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.

Copy link
Contributor Author

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()
Copy link
Member

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?

Copy link
Contributor Author

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>
@BusyJay
Copy link
Member

BusyJay commented Jan 7, 2020

I suggest to implement deadlock manager on the TiDB side for following reasons:

  1. it's not easy to watch leader role on TiKV side, TiKV can't guarantee in time role change notification. It's possible that there are two deadlock detectors both think they are valid leader;
  2. TiDB already has a leader role, implement deadlock manager is just like implement another gc/ddl mechanism, it's easy and reliable;
  3. TiKV's leader can change, region can split, replicas can be moved around for various reason at any time, it introduces unnecessary complexity and fail rate to the deadlock mechanism.

@MyonKeminta
Copy link
Contributor

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

@BusyJay
Copy link
Member

BusyJay commented Jan 7, 2020

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.

@youjiali1995
Copy link
Contributor Author

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.

@AndreMouche
Copy link
Member

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

@BusyJay
Copy link
Member

BusyJay commented Jan 7, 2020

make sure the leader of the deadlock detector won't change unless it is down

That's exactly how TiDB leader behaves.

@BusyJay
Copy link
Member

BusyJay commented Jan 7, 2020

@AndreMouche Agree. It's just an advice after seeing the effort we have been made to tweak deadlock manager.

@AndreMouche AndreMouche modified the milestones: v3.0.9, v3.1.10 Jan 7, 2020
…-role-change-observer

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@youjiali1995
Copy link
Contributor Author

/run-all-tests

Copy link
Member

@AndreMouche AndreMouche left a comment

Choose a reason for hiding this comment

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

LGTM

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.

LGTM

Copy link
Contributor

@MyonKeminta MyonKeminta left a comment

Choose a reason for hiding this comment

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

LGTM

@youjiali1995 youjiali1995 merged commit 02b77fb into tikv:master Jan 7, 2020
@youjiali1995 youjiali1995 deleted the more-solid-role-change-observer branch January 7, 2020 09:31
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jan 7, 2020
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
sre-bot pushed a commit that referenced this pull request Jan 7, 2020
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jan 9, 2020
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@AndreMouche AndreMouche removed this from the v3.1.10 milestone Jan 10, 2020
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Feb 10, 2020
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
youjiali1995 added a commit that referenced this pull request Feb 14, 2020
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
solotzg added a commit to pingcap/tidb-engine-ext that referenced this pull request Feb 15, 2020
* [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>
solotzg added a commit to pingcap/tidb-engine-ext that referenced this pull request Feb 21, 2020
* [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>
c1ay pushed a commit to c1ay/tikv that referenced this pull request May 9, 2020
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/server Component: Server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants