-
Notifications
You must be signed in to change notification settings - Fork 6
refactor(inkless): add artificial latency to metadata update #337
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.apache.kafka.common.message.DescribeTopicPartitionsResponseData; | ||
import org.apache.kafka.common.message.MetadataResponseData; | ||
import org.apache.kafka.common.network.ListenerName; | ||
import org.apache.kafka.common.utils.Time; | ||
import org.apache.kafka.metadata.LeaderAndIsr; | ||
|
||
import java.util.Collections; | ||
|
@@ -33,11 +34,13 @@ | |
import io.aiven.inkless.control_plane.MetadataView; | ||
|
||
public class InklessTopicMetadataTransformer { | ||
private final Time time; | ||
private final MetadataView metadataView; | ||
|
||
private final AtomicInteger roundRobinCounter = new AtomicInteger(); | ||
|
||
public InklessTopicMetadataTransformer(final MetadataView metadataView) { | ||
public InklessTopicMetadataTransformer(final Time time, final MetadataView metadataView) { | ||
this.time = Objects.requireNonNull(time, "time cannot be null"); | ||
this.metadataView = Objects.requireNonNull(metadataView, "metadataView cannot be null"); | ||
} | ||
|
||
|
@@ -52,10 +55,12 @@ public void transformClusterMetadata( | |
Objects.requireNonNull(topicMetadata, "topicMetadata cannot be null"); | ||
|
||
final int leaderForInklessPartitions = selectLeaderForInklessPartitions(listenerName, clientId); | ||
boolean hasInklessTopics = false; | ||
for (final var topic : topicMetadata) { | ||
if (!metadataView.isInklessTopic(topic.name())) { | ||
continue; | ||
} | ||
hasInklessTopics = true; | ||
for (final var partition : topic.partitions()) { | ||
partition.setLeaderId(leaderForInklessPartitions); | ||
final List<Integer> list = List.of(leaderForInklessPartitions); | ||
|
@@ -65,6 +70,11 @@ public void transformClusterMetadata( | |
partition.setLeaderEpoch(LeaderAndIsr.INITIAL_LEADER_EPOCH); | ||
} | ||
} | ||
if (hasInklessTopics) { | ||
// Introduce artificial latency to avoid a race condition between the metadata update and the producer | ||
// causing OutOfOrderSequenceException. | ||
time.sleep(500); | ||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it's a good idea for several reasons:
I think the problem is theoretically possible on classic Kafka, too, it's juts unlikely because of more leadership stability + the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
From what I found, metadata updates are not async (e.g. https://github.com/apache/kafka/blob/3c1f965c60789dcc8ee14ebabcbb4e16ebffc5ee/clients/src/main/java/org/apache/kafka/clients/NetworkClient.java#L642) hence 500ms (choose arbitrarily but aiming to cope with a rotation on the broker side, default 250ms) would give room to avoid the race condition; though I'd agree any other implementation could potentially handle this update asynchronously and this solution may not be enough.
I don't think it is with partition leaders. The producer state is cached on the leader and if leadership changes, it starts accepting requests after updating the state.
OutOfOrderSequence errors are retried: https://github.com/apache/kafka/blob/6f783f85362071f82da3dcef706c7e6b89b86c2a/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L829-L834 |
||
} | ||
} | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.