-
Notifications
You must be signed in to change notification settings - Fork 580
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
Partition balancer: rack awareness constraint repair #6845
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
da9cafa
c/partition_allocator: add is_rack_awareness_enabled method
ztlpn a6316b1
c/partition_balancer: add partition_balancer_state
ztlpn 670b318
c/partition_balancer_planner: get rid of the metadata param
ztlpn 5f00b51
c/partition_balancer: schedule moves repairing rack awareness constraint
ztlpn 7c35407
ut/partition_balancer: easier creation of nodes with defined rack ids
ztlpn 34aea6b
ut/partition_balancer: add rack awareness repair unit test
ztlpn 4fb4ba5
tests: add PartitionBalancerTest.test_rack_constraint_repair
ztlpn 6e41138
c/partition_balancer: improve logging
ztlpn cebb295
c/partition_balancer: partition_balancer_state unit tests
ztlpn 04e041e
c/partition_balancer: early return in planner main func
ztlpn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2022 Redpanda Data, Inc. | ||
* | ||
* Licensed as a Redpanda Enterprise file under the Redpanda Community | ||
* License (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* https://github.com/redpanda-data/redpanda/blob/master/licenses/rcl.md | ||
*/ | ||
|
||
#include "cluster/partition_balancer_state.h" | ||
|
||
#include "cluster/logger.h" | ||
#include "cluster/scheduling/partition_allocator.h" | ||
|
||
#include <absl/container/flat_hash_set.h> | ||
|
||
namespace cluster { | ||
|
||
partition_balancer_state::partition_balancer_state( | ||
ss::sharded<topic_table>& topic_table, | ||
ss::sharded<members_table>& members_table, | ||
ss::sharded<partition_allocator>& pa) | ||
: _topic_table(topic_table.local()) | ||
, _members_table(members_table.local()) | ||
, _partition_allocator(pa.local()) {} | ||
|
||
void partition_balancer_state::handle_ntp_update( | ||
const model::ns& ns, | ||
const model::topic& tp, | ||
model::partition_id p_id, | ||
const std::vector<model::broker_shard>& prev, | ||
const std::vector<model::broker_shard>& next) { | ||
if (_partition_allocator.is_rack_awareness_enabled()) { | ||
absl::flat_hash_set<model::rack_id> racks; | ||
bool is_rack_constraint_violated = false; | ||
for (const auto& bs : next) { | ||
auto rack = _partition_allocator.state().get_rack_id(bs.node_id); | ||
if (rack) { | ||
auto res = racks.insert(std::move(*rack)); | ||
if (!res.second) { | ||
is_rack_constraint_violated = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
model::ntp ntp(ns, tp, p_id); | ||
if (is_rack_constraint_violated) { | ||
auto res = _ntps_with_broken_rack_constraint.insert(std::move(ntp)); | ||
if (res.second) { | ||
vlog( | ||
clusterlog.debug, | ||
"rack constraint violated for ntp: {}, " | ||
"replica set change: {} -> {}", | ||
ntp, | ||
prev, | ||
next); | ||
} | ||
} else { | ||
auto erased = _ntps_with_broken_rack_constraint.erase(ntp); | ||
if (erased > 0) { | ||
vlog( | ||
clusterlog.debug, | ||
"rack constraint restored for ntp: {}, " | ||
"replica set change: {} -> {}", | ||
ntp, | ||
prev, | ||
next); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace cluster |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 seems like a nice clean up--consolidating state.
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.
Yeah that was the idea. Although there is not much consolidation right now, we can use this class to store some balancing-specific indexes (e.g. node -> ntp map). Will be helpful when we eventually will need to get rid of those "iterate over all ntps" loops.
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.