-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[HUDI-8378] Fix Avro schema deserializer failing with schema evolution #12111
base: master
Are you sure you want to change the base?
Conversation
} | ||
props.put(KAFKA_VALUE_DESERIALIZER_SCHEMA.key(), schemaProvider.getSourceSchema().toString()); | ||
// assign consumer group id based on the schema, since if there's a change in the schema we ensure KafkaRDDIterator doesn't use cached Kafka Consumer | ||
String groupId = props.getString(NATIVE_KAFKA_CONSUMER_GROUP_ID, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting up the group id, why not just fetch the latest schema and set up it again if the schema evolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The KafkaRDD class from the Kafka client package is caching the KafkaConsumer for a given group id and partition. As a result, we are using KafkaAvroSchemaDeserializer with the previous schema to deserialize the records. This leads to issues during schema evolution.
This changes makes sure that new KafkaConsumer is created when there's a schema change present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Kafka client itself has an option to control the cache TTL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, while creating the Kafka RDD, it's always hardcoded to true
https://github.com/apache/spark/blob/876450c4130062a80f4ecb7b7afd232b5481a99f/connector/kafka-0-10/src/main/scala/org/apache/spark/streaming/kafka010/KafkaUtils.scala#L70
Since useConsumerCache is set to true. We always get the existing consumer with outdated schema
https://github.com/apache/spark/blob/876450c4130062a80f4ecb7b7afd232b5481a99f/connector/kafka-0-10/src/main/scala/org/apache/spark/streaming/kafka010/KafkaDataConsumer.scala#L337
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we copy this utility into hudi and override the flag as false then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we override the flag to false, we might end up creating new KafkaConsumer every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create based on the schema change then? The delta-streamer is a micro-batch for each run, maybe we can add some smart strategy here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change will do exactly the same. Caching the KafkaConsumer happens as part of the RDD creation, I'm not sure we can extract that functionality of the kafka utils libr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caching the KafkaConsumer happens as part of the RDD creation
Does it make sense if we hard code the cache as false first then create/reuse the consumer based on the schema change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't control how the KafkaConsumer is created, It's done during the RDD creation. I don't think we can control that.
71c4609
to
5680f4c
Compare
Change Logs
Add consumer group id to kafka params based on the schema hash when KafkaAvroSchemaDeserializer is used to avoid kafka connector caching the KafkaConsumer causing issues with schema evolution.
Impact
Kafka connector will create a new Kafka consumer whenever there's a change in the schema instead of using cached kafka consumer.
Risk level (write none, low medium or high below)
NA
Documentation Update
Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".
ticket number here and follow the instruction to make
changes to the website.
Contributor's checklist