Repository navigation
Stop re-parsing topic URIs when a validated TopicUri already exists - #151
Open
vahidhashemian wants to merge 2 commits into
Open
vahidhashemian wants to merge 2 commits into
vahidhashemian wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The PSC client was parsing a topic URI every time it built a
TopicUriPartitionon the producer send path and the consumer record path, then immediately discarding that parse and attaching aTopicUriit already had.TopicUriPartitionnow has a constructor that keeps the caller's URI string and an already validatedTopicUriwithout running the URI and topic-RN regular expressions again. Call sites that already hold a validatedTopicUriuse that constructor, or the existingTopicUriPartition(TopicUri, int)constructor when the string is already the canonical form fromgetTopicUriAsString().This is limited to the
pscclient. The Flink connector is unchanged. The publicTopicUriPartition(String)andTopicUriPartition(String, int)constructors still parse, so callers that only have a URI string behave as before.PscProducer.validateTopicUriandPscConsumer.validateTopicUriare still the cached entry points for a new string.Producer
PscProducer.sendstill validates the message URI through the cache. The partition it attaches now keeps the exact string the caller passed, including a URI with no protocol, and the validated backendTopicUriinstance. A later send of the same string reuses that instance.PscKafkaProduceruses the same approach when it builds theKafkaMessageIdafter an ack, both in the completion callback and inFuture.get(), and whengetPartitionsreturns one partition per Kafka partition. Those message ids still carry the canonical URI string, the registeredKafkaTopicUri, and the partition Kafka assigned.Consumer
Each Kafka record and each Memq record now builds its partition from the
TopicUrialready registered for that backend topic. The resulting message id still has the same URI string, partition, offset, timestamp, serialized sizes, and, for Memq, the end-of-batch flag. The same construction is used for the partition set on a poll, Kafka rebalance callbacks, Kafka and Memqassignment(), Kafka and MemqgetPartitions(), KafkacommitSync(), and the Kafka and Memq commit callbacks, including Kafka auto-resolution both enabled and disabled.PscKafkaConsumer.committed(Collection)no longer builds a partition fromTopicPartition.topic(). That value is the Kafka topic name, so parsing it failed and the returned message id had a null topic URI. It now returns theTopicUriPartitionthe caller passed in, which is whatstartOffsetsandendOffsetsalready do.assign()still returns the partitions the caller supplied when the consumer is not subscribed.Kafka
commitSync()previously returned a message id whose topic URI was a freshly parsedBaseTopicUriand was not replaced with the registeredKafkaTopicUri. It now carries that registeredKafkaTopicUri. Equality, hash code, and ordering against a partition finalized with the same URI still match, because those are based on the URI components rather than the concrete class.Tests
The new tests compare every changed construction with the previous pattern of parsing the string and then finalizing the partition. They cover plaintext and secure Kafka and Memq URIs, the unset partition and partitions
0,1, andInteger.MAX_VALUE, equality, hash code, ordering, map and set lookup, message ids, and Java serialization. A non-canonical caller string stays distinct from the canonical partition and is preserved. The string constructors still parse a valid URI and still leave the topic URI unset when the string is invalid. Producer send, Kafka and Memq record conversion, Kafka assignment, rebalance,getPartitions,committed, and both commit-callback modes, and Memq assignment and commit, are all checked against that previous finalized result.