You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by jo...@apache.org on 2024/05/20 15:21:13 UTC
(kafka) branch 3.7 updated: KAFKA-16992: InvalidRequestException: ADD_PARTITIONS_TO_TXN with version 4 which is not enabled when upgrading from kafka (#15971)
This is an automated email from the ASF dual-hosted git repository.
jolshan pushed a commit to branch 3.7
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.7 by this push:
new 047cbe7a2db KAFKA-16992: InvalidRequestException: ADD_PARTITIONS_TO_TXN with version 4 which is not enabled when upgrading from kafka (#15971)
047cbe7a2db is described below
commit 047cbe7a2db6998d566ca08d8bd16af815525802
Author: Justine Olshan <jo...@confluent.io>
AuthorDate: Fri May 17 21:35:28 2024 -0700
KAFKA-16992: InvalidRequestException: ADD_PARTITIONS_TO_TXN with version 4 which is not enabled when upgrading from kafka (#15971)
We weren't enabling discoverBrokerVersions to check the supported versions in the AddPartitionsToTxnManager. This means that any verification request (or any AddPartitionsToTxnRequest version) from a newer broker would fail when sending to an older broker.
The bulk of this change is adding additional transactions system tests for old versions.
One test upgrades the cluster completely. This didn't catch the issue but could be useful.
The other test forces a new broker to send a verification request to an older one. Without the discoverBrokerVersions change, all tests between mixed brokers failed. (We introduced a new request version in 3.8 -- which is a separate version from the one that caused the bug for 3.5 -> 3.6) With the addition, the tests all passed.
I also manually ran a test for 3.5 -> 3.6 since the issue there was slightly different and was caused by the unstableLatestVersion flag being enabled. This change should fix this as well. 👍
Reviewers: David Jacot <dj...@confluent.io>
---
core/src/main/java/kafka/server/NetworkUtils.java | 2 +-
...test.py => transactions_mixed_versions_test.py} | 200 ++++++-------------
tests/kafkatest/tests/core/transactions_test.py | 48 +----
...ctions_test.py => transactions_upgrade_test.py} | 220 ++++++++-------------
tests/kafkatest/utils/transactions_utils.py | 55 ++++++
5 files changed, 201 insertions(+), 324 deletions(-)
diff --git a/core/src/main/java/kafka/server/NetworkUtils.java b/core/src/main/java/kafka/server/NetworkUtils.java
index 87dc7e96107..5607f2623f9 100644
--- a/core/src/main/java/kafka/server/NetworkUtils.java
+++ b/core/src/main/java/kafka/server/NetworkUtils.java
@@ -82,7 +82,7 @@ public class NetworkUtils {
config.connectionSetupTimeoutMs(),
config.connectionSetupTimeoutMaxMs(),
time,
- false,
+ true,
new ApiVersions(),
logContext
);
diff --git a/tests/kafkatest/tests/core/transactions_test.py b/tests/kafkatest/tests/core/transactions_mixed_versions_test.py
similarity index 52%
copy from tests/kafkatest/tests/core/transactions_test.py
copy to tests/kafkatest/tests/core/transactions_mixed_versions_test.py
index 90d459bb8d6..6de8f1014fd 100644
--- a/tests/kafkatest/tests/core/transactions_test.py
+++ b/tests/kafkatest/tests/core/transactions_mixed_versions_test.py
@@ -13,12 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from kafkatest.services.zookeeper import ZookeeperService
-from kafkatest.services.kafka import KafkaService, quorum
+from kafkatest.services.kafka import KafkaService, quorum, consumer_group
+from kafkatest.services.kafka.quorum import isolated_kraft
from kafkatest.services.console_consumer import ConsoleConsumer
from kafkatest.services.verifiable_producer import VerifiableProducer
from kafkatest.services.transactional_message_copier import TransactionalMessageCopier
from kafkatest.utils import is_int
+from kafkatest.utils.transactions_utils import create_and_start_copiers
+from kafkatest.version import LATEST_3_1, LATEST_3_2, LATEST_3_3, LATEST_3_4, LATEST_3_5, \
+ LATEST_3_6, DEV_BRANCH, KafkaVersion
from ducktape.tests.test import Test
from ducktape.mark import matrix
@@ -27,48 +30,34 @@ from ducktape.utils.util import wait_until
import time
-class TransactionsTest(Test):
+class TransactionsMixedVersionsTest(Test):
"""Tests transactions by transactionally copying data from a source topic to
- a destination topic and killing the copy process as well as the broker
- randomly through the process. In the end we verify that the final output
- topic contains exactly one committed copy of each message in the input
- topic.
+ a destination between brokers with different image versions. This is how transactions work
+ while the cluster is undergoing an upgrade.
"""
def __init__(self, test_context):
""":type test_context: ducktape.tests.test.TestContext"""
- super(TransactionsTest, self).__init__(test_context=test_context)
+ super(TransactionsMixedVersionsTest, self).__init__(test_context=test_context)
self.input_topic = "input-topic"
self.output_topic = "output-topic"
self.num_brokers = 3
+ self.replication_factor = 3
+
# Test parameters
- self.num_input_partitions = 2
- self.num_output_partitions = 3
- self.num_seed_messages = 100000
- self.transaction_size = 750
+ self.num_input_partitions = 1
+ self.num_output_partitions = 1
+ self.num_seed_messages = 1000
+ self.transaction_size = 5
# The transaction timeout should be lower than the progress timeout, but at
- # least as high as the request timeout (which is 30s by default). When the
- # client is hard-bounced, progress may depend on the previous transaction
- # being aborted. When the broker is hard-bounced, we may have to wait as
- # long as the request timeout to get a `Produce` response and we do not
- # want the coordinator timing out the transaction.
+ # least as high as the request timeout (which is 30s by default).
self.transaction_timeout = 40000
self.progress_timeout_sec = 60
self.consumer_group = "transactions-test-consumer-group"
- self.zk = ZookeeperService(test_context, num_nodes=1) if quorum.for_test(test_context) == quorum.zk else None
- self.kafka = KafkaService(test_context,
- num_nodes=self.num_brokers,
- zk=self.zk,
- controller_num_nodes_override=1)
-
- def setUp(self):
- if self.zk:
- self.zk.start()
-
def seed_messages(self, topic, num_seed_messages):
seed_timeout_sec = 10000
seed_producer = VerifiableProducer(context=self.test_context,
@@ -89,71 +78,6 @@ class TransactionsTest(Test):
consumer = self.start_consumer(topic, group_id="verifying_consumer")
return self.drain_consumer(consumer, num_messages)
- def bounce_brokers(self, clean_shutdown):
- for node in self.kafka.nodes:
- if clean_shutdown:
- self.kafka.restart_node(node, clean_shutdown = True)
- else:
- self.kafka.stop_node(node, clean_shutdown = False)
- gracePeriodSecs = 5
- if self.zk:
- wait_until(lambda: not self.kafka.pids(node) and not self.kafka.is_registered(node),
- timeout_sec=self.kafka.zk_session_timeout + gracePeriodSecs,
- err_msg="Failed to see timely deregistration of hard-killed broker %s" % str(node.account))
- else:
- brokerSessionTimeoutSecs = 18
- wait_until(lambda: not self.kafka.pids(node),
- timeout_sec=brokerSessionTimeoutSecs + gracePeriodSecs,
- err_msg="Failed to see timely disappearance of process for hard-killed broker %s" % str(node.account))
- time.sleep(brokerSessionTimeoutSecs + gracePeriodSecs)
- self.kafka.start_node(node)
-
- self.kafka.await_no_under_replicated_partitions()
-
- def create_and_start_message_copier(self, input_topic, input_partition, output_topic, transactional_id, use_group_metadata):
- message_copier = TransactionalMessageCopier(
- context=self.test_context,
- num_nodes=1,
- kafka=self.kafka,
- transactional_id=transactional_id,
- consumer_group=self.consumer_group,
- input_topic=input_topic,
- input_partition=input_partition,
- output_topic=output_topic,
- max_messages=-1,
- transaction_size=self.transaction_size,
- transaction_timeout=self.transaction_timeout,
- use_group_metadata=use_group_metadata
- )
- message_copier.start()
- wait_until(lambda: message_copier.alive(message_copier.nodes[0]),
- timeout_sec=10,
- err_msg="Message copier failed to start after 10 s")
- return message_copier
-
- def bounce_copiers(self, copiers, clean_shutdown):
- for _ in range(3):
- for copier in copiers:
- wait_until(lambda: copier.progress_percent() >= 20.0,
- timeout_sec=self.progress_timeout_sec,
- err_msg="%s : Message copier didn't make enough progress in %ds. Current progress: %s" \
- % (copier.transactional_id, self.progress_timeout_sec, str(copier.progress_percent())))
- self.logger.info("%s - progress: %s" % (copier.transactional_id,
- str(copier.progress_percent())))
- copier.restart(clean_shutdown)
-
- def create_and_start_copiers(self, input_topic, output_topic, num_copiers, use_group_metadata):
- copiers = []
- for i in range(0, num_copiers):
- copiers.append(self.create_and_start_message_copier(
- input_topic=input_topic,
- output_topic=output_topic,
- input_partition=i,
- transactional_id="copier-" + str(i),
- use_group_metadata=use_group_metadata
- ))
- return copiers
-
def start_consumer(self, topic_to_read, group_id):
consumer = ConsoleConsumer(context=self.test_context,
num_nodes=1,
@@ -186,33 +110,29 @@ class TransactionsTest(Test):
consumer.stop()
return consumer.messages_consumed[1]
- def copy_messages_transactionally(self, failure_mode, bounce_target,
- input_topic, output_topic,
+ def copy_messages_transactionally(self, input_topic, output_topic,
num_copiers, num_messages_to_copy,
use_group_metadata):
"""Copies messages transactionally from the seeded input topic to the
- output topic, either bouncing brokers or clients in a hard and soft
- way as it goes.
+ output topic.
This method also consumes messages in read_committed mode from the
- output topic while the bounces and copy is going on.
+ output topic.
It returns the concurrently consumed messages.
"""
- copiers = self.create_and_start_copiers(input_topic=input_topic,
- output_topic=output_topic,
- num_copiers=num_copiers,
- use_group_metadata=use_group_metadata)
+
+ copiers = create_and_start_copiers(test_context=self.test_context,
+ kafka=self.kafka,
+ consumer_group=self.consumer_group,
+ input_topic=input_topic,
+ output_topic=output_topic,
+ transaction_size=self.transaction_size,
+ transaction_timeout=self.transaction_timeout,
+ num_copiers=num_copiers,
+ use_group_metadata=use_group_metadata)
concurrent_consumer = self.start_consumer(output_topic,
group_id="concurrent_consumer")
- clean_shutdown = False
- if failure_mode == "clean_bounce":
- clean_shutdown = True
-
- if bounce_target == "brokers":
- self.bounce_brokers(clean_shutdown)
- elif bounce_target == "clients":
- self.bounce_copiers(copiers, clean_shutdown)
copier_timeout_sec = 120
for copier in copiers:
@@ -225,65 +145,65 @@ class TransactionsTest(Test):
return self.drain_consumer(concurrent_consumer, num_messages_to_copy)
def setup_topics(self):
+ assignment = ":".join(map(str, [self.kafka.idx(node) for node in self.kafka.nodes]))
+ transaction_assignment = ",".join(map(str, [assignment[::-1]] * 50))
self.kafka.topics = {
self.input_topic: {
"partitions": self.num_input_partitions,
- "replication-factor": 3,
+ "replication-factor": self.replication_factor,
+ "replica-assignment": assignment,
"configs": {
"min.insync.replicas": 2
}
},
self.output_topic: {
"partitions": self.num_output_partitions,
- "replication-factor": 3,
+ "replication-factor": self.replication_factor,
+ "replica-assignment": assignment,
+ "configs": {
+ "min.insync.replicas": 2
+ }
+ },
+ "__transaction_state": {
+ "partitions": 50,
+ "replication-factor": self.replication_factor,
+ "replica-assignment": transaction_assignment,
"configs": {
"min.insync.replicas": 2
}
}
}
- @cluster(num_nodes=9)
- @matrix(
- failure_mode=["hard_bounce", "clean_bounce"],
- bounce_target=["brokers", "clients"],
- check_order=[True, False],
- use_group_metadata=[True, False],
- metadata_quorum=[quorum.zk],
- use_new_coordinator=[False]
- )
+ @cluster(num_nodes=8)
@matrix(
- failure_mode=["hard_bounce", "clean_bounce"],
- bounce_target=["brokers", "clients"],
- check_order=[True, False],
- use_group_metadata=[True, False],
- metadata_quorum=quorum.all_kraft,
+ old_kafka_version=[str(LATEST_3_6), str(LATEST_3_5), str(LATEST_3_4), str(LATEST_3_3), str(LATEST_3_2), str(LATEST_3_1)],
+ metadata_quorum=[isolated_kraft],
use_new_coordinator=[False]
)
- def test_transactions(self, failure_mode, bounce_target, check_order, use_group_metadata, metadata_quorum=quorum.zk, use_new_coordinator=False):
+ def test_transactions_mixed_versions(self, old_kafka_version, metadata_quorum=quorum.isolated_kraft, use_new_coordinator=False):
+ oldKafkaVersion = KafkaVersion(old_kafka_version)
+ self.kafka = KafkaService(self.test_context,
+ num_nodes=self.num_brokers,
+ zk=None,
+ version=oldKafkaVersion,
+ controller_num_nodes_override=1)
+
+ self.kafka.nodes[0].version = DEV_BRANCH
+
security_protocol = 'PLAINTEXT'
self.kafka.security_protocol = security_protocol
self.kafka.interbroker_security_protocol = security_protocol
self.kafka.logs["kafka_data_1"]["collect_default"] = True
self.kafka.logs["kafka_data_2"]["collect_default"] = True
self.kafka.logs["kafka_operational_logs_debug"]["collect_default"] = True
- if check_order:
- # To check ordering, we simply create input and output topics
- # with a single partition.
- # We reduce the number of seed messages to copy to account for the fewer output
- # partitions, and thus lower parallelism. This helps keep the test
- # time shorter.
- self.num_seed_messages = self.num_seed_messages // 3
- self.num_input_partitions = 1
- self.num_output_partitions = 1
self.setup_topics()
self.kafka.start()
input_messages = self.seed_messages(self.input_topic, self.num_seed_messages)
concurrently_consumed_messages = self.copy_messages_transactionally(
- failure_mode, bounce_target, input_topic=self.input_topic,
- output_topic=self.output_topic, num_copiers=self.num_input_partitions,
- num_messages_to_copy=self.num_seed_messages, use_group_metadata=use_group_metadata)
+ input_topic=self.input_topic, output_topic=self.output_topic, num_copiers=self.num_input_partitions,
+ num_messages_to_copy=self.num_seed_messages, use_group_metadata=True)
output_messages = self.get_messages_from_topic(self.output_topic, self.num_seed_messages)
concurrently_consumed_message_set = set(concurrently_consumed_messages)
@@ -301,7 +221,3 @@ class TransactionsTest(Test):
assert input_message_set == concurrently_consumed_message_set, \
"Input and concurrently consumed output message sets are not equal. Num input messages: %d. Num concurrently_consumed_messages: %d" %\
(len(input_message_set), len(concurrently_consumed_message_set))
- if check_order:
- assert input_messages == sorted(input_messages), "The seed messages themselves were not in order"
- assert output_messages == input_messages, "Output messages are not in order"
- assert concurrently_consumed_messages == output_messages, "Concurrently consumed messages are not in order"
diff --git a/tests/kafkatest/tests/core/transactions_test.py b/tests/kafkatest/tests/core/transactions_test.py
index 90d459bb8d6..fe7953c0aa4 100644
--- a/tests/kafkatest/tests/core/transactions_test.py
+++ b/tests/kafkatest/tests/core/transactions_test.py
@@ -17,8 +17,8 @@ from kafkatest.services.zookeeper import ZookeeperService
from kafkatest.services.kafka import KafkaService, quorum
from kafkatest.services.console_consumer import ConsoleConsumer
from kafkatest.services.verifiable_producer import VerifiableProducer
-from kafkatest.services.transactional_message_copier import TransactionalMessageCopier
from kafkatest.utils import is_int
+from kafkatest.utils.transactions_utils import create_and_start_copiers
from ducktape.tests.test import Test
from ducktape.mark import matrix
@@ -110,27 +110,6 @@ class TransactionsTest(Test):
self.kafka.await_no_under_replicated_partitions()
- def create_and_start_message_copier(self, input_topic, input_partition, output_topic, transactional_id, use_group_metadata):
- message_copier = TransactionalMessageCopier(
- context=self.test_context,
- num_nodes=1,
- kafka=self.kafka,
- transactional_id=transactional_id,
- consumer_group=self.consumer_group,
- input_topic=input_topic,
- input_partition=input_partition,
- output_topic=output_topic,
- max_messages=-1,
- transaction_size=self.transaction_size,
- transaction_timeout=self.transaction_timeout,
- use_group_metadata=use_group_metadata
- )
- message_copier.start()
- wait_until(lambda: message_copier.alive(message_copier.nodes[0]),
- timeout_sec=10,
- err_msg="Message copier failed to start after 10 s")
- return message_copier
-
def bounce_copiers(self, copiers, clean_shutdown):
for _ in range(3):
for copier in copiers:
@@ -142,18 +121,6 @@ class TransactionsTest(Test):
str(copier.progress_percent())))
copier.restart(clean_shutdown)
- def create_and_start_copiers(self, input_topic, output_topic, num_copiers, use_group_metadata):
- copiers = []
- for i in range(0, num_copiers):
- copiers.append(self.create_and_start_message_copier(
- input_topic=input_topic,
- output_topic=output_topic,
- input_partition=i,
- transactional_id="copier-" + str(i),
- use_group_metadata=use_group_metadata
- ))
- return copiers
-
def start_consumer(self, topic_to_read, group_id):
consumer = ConsoleConsumer(context=self.test_context,
num_nodes=1,
@@ -199,10 +166,15 @@ class TransactionsTest(Test):
It returns the concurrently consumed messages.
"""
- copiers = self.create_and_start_copiers(input_topic=input_topic,
- output_topic=output_topic,
- num_copiers=num_copiers,
- use_group_metadata=use_group_metadata)
+ copiers = create_and_start_copiers(test_context=self.test_context,
+ kafka=self.kafka,
+ consumer_group=self.consumer_group,
+ input_topic=input_topic,
+ output_topic=output_topic,
+ transaction_size=self.transaction_size,
+ transaction_timeout=self.transaction_timeout,
+ num_copiers=num_copiers,
+ use_group_metadata=use_group_metadata)
concurrent_consumer = self.start_consumer(output_topic,
group_id="concurrent_consumer")
clean_shutdown = False
diff --git a/tests/kafkatest/tests/core/transactions_test.py b/tests/kafkatest/tests/core/transactions_upgrade_test.py
similarity index 52%
copy from tests/kafkatest/tests/core/transactions_test.py
copy to tests/kafkatest/tests/core/transactions_upgrade_test.py
index 90d459bb8d6..dff9e4b9835 100644
--- a/tests/kafkatest/tests/core/transactions_test.py
+++ b/tests/kafkatest/tests/core/transactions_upgrade_test.py
@@ -13,12 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from kafkatest.services.zookeeper import ZookeeperService
-from kafkatest.services.kafka import KafkaService, quorum
+from kafkatest.services.kafka import KafkaService, quorum, consumer_group
+from kafkatest.services.kafka.quorum import isolated_kraft
from kafkatest.services.console_consumer import ConsoleConsumer
from kafkatest.services.verifiable_producer import VerifiableProducer
from kafkatest.services.transactional_message_copier import TransactionalMessageCopier
from kafkatest.utils import is_int
+from kafkatest.utils.transactions_utils import create_and_start_copiers
+from kafkatest.version import LATEST_3_1, LATEST_3_2, LATEST_3_3, LATEST_3_4, LATEST_3_5, \
+ LATEST_3_6, DEV_BRANCH, KafkaVersion
from ducktape.tests.test import Test
from ducktape.mark import matrix
@@ -27,48 +30,35 @@ from ducktape.utils.util import wait_until
import time
-class TransactionsTest(Test):
+class TransactionsUpgradeTest(Test):
"""Tests transactions by transactionally copying data from a source topic to
- a destination topic and killing the copy process as well as the broker
- randomly through the process. In the end we verify that the final output
+ a destination topic while upgrading the cluster. In the end we verify that the final output
topic contains exactly one committed copy of each message in the input
topic.
"""
def __init__(self, test_context):
""":type test_context: ducktape.tests.test.TestContext"""
- super(TransactionsTest, self).__init__(test_context=test_context)
+ super(TransactionsUpgradeTest, self).__init__(test_context=test_context)
self.input_topic = "input-topic"
self.output_topic = "output-topic"
self.num_brokers = 3
+ self.replication_factor = 3
+
# Test parameters
- self.num_input_partitions = 2
+ self.num_input_partitions = 3
self.num_output_partitions = 3
- self.num_seed_messages = 100000
- self.transaction_size = 750
+ self.num_seed_messages = 1000
+ self.transaction_size = 5
# The transaction timeout should be lower than the progress timeout, but at
- # least as high as the request timeout (which is 30s by default). When the
- # client is hard-bounced, progress may depend on the previous transaction
- # being aborted. When the broker is hard-bounced, we may have to wait as
- # long as the request timeout to get a `Produce` response and we do not
- # want the coordinator timing out the transaction.
+ # least as high as the request timeout (which is 30s by default).
self.transaction_timeout = 40000
self.progress_timeout_sec = 60
self.consumer_group = "transactions-test-consumer-group"
- self.zk = ZookeeperService(test_context, num_nodes=1) if quorum.for_test(test_context) == quorum.zk else None
- self.kafka = KafkaService(test_context,
- num_nodes=self.num_brokers,
- zk=self.zk,
- controller_num_nodes_override=1)
-
- def setUp(self):
- if self.zk:
- self.zk.start()
-
def seed_messages(self, topic, num_seed_messages):
seed_timeout_sec = 10000
seed_producer = VerifiableProducer(context=self.test_context,
@@ -89,71 +79,6 @@ class TransactionsTest(Test):
consumer = self.start_consumer(topic, group_id="verifying_consumer")
return self.drain_consumer(consumer, num_messages)
- def bounce_brokers(self, clean_shutdown):
- for node in self.kafka.nodes:
- if clean_shutdown:
- self.kafka.restart_node(node, clean_shutdown = True)
- else:
- self.kafka.stop_node(node, clean_shutdown = False)
- gracePeriodSecs = 5
- if self.zk:
- wait_until(lambda: not self.kafka.pids(node) and not self.kafka.is_registered(node),
- timeout_sec=self.kafka.zk_session_timeout + gracePeriodSecs,
- err_msg="Failed to see timely deregistration of hard-killed broker %s" % str(node.account))
- else:
- brokerSessionTimeoutSecs = 18
- wait_until(lambda: not self.kafka.pids(node),
- timeout_sec=brokerSessionTimeoutSecs + gracePeriodSecs,
- err_msg="Failed to see timely disappearance of process for hard-killed broker %s" % str(node.account))
- time.sleep(brokerSessionTimeoutSecs + gracePeriodSecs)
- self.kafka.start_node(node)
-
- self.kafka.await_no_under_replicated_partitions()
-
- def create_and_start_message_copier(self, input_topic, input_partition, output_topic, transactional_id, use_group_metadata):
- message_copier = TransactionalMessageCopier(
- context=self.test_context,
- num_nodes=1,
- kafka=self.kafka,
- transactional_id=transactional_id,
- consumer_group=self.consumer_group,
- input_topic=input_topic,
- input_partition=input_partition,
- output_topic=output_topic,
- max_messages=-1,
- transaction_size=self.transaction_size,
- transaction_timeout=self.transaction_timeout,
- use_group_metadata=use_group_metadata
- )
- message_copier.start()
- wait_until(lambda: message_copier.alive(message_copier.nodes[0]),
- timeout_sec=10,
- err_msg="Message copier failed to start after 10 s")
- return message_copier
-
- def bounce_copiers(self, copiers, clean_shutdown):
- for _ in range(3):
- for copier in copiers:
- wait_until(lambda: copier.progress_percent() >= 20.0,
- timeout_sec=self.progress_timeout_sec,
- err_msg="%s : Message copier didn't make enough progress in %ds. Current progress: %s" \
- % (copier.transactional_id, self.progress_timeout_sec, str(copier.progress_percent())))
- self.logger.info("%s - progress: %s" % (copier.transactional_id,
- str(copier.progress_percent())))
- copier.restart(clean_shutdown)
-
- def create_and_start_copiers(self, input_topic, output_topic, num_copiers, use_group_metadata):
- copiers = []
- for i in range(0, num_copiers):
- copiers.append(self.create_and_start_message_copier(
- input_topic=input_topic,
- output_topic=output_topic,
- input_partition=i,
- transactional_id="copier-" + str(i),
- use_group_metadata=use_group_metadata
- ))
- return copiers
-
def start_consumer(self, topic_to_read, group_id):
consumer = ConsoleConsumer(context=self.test_context,
num_nodes=1,
@@ -186,33 +111,60 @@ class TransactionsTest(Test):
consumer.stop()
return consumer.messages_consumed[1]
- def copy_messages_transactionally(self, failure_mode, bounce_target,
- input_topic, output_topic,
- num_copiers, num_messages_to_copy,
- use_group_metadata):
+ def wait_until_rejoin(self):
+ for partition in range(0, self.num_input_partitions):
+ wait_until(lambda: len(self.kafka.isr_idx_list(self.input_topic, partition)) == self.replication_factor, timeout_sec=60,
+ backoff_sec=1, err_msg="Replicas did not rejoin the ISR in a reasonable amount of time")
+
+ for partition in range(0, self.num_output_partitions):
+ wait_until(lambda: len(self.kafka.isr_idx_list(self.output_topic, partition)) == self.replication_factor, timeout_sec=60,
+ backoff_sec=1, err_msg="Replicas did not rejoin the ISR in a reasonable amount of time")
+
+ def perform_upgrade(self, from_kafka_version):
+ self.logger.info("Performing rolling upgrade.")
+ for node in self.kafka.controller_quorum.nodes:
+ self.logger.info("Stopping controller node %s" % node.account.hostname)
+ self.kafka.controller_quorum.stop_node(node)
+ node.version = DEV_BRANCH
+ self.logger.info("Restarting controller node %s" % node.account.hostname)
+ self.kafka.controller_quorum.start_node(node)
+ self.wait_until_rejoin()
+ self.logger.info("Successfully restarted controller node %s" % node.account.hostname)
+ for node in self.kafka.nodes:
+ self.logger.info("Stopping broker node %s" % node.account.hostname)
+ self.kafka.stop_node(node)
+ node.version = DEV_BRANCH
+ self.logger.info("Restarting broker node %s" % node.account.hostname)
+ self.kafka.start_node(node)
+ self.wait_until_rejoin()
+ self.logger.info("Successfully restarted broker node %s" % node.account.hostname)
+ self.logger.info("Changing metadata.version to %s" % LATEST_STABLE_METADATA_VERSION)
+ self.kafka.upgrade_metadata_version(LATEST_STABLE_METADATA_VERSION)
+
+ def copy_messages_transactionally_during_upgrade(self, input_topic, output_topic,
+ num_copiers, num_messages_to_copy,
+ use_group_metadata, from_kafka_version):
"""Copies messages transactionally from the seeded input topic to the
- output topic, either bouncing brokers or clients in a hard and soft
- way as it goes.
+ output topic while an rolling upgrade occurs.
This method also consumes messages in read_committed mode from the
- output topic while the bounces and copy is going on.
+ output topic.
It returns the concurrently consumed messages.
"""
- copiers = self.create_and_start_copiers(input_topic=input_topic,
- output_topic=output_topic,
- num_copiers=num_copiers,
- use_group_metadata=use_group_metadata)
+ self.perform_upgrade(from_kafka_version)
+
+ copiers = create_and_start_copiers(test_context=self.test_context,
+ kafka=self.kafka,
+ consumer_group=self.consumer_group,
+ input_topic=input_topic,
+ output_topic=output_topic,
+ transaction_size=self.transaction_size,
+ transaction_timeout=self.transaction_timeout,
+ num_copiers=num_copiers,
+ use_group_metadata=use_group_metadata)
concurrent_consumer = self.start_consumer(output_topic,
group_id="concurrent_consumer")
- clean_shutdown = False
- if failure_mode == "clean_bounce":
- clean_shutdown = True
-
- if bounce_target == "brokers":
- self.bounce_brokers(clean_shutdown)
- elif bounce_target == "clients":
- self.bounce_copiers(copiers, clean_shutdown)
copier_timeout_sec = 120
for copier in copiers:
@@ -228,62 +180,48 @@ class TransactionsTest(Test):
self.kafka.topics = {
self.input_topic: {
"partitions": self.num_input_partitions,
- "replication-factor": 3,
+ "replication-factor": self.replication_factor,
"configs": {
"min.insync.replicas": 2
}
},
self.output_topic: {
"partitions": self.num_output_partitions,
- "replication-factor": 3,
+ "replication-factor": self.replication_factor,
"configs": {
"min.insync.replicas": 2
}
}
}
- @cluster(num_nodes=9)
+ @cluster(num_nodes=10)
@matrix(
- failure_mode=["hard_bounce", "clean_bounce"],
- bounce_target=["brokers", "clients"],
- check_order=[True, False],
- use_group_metadata=[True, False],
- metadata_quorum=[quorum.zk],
- use_new_coordinator=[False]
+ from_kafka_version=[str(LATEST_3_6), str(LATEST_3_5), str(LATEST_3_4), str(LATEST_3_3), str(LATEST_3_2), str(LATEST_3_1)],
+ metadata_quorum=[isolated_kraft],
+ use_new_coordinator=[False],
)
- @matrix(
- failure_mode=["hard_bounce", "clean_bounce"],
- bounce_target=["brokers", "clients"],
- check_order=[True, False],
- use_group_metadata=[True, False],
- metadata_quorum=quorum.all_kraft,
- use_new_coordinator=[False]
- )
- def test_transactions(self, failure_mode, bounce_target, check_order, use_group_metadata, metadata_quorum=quorum.zk, use_new_coordinator=False):
+ def test_transactions_upgrade(self, from_kafka_version, metadata_quorum=quorum.isolated_kraft, use_new_coordinator=False):
+ fromKafkaVersion = KafkaVersion(from_kafka_version)
+ self.kafka = KafkaService(self.test_context,
+ num_nodes=self.num_brokers,
+ zk=None,
+ version=fromKafkaVersion,
+ controller_num_nodes_override=1)
+
security_protocol = 'PLAINTEXT'
self.kafka.security_protocol = security_protocol
self.kafka.interbroker_security_protocol = security_protocol
self.kafka.logs["kafka_data_1"]["collect_default"] = True
self.kafka.logs["kafka_data_2"]["collect_default"] = True
self.kafka.logs["kafka_operational_logs_debug"]["collect_default"] = True
- if check_order:
- # To check ordering, we simply create input and output topics
- # with a single partition.
- # We reduce the number of seed messages to copy to account for the fewer output
- # partitions, and thus lower parallelism. This helps keep the test
- # time shorter.
- self.num_seed_messages = self.num_seed_messages // 3
- self.num_input_partitions = 1
- self.num_output_partitions = 1
self.setup_topics()
self.kafka.start()
input_messages = self.seed_messages(self.input_topic, self.num_seed_messages)
- concurrently_consumed_messages = self.copy_messages_transactionally(
- failure_mode, bounce_target, input_topic=self.input_topic,
- output_topic=self.output_topic, num_copiers=self.num_input_partitions,
- num_messages_to_copy=self.num_seed_messages, use_group_metadata=use_group_metadata)
+ concurrently_consumed_messages = self.copy_messages_transactionally_during_upgrade(
+ input_topic=self.input_topic, output_topic=self.output_topic, num_copiers=self.num_input_partitions,
+ num_messages_to_copy=self.num_seed_messages, use_group_metadata=True, from_kafka_version=from_kafka_version)
output_messages = self.get_messages_from_topic(self.output_topic, self.num_seed_messages)
concurrently_consumed_message_set = set(concurrently_consumed_messages)
@@ -301,7 +239,3 @@ class TransactionsTest(Test):
assert input_message_set == concurrently_consumed_message_set, \
"Input and concurrently consumed output message sets are not equal. Num input messages: %d. Num concurrently_consumed_messages: %d" %\
(len(input_message_set), len(concurrently_consumed_message_set))
- if check_order:
- assert input_messages == sorted(input_messages), "The seed messages themselves were not in order"
- assert output_messages == input_messages, "Output messages are not in order"
- assert concurrently_consumed_messages == output_messages, "Concurrently consumed messages are not in order"
diff --git a/tests/kafkatest/utils/transactions_utils.py b/tests/kafkatest/utils/transactions_utils.py
new file mode 100644
index 00000000000..f84c49e2b0a
--- /dev/null
+++ b/tests/kafkatest/utils/transactions_utils.py
@@ -0,0 +1,55 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from kafkatest.services.transactional_message_copier import TransactionalMessageCopier
+
+from ducktape.utils.util import wait_until
+
+def create_and_start_message_copier(test_context, kafka, consumer_group, input_topic, input_partition,
+ output_topic, transaction_size, transaction_timeout, transactional_id, use_group_metadata):
+ message_copier = TransactionalMessageCopier(
+ context=test_context,
+ num_nodes=1,
+ kafka=kafka,
+ transactional_id=transactional_id,
+ consumer_group=consumer_group,
+ input_topic=input_topic,
+ input_partition=input_partition,
+ output_topic=output_topic,
+ max_messages=-1,
+ transaction_size=transaction_size,
+ transaction_timeout=transaction_timeout,
+ use_group_metadata=use_group_metadata
+ )
+ message_copier.start()
+ wait_until(lambda: message_copier.alive(message_copier.nodes[0]),
+ timeout_sec=10,
+ err_msg="Message copier failed to start after 10 s")
+ return message_copier
+
+def create_and_start_copiers(test_context, kafka, consumer_group, input_topic, output_topic, transaction_size,
+ transaction_timeout, num_copiers, use_group_metadata):
+ copiers = []
+ for i in range(0, num_copiers):
+ copiers.append(create_and_start_message_copier(
+ test_context=test_context,
+ kafka=kafka,
+ consumer_group=consumer_group,
+ input_topic=input_topic,
+ output_topic=output_topic,
+ input_partition=i,
+ transaction_size=transaction_size,
+ transaction_timeout=transaction_timeout,
+ transactional_id="copier-" + str(i),
+ use_group_metadata=use_group_metadata
+ ))
+ return copiers