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

KAFKA-15429: reset transactionInFlight on StreamsProducer close #14326

Merged
merged 2 commits into from Sep 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -192,12 +192,11 @@ public void resetProducer() {

oldProducerTotalBlockedTime += totalBlockedTime(producer);
final long start = time.nanoseconds();
producer.close();
close();
final long closeTime = time.nanoseconds() - start;
oldProducerTotalBlockedTime += closeTime;

producer = clientSupplier.getProducer(eosV2ProducerConfigs);
transactionInitialized = false;
}

private double getMetricValue(final Map<MetricName, ? extends Metric> metrics,
Expand Down Expand Up @@ -371,6 +370,8 @@ void flush() {

void close() {
producer.close();
transactionInFlight = false;
ableegoldman marked this conversation as resolved.
Show resolved Hide resolved
transactionInitialized = false;
}

// for testing only
Expand Down
Expand Up @@ -207,6 +207,34 @@ public void before() {

// functional tests

@Test
public void shouldResetTransactionInFlightOnClose() {
// given:
eosBetaStreamsProducer.send(
new ProducerRecord<>("topic", new byte[1]), (metadata, error) -> { });
assertThat(eosBetaStreamsProducer.transactionInFlight(), is(true));

// when:
eosBetaStreamsProducer.close();

// then:
assertThat(eosBetaStreamsProducer.transactionInFlight(), is(false));
}

@Test
public void shouldResetTransactionInFlightOnReset() {
// given:
eosBetaStreamsProducer.send(
new ProducerRecord<>("topic", new byte[1]), (metadata, error) -> { });
assertThat(eosBetaStreamsProducer.transactionInFlight(), is(true));

// when:
eosBetaStreamsProducer.resetProducer();

// then:
assertThat(eosBetaStreamsProducer.transactionInFlight(), is(false));
}

@Test
public void shouldCreateProducer() {
assertThat(mockClientSupplier.producers.size(), is(1));
Expand Down