-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
raftstore: move get_region_approximate_size to split check worker #9081
Conversation
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
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
@Little-Wallace, 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 SIGs: raft(slack),scheduling(slack). |
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
// Roughly estimate the size and keys and then let split checker to update it. | ||
self.fsm.peer.approximate_size = | ||
self.fsm.peer.approximate_size.map(|x| x / new_region_count); | ||
self.fsm.peer.approximate_keys = | ||
self.fsm.peer.approximate_keys.map(|x| x / new_region_count); | ||
if let Err(e) = self.ctx.split_check_scheduler.schedule( | ||
SplitCheckTask::GetRegionApproximateSizeAndKeys { | ||
region: self.fsm.peer.region().clone(), | ||
pending_tasks: Arc::new(AtomicU64::new(1)), | ||
cb: Box::new(move |_, _| {}), | ||
}, | ||
) { | ||
error!( | ||
"failed to schedule split check task"; | ||
"region_id" => self.fsm.region_id(), | ||
"peer_id" => self.fsm.peer_id(), | ||
"err" => ?e, | ||
); | ||
} |
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 not leader, this task is very wasteful and the approximate_size
& approximate_key
are no need to be updated.
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.
And I think self.fsm.peer.heartbeat_pd
should be called here if it's a leader.
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 not leader, this task is very wasteful and the
approximate_size
&approximate_key
are no need to be updated.
Oh, I didn't notice here in the last update. I will add some check later.
And I think self.fsm.peer.heartbeat_pd should be called here if it's a leader.
heartbeat_pd
is called a few lines before here.
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.
@gengliqi I have updated. PTAL.
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 think we can move these codes to the upper if is_leader
.
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 have updated again. Please have a look.
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
Signed-off-by: gozssky <[email protected]>
// It's not correct anymore, so set it to None to let split checker update it. | ||
self.fsm.peer.approximate_size = None; |
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.
Hmmm, I think we should remove these lines?
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 for non-leader peers. As the previous comment says, the size is not correct anymore.
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 we use the estimated size for non-leader peers but not to update it size immediately, I don't know whether there are
potential risks?
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 self.fsm.peer.approximate_size
is none, the latter estimated_size
is always none.
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.
There is no potential risk because the approximate_size
and approximate_keys
are meaningful only on the leader.
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.
Should it be meaningful if a follower becomes a leader?
If self.fsm.peer.approximate_size is none, the latter estimated_size is always none.
Sorry, I make a mistake here.
let _ = self.router.send( | ||
region.get_id(), | ||
CasualMessage::RegionApproximateSize { size }, | ||
); | ||
let _ = self.router.send( | ||
region.get_id(), | ||
CasualMessage::RegionApproximateKeys { keys }, | ||
); |
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.
These data may be sent to a different peer instead of the expected one in rare circumstances. I find it is the same as the original code of RegionApproximateSize/Keys
, which also has this problem. It seems that the side effect is little but it's risky. I will file an issue for that.
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.
Sounds like a potential risk. Please let me know what caused it to happen when you are free.
Signed-off-by: gozssky <[email protected]>
@gengliqi, 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: scheduling(slack). |
/lgtm |
/merge |
/run-all-tests |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-4.0 in PR #9185 |
) (#9185) Signed-off-by: ti-srebot <[email protected]> Signed-off-by: gozssky <[email protected]>
What problem does this PR solve?
When peer's approximate size or keys is none,region heartbeat need to directly read rocksdb to get size and keys. It will affect other region's heartbeat. This PR move
get_region_approximate_size
andget_region_approximate_keys
to split worker's thread so that most regions' heartbeat will go smoothly.What is changed and how it works?
What's Changed:
Add a new task type
GetRegionApproximateSizeAndKeys
to split checker. For this task, split check worker will read rocksdb to get size and keys, and execute an callback.Check List
Tests
Release note