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

CORE-1972 don't mark rebalance complete if some partitions are not moveable #18489

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/v/cluster/partition_balancer_planner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1275,11 +1275,17 @@ void partition_balancer_planner::reassignable_partition::revert(
_reallocated->partition.is_original(move.previous()->node_id),
"ntp {}: move {}->{} should have been from original node",
_ntp,
move.current(),
move.previous());
move.previous(),
move.current());
Comment on lines 1277 to +1279
Copy link
Member

Choose a reason for hiding this comment

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

not confusing at all!

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's an assert so I guess nobody noticed 🤷‍♂️ no idea why I wrote it like this in the first place


auto err = _reallocated->partition.try_revert(move);
vassert(err == errc::success, "ntp {}: revert error: {}", _ntp, err);
vlog(
clusterlog.info,
"ntp {}: reverted previously scheduled move {} -> {}",
_ntp,
move.previous()->node_id,
move.current().node_id);

{
// adjust topic node counts
Expand Down Expand Up @@ -1947,6 +1953,10 @@ ss::future<> partition_balancer_planner::get_counts_rebalancing_actions(
}
}
},
[&](immutable_partition& p) {
p.report_failure(change_reason::partition_count_rebalancing);
should_stop = false;
},
[](auto&) {});

return ss::stop_iteration::no;
Expand All @@ -1956,7 +1966,7 @@ ss::future<> partition_balancer_planner::get_counts_rebalancing_actions(
double cur_objective = calc_objective(domain);
vlog(
clusterlog.info,
"counts rebalancing objective in domain {}: {:6} -> {:6}",
"counts rebalancing objective in domain {}: {:.6} -> {:.6}",
domain,
orig_objective,
cur_objective);
Expand Down
7 changes: 6 additions & 1 deletion tests/rptest/tests/end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(self,

def start_redpanda(self,
num_nodes=1,
num_started_nodes=None,
extra_rp_conf=None,
si_settings=None,
environment=None,
Expand Down Expand Up @@ -122,7 +123,11 @@ def start_redpanda(self,
self.redpanda._installer.install(self.redpanda.nodes,
version_to_install)

self.redpanda.start(auto_assign_node_id=new_bootstrap,
started_nodes = None
if num_started_nodes is not None:
started_nodes = self.redpanda.nodes[:num_started_nodes]
self.redpanda.start(nodes=started_nodes,
auto_assign_node_id=new_bootstrap,
omit_seeds_on_idx_one=not new_bootstrap)
if version_to_install and install_opts.num_to_upgrade > 0:
# Perform the upgrade rather than starting each node on the
Expand Down
64 changes: 64 additions & 0 deletions tests/rptest/tests/partition_balancer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,3 +1142,67 @@ def test_transfer_controller_leadership(self):
target_id=transfer_to_idx)

self.wait_until_ready()

@skip_debug_mode
@cluster(num_nodes=7, log_allow_list=CHAOS_LOG_ALLOW_LIST)
def test_recovery_mode_rebalance_finish(self):
"""
Test that rebalancing on node add correctly finishes
if some (but not all) nodes were in recovery mode.
"""

# start first 3 nodes and create some partitions on them
self.start_redpanda(num_nodes=5,
num_started_nodes=3,
new_bootstrap=True)
self.topic = TopicSpec(partition_count=50)
self.client().create_topic(self.topic)

self.start_producer(1)
self.start_consumer(1)
self.await_startup()

# restart seed nodes in recovery mode
seed_nodes = self.redpanda.nodes[:3]
self.redpanda.restart_nodes(
seed_nodes,
auto_assign_node_id=True,
omit_seeds_on_idx_one=False,
override_cfg_params={"recovery_mode_enabled": True})

# add 2 more nodes and make sure the balancer runs on one of them
# (it can't run on seed nodes because of recovery mode)
joiner_nodes = self.redpanda.nodes[3:]
for node in joiner_nodes:
self.redpanda.start_node(node,
auto_assign_node_id=True,
omit_seeds_on_idx_one=False)
self.redpanda.wait_for_membership(first_start=False)

admin = Admin(self.redpanda)

admin.transfer_leadership_to(namespace='redpanda',
topic='controller',
partition=0,
target_id=self.redpanda.node_id(
joiner_nodes[0]))

# the balancer will stall because not all partitions are moveable
self.wait_until_status(lambda s: s["status"] == "stalled")

# restart seed nodes in normal mode
self.redpanda.restart_nodes(seed_nodes, auto_assign_node_id=True)
self.redpanda.wait_for_membership(first_start=False)

self.wait_until_ready()

# check that partition counts are balanced
partition_counts = [
len(admin.get_partitions(node=n)) for n in self.redpanda.nodes
]
self.logger.info(f"partition counts: {partition_counts}")
avg = sum(partition_counts) / len(partition_counts)
assert all(abs(c - avg) / avg < 0.05 for c in partition_counts), \
"partition counts not balanced"

self.run_validation(consumer_timeout_sec=CONSUMER_TIMEOUT)
Loading