Skip to content

Commit

Permalink
WIP ducktape pinning test
Browse files Browse the repository at this point in the history
  • Loading branch information
ztlpn committed Oct 7, 2024
1 parent 4abc39b commit 5ad3eae
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion tests/rptest/tests/leadership_transfer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import math

from rptest.services.cluster import cluster
from rptest.services.redpanda import RESTART_LOG_ALLOW_LIST
from rptest.services.redpanda import RESTART_LOG_ALLOW_LIST, LoggingConfig
from ducktape.utils.util import wait_until
from rptest.clients.kafka_cat import KafkaCat
from rptest.clients.rpk import RpkTool
from rptest.util import wait_until_result
from rptest.clients.types import TopicSpec
from rptest.services.admin import Admin
Expand Down Expand Up @@ -339,3 +340,64 @@ def all_partitions_present(num_nodes, per_node=None):
expected_min = math.floor(expected_on_shard * 0.8)
assert count >= expected_min, \
f"leader count on shard {s} ({count}) is < {expected_min}"


class LeadershipPinningTest(RedpandaTest):
def __init__(self, test_context):
super(LeadershipPinningTest, self).__init__(
test_context=test_context,
num_brokers=6,
extra_rp_conf={
'enable_rack_awareness': True,
# 'leader_balancer_idle_timeout': 20000,
},
log_config=LoggingConfig('info',
logger_levels={'cluster': 'trace'}),
)

def setUp(self):
pass

def _get_leaders_by_node(self):
kc = KafkaCat(self.redpanda)
md = kc.metadata()
leaders = []
for topic in md["topics"]:
leaders.extend(p["leader"] for p in topic["partitions"])
return dict(collections.Counter(leaders))

@cluster(num_nodes=6, log_allow_list=RESTART_LOG_ALLOW_LIST)
def test_leadership_pinning(self):
rack_layout = ['A', 'A', 'B', 'B', 'C', 'C']
for ix, node in enumerate(self.redpanda.nodes):
self.redpanda.set_extra_node_conf(node, {
'rack': rack_layout[ix],
})
self.redpanda.add_extra_rp_conf(
{'default_leaders_preference': "racks: A"})
self.redpanda.start()

rpk = RpkTool(self.redpanda)

rpk.create_topic("foo", partitions=61, replicas=3)
rpk.create_topic("bar",
partitions=20,
replicas=3,
config={"redpanda.leaders.preference": "racks: B"})

rpk.alter_topic_config("bar", "redpanda.leaders.preference",
"racks: B, C")

for i in range(20):
time.sleep(5)
self.logger.warn(
f"FFF {sorted(self._get_leaders_by_node().items())}")

self.logger.warn(f"FFF ------------------")

rpk.alter_topic_config("foo", "redpanda.leaders.preference", "none")

for i in range(6):
time.sleep(5)
self.logger.warn(
f"FFF {sorted(self._get_leaders_by_node().items())}")

0 comments on commit 5ad3eae

Please sign in to comment.